From 0e3a3b2face6d51f66169cfa2620cadc38f03744 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 15:39:16 +0100 Subject: [PATCH 01/22] Cleanup blank chatbox checking code --- src/hu_stuff.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f4f52f5cf..e22f6c651 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1028,25 +1028,15 @@ void HU_Ticker(void) static boolean teamtalk = false; -// Clear spaces so we don't end up with messages only made out of emptiness -static boolean HU_clearChatSpaces(void) +static boolean HU_chatboxContainsOnlySpaces(void) { - size_t i = 0; // Used to just check our message - char c; // current character we're iterating. - boolean nothingbutspaces = true; + size_t i; - for (; i < strlen(w_chat); i++) // iterate through message and eradicate all spaces that don't belong. - { - c = w_chat[i]; - if (!c) - break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. + for (i = 0; w_chat[i]; i++) + if (w_chat[i] != ' ') + return false; - if (c != ' ') // Isn't a space - { - nothingbutspaces = false; - } - } - return nothingbutspaces; + return true; } // @@ -1062,8 +1052,9 @@ static void HU_queueChatChar(INT32 c) size_t ci = 2; INT32 target = 0; - if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. - return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + // if our message was nothing but spaces, don't send it. + if (HU_chatboxContainsOnlySpaces()) + return; do { c = w_chat[-2+ci++]; From cdb809a4340122f77400454c24d47d7fabb607b2 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 15:41:54 +0100 Subject: [PATCH 02/22] Cleanup chatbox reset code # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index e22f6c651..7644bcb2d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1048,7 +1048,6 @@ static void HU_queueChatChar(INT32 c) { char buf[2+256]; char *msg = &buf[2]; - size_t i; size_t ci = 2; INT32 target = 0; @@ -1061,15 +1060,8 @@ static void HU_queueChatChar(INT32 c) if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. buf[ci-1]=c; } while (c); - i = 0; - for (;(i Date: Sun, 2 Jan 2022 15:48:31 +0100 Subject: [PATCH 03/22] Cleanup chatbox sanitizing code --- src/hu_stuff.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 7644bcb2d..430c56a1a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1048,18 +1048,21 @@ static void HU_queueChatChar(INT32 c) { char buf[2+256]; char *msg = &buf[2]; - size_t ci = 2; + size_t ci; INT32 target = 0; // if our message was nothing but spaces, don't send it. if (HU_chatboxContainsOnlySpaces()) return; - do { - c = w_chat[-2+ci++]; - if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. - buf[ci-1]=c; - } while (c); + // copy printable characters and terminating '\0' only. + for (ci = 2; w_chat[ci-2]; ci++) + { + c = w_chat[ci-2]; + if (c >= ' ' && !(c & 0x80)) + buf[ci] = c; + }; + buf[ci] = '\0'; memset(w_chat, '\0', HU_MAXMSGLEN); c_input = 0; From 2ccb2229140e2e15adb3be41f504ce35a53217d0 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:08:10 +0100 Subject: [PATCH 04/22] Cleanup chat code a little # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 430c56a1a..8b024fe1c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1039,11 +1039,8 @@ static boolean HU_chatboxContainsOnlySpaces(void) return true; } -// -// -static void HU_queueChatChar(INT32 c) +static void HU_queueChatChar(char c) { - // send automaticly the message (no more chat char) if (c == KEY_ENTER) { char buf[2+256]; @@ -1093,7 +1090,7 @@ static void HU_queueChatChar(INT32 c) strncpy(playernum, msg+3, 3); // check for undesirable characters in our "number" - if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) + if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) { // check if playernum[1] is a space if (playernum[1] == ' ') @@ -1106,17 +1103,13 @@ static void HU_queueChatChar(INT32 c) } } // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0) + if (spc != 0 && msg[5] != ' ') { - if (msg[5] != ' ') - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + return; } target = atoi(playernum); // turn that into a number - //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! if (target < MAXPLAYERS && playeringame[target]) // player exists @@ -1133,11 +1126,7 @@ static void HU_queueChatChar(INT32 c) } if (ci > 3) // don't send target+flags+empty message. { - if (teamtalk) - buf[0] = -1; // target - else - buf[0] = target; - + buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } From 4fc770aa7be1a45a6933b21c5ad377eb3c05f6b3 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:38:49 +0100 Subject: [PATCH 05/22] Group related chat stuff together # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 143 ++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 8b024fe1c..f78bfa16b 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -845,71 +845,6 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) #endif } -// Handles key input and string input -// -static inline boolean HU_keyInChatString(char *s, char ch) -{ - size_t l; - - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && fontv[HU_FONT].font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - while (m>=c_input) - { - if (s[m]) - s[m+1] = (s[m]); - if (m == 0) // prevent overflow - break; - m--; - } - s[c_input] = ch; // and replace this. - } - c_input++; - return true; - } - return false; - } - else if (ch == KEY_BACKSPACE) - { - size_t i = c_input; - - if (c_input <= 0) - return false; - - if (!s[i-1]) - return false; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return false; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } - c_input--; - } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key -} - #endif // @@ -1027,6 +962,10 @@ void HU_Ticker(void) #ifndef NONET static boolean teamtalk = false; +static boolean justscrolleddown; +static boolean justscrolledup; +static INT16 typelines = 1; // number of drawfill lines we need when drawing the chat. it's some weird hack and might be one frame off but I'm lazy to make another loop. +// It's up here since it has to be reset when we open the chat. static boolean HU_chatboxContainsOnlySpaces(void) { @@ -1133,6 +1072,73 @@ static void HU_queueChatChar(char c) return; } } + +// Handles key input and string input +// +static inline boolean HU_keyInChatString(char *s, char ch) +{ + size_t l; + + if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) + || ch == ' ') // Allow spaces, of course + { + l = strlen(s); + if (l < HU_MAXMSGLEN - 1) + { + if (c_input >= strlen(s)) // don't do anything complicated + { + s[l++] = ch; + s[l]=0; + } + else + { + + // move everything past c_input for new characters: + size_t m = HU_MAXMSGLEN-1; + while (m>=c_input) + { + if (s[m]) + s[m+1] = (s[m]); + if (m == 0) // prevent overflow + break; + m--; + } + s[c_input] = ch; // and replace this. + } + c_input++; + return true; + } + return false; + } + else if (ch == KEY_BACKSPACE) + { + size_t i = c_input; + + if (c_input <= 0) + return false; + + if (!s[i-1]) + return false; + + if (i >= strlen(s)-1) + { + s[strlen(s)-1] = 0; + c_input--; + return false; + } + + for (; (i < HU_MAXMSGLEN); i++) + { + s[i-1] = s[i]; + } + c_input--; + } + else if (ch != KEY_ENTER) + return false; // did not eat key + + return true; // ate the key +} + #endif void HU_clearChatChars(void) @@ -1144,13 +1150,6 @@ void HU_clearChatChars(void) I_UpdateMouseGrab(); } -#ifndef NONET -static boolean justscrolleddown; -static boolean justscrolledup; -static INT16 typelines = 1; // number of drawfill lines we need when drawing the chat. it's some weird hack and might be one frame off but I'm lazy to make another loop. -// It's up here since it has to be reset when we open the chat. -#endif - // // Returns true if key eaten // From 4c59bb3b2b5e9782b8aa4672b02d22bd85e1e2ae Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:55:14 +0100 Subject: [PATCH 06/22] Turn HU_queueChatChar into HU_sendChatMessage # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 180 +++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 96 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f78bfa16b..b4a3d2fbb 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -978,104 +978,99 @@ static boolean HU_chatboxContainsOnlySpaces(void) return true; } -static void HU_queueChatChar(char c) +static void HU_sendChatMessage(void) { - if (c == KEY_ENTER) + char buf[2+256]; + char *msg = &buf[2]; + size_t ci; + INT32 target = 0; + + // if our message was nothing but spaces, don't send it. + if (HU_chatboxContainsOnlySpaces()) + return; + + // copy printable characters and terminating '\0' only. + for (ci = 2; w_chat[ci-2]; ci++) { - char buf[2+256]; - char *msg = &buf[2]; - size_t ci; - INT32 target = 0; + char c = w_chat[ci-2]; + if (c >= ' ' && !(c & 0x80)) + buf[ci] = c; + }; + buf[ci] = '\0'; - // if our message was nothing but spaces, don't send it. - if (HU_chatboxContainsOnlySpaces()) - return; + memset(w_chat, '\0', HU_MAXMSGLEN); + c_input = 0; - // copy printable characters and terminating '\0' only. - for (ci = 2; w_chat[ci-2]; ci++) + // last minute mute check + if (CHAT_MUTE) + { + HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + return; + } + + if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + { + INT32 spc = 1; // used if playernum[1] is a space. + char playernum[3]; + const char *newmsg; + + // what we're gonna do now is check if the player exists + // with that logic, characters 4 and 5 are our numbers: + + // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. + if (teamtalk) { - c = w_chat[ci-2]; - if (c >= ' ' && !(c & 0x80)) - buf[ci] = c; - }; - buf[ci] = '\0'; - - memset(w_chat, '\0', HU_MAXMSGLEN); - c_input = 0; - - // last minute mute check - if (CHAT_MUTE) - { - HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); return; } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + strncpy(playernum, msg+3, 3); + // check for undesirable characters in our "number" + if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) { - INT32 spc = 1; // used if playernum[1] is a space. - char playernum[3]; - const char *newmsg; - - // what we're gonna do now is check if the player exists - // with that logic, characters 4 and 5 are our numbers: - - // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. - if (teamtalk) - { - HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); - return; - } - - strncpy(playernum, msg+3, 3); - - // check for undesirable characters in our "number" - if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) - { - // check if playernum[1] is a space - if (playernum[1] == ' ') - spc = 0; - // let it slide - else - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } - } - // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0 && msg[5] != ' ') + // check if playernum[1] is a space + if (playernum[1] == ' ') + spc = 0; + // let it slide + else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); return; } - - target = atoi(playernum); // turn that into a number - - // check for target player, if it doesn't exist then we can't send the message! - if (target < MAXPLAYERS && playeringame[target]) // player exists - target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! - else - { - HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same - return; - } - - // we need to get rid of the /pm - newmsg = msg+5+spc; - strlcpy(msg, newmsg, 255); } - if (ci > 3) // don't send target+flags+empty message. + // I'm very bad at C, I swear I am, additional checks eww! + if (spc != 0 && msg[5] != ' ') { - buf[0] = teamtalk ? -1 : target; // target - buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + return; } - return; + + target = atoi(playernum); // turn that into a number + + // check for target player, if it doesn't exist then we can't send the message! + if (target < MAXPLAYERS && playeringame[target]) // player exists + target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + else + { + HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + return; + } + + // we need to get rid of the /pm + newmsg = msg+5+spc; + strlcpy(msg, newmsg, 255); + } + if (ci > 3) // don't send target+flags+empty message. + { + buf[0] = teamtalk ? -1 : target; // target + buf[1] = 0; // flags + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } // Handles key input and string input // -static inline boolean HU_keyInChatString(char *s, char ch) +static inline void HU_keyInChatString(char *s, char ch) { size_t l; @@ -1106,25 +1101,25 @@ static inline boolean HU_keyInChatString(char *s, char ch) s[c_input] = ch; // and replace this. } c_input++; - return true; + return; } - return false; + return; } else if (ch == KEY_BACKSPACE) { size_t i = c_input; if (c_input <= 0) - return false; + return; if (!s[i-1]) - return false; + return; if (i >= strlen(s)-1) { s[strlen(s)-1] = 0; c_input--; - return false; + return; } for (; (i < HU_MAXMSGLEN); i++) @@ -1133,10 +1128,6 @@ static inline boolean HU_keyInChatString(char *s, char ch) } c_input--; } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key } #endif @@ -1246,14 +1237,9 @@ boolean HU_Responder(event_t *ev) { memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. c_input += pastelen; - /*size_t i = 0; - for (;i= c_input) @@ -1270,12 +1256,11 @@ boolean HU_Responder(event_t *ev) } } - if (!CHAT_MUTE && HU_keyInChatString(w_chat,c)) - { - HU_queueChatChar(c); - } if (c == KEY_ENTER) { + if (!CHAT_MUTE) + HU_sendChatMessage(); + chat_on = false; c_input = 0; // reset input cursor chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) @@ -1316,6 +1301,9 @@ boolean HU_Responder(event_t *ev) else c_input++; } + else if (!CHAT_MUTE) + HU_keyInChatString(w_chat, c); + return true; } #endif From 5d406375a80d539907733f75667667950e6bc4a7 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 23:06:34 +0100 Subject: [PATCH 07/22] Cleanup and fix chat deleting and pasting # Conflicts: # src/hu_stuff.c # src/hu_stuff.h --- src/hu_stuff.c | 88 +++++++++----------------------------------------- src/hu_stuff.h | 4 +-- 2 files changed, 18 insertions(+), 74 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index b4a3d2fbb..01f5bde1f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -81,8 +81,7 @@ patch_t *frameslash; // framerate stuff. Used in screen.c static player_t *plr; boolean chat_on; // entering a chat message? -boolean hu_keystrokes; // :) -static char w_chat[HU_MAXMSGLEN]; +static char w_chat[HU_MAXMSGLEN + 1]; static size_t c_input = 0; // let's try to make the chat input less shitty. static boolean headsupactive = false; boolean hu_showscores; // draw rankings @@ -998,7 +997,7 @@ static void HU_sendChatMessage(void) }; buf[ci] = '\0'; - memset(w_chat, '\0', HU_MAXMSGLEN); + memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; // last minute mute check @@ -1068,64 +1067,27 @@ static void HU_sendChatMessage(void) } } +// // Handles key input and string input // static inline void HU_keyInChatString(char *s, char ch) { - size_t l; - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) || ch == ' ') // Allow spaces, of course { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - while (m>=c_input) - { - if (s[m]) - s[m+1] = (s[m]); - if (m == 0) // prevent overflow - break; - m--; - } - s[c_input] = ch; // and replace this. - } - c_input++; + if (strlen(s) >= HU_MAXMSGLEN) return; - } - return; + + memmove(&s[c_input + 1], &s[c_input], strlen(s) - c_input + 1); + s[c_input] = ch; + c_input++; } else if (ch == KEY_BACKSPACE) { - size_t i = c_input; - if (c_input <= 0) return; - if (!s[i-1]) - return; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } + memmove(&s[c_input - 1], &s[c_input], strlen(s) - c_input + 1); c_input--; } } @@ -1134,7 +1096,7 @@ static inline void HU_keyInChatString(char *s, char ch) void HU_clearChatChars(void) { - memset(w_chat, '\0', HU_MAXMSGLEN); + memset(w_chat, '\0', sizeof(w_chat)); chat_on = false; c_input = 0; @@ -1219,12 +1181,11 @@ boolean HU_Responder(event_t *ev) // pasting. pasting is cool. chat is a bit limited, though :( if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) { - const char *paste = I_ClipboardPaste(); + const char *paste; size_t chatlen; size_t pastelen; - // create a dummy string real quickly - + paste = I_ClipboardPaste(); if (paste == NULL) return true; @@ -1233,27 +1194,10 @@ boolean HU_Responder(event_t *ev) if (chatlen+pastelen > HU_MAXMSGLEN) return true; // we can't paste this!! - if (c_input >= strlen(w_chat)) // add it at the end of the string. - { - memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. - c_input += pastelen; - return true; - } - else // otherwise, we need to shift everything and make space, etc etc - { - size_t i = HU_MAXMSGLEN-1; - while (i >= c_input) - { - if (w_chat[i]) - w_chat[i+pastelen] = w_chat[i]; - if (i == 0) // prevent overflow - break; - i--; - } - memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. - c_input += pastelen; - return true; - } + memmove(&w_chat[c_input + pastelen], &w_chat[c_input], pastelen); + memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. + c_input += pastelen; + return true; } if (c == KEY_ENTER) diff --git a/src/hu_stuff.h b/src/hu_stuff.h index d81dba2a6..bbe906fa9 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -80,8 +80,8 @@ typedef struct //------------------------------------ // chat stuff //------------------------------------ -#define HU_MAXMSGLEN 224 -#define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. +#define HU_MAXMSGLEN 223 +#define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. #define NETSPLITSCREEN // why the hell WOULDN'T we want this? #ifdef NETSPLITSCREEN #define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640) From cf6dfecc6a622b0a45afa565f3a5f4982d5d6607 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 23:19:34 +0100 Subject: [PATCH 08/22] Cleanup chat event handling # Conflicts: # src/hu_stuff.c --- src/hu_stuff.c | 53 ++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 01f5bde1f..8e027f6b4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1067,31 +1067,6 @@ static void HU_sendChatMessage(void) } } -// -// Handles key input and string input -// -static inline void HU_keyInChatString(char *s, char ch) -{ - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - if (strlen(s) >= HU_MAXMSGLEN) - return; - - memmove(&s[c_input + 1], &s[c_input], strlen(s) - c_input + 1); - s[c_input] = ch; - c_input++; - } - else if (ch == KEY_BACKSPACE) - { - if (c_input <= 0) - return; - - memmove(&s[c_input - 1], &s[c_input], strlen(s) - c_input + 1); - c_input--; - } -} - #endif void HU_clearChatChars(void) @@ -1179,12 +1154,15 @@ boolean HU_Responder(event_t *ev) c = CON_ShiftChar(c); // pasting. pasting is cool. chat is a bit limited, though :( - if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) + if ((c == 'v' || c == 'V') && ctrldown) { const char *paste; size_t chatlen; size_t pastelen; + if (CHAT_MUTE) + return true; + paste = I_ClipboardPaste(); if (paste == NULL) return true; @@ -1199,8 +1177,7 @@ boolean HU_Responder(event_t *ev) c_input += pastelen; return true; } - - if (c == KEY_ENTER) + else if (c == KEY_ENTER) { if (!CHAT_MUTE) HU_sendChatMessage(); @@ -1245,8 +1222,24 @@ boolean HU_Responder(event_t *ev) else c_input++; } - else if (!CHAT_MUTE) - HU_keyInChatString(w_chat, c); + else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font[c-HU_FONTSTART]) + || c == ' ') // Allow spaces, of course + { + if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN) + return true; + + memmove(&w_chat[c_input + 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); + w_chat[c_input] = c; + c_input++; + } + else if (c == KEY_BACKSPACE) + { + if (CHAT_MUTE || c_input <= 0) + return true; + + memmove(&w_chat[c_input - 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); + c_input--; + } return true; } From bc62dc821438dd557a1572b39a5113e513b9a629 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:06:20 +0100 Subject: [PATCH 09/22] Fix single-letter messages not being sent --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 8e027f6b4..389d245f4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1059,7 +1059,7 @@ static void HU_sendChatMessage(void) newmsg = msg+5+spc; strlcpy(msg, newmsg, 255); } - if (ci > 3) // don't send target+flags+empty message. + if (ci > 2) // don't send target+flags+empty message. { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags From de4eed6af24f091bf8547ec991eaf6ddf5545b24 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:06:43 +0100 Subject: [PATCH 10/22] Add SKIPSTRINGN macro --- src/byteptr.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/byteptr.h b/src/byteptr.h index fd178ba3b..fd3c523cb 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -143,7 +143,8 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) #define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) -#define SKIPSTRING(p) while (READCHAR(p) != '\0') +#define SKIPSTRING(p) while (READCHAR(p) != '\0') +#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); }) #define READSTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} while (0) #define READSTRING(p,s) do { size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} while (0) From 94f691f21646889eb0b16396bbef8ff3cff1bf0c Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:08:23 +0100 Subject: [PATCH 11/22] Fix long chat messages crashing the game --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 389d245f4..69e77020c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -651,7 +651,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); msg = (char *)*p; - SKIPSTRING(*p); + SKIPSTRINGN(*p, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { From 47c7351928f958244a222970b2e16c2bdc795eb2 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:30:16 +0100 Subject: [PATCH 12/22] Support delete key in chatbox --- src/hu_stuff.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 69e77020c..10c92a72c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1240,6 +1240,13 @@ boolean HU_Responder(event_t *ev) memmove(&w_chat[c_input - 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); c_input--; } + else if (c == KEY_DEL) + { + if (CHAT_MUTE || c_input >= strlen(w_chat)) + return true; + + memmove(&w_chat[c_input], &w_chat[c_input + 1], strlen(w_chat) - c_input); + } return true; } From d3d2205932fe20d7f6ee01dbdb7822a2eb01da15 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 22:37:19 +0100 Subject: [PATCH 13/22] Fix long chat messages causing net command failures --- src/hu_stuff.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 10c92a72c..a2f069b77 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -641,7 +641,8 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) SINT8 target; UINT8 flags; const char *dispname; - char *msg; + char msgbuf[HU_MAXMSGLEN + 1]; + char *msg = msgbuf; boolean action = false; char *ptr; INT32 spam_eatmsg = 0; @@ -650,8 +651,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); - msg = (char *)*p; - SKIPSTRINGN(*p, HU_MAXMSGLEN); + READSTRINGN(*p, msgbuf, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { @@ -995,7 +995,11 @@ static void HU_sendChatMessage(void) if (c >= ' ' && !(c & 0x80)) buf[ci] = c; }; - buf[ci] = '\0'; + if (ci-2 < HU_MAXMSGLEN) + { + buf[ci] = '\0'; + ci++; + } memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; @@ -1063,7 +1067,7 @@ static void HU_sendChatMessage(void) { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + SendNetXCmd(XD_SAY, buf, ci); } } From c7e495bf8ba1221bddc50264fce7dfb2933594fb Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 18:56:42 +0100 Subject: [PATCH 14/22] Make byte stream manipulation code easier to read # Conflicts: # src/byteptr.h --- src/byteptr.h | 61 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index fd3c523cb..56a739eb3 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -139,13 +139,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #undef DEALIGNED -#define WRITESTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); if (tmp_i < n) WRITECHAR(p, '\0');} while (0) -#define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) -#define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) +#define WRITESTRINGN(p, s, n) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + if (tmp_i < n) \ + WRITECHAR(p, '\0'); \ +}) -#define SKIPSTRING(p) while (READCHAR(p) != '\0') -#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); }) +#define WRITESTRING(p, s) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + WRITECHAR(p, '\0'); \ +}) -#define READSTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} while (0) -#define READSTRING(p,s) do { size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';} while (0) -#define READMEM(p,s,n) do { memcpy(s, p, n); p += n; } while (0) +#define WRITEMEM(p, s, n) ({ \ + memcpy(p, s, n); \ + p += n; \ +}) + +#define SKIPSTRING(p) while (READCHAR(p) != '\0') + +#define SKIPSTRINGN(p, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n && READCHAR(p) != '\0') \ + tmp_i++; \ +}) + +#define READSTRINGN(p, s, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + +#define READSTRING(p, s) ({ \ + size_t tmp_i = 0; \ + \ + while ((s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + +#define READMEM(p, s, n) ({ \ + memcpy(s, p, n); \ + p += n; \ +}) From 8558323c445e23f76feded33e94294fbf58ed1cf Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 18:57:18 +0100 Subject: [PATCH 15/22] Add READSTRINGL and WRITESTRINGL macros --- src/byteptr.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/byteptr.h b/src/byteptr.h index 56a739eb3..cd7e912b6 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -149,6 +149,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) WRITECHAR(p, '\0'); \ }) +#define WRITESTRINGL(p, s, n) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; tmp_i < n - 1 && s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + WRITECHAR(p, '\0'); \ +}) + #define WRITESTRING(p, s) ({ \ size_t tmp_i; \ \ @@ -181,6 +190,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) s[tmp_i] = '\0'; \ }) +#define READSTRINGL(p, s, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n - 1 && (s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + #define READSTRING(p, s) ({ \ size_t tmp_i = 0; \ \ From 75e4f07e12a52386bf57177f892b420f9f423e64 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 19:31:41 +0100 Subject: [PATCH 16/22] Fix say command and its variants using hardcoded buffer size --- src/hu_stuff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a2f069b77..2b38697c4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -464,7 +464,7 @@ void HU_AddChatText(const char *text, boolean playsound) static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) { - char buf[254]; + char buf[2 + HU_MAXMSGLEN + 1]; size_t numwords, ix; char *msg = &buf[2]; const size_t msgspace = sizeof buf - 2; @@ -541,7 +541,7 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) } buf[0] = target; newmsg = msg+5+spc; - strlcpy(msg, newmsg, 252); + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); From 32e7442d0040fdd5efbf7ddbac44aef3fabe0126 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 19:57:15 +0100 Subject: [PATCH 17/22] Revert "Fix long chat messages causing net command failures" This reverts commit 13778247990d60c2ad8aa5729bc0397ab764eaaa. --- src/hu_stuff.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2b38697c4..74eb13813 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -641,8 +641,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) SINT8 target; UINT8 flags; const char *dispname; - char msgbuf[HU_MAXMSGLEN + 1]; - char *msg = msgbuf; + char *msg; boolean action = false; char *ptr; INT32 spam_eatmsg = 0; @@ -651,7 +650,8 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); - READSTRINGN(*p, msgbuf, HU_MAXMSGLEN); + msg = (char *)*p; + SKIPSTRINGN(*p, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { @@ -995,11 +995,7 @@ static void HU_sendChatMessage(void) if (c >= ' ' && !(c & 0x80)) buf[ci] = c; }; - if (ci-2 < HU_MAXMSGLEN) - { - buf[ci] = '\0'; - ci++; - } + buf[ci] = '\0'; memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; @@ -1067,7 +1063,7 @@ static void HU_sendChatMessage(void) { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, ci); + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } From 0036559bef02cf1223e8286cc27a6a1680e13728 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:03:29 +0100 Subject: [PATCH 18/22] Add SKIPSTRINGL macro --- src/byteptr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/byteptr.h b/src/byteptr.h index cd7e912b6..79e3f99c0 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -181,6 +181,8 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) tmp_i++; \ }) +#define SKIPSTRINGL(p, n) SKIPSTRINGN(p, n) + #define READSTRINGN(p, s, n) ({ \ size_t tmp_i = 0; \ \ From 9f37c240a400c2205b27b88b9c8d884ff5a48a9a Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:05:58 +0100 Subject: [PATCH 19/22] Fix long chat messages causing net command failures --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 74eb13813..fe8d57667 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -651,7 +651,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); msg = (char *)*p; - SKIPSTRINGN(*p, HU_MAXMSGLEN); + SKIPSTRINGL(*p, HU_MAXMSGLEN + 1); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { From d5367d2e657f973ac3e571dcbe96c509655ab4bc Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:12:27 +0100 Subject: [PATCH 20/22] Fix message sending code using hardcoded buffer size --- src/hu_stuff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fe8d57667..4707927d5 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -979,7 +979,7 @@ static boolean HU_chatboxContainsOnlySpaces(void) static void HU_sendChatMessage(void) { - char buf[2+256]; + char buf[2 + HU_MAXMSGLEN + 1]; char *msg = &buf[2]; size_t ci; INT32 target = 0; @@ -1057,7 +1057,7 @@ static void HU_sendChatMessage(void) // we need to get rid of the /pm newmsg = msg+5+spc; - strlcpy(msg, newmsg, 255); + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } if (ci > 2) // don't send target+flags+empty message. { From e9d7c2eee3af3c241579bac777a96dfefd71896e Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 5 Sep 2022 16:37:44 +0100 Subject: [PATCH 21/22] Fix regressions in merge process - Re-replace `hu_font` with `fontv[HU_FONT].font` - Re-init hu_keystrokes --- src/hu_stuff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 4707927d5..f88884c50 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -80,6 +80,7 @@ patch_t *framecounter; patch_t *frameslash; // framerate stuff. Used in screen.c static player_t *plr; +boolean hu_keystrokes; // :) boolean chat_on; // entering a chat message? static char w_chat[HU_MAXMSGLEN + 1]; static size_t c_input = 0; // let's try to make the chat input less shitty. @@ -1222,7 +1223,7 @@ boolean HU_Responder(event_t *ev) else c_input++; } - else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font[c-HU_FONTSTART]) + else if ((c >= HU_FONTSTART && c <= HU_FONTEND && fontv[HU_FONT].font[c-HU_FONTSTART]) || c == ' ') // Allow spaces, of course { if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN) @@ -1796,8 +1797,8 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; - INT32 charwidth = 8 * con_scalefactor; //(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; - INT32 charheight = 8 * con_scalefactor; //(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; + INT32 charwidth = 8 * con_scalefactor; //(fontv[HU_FONT].font['A'-HU_FONTSTART]->width) * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; //(fontv[HU_FONT].font['A'-HU_FONTSTART]->height) * con_scalefactor; if (teamtalk) { talk = ttalk; @@ -1818,7 +1819,7 @@ static void HU_DrawChat_Old(void) } else { - //charwidth = (hu_font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (fontv[HU_FONT].font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, true); } c += charwidth; @@ -1846,7 +1847,7 @@ static void HU_DrawChat_Old(void) } else { - //charwidth = (hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = (fontv[HU_FONT].font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, true); } From 9e11eff9d843b6c63a931ef4d9a96c5f182060e1 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 5 Sep 2022 16:49:27 +0100 Subject: [PATCH 22/22] Perform incantations so the byteptr.h macros are valid ISO C --- src/byteptr.h | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index 79e3f99c0..5d1b50630 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -139,7 +139,7 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #undef DEALIGNED -#define WRITESTRINGN(p, s, n) ({ \ +#define WRITESTRINGN(p, s, n) do { \ size_t tmp_i; \ \ for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \ @@ -147,70 +147,70 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) \ if (tmp_i < n) \ WRITECHAR(p, '\0'); \ -}) +} while (0) -#define WRITESTRINGL(p, s, n) ({ \ +#define WRITESTRINGL(p, s, n) do { \ size_t tmp_i; \ \ for (tmp_i = 0; tmp_i < n - 1 && s[tmp_i] != '\0'; tmp_i++) \ WRITECHAR(p, s[tmp_i]); \ \ WRITECHAR(p, '\0'); \ -}) +} while (0) -#define WRITESTRING(p, s) ({ \ +#define WRITESTRING(p, s) do { \ size_t tmp_i; \ \ for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \ WRITECHAR(p, s[tmp_i]); \ \ WRITECHAR(p, '\0'); \ -}) +} while (0) -#define WRITEMEM(p, s, n) ({ \ - memcpy(p, s, n); \ - p += n; \ -}) +#define WRITEMEM(p, s, n) do { \ + memcpy(p, s, n); \ + p += n; \ +} while (0) #define SKIPSTRING(p) while (READCHAR(p) != '\0') -#define SKIPSTRINGN(p, n) ({ \ +#define SKIPSTRINGN(p, n) do { \ size_t tmp_i = 0; \ \ while (tmp_i < n && READCHAR(p) != '\0') \ tmp_i++; \ -}) +} while (0) #define SKIPSTRINGL(p, n) SKIPSTRINGN(p, n) -#define READSTRINGN(p, s, n) ({ \ +#define READSTRINGN(p, s, n) do { \ size_t tmp_i = 0; \ \ while (tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0') \ tmp_i++; \ \ s[tmp_i] = '\0'; \ -}) +} while (0) -#define READSTRINGL(p, s, n) ({ \ +#define READSTRINGL(p, s, n) do { \ size_t tmp_i = 0; \ \ while (tmp_i < n - 1 && (s[tmp_i] = READCHAR(p)) != '\0') \ tmp_i++; \ \ s[tmp_i] = '\0'; \ -}) +} while (0) -#define READSTRING(p, s) ({ \ +#define READSTRING(p, s) do { \ size_t tmp_i = 0; \ \ while ((s[tmp_i] = READCHAR(p)) != '\0') \ tmp_i++; \ \ s[tmp_i] = '\0'; \ -}) +} while (0) -#define READMEM(p, s, n) ({ \ - memcpy(s, p, n); \ - p += n; \ -}) +#define READMEM(p, s, n) do { \ + memcpy(s, p, n); \ + p += n; \ +} while (0)