X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=keys.c;h=9ff4853311313e4104819f30b990c603370b3f18;hb=0b02091d9a19d2a37744309eea401cf7663742a2;hp=cef9dc91d2e21286aed5e1d02702230b34fb9e74;hpb=775c0f6d056c37d2e23f9a96ec827023fe5e3404;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index cef9dc91..9ff48533 100644 --- a/keys.c +++ b/keys.c @@ -694,7 +694,7 @@ Interactive line editing and console scrollback ==================== */ -int chat_mode; // 0 for say, 1 for say_team, -1 for command +signed char chat_mode; // 0 for say, 1 for say_team, -1 for command char chat_buffer[MAX_INPUTLINE]; int chat_bufferpos = 0; @@ -1351,6 +1351,7 @@ the K_* names are matched up. int Key_StringToKeynum (const char *str) { + Uchar ch; const keyname_t *kn; if (!str || !str[0]) @@ -1362,7 +1363,11 @@ Key_StringToKeynum (const char *str) if (!strcasecmp (str, kn->name)) return kn->keynum; } - return -1; + + // non-ascii keys are Unicode codepoints, so give the character if it's valid; + // error message have more than one character, don't allow it + ch = u8_getnchar(str, &str, 3); + return (ch == 0 || *str != 0) ? -1 : (int)ch; } /* @@ -1387,13 +1392,9 @@ Key_KeynumToString (int keynum, char *tinystr, size_t tinystrlength) return kn->name; // if it is printable, output it as a single character - if (keynum > 32 && keynum < 256) + if (keynum > 32) { - if (tinystrlength >= 2) - { - tinystr[0] = keynum; - tinystr[1] = 0; - } + u8_fromchar(keynum, tinystr, tinystrlength); return tinystr; } @@ -1586,7 +1587,7 @@ static void Key_PrintBindList(int j) { char bindbuf[MAX_INPUTLINE]; - char tinystr[2]; + char tinystr[TINYSTR_LEN]; const char *p; int i; @@ -1597,9 +1598,9 @@ Key_PrintBindList(int j) { Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); if (j == 0) - Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); else - Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); } } } @@ -1679,7 +1680,7 @@ Key_WriteBindings (qfile_t *f) { int i, j; char bindbuf[MAX_INPUTLINE]; - char tinystr[2]; + char tinystr[TINYSTR_LEN]; const char *p; // Override default binds @@ -1694,9 +1695,9 @@ Key_WriteBindings (qfile_t *f) { Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind if (j == 0) - FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); else - FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf); + FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf); } } } @@ -1971,14 +1972,12 @@ Key_Event (int key, int ascii, qbool down) { // button commands add keynum as a parm if (bind[0] == '+') - Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); else - { - Cbuf_AddText (cmd, bind); - Cbuf_AddText (cmd, "\n"); - } - } else if(bind[0] == '+' && !down && keydown[key] == 0) - Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); + Cbuf_InsertText(cmd, bind); + } + else if(bind[0] == '+' && !down && keydown[key] == 0) + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); } return; } @@ -2009,7 +2008,7 @@ Key_Event (int key, int ascii, qbool down) { if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG) { - Cbuf_AddText(cmd, "toggleconsole\n"); // Deferred to next frame so we're not sending the text event to the console. + Cbuf_InsertText(cmd, "toggleconsole\n"); // Deferred to next frame so we're not sending the text event to the console. tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game) return; } @@ -2052,14 +2051,12 @@ Key_Event (int key, int ascii, qbool down) { // button commands add keynum as a parm if (bind[0] == '+') - Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key)); else - { - Cbuf_AddText (cmd, bind); - Cbuf_AddText (cmd, "\n"); - } - } else if(bind[0] == '+' && !down && keydown[key] == 0) - Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); + Cbuf_InsertText(cmd, bind); + } + else if(bind[0] == '+' && !down && keydown[key] == 0) + Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key)); } break; default: