]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
IRC: simplify line splitting
authorJānis Rūcis <parasti@gmail.com>
Tue, 30 Mar 2010 12:45:47 +0000 (15:45 +0300)
committerJānis Rūcis <parasti@gmail.com>
Sun, 27 Jun 2010 12:23:20 +0000 (15:23 +0300)
irc.c

diff --git a/irc.c b/irc.c
index 672e5b650a57ad2ee61e7b3a96768f775c476df2..c3d2cc928836ae3e56068889b9896a8af1e73bca 100644 (file)
--- 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;