aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.c40
1 files 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);
+ }
+}