From 7a784244625d5489c0fc779201c349555dc5f8bc Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Mon, 27 Oct 2014 16:23:33 +0800 Subject: [BUILTIN] Simplify echo command Signed-off-by: Herbert Xu --- src/bltin/printf.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/bltin/printf.c b/src/bltin/printf.c index 6f39526..9673e10 100644 --- a/src/bltin/printf.c +++ b/src/bltin/printf.c @@ -442,33 +442,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; } -- cgit 1.4.1