diff options
author | Rob Landley <rob@landley.net> | 2015-01-06 12:07:20 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-01-06 12:07:20 -0600 |
commit | cc39d95a344240bec8f0c74a02c74d54620b735d (patch) | |
tree | 3698fdd43caf67cac4eb3e1a13cd8b6a3474a5b2 /toys/pending | |
parent | a8df744605cb95dfb4bdd45ff64f7932166cc907 (diff) | |
download | toybox-cc39d95a344240bec8f0c74a02c74d54620b735d.tar.gz |
More printf cleanup, and test suite entries.
Fixes bug introduced last time where toys.optargs was both snapshotted and used
directly and the two fell out of sync.
Diffstat (limited to 'toys/pending')
-rw-r--r-- | toys/pending/printf.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/toys/pending/printf.c b/toys/pending/printf.c index b683128f..3d1a73f2 100644 --- a/toys/pending/printf.c +++ b/toys/pending/printf.c @@ -14,8 +14,7 @@ config PRINTF usage: printf FORMAT [ARGUMENT...] Format and print ARGUMENT(s) according to FORMAT, using C printf syntax - (percent escapes for cdeEfgGiosuxX, slash escapes for \abefnrtv0 or - \0OCT or 0xHEX). + (% escapes for cdeEfgGiosuxX, \ escapes for abefnrtv0 or \OCTAL or \xHEX). */ #define FOR_printf @@ -50,9 +49,9 @@ static char *get_format(char *f) } // Print arguments with corresponding conversion and width and precision. -static void print(char *fmt, int w, int p) +static void print(char *fmt, int w, int p, char *arg) { - char *ptr = fmt, *ep = 0, *format = 0, *arg = *toys.optargs; + char *ptr = fmt, *ep = 0, *format = 0; errno = 0; if (strchr("diouxX", *ptr)) { @@ -145,7 +144,7 @@ void printf_main(void) for (f = format; *f; f++) { if (eat(&f, '\\')) putchar(handle_slash(&f)); - else if (*f != '%' || *++f == '%') xputc(*f); + else if (!eat(&f, '%') || *f == '%') putchar(*f); else if (*f == 'b') for (p = *arg ? *(arg++) : ""; *p; p++) putchar(eat(&p, '\\') ? handle_slash(&p) : *p); @@ -163,7 +162,7 @@ void printf_main(void) if (!eat(&f, '.')) break; } if (!(p = strchr("diouxXfeEgGcs", *f))) - perror_exit("bad format@%ld", f-format); + error_exit("bad format@%ld", f-format); else { int len = f-start; @@ -172,7 +171,7 @@ void printf_main(void) //pitfall: handle diff b/w * and .* if ((TT.hv_w-1) == TT.hv_p) TT.hv_w = NULL; memcpy((p = xzalloc(len+1)), start, len); - print(p+len-1, wp[0], wp[1]); + print(p+len-1, wp[0], wp[1], *arg); if (*arg) arg++; free(p); p = NULL; |