From: Jānis Rūcis Date: Tue, 30 Mar 2010 12:45:47 +0000 (+0300) Subject: IRC: simplify line splitting X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b454a13a39cb1290a0d69ad7e11a672f66f6189c;p=xonotic%2Fdarkplaces.git IRC: simplify line splitting --- diff --git a/irc.c b/irc.c index 672e5b65..c3d2cc92 100644 --- a/irc.c +++ b/irc.c @@ -122,34 +122,28 @@ static void IRC_ProcessMessages(void) while (remaining_len > 0) { - char *cr; + char *nl; + int len; - cr = memchr((void *) remaining, '\r', remaining_len); + nl = memchr((void *) remaining, '\n', remaining_len); - if (!cr || cr == remaining + remaining_len - 1) + if (!nl) { /* Probably incomplete message. */ memmove(irc_incoming, remaining, remaining_len); break; } - if (cr[1] == '\n') - { - int len = (cr - remaining) + 2; + nl[0] = 0; - cr[0] = 0; - cr[1] = 0; + if (nl != remaining && nl[-1] == '\r') + nl[-1] = 0; - Con_Printf("[IRC] %s\n", remaining); + Con_Printf("[IRC] %s\n", remaining); - remaining += len; - remaining_len -= len; - } - else - { - /* Garbage or embedded CR? Discard it and retry. */ - cr[0] = '.'; - } + len = (nl - remaining) + 1; + remaining += len; + remaining_len -= len; } irc_incoming_len = remaining_len;