aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2018-04-02 05:17:47 +0200
committerEinhard Leichtfuß <alguien@respiranto.de>2018-04-02 05:17:47 +0200
commitc35641431f57525e54b33224f0fce3d17d7aec2e (patch)
treed1bde8f03a4f1b41d8d38068bf73f76320645556
parent968e70b04478b3a1ecdab16f75e455cd3e6bab3c (diff)
downloadauria-c35641431f57525e54b33224f0fce3d17d7aec2e.tar.gz
auria-c35641431f57525e54b33224f0fce3d17d7aec2e.tar.xz
Split off code into passthrough_word() in parse.c
-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);
+ }
+}