From: nyov Date: Mon, 5 Dec 2011 00:14:34 +0000 (+0100) Subject: chat: adopting console code style, var name changes only X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d0b9960af36c29b0b9ddac57d8d17f7c983103ae;p=xonotic%2Fdarkplaces.git chat: adopting console code style, var name changes only --- diff --git a/console.c b/console.c index 831c30a9..b0bedd08 100644 --- a/console.c +++ b/console.c @@ -606,7 +606,7 @@ static void Con_MessageMode_f (void) if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = strlen(chat_buffer); + chat_bufferpos = strlen(chat_buffer); } } @@ -623,7 +623,7 @@ static void Con_MessageMode2_f (void) if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = strlen(chat_buffer); + chat_bufferpos = strlen(chat_buffer); } } @@ -638,7 +638,7 @@ static void Con_CommandMode_f (void) if(Cmd_Argc() > 1) { dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); - chat_bufferlen = strlen(chat_buffer); + chat_bufferpos = strlen(chat_buffer); } chat_mode = -1; // command } diff --git a/keys.c b/keys.c index 123746ed..9b465980 100644 --- a/keys.c +++ b/keys.c @@ -1233,13 +1233,14 @@ Key_Console (int key, int unicode) int chat_mode; char chat_buffer[MAX_INPUTLINE]; -unsigned int chat_bufferlen = 0; +unsigned int chat_bufferpos = 0; static void -Key_Message (int key, int ascii) +Key_Message (int key, int unicode) { + // nyov: adopted Key_Console style here, so both functions could merge common code at some point. char vabuf[1024]; - if (key == K_ENTER || ascii == 10 || ascii == 13) + if (key == K_ENTER || unicode == /* LF */ 10 || unicode == /* CR */ 13) { if(chat_mode < 0) Cmd_ExecuteString(chat_buffer, src_command, true); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases! @@ -1247,47 +1248,45 @@ Key_Message (int key, int ascii) Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "%s %s", chat_mode ? "say_team" : "say ", chat_buffer)); key_dest = key_game; - chat_bufferlen = 0; + chat_bufferpos = 0; chat_buffer[0] = 0; return; } - // TODO add support for arrow keys and simple editing - if (key == K_ESCAPE) { key_dest = key_game; - chat_bufferlen = 0; + chat_bufferpos = 0; chat_buffer[0] = 0; return; } - if (key == K_BACKSPACE) { - if (chat_bufferlen) { - chat_bufferlen = u8_prevbyte(chat_buffer, chat_bufferlen); - chat_buffer[chat_bufferlen] = 0; - } + if(key == K_TAB) { + chat_bufferpos = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferpos); return; } - if(key == K_TAB) { - chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen); + if (key == K_BACKSPACE) { + if (chat_bufferpos) { + chat_bufferpos = u8_prevbyte(chat_buffer, chat_bufferpos); + chat_buffer[chat_bufferpos] = 0; + } return; } - // ctrl+key generates an ascii value < 32 and shows a char from the charmap - if (ascii > 0 && ascii < 32 && utf8_enable.integer) - ascii = 0xE000 + ascii; + // TODO add support for arrow keys and simple editing - if (chat_bufferlen == sizeof (chat_buffer) - 1) - return; // all full + // ctrl+key generates an ascii value < 32 and shows a char from the charmap + if (unicode > 0 && unicode < 32 && utf8_enable.integer) + unicode = 0xE000 + unicode; - if (!ascii) + if (!unicode) return; // non printable - chat_bufferlen += u8_fromchar(ascii, chat_buffer+chat_bufferlen, sizeof(chat_buffer) - chat_bufferlen - 1); + if (chat_bufferpos < sizeof (chat_buffer) - 1) + chat_bufferpos += u8_fromchar(unicode, chat_buffer+chat_bufferpos, sizeof(chat_buffer) - chat_bufferpos - 1); - //chat_buffer[chat_bufferlen++] = ascii; - //chat_buffer[chat_bufferlen] = 0; + //chat_buffer[chat_bufferpos++] = unicode; + //chat_buffer[chat_bufferpos] = 0; } //============================================================================ diff --git a/keys.h b/keys.h index a84eb4c6..5833451b 100644 --- a/keys.h +++ b/keys.h @@ -369,7 +369,7 @@ extern char *keybindings[MAX_BINDMAPS][MAX_KEYS]; extern int chat_mode; // 0 for say, 1 for say_team, -1 for command extern char chat_buffer[MAX_INPUTLINE]; -extern unsigned int chat_bufferlen; +extern unsigned int chat_bufferpos; void Key_ClearEditLine(int edit_line); void Key_WriteBindings(qfile_t *f);