Permalink
Browse files

Move handling of numeric responses out to irc.c

  • Loading branch information...
Sound and Fury
Sound and Fury committed Aug 15, 2010
1 parent 92ce65a commit 83af8c16a22dc2604d59d7cacf369b89caa4256d
Showing with 47 additions and 38 deletions.
  1. +2 −2 Makefile
  2. +40 −0 irc.c
  3. +2 −1 irc.h
  4. +2 −0 plans
  5. +1 −34 quirc.c
  6. +0 −1 quirc.h
View
@@ -6,7 +6,7 @@ AWK ?= gawk
VERSION := `git describe --tags`
PREFIX ?= /usr/local
LIBS := ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o
-INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h numeric.h version.h
+INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h version.h
all: quirc
@@ -21,7 +21,7 @@ quirc: quirc.c $(LIBS) $(INCLUDE)
%.o: %.c %.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
-irc.o: irc.c irc.h bits.h buffer.h colour.h config.h
+irc.o: irc.c irc.h bits.h buffer.h colour.h config.h numeric.h
bits.o: bits.c bits.h ttyesc.h colour.h config.h
View
40 irc.c
@@ -131,3 +131,43 @@ int irc_rx(int fd, char ** data)
}
return(0);
}
+
+int irc_numeric(char *cmd, int b)
+{
+ int num=0;
+ sscanf(cmd, "%d", &num);
+ switch(num)
+ {
+ case RPL_NAMREPLY:
+ // 353 dest {@|+} #chan :name [name [...]]
+ strtok(NULL, " "); // dest
+ strtok(NULL, " "); // @ or +, dunno what for
+ char *ch=strtok(NULL, " "); // channel
+ int b2;
+ for(b2=0;b2<nbufs;b2++)
+ {
+ if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (strcasecmp(ch, bufs[b2].bname)==0))
+ {
+ char *nn;
+ while((nn=strtok(NULL, ":@ ")))
+ {
+ n_add(&bufs[b2].nlist, nn);
+ }
+ }
+ }
+ break;
+ case RPL_MOTDSTART:
+ case RPL_MOTD:
+ case RPL_ENDOFMOTD:
+ // silently ignore the motd, because they're always far too long and annoying
+ break;
+ default:
+ ;
+ char *rest=strtok(NULL, "");
+ char umsg[16+strlen(rest)];
+ sprintf(umsg, "<<%d? %s", num, rest);
+ buf_print(b, c_unn, umsg, true);
+ break;
+ }
+ return(num);
+}
View
3 irc.h
@@ -23,9 +23,10 @@
#include "buffer.h"
#include "colour.h"
#include "config.h"
+#include "numeric.h"
int irc_connect(char *server, char *portno, char *nick, char *username, char *fullname, fd_set *master, int *fdmax);
int autoconnect(fd_set *master, int *fdmax);
int irc_tx(int fd, char * packet);
int irc_rx(int fd, char ** data);
-
+int irc_numeric(char *cmd, int b); // strtok() state leaks across the boundaries of this function, beware!
View
2 plans
@@ -9,3 +9,5 @@ curses. The current hardwired ANSI-escapes code for painting the screen is clum
Interface separation. The main event loop is currently chock-full of implementation details; it should just be a command parser and marshal. Some work has been done in this direction (0.4.8 changes) but there's a lot left to do.
Input editing. Should use something based on Emacs line editing keys (C-a will mean 'go to start of line', unlike now when it means 'backspace to start of line'!). May be provided by curses - investigate.
+
+MOTD. The numerics handler currently ignores these.
View
35 quirc.c
@@ -184,40 +184,7 @@ int main(int argc, char *argv[])
if(*packet==':') *p=0;
if(isdigit(*cmd))
{
- int num=0;
- sscanf(cmd, "%d", &num);
- switch(num)
- {
- case RPL_NAMREPLY:
- // 353 dest {@|+} #chan :name [name [...]]
- strtok(NULL, " "); // dest
- strtok(NULL, " "); // @ or +, dunno what for
- char *ch=strtok(NULL, " "); // channel
- int b2;
- for(b2=0;b2<nbufs;b2++)
- {
- if((bufs[b2].server==b) && (bufs[b2].type==CHANNEL) && (strcasecmp(ch, bufs[b2].bname)==0))
- {
- char *nn;
- while((nn=strtok(NULL, ":@ ")))
- {
- n_add(&bufs[b2].nlist, nn);
- }
- }
- }
- break;
- case RPL_MOTDSTART:
- case RPL_MOTD:
- case RPL_ENDOFMOTD:
- // silently ignore the motd, because they're always far too long and annoying
- break;
- default:
- ;
- char umsg[16+strlen(cmd+4)];
- sprintf(umsg, "<<%d? %s", num, cmd+4);
- buf_print(b, c_unn, umsg, true);
- break;
- }
+ irc_numeric(cmd, b);
}
else if(strcmp(cmd, "PING")==0)
{
View
@@ -21,7 +21,6 @@
#include "irc.h"
#include "bits.h"
#include "buffer.h"
-#include "numeric.h"
#include "config.h"
#include "input.h"
#include "version.h"

0 comments on commit 83af8c1

Please sign in to comment.