From c35641431f57525e54b33224f0fce3d17d7aec2e Mon Sep 17 00:00:00 2001 From: Einhard Leichtfuß Date: Mon, 2 Apr 2018 05:17:47 +0200 Subject: Split off code into passthrough_word() in parse.c --- parse.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/parse.c b/parse.c index 3134397..e8871d1 100644 --- a/parse.c +++ b/parse.c @@ -47,6 +47,9 @@ _Bool break_lines; /* set iff stdout is a tty */ unsigned short width; /* terminal width, not relevant if ! break_lines */ unsigned short n; /* actual broken line maximum length; excl. offsets */ +_Bool passthrough_word(); + + int main(int argc, char **argv) { if (argc < 3) @@ -96,30 +99,15 @@ int main(int argc, char **argv) cond_set_color(COLOR_NOCOLOR COLOR_BVIOLET); fputs("aur/", stdout); cond_set_color(COLOR_NOCOLOR COLOR_BWHITE); - while (1) - { - if (c == ' ') - break; - if (c == EOF || c == '\n') - return 1; - putchar(c); - c = getchar(); - } + ungetc(c, stdin); + if (! passthrough_word()) return 1; cond_set_color(COLOR_NOCOLOR); putchar(' '); /* Read and print version string - delimited by space. */ cond_set_color(COLOR_BGREEN); - while (1) - { - c = getchar(); - if (c == ' ') - break; - if (c == EOF || c == '\n') - return 1; - putchar(c); - } + if (! passthrough_word()) return 1; cond_set_color(COLOR_NOCOLOR); putchar('\n'); @@ -194,3 +182,19 @@ int main(int argc, char **argv) /* Should never be reached. */ return 0; } + + +_Bool passthrough_word() +{ + char c; + + while (1) + { + c = getchar(); + if (c == ' ') + return 1; + if (c == EOF || c == '\n') + return 0; + putchar(c); + } +} -- cgit v1.2.3