From a37b02d2d19b82eef410cd9acb116ff3a4eae55b Mon Sep 17 00:00:00 2001 From: Michael Czigler <37268479+mcpcpc@users.noreply.github.com> Date: Wed, 23 Sep 2020 11:25:47 -0400 Subject: second fix for wordwrap --- kirc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'kirc.c') diff --git a/kirc.c b/kirc.c index 21ba945..017e9ab 100644 --- a/kirc.c +++ b/kirc.c @@ -121,7 +121,7 @@ printw(const char *format, ...) { va_list argptr; char *tok, line[MSG_MAX]; - size_t i, wordwidth, spaceleft, spacewidth = 1; + size_t i, wordwidth, spaceleft = cmax, spacewidth = 1; va_start(argptr, format); vsnprintf(line, MSG_MAX, format, argptr); @@ -129,20 +129,19 @@ printw(const char *format, ...) { if (olog) log_append(line, olog); - for (i = 0; line[i] == ' '; ++i) putchar(line[i]); - - spaceleft = cmax - (i - 1); + for (i = 0; line[i] == ' '; ++i) { + putchar(line[i]); + } - for(tok = strtok(&line[i], " "); tok != NULL; tok = strtok(NULL, " ")) { + for(tok = strtok(line, " "); tok != NULL; tok = strtok(NULL, " ")) { wordwidth = strlen(tok); - if ((wordwidth + spacewidth) > spaceleft) { printf("\n%*.s%s ", (int) gutl + 1, " ", tok); - spaceleft = cmax - (gutl + 1 + wordwidth + spacewidth); + spaceleft = cmax - (gutl + 1); } else { printf("%s ", tok); - spaceleft = spaceleft - (wordwidth + spacewidth); } + spaceleft -= (wordwidth + spacewidth); } putchar('\n'); @@ -254,7 +253,7 @@ handle_user_input(void) { } static int -keyboardhit() { +keyboard_hit() { struct termios save, tp; int byteswaiting; @@ -323,7 +322,7 @@ main(int argc, char **argv) { if (fds[0].revents & POLLIN) { handle_user_input(); } - if (fds[1].revents & POLLIN && (keyboardhit() < 1)) { + if (fds[1].revents & POLLIN && (keyboard_hit() < 1)) { int rc = handle_server_message(); if (rc != 0) { if (rc == -2) return EXIT_FAILURE; -- cgit v1.2.3