- if(!strncmp(msg + 1, "j ", 2) && (msg[3] == '#'))
- snprintf(bufout, sizeof bufout, "JOIN %s\r\n", &msg[3]);
- else if(!strncmp(msg + 1, "l ", 2))
- snprintf(bufout, sizeof bufout, "PART %s :sic - 300 LOC are too much!\r\n", &msg[3]);
- else if(!strncmp(msg + 1, "m ", 2)) {
- if((p = strchr(&msg[3], ' ')))
- *(p++) = 0;
- privmsg(&msg[3], p);
- return;
- }
- else if(!strncmp(msg + 1, "s ", 2)) {
- strncpy(channel, &msg[3], sizeof channel);
- return;
- }
- else if(!strncmp(msg + 1, "t ", 2)) {
- if((p = strchr(&msg[3], ' ')))
- *(p++) = 0;
- snprintf(bufout, sizeof bufout, "TOPIC %s :%s\r\n", &msg[3], p);
- }
- else
- snprintf(bufout, sizeof bufout, "%s\r\n", &msg[1]);
- write(srv, bufout, strlen(bufout));
-}
-
-static unsigned int
-tokenize(char **result, unsigned int reslen, char *str, char delim) {
- char *p, *n;
- unsigned int i = 0;
-
- if(!str)
- return 0;
- for(n = str; *n == delim; n++);
- p = n;
- for(i = 0; *n != 0;) {
- if(i == reslen)
- return i;
- if(*n == delim) {
- *n = 0;
- if(strlen(p))
- result[i++] = p;
- p = ++n;
- } else
- n++;
+ c = *++s;
+ if(c != '\0' && isspace((unsigned char)s[1])) {
+ p = s + 2;
+ switch(c) {
+ case 'j':
+ sout("JOIN %s", p);
+ if(channel[0] == '\0')
+ strlcpy(channel, p, sizeof channel);
+ return;
+ case 'l':
+ s = eat(p, isspace, 1);
+ p = eat(s, isspace, 0);
+ if(!*s)
+ s = channel;
+ if(*p)
+ *p++ = '\0';
+ if(!*p)
+ p = DEFAULT_PARTING_MESSAGE;
+ sout("PART %s :%s", s, p);
+ return;
+ case 'm':
+ s = eat(p, isspace, 1);
+ p = eat(s, isspace, 0);
+ if(*p)
+ *p++ = '\0';
+ privmsg(s, p);
+ return;
+ case 's':
+ strlcpy(channel, p, sizeof channel);
+ return;
+ }