]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
added BX_WAL_SUPPORT to extensions list and documented it (.wal texture support has...
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 93ddfadaf729da136fc77971f65d65a44cfdb56c..7ef45f1dedabeaeaae1063530e5830693afcf385 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -23,6 +23,8 @@
 #include "quakedef.h"
 #include "cl_video.h"
 
+cvar_t con_closeontoggleconsole = {CVAR_SAVE, "con_closeontoggleconsole","0", "allows toggleconsole binds to close the console as well"};
+
 /*
 key up events are sent even if in console mode
 */
@@ -280,7 +282,7 @@ Key_Console (int key, char ascii)
                        if (i > 0)
                        {
                                cbd[i]=0;
-                               strcat(key_lines[edit_line], cbd);
+                               strlcat(key_lines[edit_line], cbd, sizeof(key_lines[edit_line]));
                                key_linepos += i;
                        }
                        Z_Free(cbd);
@@ -302,6 +304,8 @@ Key_Console (int key, char ascii)
                Cbuf_AddText (key_lines[edit_line]+1);  // skip the ]
                Cbuf_AddText ("\n");
                Con_Printf("%s\n",key_lines[edit_line]);
+               if(key_lines[edit_line][1] == 0) // empty line (just a ])?
+                       return; // no, no, you can't submit empty lines to the history...
                // LordHavoc: redesigned edit_line/history_line
                edit_line = 31;
                history_line = edit_line;
@@ -358,7 +362,7 @@ Key_Console (int key, char ascii)
        {
                if (key_linepos > 1)
                {
-                       strcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos);
+                       strlcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos, sizeof(key_lines[edit_line]) + 1 - key_linepos);
                        key_linepos--;
                }
                return;
@@ -367,8 +371,10 @@ Key_Console (int key, char ascii)
        // delete char on cursor
        if (key == K_DEL || key == K_KP_DEL)
        {
-               if (key_linepos < (int)strlen(key_lines[edit_line]))
-                       strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1);
+               size_t linelen;
+               linelen = strlen(key_lines[edit_line]);
+               if (key_linepos < (int)linelen)
+                       memmove(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1, linelen - key_linepos);
                return;
        }
 
@@ -410,9 +416,11 @@ Key_Console (int key, char ascii)
        {
                if (history_line > 0 && key_lines[history_line-1][1])
                {
+                       size_t linelen;
                        history_line--;
-                       strcpy(key_lines[edit_line], key_lines[history_line]);
-                       key_linepos = (int)strlen(key_lines[edit_line]);
+                       linelen = strlen(key_lines[history_line]);
+                       memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
+                       key_linepos = (int)linelen;
                }
                return;
        }
@@ -429,8 +437,10 @@ Key_Console (int key, char ascii)
                }
                else
                {
-                       strcpy(key_lines[edit_line], key_lines[history_line]);
-                       key_linepos = (int)strlen(key_lines[edit_line]);
+                       size_t linelen;
+                       linelen = strlen(key_lines[history_line]);
+                       memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
+                       key_linepos = (int)linelen;
                }
                return;
        }
@@ -607,7 +617,7 @@ Key_SetBinding (int keynum, int bindmap, const char *binding)
 // allocate memory for new binding
        l = strlen (binding);
        newbinding = (char *)Z_Malloc (l + 1);
-       strcpy (newbinding, binding);
+       memcpy (newbinding, binding, l + 1);
        newbinding[l] = 0;
        keybindings[bindmap][keynum] = newbinding;
 }
@@ -818,6 +828,8 @@ Key_Init (void)
        Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
        Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
        Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
+
+       Cvar_RegisterVariable (&con_closeontoggleconsole);
 }
 
 const char *Key_GetBind (int key)
@@ -951,13 +963,13 @@ Key_Event (int key, char ascii, qboolean down)
                return;
        }
 
-#if 1
+#if 0
        // ignore binds (other than the above escape/F1-F12 keys) while in console
        if (key_consoleactive && down)
 #else
        // respond to toggleconsole binds while in console unless the pressed key
        // happens to be the color prefix character (such as on German keyboards)
-       if (key_consoleactive && down && (strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG))
+       if (key_consoleactive && down && (!con_closeontoggleconsole.integer || !bind || strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG))
 #endif
        {
                Key_Console (key, ascii);