From 5e54e4f51dbb781ae5cb7c57b20affde3dbe1e9e Mon Sep 17 00:00:00 2001 From: mcpcpc Date: Mon, 10 Aug 2020 07:18:23 -0400 Subject: possible fix for garbage printing with ':m' README: fix usage for password 2nd attempt to fix garbage printing fix typo 2nd fix cleanup guard against accidental WAIT_SIG read move WAIT_SIG check after garbage cleanup experiment with disabling echo update update update enable backspace in stdin from virtual terminal update --- README | 2 +- kirc.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README b/README index 0245fa9..61bb387 100644 --- a/README +++ b/README @@ -50,6 +50,6 @@ usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-k password] [-v|V] -p server port (default: '6667') -c channel name (default: '#kisslinux') -n user nickname --n user password +-k user password -v version information -V verbose output (e.g. raw stream) diff --git a/kirc.c b/kirc.c index 820cc05..457173d 100644 --- a/kirc.c +++ b/kirc.c @@ -29,9 +29,10 @@ kbhit(void) { int byteswaiting; struct termios term; + term.c_cc[VERASE] = 127; + tcgetattr(0, &term); fd_set fds; struct timespec ts = {0}; - tcgetattr(0, &term); struct termios term2 = term; @@ -54,7 +55,7 @@ raw(char *fmt, ...) { vsnprintf(sbuf, BUFF, fmt, ap); va_end(ap); - if (verb) printf("<< %s", sbuf); + if (verb) printf("<< \x1b[33m%s\x1b[0m", sbuf); write(conn, sbuf, strlen(sbuf)); } @@ -127,7 +128,7 @@ pars(int sl, char *buf) { buf_c[o + 1] = '\0'; o = -1; - if (verb) printf(">> %s", buf_c); + if (verb) printf(">> \x1b[33m%s\x1b[0m", buf_c); if (!strncmp(buf_c, "PING", 4)) { buf_c[1] = 'O'; @@ -164,7 +165,7 @@ main(int argc, char **argv) { while ((cval = getopt(argc, argv, "s:p:n:k:c:vV")) != -1) { switch (cval) { - case 'v' : printf("kirc 0.0.1\n"); break; + case 'v' : puts("kirc 0.0.1"); break; case 'V' : verb = 1; break; case 's' : host = optarg; break; case 'p' : port = optarg; break; @@ -188,15 +189,17 @@ main(int argc, char **argv) { pid_t pid = fork(); if (pid == 0) { - int sl; + int sl, i, j; char u[CMAX]; con(); while ((sl = read(conn, sbuf, BUFF))) { pars(sl, sbuf); - if ((read(fd[0], u, CMAX) > 0) && !strstr(u, "WAIT_SIG")) { - raw("%s\r\n", u); + if (read(fd[0], u, CMAX) > 0) { + for (i = 0; u[i] != '\n'; i++) continue; + for (j = i; j < CMAX; j++) u[j] = ' '; + if (!strstr(u, "WAIT_SIG")) raw("%-*.*s\r\n", i, i, u); } } printf("(press to quit)\n"); @@ -216,12 +219,11 @@ main(int argc, char **argv) { switch (usrin[1]) { case 'q': - write(fd[1], "quit", sizeof("quit")); + dprintf(fd[1],"quit\n"); break; case 'm': while (isspace(*cmd_val)) cmd_val++; - dprintf(fd[1], "privmsg #%s :%-*s", \ - chan, CMAX - strlen(chan) - 11, cmd_val); + dprintf(fd[1], "privmsg #%s :%s", chan, cmd_val); break; } } -- cgit v1.2.3