diff options
author | epoch <epoch@hack.thebackupbox.net> | 2019-05-19 09:23:09 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2019-05-19 09:23:09 +0000 |
commit | e02e4b69e237d16f19530b071fbb081a811e8ebe (patch) | |
tree | f3b52639891d378c1bd4bc08c4e0b27dc7483ddd | |
parent | 5ed56236f1ee57e71c91d356c7160aedc6e515f0 (diff) | |
download | libidc-e02e4b69e237d16f19530b071fbb081a811e8ebe.tar.gz libidc-e02e4b69e237d16f19530b071fbb081a811e8ebe.zip |
renamed everything to idc from line.
-rw-r--r-- | GNUmakefile | 13 | ||||
-rw-r--r-- | idc.h (renamed from line.h) | 0 | ||||
-rw-r--r-- | ircify.c | 19 | ||||
-rw-r--r-- | libidc.c (renamed from libline.c) | 14 |
4 files changed, 29 insertions, 17 deletions
diff --git a/GNUmakefile b/GNUmakefile index 12237ab..fc8701d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,14 +1,15 @@ CFLAGS=-fpic -shared -pedantic -Wall -g3 -TARGET=libline.so +TARGET=libidc.so PREFIX:=/usr/local -all: libline.so ircify +all: libidc.so ircify -ircify: LDLIBS=-Lline +ircify: LDLIBS=-lidc +ircify: CFLAGS=-g3 -Wall -pedantic ircify: ircify.c -$(TARGET): libline.o - ld -shared -o $(TARGET) libline.o +$(TARGET): libidc.o + ld -shared -o $(TARGET) libidc.o clean: rm -f $(TARGET) ircify @@ -18,4 +19,4 @@ install: all mkdir -p $(PREFIX)/lib mkdir -p $(PREFIX)/include install $(TARGET) $(PREFIX)/lib/$(TARGET) - install line.h $(PREFIX)/include/line.h + install idc.h $(PREFIX)/include/idc.h @@ -8,14 +8,20 @@ extern struct global libline; int pin[2]; int pout[2]; +char channel[256]; + void line_handler(struct shit *me,char *line) { char tmp[1024]; if(!strncmp(line,"PING ",5)) { - line[1]='O'; - printf("%s\r\n",line); + printf("PONG :%s\r\n",line+5); + fflush(stdout); } if(*line == ':') { if(strchr(line,' ')) { + if(!strncmp(strchr(line,' ')," 376 ",5)) { + printf("JOIN %s\r\n",channel); + fflush(stdout); + } if(!strncmp(strchr(line,' ')," PRIVMSG ",9)) { if(strchr(line+1,':')) { snprintf(tmp,sizeof(tmp),"%s\n",strchr(line+1,':')+1); @@ -24,17 +30,18 @@ void line_handler(struct shit *me,char *line) { } } } - fprintf(stderr,"READ SHIT: %s\n",line); + fprintf(stderr,"%s\n",line); } -char channel[256]; - void line_handler2(struct shit *me,char *line) { printf("PRIVMSG %s :%s\r\n",channel,line); - fflush(stdout); } int main(int argc,char *argv[]) { + setlinebuf(stdout); + printf("NICK revbot\r\n"); + printf("USER asdf asdf asdf :asdf\r\n"); + fflush(stdout); strcpy(channel,argv[1]); argv+=2; int i=0; @@ -11,7 +11,7 @@ #include <errno.h> //#define CHUNK 4096 -#include "line.h" +#include "idc.h" #define TSIZE 65536 @@ -128,11 +128,11 @@ int select_on_everything() { // if((j=select(fdmax+1,&readfs,0,0,&timeout)) == -1 ) { if((j=select(libline.fdmax+1,&readfs,0,0,NULL)) == -1 ) {//we want to select-sleep as long as possible. //any reason to wake up should be a file descriptor in the list. (works for X11 events, dunno about others) - //on error filedescriptors aren't changed //the value of timeout is undefined //so says the linux man page for select. - return perror("select"),1; + if(errno != 0) return perror("select"),1; + else perror("wtf? select"); //continue; } @@ -141,11 +141,15 @@ int select_on_everything() { for(i=0;libline.fds[i].fd != -1 && j>0;i++) { if(!FD_ISSET(libline.fds[i].fd,&readfs)) continue;//did not find one. hurry back to the for loop j--;//we found one. trying to get j==0 so we can get out of here early. - if((n=read(libline.fds[i].fd,libline.fds[i].buffer,CHUNK)) <= 0) { - snprintf(tmp,sizeof(tmp)-1,"fd %d: read",libline.fds[i].fd);//hopefully this doesn't error and throw off error messages. + if((n=read(libline.fds[i].fd,libline.fds[i].buffer,CHUNK)) < 0) { + snprintf(tmp,sizeof(tmp)-1,"fd %d: read perror:",libline.fds[i].fd);//hopefully this doesn't error and throw off error messages. perror(tmp); return 2; } + if(n == 0) { + fprintf(stderr,"reached EOF on fd: %d\n",libline.fds[i].fd); + return 3; + } if(libline.fds[i].bllen+n > libline.fds[i].blsize) {//this is probably off... t=malloc(libline.fds[i].blsize+n); if(!t) exit(253); |