diff options
Diffstat (limited to 'toys/posix/echo.c')
-rw-r--r-- | toys/posix/echo.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/toys/posix/echo.c b/toys/posix/echo.c index 70f4ce5e..639f87ab 100644 --- a/toys/posix/echo.c +++ b/toys/posix/echo.c @@ -9,19 +9,18 @@ * We also honor -- to _stop_ option parsing (bash doesn't, we go with * consistency over compatibility here). -USE_ECHO(NEWTOY(echo, "^?Een[-eE]", TOYFLAG_BIN|TOYFLAG_MAYFORK)) +USE_ECHO(NEWTOY(echo, "^?en", TOYFLAG_BIN)) config ECHO bool "echo" default y help - usage: echo [-neE] [args...] + usage: echo [-ne] [args...] Write each argument to stdout, with one space between each, followed by a newline. -n No trailing newline - -E Print escape sequences literally (default) -e Process the following escape sequences: \\ Backslash \0NNN Octal values (1 to 3 digits) @@ -51,7 +50,7 @@ void echo_main(void) // Should we output arg verbatim? - if (!FLAG(e)) { + if (!(toys.optflags & FLAG_e)) { xprintf("%s", arg); continue; } @@ -66,7 +65,7 @@ void echo_main(void) int slash = *(c++), n = unescape(slash); if (n) out = n; - else if (slash=='c') return; + else if (slash=='c') goto done; else if (slash=='0') { out = 0; while (*c>='0' && *c<='7' && n++<3) out = (out*8)+*(c++)-'0'; @@ -79,13 +78,7 @@ void echo_main(void) if (temp>='a' && temp<='f') { out = (out*16)+temp-'a'+10; c++; - } else { - if (n==1) { - --c; - out = '\\'; - } - break; - } + } else break; } } // Slash in front of unknown character, print literal. @@ -96,5 +89,7 @@ void echo_main(void) } // Output "\n" if no -n - if (!FLAG(n)) putchar('\n'); + if (!(toys.optflags&FLAG_n)) putchar('\n'); +done: + xflush(); } |