klibc-bot for Herbert Xu
2019-Jan-25 03:15 UTC
[klibc] [klibc:update-dash] [BUILTIN] Simplify echo command
Commit-ID: f835bc21ece0ec55824bd7538e4c2a04489812ef Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=f835bc21ece0ec55824bd7538e4c2a04489812ef Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Mon, 27 Oct 2014 16:23:33 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Fri, 25 Jan 2019 02:57:21 +0000 [klibc] [BUILTIN] Simplify echo command Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/bltin/printf.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/usr/dash/bltin/printf.c b/usr/dash/bltin/printf.c index 0e150d36..d4ae794d 100644 --- a/usr/dash/bltin/printf.c +++ b/usr/dash/bltin/printf.c @@ -448,33 +448,21 @@ check_conversion(const char *s, const char *ep) int echocmd(int argc, char **argv) { - int nonl = 0; - struct output *outs = out1; - - if (!*++argv) - goto end; - if (equal(*argv, "-n")) { - nonl = ~nonl; - if (!*++argv) - goto end; - } + int nonl; + + nonl = *++argv ? equal(*argv, "-n") : 0; + argv += nonl; do { int c; - nonl += print_escape_str("%s", NULL, NULL, *argv); + if (likely(*argv)) + nonl += print_escape_str("%s", NULL, NULL, *argv++); if (nonl > 0) break; - c = ' '; - if (!*++argv) { -end: - if (nonl) { - break; - } - c = '\n'; - } - outc(c, outs); + c = *argv ? ' ' : '\n'; + out1c(c); } while (*argv); return 0; }
Possibly Parallel Threads
- [klibc:update-dash] dash: [BUILTIN] Simplify echo command
- [klibc:update-dash] builtin: Move echo space/nl handling into print_escape_str
- [klibc:update-dash] dash: builtin: Move echo space/nl handling into print_escape_str
- [klibc:update-dash] [BUILTIN] Handle embedded NULs correctly in printf
- [klibc:update-dash] dash: [BUILTIN] Handle embedded NULs correctly in printf