klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [BUILTIN] Simplify echo command
Commit-ID: 1fb4949c5a40f0bb6da7993a2ab034ec3b39477d Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=1fb4949c5a40f0bb6da7993a2ab034ec3b39477d 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: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [BUILTIN] Simplify echo command [ dash commit 7a784244625d5489c0fc779201c349555dc5f8bc ] 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; }
Reasonably Related Threads
- [klibc:update-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