diff options
author | Michael Czigler <37268479+mcpcpc@users.noreply.github.com> | 2020-09-23 11:25:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-23 11:25:47 -0400 |
commit | a37b02d2d19b82eef410cd9acb116ff3a4eae55b (patch) | |
tree | 447e5a8ae5f60aa3d968d8eaf2021e147d79ec62 | |
parent | Update kirc.c (diff) | |
download | kirc-a37b02d2d19b82eef410cd9acb116ff3a4eae55b.tar.gz kirc-a37b02d2d19b82eef410cd9acb116ff3a4eae55b.tar.bz2 kirc-a37b02d2d19b82eef410cd9acb116ff3a4eae55b.tar.xz kirc-a37b02d2d19b82eef410cd9acb116ff3a4eae55b.tar.zst kirc-a37b02d2d19b82eef410cd9acb116ff3a4eae55b.zip |
second fix for wordwrap
-rw-r--r-- | kirc.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -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; |