diff --git a/format_output.c b/format_output.c index dc5ed18..49e667e 100644 --- a/format_output.c +++ b/format_output.c @@ -3,30 +3,17 @@ int main() { - int second = 0; static char *buf = NULL; static size_t size = 0; - ssize_t len = 0; - for (long n=1; (len = getline(&buf, &size, stdin)) > 0; n++) + long n = 1; + while(getline(&buf, &size, stdin) > 0) { - if (n < 5) + if (n++ < 5) /* overflow possible */ continue; - if (len && buf[len - 1] == '\n') - buf[len - 1] = '\0'; if (strncmp(buf,"-->", 3) == 0) - { - if (second) - { - second = 0; - } - else - { putchar('\n'); - second = 1; - } - } - else if (buf[0] != 0) /* Don't print newline at EOF */ - puts(buf); + else if (buf[0] != 10) + fputs(buf, stdout); } return 0; } diff --git a/popup.c b/popup.c index 97d5559..c4c142e 100644 --- a/popup.c +++ b/popup.c @@ -62,7 +62,7 @@ int get_max_len(char *string, XftFont *font, int max_text_width) eol--; } - for (int i = 0; i < eol; i++) + for (int i = 0; i < MIN(eol+1, strlen(string)); i++) if (string[i] == '\n') { string[i] = ' '; @@ -73,11 +73,9 @@ int get_max_len(char *string, XftFont *font, int max_text_width) while (eol && (string[eol] & 0xC0) == 0x80) --eol; - if (info.width <= max_text_width) - return eol; - - - /* prefer splitting at spaces */ + /* uncomment to always split at spaces */ + /* if (info.width <= max_text_width) */ + /* return eol; */ /* int temp = eol; */ /* while (string[eol] != ' ' && eol) */ /* --eol; */ @@ -141,7 +139,7 @@ int main() } free(buf); if (num_of_lines == 0) - die("stdin is empty"); + die("stdin is empty"); unsigned int text_height = font->ascent - font->descent; unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;