condump improvements

Default output file extension to ".txt"
Show output filename in error message.
Use Windows line endings on Windows.
Dynamically allocate line buffer. (by ZTM)
This commit is contained in:
Ensiform 2013-02-15 22:49:08 -06:00 committed by Zack Middleton
parent e5f7e1de52
commit 3041eee0cf
1 changed files with 24 additions and 6 deletions

View File

@ -178,7 +178,9 @@ void Con_Dump_f (void)
int l, x, i;
short *line;
fileHandle_t f;
char buffer[1024];
int bufferlen;
char *buffer;
char filename[MAX_QPATH];
if (Cmd_Argc() != 2)
{
@ -186,12 +188,15 @@ void Con_Dump_f (void)
return;
}
Com_Printf ("Dumped console text to %s.\n", Cmd_Argv(1) );
Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".txt" );
f = FS_FOpenFileWrite( Cmd_Argv( 1 ) );
Com_Printf ("Dumped console text to %s.\n", filename );
f = FS_FOpenFileWrite( filename );
if (!f)
{
Com_Printf ("ERROR: couldn't open.\n");
Com_Printf ("ERROR: couldn't open %s.\n", filename);
return;
}
@ -206,8 +211,16 @@ void Con_Dump_f (void)
break;
}
#ifdef _WIN32
bufferlen = con.linewidth + 3 * sizeof ( char );
#else
bufferlen = con.linewidth + 2 * sizeof ( char );
#endif
buffer = Hunk_AllocateTempMemory( bufferlen );
// write the remaining lines
buffer[con.linewidth] = 0;
buffer[bufferlen-1] = 0;
for ( ; l <= con.current ; l++)
{
line = con.text + (l%con.totallines)*con.linewidth;
@ -220,10 +233,15 @@ void Con_Dump_f (void)
else
break;
}
strcat( buffer, "\n" );
#ifdef _WIN32
Q_strcat(buffer, bufferlen, "\r\n");
#else
Q_strcat(buffer, bufferlen, "\n");
#endif
FS_Write(buffer, strlen(buffer), f);
}
Hunk_FreeTempMemory( buffer );
FS_FCloseFile( f );
}