On Thu, Apr 15, 2010 at 02:57:59AM +0400, anonymous wrote: > Also sometimes sic.c uses tok(&s) function instead of ctok(&s, ' ') > even if RFC says there should be only one space character.
Fix: RFC says there should be only spaces, while tok accepts tabs, newlines etc. Here is a patch that use `skip` instead of ctok. It also adds output of command parameters so you can see channel names when you execute LIST command (by typing :list). There are two FIXMEs because there could be more than one space. Maybe it is possible to use strchr() sometimes. In implementation of skip(), for example. diff -r 10f41d80803e sic.c --- a/sic.c Tue Mar 23 18:00:37 2010 +0000 +++ b/sic.c Thu Apr 15 04:19:20 2010 +0400 @@ -61,7 +61,7 @@ if(msg[0] == '\0') return; - msg = ctok(&msg, '\n'); + skip(msg, '\n'); if(msg[0] != ':') { privmsg(channel, msg); return; @@ -101,22 +101,22 @@ } static void -parsesrv(char *msg) { - char *cmd, *p, *usr, *txt; +parsesrv(char *cmd) { + char *msg, *usr, *txt; usr = host; - if(!msg || !*msg) + if(!cmd || !*cmd) return; - if(msg[0] == ':') { - msg++; - p = tok(&msg); - if(!*msg) + if(cmd[0] == ':') { + usr = cmd + 1; + cmd = skip(usr, ' '); /* FIXME: skip more than 1 space */ + if(cmd[0] == '\0') return; - usr = ctok(&p, '!'); + skip(usr, '!'); } - txt = ctok(&msg, '\r'); - msg = ctok(&txt, ':'); - cmd = tok(&msg); + skip(cmd, '\r'); + msg = skip(cmd, ' '); /* FIXME too */ + txt = skip(msg, ':'); if(!strcmp("PONG", cmd)) return; if(!strcmp("PRIVMSG", cmd)) @@ -124,7 +124,7 @@ else if(!strcmp("PING", cmd)) sout("PONG %s", txt); else { - pout(usr, ">< %s: %s", cmd, txt); + pout(usr, ">< %s (%s): %s", cmd, msg, txt); if(!strcmp("NICK", cmd) && !strcmp(usr, nick)) strlcpy(nick, txt, sizeof nick); } diff -r 10f41d80803e util.c --- a/util.c Tue Mar 23 18:00:37 2010 +0000 +++ b/util.c Thu Apr 15 04:19:20 2010 +0400 @@ -69,13 +69,10 @@ } static char* -ctok(char **s, int c) { - char *p, *q; - - q = *s; - for(p = q; *p && *p != c; p++) - ; - if(*p) *p++ = '\0'; - *s = p; - return q; +skip(char *s, char c) { + while(*s != c && *s != '\0') + s++; + if (*s != '\0') + *s++ = '\0'; + return s; }