style change - irc - IRC client based on c9x.me/irc client (HTM) git clone git://git.codemadness.org/irc (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit fea5b2171f559a5aac7b38773659eca26064562d (DIR) parent 35d40adb208fd0c8ded353fb80b202d5f6f0b77e (HTM) Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu> Date: Tue, 3 May 2016 21:31:50 -0400 style change Diffstat: M irc.c | 501 +++++++++++++++++-------------- 1 file changed, 282 insertions(+), 219 deletions(-) --- (DIR) diff --git a/irc.c b/irc.c @@ -23,34 +23,42 @@ #undef CTRL #define CTRL(x) (x & 037) -#define SCROLL 15 -#define INDENT 23 -#define DATEFMT "%H:%M" -#define PFMT " %-12s < %s" +#define SCROLL 15 +#define INDENT 23 +#define DATEFMT "%H:%M" +#define PFMT " %-12s < %s" #define PFMTHIGH "> %-12s < %s" -#define SRV "irc.oftc.net" -#define PORT 6667 +#define SRV "irc.oftc.net" +#define PORT 6667 -enum { ChanLen = 64, LineLen = 512, MaxChans = 16, BufSz = 2048, LogSz = 4096 }; +enum { + ChanLen = 64, + LineLen = 512, + MaxChans = 16, + BufSz = 2048, + LogSz = 4096 +}; -char nick[64]; -int quit, winchg; -int sfd; /* Server file descriptor. */ struct { int x; int y; WINDOW *sw, *mw, *iw; -} scr; /* Screen relative data. */ +} scr; + struct Chan { char name[ChanLen]; char *buf, *eol; - int n; /* Scroll offset. */ - size_t sz; /* size of buf. */ + int n; /* Scroll offset. */ + size_t sz; /* Size of buf. */ char high; /* Nick highlight. */ - char new; /* New message. */ + char new; /* New message. */ } chl[MaxChans]; + +char nick[64]; +int quit, winchg; +int sfd; /* Server file descriptor. */ int nch, ch; /* Current number of channels, and current channel. */ -char outb[BufSz], *outp=outb; /* Output buffer. */ +char outb[BufSz], *outp = outb; /* Output buffer. */ static FILE *logfp; static void scmd(char *, char *, char *, char *); @@ -70,13 +78,14 @@ static void sndf(const char *fmt, ...) { va_list vl; - size_t n, l=BufSz-(outp-outb); + size_t n, l = BufSz - (outp - outb); - if (l<2) return; + if (l < 2) + return; va_start(vl, fmt); - n=vsnprintf(outp, l-2, fmt, vl); + n = vsnprintf(outp, l - 2, fmt, vl); va_end(vl); - outp += n>l-2 ? l-2 : n; + outp += n > l - 2 ? l - 2 : n; *outp++ = '\r'; *outp++ = '\n'; } @@ -84,40 +93,45 @@ sndf(const char *fmt, ...) static int srd(void) { - static char l[BufSz], *p=l; + static char l[BufSz], *p = l; char *s, *usr, *cmd, *par, *data; int rd; - if (p-l>=BufSz) p=l; /* Input buffer overflow, there should something better to do. */ - rd=read(sfd, p, BufSz-(p-l)); - if (rd<0) { - if (errno==EINTR) return 1; + if (p - l >= BufSz) + p = l; /* Input buffer overflow, there should something better to do. */ + rd = read(sfd, p, BufSz - (p - l)); + if (rd < 0) { + if (errno == EINTR) + return 1; panic("IO error while reading."); } - if (rd==0) return 0; - p+=rd; + if (rd == 0) + return 0; + p += rd; for (;;) { /* Cycle on all received lines. */ - if (!(s=memchr(l, '\n', p-l))) + if (!(s = memchr(l, '\n', p - l))) return 1; - if (s>l && s[-1]=='\r') - s[-1]=0; + if (s > l && s[-1] == '\r') + s[-1] = 0; *s++ = 0; - if (*l==':') { - if (!(cmd=strchr(l, ' '))) goto lskip; + if (*l == ':') { + if (!(cmd = strchr(l, ' '))) + goto lskip; *cmd++ = 0; - usr = l+1; + usr = l + 1; } else { usr = 0; cmd = l; } - if (!(par=strchr(cmd, ' '))) goto lskip; + if (!(par = strchr(cmd, ' '))) + goto lskip; *par++ = 0; - if ((data=strchr(par, ':'))) + if ((data = strchr(par, ':'))) *data++ = 0; scmd(usr, cmd, par, data); lskip: - memmove(l, s, p-s); - p-=s-l; + memmove(l, s, p - s); + p -= s - l; } } @@ -136,9 +150,9 @@ dial(const char *host, short port) sin.sin_port = htons(port); freeaddrinfo(ai); f = socket(AF_INET, SOCK_STREAM, 0); - if (f<0) + if (f < 0) panic("Cannot create socket."); - if (connect(f, (struct sockaddr *)&sin, sizeof sin)<0) + if (connect(f, (struct sockaddr *)&sin, sizeof sin) < 0) panic("Cannot connect to host."); return f; } @@ -146,16 +160,16 @@ dial(const char *host, short port) static int chadd(char *name) { - if (nch>=MaxChans || strlen(name)>=ChanLen) + if (nch >= MaxChans || strlen(name) >= ChanLen) return -1; strcpy(chl[nch].name, name); - chl[nch].sz=LogSz; - chl[nch].buf=malloc(LogSz); + chl[nch].sz = LogSz; + chl[nch].buf = malloc(LogSz); if (!chl[nch].buf) panic("Out of memory."); - chl[nch].eol=chl[nch].buf; - chl[nch].n=0; - ch=nch++; + chl[nch].eol = chl[nch].buf; + chl[nch].n = 0; + ch = nch++; tdrawbar(); return nch; } @@ -166,7 +180,7 @@ chfind(char *name) int i; assert(name); - for (i=nch-1; i>0; i--) + for (i = nch - 1; i > 0; i--) if (!strcmp(chl[i].name, name)) break; return i; @@ -177,11 +191,12 @@ chdel(char *name) { int n; - if (!(n=chfind(name))) return 0; + if (!(n = chfind(name))) + return 0; nch--; free(chl[n].buf); - memmove(&chl[n], &chl[n+1], (nch-n)*sizeof(struct Chan)); - ch=nch-1; + memmove(&chl[n], &chl[n + 1], (nch - n) * sizeof(struct Chan)); + ch = nch - 1; tdrawbar(); return 1; } @@ -192,19 +207,22 @@ pushl(char *p, char *e) int x; char *w; - if ((w=memchr(p, '\n', e-p))) e=w+1; - for (w=p, x=0;; p++, x++) { - if (x>=scr.x) { + if ((w = memchr(p, '\n', e - p))) + e = w + 1; + for (w = p, x = 0;; p++, x++) { + if (x >= scr.x) { waddch(scr.mw, '\n'); - for (x=0; x<INDENT; x++) + for (x = 0; x < INDENT; x++) waddch(scr.mw, ' '); - if (*w==' ') w++; - x+=p-w; + if (*w == ' ') + w++; + x += p - w; } - if (p>=e || *p==' ' || p-w+INDENT>=scr.x-1) { - for (; w<p; w++) + if (p >= e || *p == ' ' || p - w + INDENT >= scr.x - 1) { + for (; w < p; w++) waddch(scr.mw, *w); - if (p>=e) return e; + if (p >= e) + return e; } } } @@ -212,47 +230,51 @@ pushl(char *p, char *e) static void pushf(int cn, const char *fmt, ...) { - struct Chan *const c=&chl[cn]; - size_t n, blen=c->eol-c->buf; + struct Chan *const c = &chl[cn]; + size_t n, blen = c->eol - c->buf; va_list vl; time_t t; char *s; struct tm *tm, *gmtm; - if (blen+LineLen>=c->sz) { + if (blen + LineLen >= c->sz) { c->sz *= 2; - c->buf=realloc(c->buf, c->sz); - if (!c->buf) panic("Out of memory."); - c->eol=c->buf+blen; + c->buf = realloc(c->buf, c->sz); + if (!c->buf) + panic("Out of memory."); + c->eol = c->buf + blen; } - t=time(0); - if (!(tm=localtime(&t))) panic("Localtime failed."); - n=strftime(c->eol, LineLen, DATEFMT, tm); - if (!(gmtm=gmtime(&t))) panic("Gmtime failed."); + t = time(0); + if (!(tm = localtime(&t))) + panic("Localtime failed."); + n = strftime(c->eol, LineLen, DATEFMT, tm); + if (!(gmtm = gmtime(&t))) + panic("Gmtime failed."); c->eol[n++] = ' '; va_start(vl, fmt); s = c->eol + n; - n+=vsnprintf(s, LineLen-n-1, fmt, vl); + n += vsnprintf(s, LineLen - n - 1, fmt, vl); va_end(vl); if (logfp) { fprintf(logfp, "%-12.12s\t%04d-%02d-%02dT%02d:%02d:%02dZ\t%s\n", c->name, gmtm->tm_year + 1900, gmtm->tm_mon + 1, gmtm->tm_mday, - gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec, - s); + gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec, s); fflush(logfp); } strcat(c->eol, "\n"); - if (n>=LineLen-1) - c->eol+=LineLen-1; + if (n >= LineLen - 1) + c->eol += LineLen - 1; else - c->eol+=n+1; - if (cn==ch && c->n==0) { - char *p=c->eol-n-1; - if (p!=c->buf) waddch(scr.mw, '\n'); - pushl(p, c->eol-1); + c->eol += n + 1; + if (cn == ch && c->n == 0) { + char *p = c->eol - n - 1; + + if (p != c->buf) + waddch(scr.mw, '\n'); + pushl(p, c->eol - 1); wrefresh(scr.mw); } } @@ -261,43 +283,49 @@ static void scmd(char *usr, char *cmd, char *par, char *data) { int s, c; - char *pm=strtok(par, " "); + char *pm = strtok(par, " "); - if (!usr) usr="?"; + if (!usr) + usr = "?"; else { - char *bang=strchr(usr, '!'); + char *bang = strchr(usr, '!'); if (bang) - *bang=0; + *bang = 0; } if (!strcmp(cmd, "PRIVMSG")) { - if (!pm || !data) return; - c=chfind(pm); + if (!pm || !data) + return; + c = chfind(pm); if (strcasestr(data, nick)) { pushf(c, PFMTHIGH, usr, data); chl[c].high |= ch != c; - } else + } else pushf(c, PFMT, usr, data); if (ch != c) { - chl[c].new=1; + chl[c].new = 1; tdrawbar(); } } else if (!strcmp(cmd, "PING")) { - sndf("PONG :%s", data?data:"(null)"); + sndf("PONG :%s", data ? data : "(null)"); } else if (!strcmp(cmd, "PART")) { - if (!pm) return; + if (!pm) + return; pushf(chfind(pm), "-!- %s has left %s", usr, pm); } else if (!strcmp(cmd, "JOIN")) { - if (!pm) return; + if (!pm) + return; pushf(chfind(pm), "-!- %s has joined %s", usr, pm); } else if (!strcmp(cmd, "470")) { /* Channel forwarding. */ - char *ch=strtok(0, " "), *fch=strtok(0, " "); - if (!ch || !fch || !(s=chfind(ch))) return; + char *ch = strtok(0, " "), *fch = strtok(0, " "); + + if (!ch || !fch || !(s = chfind(ch))) + return; chl[s].name[0] = 0; - strncat(chl[s].name, fch, ChanLen-1); + strncat(chl[s].name, fch, ChanLen - 1); tdrawbar(); } else if (!strcmp(cmd, "471") || !strcmp(cmd, "473") - || !strcmp(cmd, "474") || !strcmp(cmd, "475")) { /* Join error. */ - if ((pm=strtok(0, " "))) { + || !strcmp(cmd, "474") || !strcmp(cmd, "475")) { /* Join error. */ + if ((pm = strtok(0, " "))) { chdel(pm); pushf(0, "-!- Cannot join channel %s (%s)", pm, cmd); tredraw(); @@ -306,53 +334,58 @@ scmd(char *usr, char *cmd, char *par, char *data) return; } else if (!strcmp(cmd, "NOTICE") || !strcmp(cmd, "375") || !strcmp(cmd, "372") || !strcmp(cmd, "376")) { - pushf(0, "%s", data?data:""); + pushf(0, "%s", data ? data : ""); } else - pushf(0, "%s - %s %s", cmd, par, data?data:"(null)"); + pushf(0, "%s - %s %s", cmd, par, data ? data : "(null)"); } static void uparse(char *m) { - char *p=m; + char *p = m; - if (!p[0] || (p[1]!=' ' && p[1]!=0)) { + if (!p[0] || (p[1] != ' ' && p[1] != 0)) { pmsg: - if (ch==0) return; - m+=strspn(m, " "); - if (!*m) return; + if (ch == 0) + return; + m += strspn(m, " "); + if (!*m) + return; pushf(ch, PFMT, nick, m); sndf("PRIVMSG %s :%s", chl[ch].name, m); return; } switch (*p) { case 'j': /* Join channels. */ - p+=1+(p[1]==' '); - p=strtok(p, " "); + p += 1 + (p[1] == ' '); + p = strtok(p, " "); while (p) { - if (chadd(p)<0) break; + if (chadd(p) < 0) + break; sndf("JOIN %s", p); - p=strtok(0, " "); + p = strtok(0, " "); } tredraw(); return; case 'l': /* Leave channels. */ - p+=1+(p[1]==' '); + p += 1 + (p[1] == ' '); if (!*p) { - if (ch==0) return; /* Cannot leave server window. */ + if (ch == 0) + return; /* Cannot leave server window. */ strcat(p, chl[ch].name); } - p=strtok(p, " "); + p = strtok(p, " "); while (p) { if (chdel(p)) sndf("PART %s", p); - p=strtok(0, " "); + p = strtok(0, " "); } tredraw(); return; case 'm': /* Private message. */ - m=p+1+(p[1]==' '); - if (!(p=strchr(m, ' '))) return; + m = p + 1 + (p[1] == ' '); + if (!(p = strchr(m, ' '))) + return; *p++ = 0; sndf("PRIVMSG %s :%s", m, p); return; @@ -361,7 +394,7 @@ uparse(char *m) sndf("%s", &p[2]); return; case 'q': /* Quit. */ - quit=1; + quit = 1; return; default: /* Send on current channel. */ goto pmsg; @@ -371,7 +404,8 @@ uparse(char *m) static void sigwinch(int sig) { - if (sig) winchg=1; + if (sig) + winchg = 1; } static void @@ -383,14 +417,15 @@ tinit(void) raw(); noecho(); getmaxyx(stdscr, scr.y, scr.x); - if (scr.y<4) panic("Screen too small."); - if ((scr.sw=newwin(1, scr.x, 0, 0))==0 - || (scr.mw=newwin(scr.y-2, scr.x, 1, 0))==0 - || (scr.iw=newwin(1, scr.x, scr.y-1, 0))==0) + if (scr.y < 4) + panic("Screen too small."); + if ((scr.sw = newwin(1, scr.x, 0, 0)) == 0 + || (scr.mw = newwin(scr.y - 2, scr.x, 1, 0)) == 0 + || (scr.iw = newwin(1, scr.x, scr.y - 1, 0)) == 0) panic("Cannot create windows."); keypad(scr.iw, 1); scrollok(scr.mw, 1); - if (has_colors()==TRUE) { + if (has_colors() == TRUE) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgd(scr.sw, COLOR_PAIR(1)); @@ -402,16 +437,16 @@ tresize(void) { struct winsize ws; - winchg=0; - if (ioctl(0, TIOCGWINSZ, &ws)<0) + winchg = 0; + if (ioctl(0, TIOCGWINSZ, &ws) < 0) panic("Ioctl (TIOCGWINSZ) failed."); - resizeterm(scr.y=ws.ws_row, scr.x=ws.ws_col); - if (scr.y<3 || scr.x<10) + resizeterm(scr.y = ws.ws_row, scr.x = ws.ws_col); + if (scr.y < 3 || scr.x < 10) panic("Screen too small."); - wresize(scr.mw, scr.y-2, scr.x); + wresize(scr.mw, scr.y - 2, scr.x); wresize(scr.iw, 1, scr.x); wresize(scr.sw, 1, scr.x); - mvwin(scr.iw, scr.y-1, 0); + mvwin(scr.iw, scr.y - 1, 0); tredraw(); tdrawbar(); } @@ -419,43 +454,49 @@ tresize(void) static void tredraw(void) { - struct Chan *const c=&chl[ch]; + struct Chan *const c = &chl[ch]; char *q, *p; - int llen=0, nl=-1; + int llen = 0, nl = -1; - if (c->eol==c->buf) { + if (c->eol == c->buf) { wclear(scr.mw); wrefresh(scr.mw); return; } - p=c->eol-1; + p = c->eol - 1; if (c->n) { - int i=c->n; - for (; p>c->buf; p--) - if (*p=='\n' && !i--) break; - if (p==c->buf) c->n-=i; + int i = c->n; + + for (; p > c->buf; p--) + if (*p == '\n' && !i--) + break; + if (p == c->buf) + c->n -= i; } - q=p; - while (nl<scr.y-2) { - llen=0; - while (*q!='\n' && q>c->buf) + q = p; + while (nl < scr.y - 2) { + llen = 0; + while (*q != '\n' && q > c->buf) q--, llen++; - nl += 1+llen/scr.x; - if (q==c->buf) break; + nl += 1 + llen / scr.x; + if (q == c->buf) + break; q--; } - if (q!=c->buf) q+=2; - for (llen=0; nl>scr.y-2; ) { /* Maybe we must split the top line. */ - if (q[llen]=='\n' || llen>=scr.x) { - q+=llen+(q[llen]=='\n'); - llen=0; + if (q != c->buf) + q += 2; + for (llen = 0; nl > scr.y - 2;) { /* Maybe we must split the top line. */ + if (q[llen] == '\n' || llen >= scr.x) { + q += llen + (q[llen] == '\n'); + llen = 0; nl--; - } else llen++; + } else + llen++; } wclear(scr.mw); wmove(scr.mw, 0, 0); - while (q<p) - q=pushl(q, p); + while (q < p) + q = pushl(q, p); wrefresh(scr.mw); } @@ -463,24 +504,28 @@ static void tdrawbar(void) { size_t l; - int fst=ch; + int fst = ch; - for (l=0; fst>0 && l<scr.x/2; fst--) - l+=strlen(chl[fst].name)+3; + for (l = 0; fst > 0 && l < scr.x / 2; fst--) + l += strlen(chl[fst].name) + 3; werase(scr.sw); - for (l=0; fst<nch && l<scr.x; fst++) { - char *p=chl[fst].name; + for (l = 0; fst < nch && l < scr.x; fst++) { + char *p = chl[fst].name; - if (fst==ch) wattron(scr.sw, A_BOLD); + if (fst == ch) + wattron(scr.sw, A_BOLD); waddch(scr.sw, '['), l++; - if (chl[fst].high) waddch(scr.sw, '>'), l++; - else if (chl[fst].new) waddch(scr.sw, '+'), l++; - for (; *p && l<scr.x; p++, l++) + if (chl[fst].high) + waddch(scr.sw, '>'), l++; + else if (chl[fst].new) + waddch(scr.sw, '+'), l++; + for (; *p && l < scr.x; p++, l++) waddch(scr.sw, *p); - if (l<scr.x-1) - waddstr(scr.sw, "] "), l+=2; - if (fst==ch) wattroff(scr.sw, A_BOLD); + if (l < scr.x - 1) + waddstr(scr.sw, "] "), l += 2; + if (fst == ch) + wattroff(scr.sw, A_BOLD); } wrefresh(scr.sw); } @@ -490,103 +535,113 @@ tgetch(void) { static char l[BufSz]; static size_t shft, cu, len; - size_t dirty=len+1, i; + size_t dirty = len + 1, i; int c; - c=wgetch(scr.iw); + c = wgetch(scr.iw); switch (c) { case CTRL('n'): - ch=(ch+1)%nch; - chl[ch].high=chl[ch].new=0; + ch = (ch + 1) % nch; + chl[ch].high = chl[ch].new = 0; tdrawbar(); tredraw(); return; case CTRL('p'): - ch=(ch+nch-1)%nch; - chl[ch].high=chl[ch].new=0; + ch = (ch + nch - 1) % nch; + chl[ch].high = chl[ch].new = 0; tdrawbar(); tredraw(); return; case KEY_PPAGE: - chl[ch].n+=SCROLL; + chl[ch].n += SCROLL; tredraw(); return; case KEY_NPAGE: - chl[ch].n-=SCROLL; - if (chl[ch].n<0) chl[ch].n=0; + chl[ch].n -= SCROLL; + if (chl[ch].n < 0) + chl[ch].n = 0; tredraw(); return; case CTRL('a'): - cu=0; + cu = 0; break; case CTRL('e'): - cu=len; + cu = len; break; case CTRL('b'): case KEY_LEFT: - if (cu) cu--; + if (cu) + cu--; break; case CTRL('f'): case KEY_RIGHT: - if (cu<len) cu++; + if (cu < len) + cu++; break; case CTRL('k'): - dirty=len=cu; + dirty = len = cu; break; case CTRL('u'): - if (cu==0) return; - len-=cu; + if (cu == 0) + return; + len -= cu; memmove(l, &l[cu], len); - dirty=cu=0; + dirty = cu = 0; break; case CTRL('d'): - if (cu>=len) return; - memmove(&l[cu], &l[cu+1], len-cu-1); - dirty=cu; + if (cu >= len) + return; + memmove(&l[cu], &l[cu + 1], len - cu - 1); + dirty = cu; len--; break; case KEY_BACKSPACE: - if (cu==0) return; - memmove(&l[cu-1], &l[cu], len-cu); - dirty=--cu; + if (cu == 0) + return; + memmove(&l[cu - 1], &l[cu], len - cu); + dirty = --cu; len--; break; case '\n': - l[len]=0; + l[len] = 0; uparse(l); - dirty=cu=len=0; + dirty = cu = len = 0; break; default: - if (c>CHAR_MAX || len>=BufSz-1) return; /* Skip other curses codes. */ - memmove(&l[cu+1], &l[cu], len-cu); - dirty=cu; + if (c > CHAR_MAX || len >= BufSz - 1) + return; /* Skip other curses codes. */ + memmove(&l[cu + 1], &l[cu], len - cu); + dirty = cu; len++; - l[cu++]=c; + l[cu++] = c; break; } - while (cu<shft) - dirty=0, shft -= shft>=scr.x/2 ? scr.x/2 : shft; - while (cu>=scr.x+shft) - dirty=0, shft += scr.x/2; - if (dirty<=shft) - i=shft; - else if (dirty>scr.x+shft || dirty>len) + while (cu < shft) + dirty = 0, shft -= shft >= scr.x / 2 ? scr.x / 2 : shft; + while (cu >= scr.x + shft) + dirty = 0, shft += scr.x / 2; + if (dirty <= shft) + i = shft; + else if (dirty > scr.x + shft || dirty > len) goto mvcur; else - i=dirty; - wmove(scr.iw, 0, i-shft); + i = dirty; + wmove(scr.iw, 0, i - shft); wclrtoeol(scr.iw); - for (; i-shft<scr.x && i<len; i++) + for (; i - shft < scr.x && i < len; i++) waddch(scr.iw, l[i]); -mvcur: wmove(scr.iw, 0, cu-shft); +mvcur: wmove(scr.iw, 0, cu - shft); } static void treset(void) { - if (scr.mw) delwin(scr.mw); - if (scr.sw) delwin(scr.sw); - if (scr.iw) delwin(scr.iw); + if (scr.mw) + delwin(scr.mw); + if (scr.sw) + delwin(scr.sw); + if (scr.iw) + delwin(scr.iw); endwin(); } @@ -599,7 +654,7 @@ main(int argc, char *argv[]) unsigned short port = PORT; int o; - while ((o=getopt(argc, argv, "hn:u:s:p:l:"))>=0) + while ((o = getopt(argc, argv, "hn:u:s:p:l:")) >= 0) switch (o) { case 'h': case '?': @@ -607,11 +662,12 @@ main(int argc, char *argv[]) fputs("usage: irc [-n NICK] [-u USER] [-s SERVER] [-p PORT] [-l LOGFILE ] [-h]\n", stderr); exit(0); case 'l': - if (!(logfp=fopen(optarg, "a"))) + if (!(logfp = fopen(optarg, "a"))) panic("fopen: logfile"); break; case 'n': - if (strlen(optarg)>=sizeof nick) goto usage; + if (strlen(optarg) >= sizeof nick) + goto usage; strcpy(nick, optarg); break; case 'u': @@ -621,21 +677,25 @@ main(int argc, char *argv[]) server = optarg; break; case 'p': - if (!(port=strtol(optarg, 0, 0))) goto usage; + if (!(port = strtol(optarg, 0, 0))) + goto usage; break; } - if (!nick[0] && ircnick && strlen(ircnick)<sizeof nick) + if (!nick[0] && ircnick && strlen(ircnick) < sizeof nick) strcpy(nick, ircnick); - if (!nick[0]) goto usage; - if (!user) user="anonymous"; + if (!nick[0]) + goto usage; + if (!user) + user = "anonymous"; tinit(); - sfd=dial(server, port); + sfd = dial(server, port); chadd("*server*"); sndf("NICK %s", nick); sndf("USER %s 8 * :%s", user, user); sndf("MODE %s +i", nick); while (!quit) { fd_set rfs, wfs; + int ret; if (winchg) @@ -644,28 +704,31 @@ main(int argc, char *argv[]) FD_ZERO(&rfs); FD_SET(0, &rfs); FD_SET(sfd, &rfs); - if (outp!=outb) + if (outp != outb) FD_SET(sfd, &wfs); - ret=select(sfd+1, &rfs, &wfs, 0, 0); - if (ret<0) { - if (errno==EINTR) continue; + ret = select(sfd + 1, &rfs, &wfs, 0, 0); + if (ret < 0) { + if (errno == EINTR) + continue; panic("Select failed."); } if (FD_ISSET(sfd, &rfs)) { if (!srd()) - quit=1; + quit = 1; } if (FD_ISSET(sfd, &wfs)) { int wr; - wr=write(sfd, outb, outp-outb); - if (wr<0) { - if (errno==EINTR) continue; + wr = write(sfd, outb, outp - outb); + if (wr < 0) { + if (errno == EINTR) + continue; panic("Write error."); } - if (wr==0) continue; - outp-=wr; - memmove(outb, outb+wr, outp-outb); + if (wr == 0) + continue; + outp -= wr; + memmove(outb, outb + wr, outp - outb); } if (FD_ISSET(0, &rfs)) { tgetch();