diff options
author | Ensiform <ensiform@gmail.com> | 2013-02-15 22:49:08 -0600 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-02-16 21:58:26 +0000 |
commit | 2994a958ec86b8be16cb387cdc369cf6205e940f (patch) | |
tree | 145cc91693cc10c24c76dff1aa95c1237d38960f | |
parent | 918b1e975c86fa8ddcd678ade1ded59b7a0f2288 (diff) |
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)
-rw-r--r-- | src/client/cl_console.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/client/cl_console.c b/src/client/cl_console.c index 22568b39..a1c7258c 100644 --- a/src/client/cl_console.c +++ b/src/client/cl_console.c @@ -114,7 +114,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) { @@ -122,12 +124,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; } @@ -142,8 +147,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; @@ -156,10 +169,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 ); } |