]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
Remove code duplication in messagemodes and commandmode
[xonotic/darkplaces.git] / console.c
index 75809f49eb1d8504606816b540b1080a18b628ba..58409bef3164a3b9e012ea42b43a04ae8b5ae51d 100644 (file)
--- a/console.c
+++ b/console.c
@@ -1,5 +1,6 @@
 /*
 Copyright (C) 1996-1997 Id Software, Inc.
+Copyright (C) 2000-2020 DarkPlaces contributors
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -523,14 +524,16 @@ Log_Close
 */
 void Log_Close (void)
 {
-       if (logfile == NULL)
-               return;
+       qfile_t* l = logfile;
 
-       FS_Print (logfile, Log_Timestamp ("Log stopped"));
-       FS_Print (logfile, "\n");
-       FS_Close (logfile);
+       if (l == NULL)
+               return;
 
+       FS_Print (l, Log_Timestamp ("Log stopped"));
+       FS_Print (l, "\n");
        logfile = NULL;
+       FS_Close (l);
+
        crt_log_file[0] = '\0';
 }
 
@@ -708,16 +711,12 @@ void Con_ClearNotify (void)
                        CON_LINES(i).mask |= CON_MASK_HIDENOTIFY;
 }
 
-
-/*
-================
-Con_MessageMode_f
-================
-*/
-static void Con_MessageMode_f(cmd_state_t *cmd)
+static void Con_MsgCmdMode(cmd_state_t *cmd, signed char mode)
 {
+       if (cls.demoplayback && mode >= 0)
+               return;
        key_dest = key_message;
-       chat_mode = 0; // "say"
+       chat_mode = mode;
        if(Cmd_Argc(cmd) > 1)
        {
                dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
@@ -725,21 +724,28 @@ static void Con_MessageMode_f(cmd_state_t *cmd)
        }
 }
 
+/*
+================
+Con_MessageMode_f
+
+"say"
+================
+*/
+static void Con_MessageMode_f(cmd_state_t *cmd)
+{
+       Con_MsgCmdMode(cmd, 0);
+}
 
 /*
 ================
 Con_MessageMode2_f
+
+"say_team"
 ================
 */
 static void Con_MessageMode2_f(cmd_state_t *cmd)
 {
-       key_dest = key_message;
-       chat_mode = 1; // "say_team"
-       if(Cmd_Argc(cmd) > 1)
-       {
-               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
-               chat_bufferpos = (unsigned int)strlen(chat_buffer);
-       }
+       Con_MsgCmdMode(cmd, 1);
 }
 
 /*
@@ -749,13 +755,7 @@ Con_CommandMode_f
 */
 static void Con_CommandMode_f(cmd_state_t *cmd)
 {
-       key_dest = key_message;
-       if(Cmd_Argc(cmd) > 1)
-       {
-               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
-               chat_bufferpos = (unsigned int)strlen(chat_buffer);
-       }
-       chat_mode = -1; // command
+       Con_MsgCmdMode(cmd, -1);
 }
 
 /*
@@ -930,9 +930,7 @@ void Con_Init (void)
        Cmd_AddCommand(CF_SHARED, "condump", Con_ConDump_f, "output console history to a file (see also log_file)");
 
        con_initialized = true;
-       // initialize console window (only used by sys_win.c)
-       Sys_InitConsole();
-       
+
        Con_Print("Console initialized.\n");
 }
 
@@ -941,7 +939,8 @@ void Con_Shutdown (void)
        if (con_mutex) Thread_LockMutex(con_mutex);
        ConBuffer_Shutdown(&con);
        if (con_mutex) Thread_UnlockMutex(con_mutex);
-       if (con_mutex) Thread_DestroyMutex(con_mutex);con_mutex = NULL;
+       if (con_mutex) Thread_DestroyMutex(con_mutex);
+       con_mutex = NULL;
 }
 
 /*
@@ -1360,11 +1359,11 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                                *out++ = 'm';
                                        }
                                        *out++ = 0;
-                                       Sys_PrintToTerminal(printline);
+                                       Sys_Print(printline);
                                }
                                else if(sys_colortranslation.integer == 2) // Quake
                                {
-                                       Sys_PrintToTerminal(line);
+                                       Sys_Print(line);
                                }
                                else // strip
                                {
@@ -1415,7 +1414,7 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                                }
                                        }
                                        *out++ = 0;
-                                       Sys_PrintToTerminal(printline);
+                                       Sys_Print(printline);
                                }
                        }
                        // empty the line buffer
@@ -1666,7 +1665,7 @@ static float Con_WordWidthFunc(void *passthrough, const char *w, size_t *length,
                return DrawQ_TextWidth(w, *length, ti->fontsize, ti->fontsize, false, ti->font);
        else
        {
-               Sys_PrintfToTerminal("Con_WordWidthFunc: can't get here (maxWidth should never be %f)\n", maxWidth);
+               Sys_Printf("Con_WordWidthFunc: can't get here (maxWidth should never be %f)\n", maxWidth);
                // Note: this is NOT a Con_Printf, as it could print recursively
                return 0;
        }