summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cic.c36
-rw-r--r--util.c2
2 files changed, 16 insertions, 22 deletions
diff --git a/cic.c b/cic.c
index 6a11478..3801996 100644
--- a/cic.c
+++ b/cic.c
@@ -35,7 +35,6 @@ static int rows;
static int cols;
static int running;
static int got_sigwinch;
-static int curline;
#include "util.c"
@@ -45,20 +44,12 @@ pout(char *channel, char *fmt, ...) {
time_t t;
va_list ap;
- /*if (curline == rows-3) {
- wscrl(viewwin, 1);
- curline -= 1;
- }
- else
- curline++;*/
-
va_start(ap, fmt);
vsnprintf(bufout, sizeof bufout, fmt, ap);
va_end(ap);
t = time(NULL);
strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t));
wprintw(viewwin, "%-12s: %s %s\n", channel, timestr, bufout);
- //mvwprintw(viewwin, curline, 0, "%-12s: %s %s", channel, timestr, bufout);
wrefresh(viewwin);
wrefresh(inputwin);
}
@@ -214,7 +205,7 @@ void gettermsize(void)
while (ioctl(STDIN_FILENO, TIOCGWINSZ, &w) == -1)
if (errno != EINTR) {
- endwin();
+ //endwin();
eprint("cic: failed to get term size");
}
rows = w.ws_row;
@@ -256,6 +247,11 @@ void sigwinch(int unused)
got_sigwinch = 1;
}
+void cleanup(void)
+{
+ if (!isendwin())
+ endwin();
+}
static void
usage(void) {
@@ -307,11 +303,10 @@ main(int argc, char *argv[]) {
sigaction(SIGWINCH, &sa, NULL);
srv = fdopen(dial(host, port), "r+");
- if (!srv) {
- endwin();
+ if (!srv)
eprint("fdopen:");
- }
- /* login */
+
+ /* login (PASS doesn't seem to work on oftc, but works on freenode) */
if(password)
sout("PASS %s", password);
sout("NICK %s", nick);
@@ -330,8 +325,11 @@ main(int argc, char *argv[]) {
timeout(0);
refresh();
+ atexit(cleanup);
+
gettermsize();
+ /* window init */
viewwin = newwin(rows - 2, cols, 0, 0);
idlok(viewwin, TRUE);
scrollok(viewwin, TRUE);
@@ -358,22 +356,17 @@ main(int argc, char *argv[]) {
if(n < 0) {
if(errno == EINTR)
continue;
- endwin();
eprint("cic: error on select():");
}
else if(n == 0) {
- if(time(NULL) - trespond >= 300) {
- endwin();
+ if(time(NULL) - trespond >= 300)
eprint("cic shutting down: parse timeout\n");
- }
sout("PING %s", host);
continue;
}
if(FD_ISSET(fileno(srv), &rd)) {
- if(fgets(bufsrv, sizeof bufin, srv) == NULL) {
- endwin();
+ if(fgets(bufsrv, sizeof bufin, srv) == NULL)
eprint("cic: remote host closed connection\n");
- }
parsesrv(bufsrv);
trespond = time(NULL);
}
@@ -383,6 +376,5 @@ main(int argc, char *argv[]) {
}
}
- endwin();
return 0;
}
diff --git a/util.c b/util.c
index 8afa58f..aa11896 100644
--- a/util.c
+++ b/util.c
@@ -7,6 +7,8 @@ static void
eprint(const char *fmt, ...) {
va_list ap;
+ if (!isendwin())
+ endwin();
va_start(ap, fmt);
vsnprintf(bufout, sizeof bufout, fmt, ap);
va_end(ap);