]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
chat: adopting console code style, var name changes only
authornyov <nyov@nexnode.net>
Mon, 5 Dec 2011 00:14:34 +0000 (01:14 +0100)
committernyov <nyov@nexnode.net>
Mon, 5 Dec 2011 00:14:34 +0000 (01:14 +0100)
console.c
keys.c
keys.h

index 831c30a9f35a8dbfdff36f1e52ad53590e74ef25..b0bedd0842f07585025b97363e6a5c72c73845c7 100644 (file)
--- 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 123746ed3c2b8f8f1326dea6e333d07c822ad264..9b4659804a2ae1eab010eef86c6bbcb203585764 100644 (file)
--- 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 a84eb4c6f7cced9246b4faaf430ffb851467ed28..5833451b14dd111b7f973e8a695490b1858ca43c 100644 (file)
--- 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);