diff options
| author | John Vogel <jvogel4@stny.rr.com> | 2015-12-06 11:33:14 -0500 |
|---|---|---|
| committer | John Vogel <jvogel4@stny.rr.com> | 2015-12-06 11:33:14 -0500 |
| commit | 171720bd86ef5f5f5cfff5a839df0f5a24f82460 (patch) | |
| tree | deb04431830c98ec8f8348b5d4d185d9e2091f78 /cic.c | |
| parent | cac955deb5f193ffd9e62213f744890488f35060 (diff) | |
| download | cic-171720bd86ef5f5f5cfff5a839df0f5a24f82460.tar.gz | |
Adjust pout, getinput and args for paging
Diffstat (limited to 'cic.c')
| -rw-r--r-- | cic.c | 49 |
1 files changed, 47 insertions, 2 deletions
@@ -8,7 +8,10 @@ #include <time.h> #include <unistd.h> #include <signal.h> +#include <limits.h> #include <sys/ioctl.h> +#include <sys/types.h> +#include <pwd.h> #include <errno.h> #include <curses.h> @@ -20,14 +23,17 @@ char *argv0; static char *host = DEFAULT_HOST; static char *port = DEFAULT_PORT; -static char *password; +static char *password = NULL; static char nick[32]; static char bufsrv[4096]; static char bufin[4096]; static char bufout[4096]; static char channel[256]; +static char logfile[PATH_MAX]; static time_t trespond; static FILE *srv; +static FILE *log; +static long logstartpos; static WINDOW *viewwin; static WINDOW *barwin; static WINDOW *inputwin; @@ -37,6 +43,7 @@ static int running; static int got_sigwinch; #include "util.c" +#include "page.c" static void pout(char *channel, char *fmt, ...) { @@ -50,6 +57,7 @@ pout(char *channel, char *fmt, ...) { t = time(NULL); strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t)); wprintw(viewwin, "%-12s: %s %s\n", channel, timestr, bufout); + fprintf(log, "%-12s: %s %s\n", channel, timestr, bufout); wrefresh(viewwin); wrefresh(inputwin); } @@ -172,6 +180,12 @@ int getinput(char *buf, size_t sz) wclrtoeol(inputwin); wrefresh(inputwin); goto done; + case CONTROL('P'): + displayfile(log, 0, rows-2, cols, 0, 0); + touchwin(viewwin); + wrefresh(viewwin); + wrefresh(inputwin); + break; case KEY_BACKSPACE: if (pos) { pos--; @@ -249,6 +263,8 @@ void sigwinch(int unused) void cleanup(void) { + fclose(srv); + fclose(log); if (!isendwin()) endwin(); } @@ -262,6 +278,7 @@ int main(int argc, char *argv[]) { struct sigaction sa; struct timeval tv; + struct passwd *pw; const char *user = getenv("USER"); int n; fd_set rd; @@ -271,6 +288,7 @@ main(int argc, char *argv[]) { if (!isatty(STDOUT_FILENO)) eprint("cic: stdout is not a terminal"); + logfile[0] = '\0'; strlcpy(nick, user ? user : "unknown", sizeof nick); ARGBEGIN { case 'h': @@ -285,6 +303,11 @@ main(int argc, char *argv[]) { case 'k': password = EARGF(usage()); break; + case 'l': + /* TODO: needs checking for truncation; we check for PATH_MAX + * later, not PATH_MAX-1 */ + strlcpy(logfile, EARGF(usage()), sizeof logfile); + break; case 'v': eprint("cic-"VERSION", © 2005-2014 Kris Maglione, Anselm R. Garbe, Nico Golde, John Vogel\n"); break; @@ -302,9 +325,28 @@ main(int argc, char *argv[]) { sa.sa_handler = sigwinch; sigaction(SIGWINCH, &sa, NULL); + if (!logfile[0]) { + while ((pw = getpwuid(getuid())) == NULL) + if (errno != EINTR) + eprint("getpwuid:"); + n = snprintf(logfile, PATH_MAX, "%s/%s", pw->pw_dir, DEFAULT_LOG); + } + else { + n = strlen(logfile); + } + if (n >= PATH_MAX) + eprint("log file path (%d) exceeds PATH_MAX (%d)", n, PATH_MAX); + log = fopen(logfile, "a+"); + if (!log) + eprint("fopen:"); + fseek(log, 0, SEEK_END); + logstartpos = ftell(log); + srv = fdopen(dial(host, port), "r+"); - if (!srv) + if (!srv) { + fclose(log); eprint("fdopen:"); + } /* login (PASS doesn't seem to work on oftc, but works on freenode) */ if(password) @@ -313,6 +355,7 @@ main(int argc, char *argv[]) { sout("USER %s localhost %s :%s", nick, host, nick); fflush(srv); setbuf(srv, NULL); + setbuf(log, NULL); /* curses init */ initscr(); @@ -340,6 +383,8 @@ main(int argc, char *argv[]) { wrefresh(barwin); wrefresh(inputwin); + pout("cic main", "--- started logging (pos=%ld)---", logstartpos); + running = 1; got_sigwinch = 0; while (running) { /* main loop */ |
