From 3041eee0cf1e09350da5e000bebe3d306c56d3d1 Mon Sep 17 00:00:00 2001 From: Ensiform Date: Fri, 15 Feb 2013 22:49:08 -0600 Subject: [PATCH] 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) --- code/client/cl_console.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/code/client/cl_console.c b/code/client/cl_console.c index 29b98942..bc34e151 100644 --- a/code/client/cl_console.c +++ b/code/client/cl_console.c @@ -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 ); }