Signed-off-by: Herbert Xu <[email protected]>
---
ChangeLog | 1 +
src/bltin/printf.c | 28 ++++++++--------------------
2 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 60fd4b6..f015066 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@
* Remove getintmax in printf.
* Use error instead of warnx for fatal errors in printf.
* Optimise handling of backslash octals in printf.
+ * Simplify echo command.
2014-10-13 Eric Blake <[email protected]>
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;
}
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html