Skip to content

Commit a37b02d

Browse files
authored
second fix for wordwrap
1 parent 62c4b0c commit a37b02d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

kirc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,27 @@ printw(const char *format, ...) {
121121

122122
va_list argptr;
123123
char *tok, line[MSG_MAX];
124-
size_t i, wordwidth, spaceleft, spacewidth = 1;
124+
size_t i, wordwidth, spaceleft = cmax, spacewidth = 1;
125125

126126
va_start(argptr, format);
127127
vsnprintf(line, MSG_MAX, format, argptr);
128128
va_end(argptr);
129129

130130
if (olog) log_append(line, olog);
131131

132-
for (i = 0; line[i] == ' '; ++i) putchar(line[i]);
133-
134-
spaceleft = cmax - (i - 1);
132+
for (i = 0; line[i] == ' '; ++i) {
133+
putchar(line[i]);
134+
}
135135

136-
for(tok = strtok(&line[i], " "); tok != NULL; tok = strtok(NULL, " ")) {
136+
for(tok = strtok(line, " "); tok != NULL; tok = strtok(NULL, " ")) {
137137
wordwidth = strlen(tok);
138-
139138
if ((wordwidth + spacewidth) > spaceleft) {
140139
printf("\n%*.s%s ", (int) gutl + 1, " ", tok);
141-
spaceleft = cmax - (gutl + 1 + wordwidth + spacewidth);
140+
spaceleft = cmax - (gutl + 1);
142141
} else {
143142
printf("%s ", tok);
144-
spaceleft = spaceleft - (wordwidth + spacewidth);
145143
}
144+
spaceleft -= (wordwidth + spacewidth);
146145
}
147146

148147
putchar('\n');
@@ -254,7 +253,7 @@ handle_user_input(void) {
254253
}
255254

256255
static int
257-
keyboardhit() {
256+
keyboard_hit() {
258257

259258
struct termios save, tp;
260259
int byteswaiting;
@@ -323,7 +322,7 @@ main(int argc, char **argv) {
323322
if (fds[0].revents & POLLIN) {
324323
handle_user_input();
325324
}
326-
if (fds[1].revents & POLLIN && (keyboardhit() < 1)) {
325+
if (fds[1].revents & POLLIN && (keyboard_hit() < 1)) {
327326
int rc = handle_server_message();
328327
if (rc != 0) {
329328
if (rc == -2) return EXIT_FAILURE;

0 commit comments

Comments
 (0)