aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile7
-rw-r--r--bee.c5
-rw-r--r--conf.h2
-rw-r--r--irc.c14
-rw-r--r--util.c2
6 files changed, 26 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c484265
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.o
+apiobot
+
diff --git a/Makefile b/Makefile
index cb02b50..2269f1c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
.POSIX:
.SUFFIXES: .c .o
-CFLAGS=-Wall
CC=cc
debug=-g -DDEBUG -DLOCAL
+CFLAGS=$(MORE_CFLAGS) -Wall
OBJS=bee.o irc.o util.o
@@ -12,10 +12,11 @@ apiobot: $(OBJS)
$(CC) $(CFLAGS) -o apiobot $(OBJS)
debug:
- $(CC) $(CFLAGS) $(debug) -o apiobot $(OBJS)
+ make apiobot MORE_CFLAGS="-DDEBUG -DLOCAL -g"
+
.c.o:
- $(CC) -c $< $(CFLAGS) -o $@
+ $(CC) $(CFLAGS) -c $< -o $@
run: all
./apiobot
diff --git a/bee.c b/bee.c
index f7d1270..41fc24d 100644
--- a/bee.c
+++ b/bee.c
@@ -3,11 +3,12 @@
#include <stdio.h>
+
int
main()
{
- if (!irc_connect()) { fputs("irc_connect\n",stderr); return 1; }
- if (!irc_handshake()) { fputs("irc_handshake\n",stderr); return 1; }
+ if (irc_connect()) { fputs("falure in irc_connect\n",stderr); return 1; }
+ if (irc_handshake()) { fputs("failure in irc_handshake\n",stderr); return 1; }
int x;
do {
diff --git a/conf.h b/conf.h
index 80d7181..96fbce5 100644
--- a/conf.h
+++ b/conf.h
@@ -25,9 +25,11 @@
printf(name " [%s]\n",__xxx); \
free(__xxx); \
} while (0)
+ #define DPf(...) fprintf(stderr,__VA_ARGS__)
#else
#define DP(x)
#define DPn(n,x,l)
+ #define DPf(...)
#endif
#define NICK "Bee"
diff --git a/irc.c b/irc.c
index 5c206bd..314c3b7 100644
--- a/irc.c
+++ b/irc.c
@@ -13,6 +13,8 @@ irc_connect()
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
+ printf("connecting to %s:%s....\n",HOST,PORT);
+
int status;
struct addrinfo *res;
if ((status = getaddrinfo(HOST, PORT, &hints, &res)) != 0) {
@@ -103,10 +105,16 @@ irc_recv()
return -1;
}
+ DPf("recieved %ld ",amt);
+
// find the end of a message
char *c;
char *end = recv_cur+amt;
char *msg_start = recv_buf;
+
+
+ DPn("BUF",recv_buf,end-recv_buf);
+
for (c=recv_buf; c<end; c++) {
if (*c == '\r' && *(c+1) == '\n') {
handle(msg_start, (c+2)-msg_start);
@@ -123,7 +131,11 @@ irc_recv()
fprintf(stderr,"my receive buffer is filled with NONSENSE!!!\n");
return -1;
}
- memmove(recv_buf, msg_start, remlen);
+ if (recv_buf != msg_start) {
+ DPf("mem moving %ld\n",remlen);
+ memmove(recv_buf, msg_start, remlen);
+ }
+ recv_cur = recv_buf + remlen;
}
return 0;
diff --git a/util.c b/util.c
index c545724..3c51df7 100644
--- a/util.c
+++ b/util.c
@@ -13,5 +13,5 @@ ssize_t sendall(int sockfd, void *buf, size_t len) {
total_sent += sent;
} while (total_sent < len);
DPn("SEND",buf,len);
- return total_sent;
+ return 0;
}