Permalink
Browse files

Things generally are now buffer-aware

  • Loading branch information...
1 parent ceabeb9 commit a9c16e9e9d12010d5962eac26b4585a34987f1ed Sound and Fury committed Jul 27, 2010
Showing with 473 additions and 449 deletions.
  1. +4 −0 bits.h
  2. +20 −0 buffer.c
  3. +7 −2 buffer.h
  4. +1 −4 irc.h
  5. +441 −443 quirc.c
View
4 bits.h
@@ -10,6 +10,10 @@
#include <stdlib.h>
#include <string.h>
+// helper fn macros
+#define max(a,b) ((a)>(b)?(a):(b))
+#define min(a,b) ((a)<(b)?(a):(b))
+
int width, height; // term size (set in quirc.c)
char * fgetl(FILE *); // gets a line of string data; returns a malloc-like pointer (preserves trailing \n)
View
@@ -13,6 +13,9 @@ int init_buffer(buffer *buf, btype type, char *bname, int nlines)
buf->type=type;
buf->bname=bname;
buf->nlist=NULL;
+ buf->handle=0;
+ buf->server=NULL;
+ buf->nick=NULL;
buf->nlines=nlines;
buf->ptr=0;
buf->lc=(colour *)malloc(nlines*sizeof(colour));
@@ -25,6 +28,7 @@ int init_buffer(buffer *buf, btype type, char *bname, int nlines)
int add_to_buffer(buffer *buf, colour lc, char *lt)
{
buf->lc[buf->ptr]=lc;
+ if(buf->filled) free(buf->lt[buf->ptr]);
buf->lt[buf->ptr]=strdup(lt);
buf->ts[buf->ptr]=time(NULL);
buf->ptr=(buf->ptr+1)%buf->nlines;
@@ -44,3 +48,19 @@ int buf_print(buffer *buf, colour lc, char *lt, bool nl)
return(add_to_buffer(buf, lc, lt));
return(0);
}
+
+void in_update(char *inp)
+{
+ printf(LOCATE, height, 1);
+ int ino=inp?strlen(inp):0;
+ if(ino>78)
+ {
+ int off=20*max((ino+27-width)/20, 0);
+ printf("%.10s ... %s" CLR, inp, inp+off+10);
+ }
+ else
+ {
+ printf("%s" CLR, inp?inp:"");
+ }
+ fflush(stdout);
+}
View
@@ -26,15 +26,18 @@ typedef enum
STATUS,
SERVER,
CHANNEL,
- PRIVATE
+ PRIVATE // right now we don't have handy private chat, you just have to /msg in a server or channel
}
btype;
-typedef struct
+typedef struct _buf
{
btype type;
char *bname; // "status" or serverloc or #channel or nick (resp. types)
name *nlist; // only used for channels and private
+ int handle; // used for server
+ struct _buf *server; //used by channels and private to denote their 'parent' server. In server, points to self
+ char *nick; // used for server
int nlines;
int ptr;
colour *lc;
@@ -44,8 +47,10 @@ typedef struct
}
buffer;
+int nbufs;
buffer *bufs;
int init_buffer(buffer *buf, btype type, char *bname, int nlines);
int add_to_buffer(buffer *buf, colour lc, char *lt);
int buf_print(buffer *buf, colour lc, char *lt, bool nl); // don't include trailing \n, because buf_print appends CLR \n
+void in_update(char *inp);
View
5 irc.h
@@ -16,10 +16,7 @@
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
-
-// helper fn macros
-#define max(a,b) ((a)>(b)?(a):(b))
-#define min(a,b) ((a)<(b)?(a):(b))
+#include "bits.h"
int irc_connect(char *server, char *portno, char *nick, char *username, char *fullname, fd_set *master, int *fdmax);
int irc_tx(int fd, char * packet);
Oops, something went wrong.

0 comments on commit a9c16e9

Please sign in to comment.