]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
removed trailing comments on cvar declarations and Cmd_AddCommand calls
[xonotic/darkplaces.git] / console.c
index 3d613a813ba8fb86be5142aa41da92669924791c..d279594c3d7f243b22adfbf7095814128382661e 100644 (file)
--- a/console.c
+++ b/console.c
@@ -43,7 +43,7 @@ char con_text[CON_TEXTSIZE];
 
 cvar_t con_notifytime = {CVAR_SAVE, "con_notifytime","3", "how long notify lines last, in seconds"};
 cvar_t con_notify = {CVAR_SAVE, "con_notify","4", "how many notify lines to show (0-32)"};
-cvar_t con_textsize = {CVAR_SAVE, "con_textsize","8", "console text size in virtual 2D pixels"};       //[515]: console text size in pixels
+cvar_t con_textsize = {CVAR_SAVE, "con_textsize","8", "console text size in virtual 2D pixels"};
 
 
 cvar_t sys_specialcharactertranslation = {0, "sys_specialcharactertranslation", "1", "terminal console conchars to ASCII translation (set to 0 if your conchars.tga is for an 8bit character set or if you want raw output)"};
@@ -391,6 +391,47 @@ static void Con_Maps_f (void)
                GetMapList("", NULL, 0);
 }
 
+void Con_ConDump_f (void)
+{
+       int i, l;
+       qboolean allblankssofar;
+       const char *text;
+       qfile_t *file;
+       char temp[MAX_INPUTLINE+2];
+       if (Cmd_Argc() != 2)
+       {
+               Con_Printf("usage: condump <filename>\n");
+               return;
+       }
+       file = FS_Open(Cmd_Argv(1), "wb", false, false);
+       if (!file)
+       {
+               Con_Printf("condump: unable to write file \"%s\"\n", Cmd_Argv(1));
+               return;
+       }
+       // iterate over the entire console history buffer line by line
+       allblankssofar = true;
+       for (i = 0;i < con_totallines;i++)
+       {
+               text = con_text + ((con_current + 1 + i) % con_totallines)*con_linewidth;
+               // count the used characters on this line
+               for (l = min(con_linewidth, (int)sizeof(temp));l > 0 && text[l-1] == ' ';l--);
+               // if not a blank line, begin output
+               if (l)
+                       allblankssofar = false;
+               // output the current line to the file
+               if (!allblankssofar)
+               {
+                       if (l)
+                               memcpy(temp, text, l);
+                       temp[l] = '\n';
+                       temp[l+1] = 0;
+                       FS_Print(file, temp);
+               }
+       }
+       FS_Close(file);
+}
+
 /*
 ================
 Con_Init
@@ -427,7 +468,8 @@ void Con_Init (void)
        Cmd_AddCommand ("messagemode", Con_MessageMode_f, "input a chat message to say to everyone");
        Cmd_AddCommand ("messagemode2", Con_MessageMode2_f, "input a chat message to say to only your team");
        Cmd_AddCommand ("clear", Con_Clear_f, "clear console history");
-       Cmd_AddCommand ("maps", Con_Maps_f, "list information about available maps");   // By [515]
+       Cmd_AddCommand ("maps", Con_Maps_f, "list information about available maps");
+       Cmd_AddCommand ("condump", Con_ConDump_f, "output console history to a file (see also log_file)");
 
        con_initialized = true;
        Con_Print("Console initialized.\n");
@@ -639,12 +681,12 @@ void Con_Print(const char *msg)
                                        {
                                                switch(*in)
                                                {
-                                                       case '^':
+                                                       case STRING_COLOR_TAG:
                                                                switch(in[1])
                                                                {
-                                                                       case '^':
+                                                                       case STRING_COLOR_TAG:
                                                                                ++in;
-                                                                               *out++ = '^';
+                                                                               *out++ = STRING_COLOR_TAG;
                                                                                break;
                                                                        case '0':
                                                                        case '7':
@@ -698,7 +740,7 @@ void Con_Print(const char *msg)
                                                                                *out++ = 0x1B; *out++ = '['; *out++ = '0'; *out++ = ';'; *out++ = '1'; *out++ = 'm';
                                                                                break;
                                                                        default:
-                                                                               *out++ = '^';
+                                                                               *out++ = STRING_COLOR_TAG;
                                                                                break;
                                                                }
                                                                break;
@@ -737,12 +779,12 @@ void Con_Print(const char *msg)
                                        {
                                                switch(*in)
                                                {
-                                                       case '^':
+                                                       case STRING_COLOR_TAG:
                                                                switch(in[1])
                                                                {
-                                                                       case '^':
+                                                                       case STRING_COLOR_TAG:
                                                                                ++in;
-                                                                               *out++ = '^';
+                                                                               *out++ = STRING_COLOR_TAG;
                                                                                break;
                                                                        case '0':
                                                                        case '1':
@@ -757,7 +799,7 @@ void Con_Print(const char *msg)
                                                                                ++in;
                                                                                break;
                                                                        default:
-                                                                               *out++ = '^';
+                                                                               *out++ = STRING_COLOR_TAG;
                                                                                break;
                                                                }
                                                                break;
@@ -938,7 +980,7 @@ void Con_DrawNotify (void)
                        // count up to the last non-whitespace, and ignore color codes
                        for (j = 0;j < con_linewidth && text[j];j++)
                        {
-                               if (text[j] == '^' && (text[j+1] >= '0' && text[j+1] <= '9'))
+                               if (text[j] == STRING_COLOR_TAG && (text[j+1] >= '0' && text[j+1] <= '9'))
                                {
                                        j++;
                                        continue;