X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=echo.c;h=6890d95e0b87a967ecb6c63f9d1b48deefe45b20;hb=d8ad76cb31ff7c4b2d97cc66eafc4297f5cea7d7;hp=b31f2229bb784e9b3ff39ade751f51ff137c44b7;hpb=59b9e870243c56a9c5ec045a925e4e9b3f1f6c3c;p=oweals%2Fbusybox.git diff --git a/echo.c b/echo.c index b31f2229b..6890d95e0 100644 --- a/echo.c +++ b/echo.c @@ -22,71 +22,43 @@ * Original copyright notice is retained at the end of this file. */ -#include "internal.h" +#include "busybox.h" #include -static const char uname_usage[] = - "echo [-neE] [ARG ...]\n" -#ifndef BB_FEATURE_TRIVIAL_HELP - "\nPrints the specified ARGs to stdout\n\n" - "Options:\n" - "\t-n\tsuppress trailing newline\n" - "\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n" - "\t-E\tdisable interpretation of backslash-escaped characters\n" -#endif - ; - extern int echo_main(int argc, char** argv) { register char **ap; - register char *p; - register char c; + char *p; + int c; int nflag = 0; int eflag = 0; - ap = argv; - if (argc) - ap++; - while ((p = *ap) != NULL && *p == '-') { - if (strcmp(p, "-n")==0) { + + while ((c = getopt(argc, argv, "neE")) != EOF) { + switch (c) { + case 'n': nflag = 1; - } else if (strcmp(p, "-e")==0) { + break; + case 'e': eflag = 1; - } else if (strcmp(p, "-E")==0) { + break; + case 'E': eflag = 0; + break; + default: + usage(echo_usage); } - else if (strncmp(p, "--", 2)==0) { - usage( uname_usage); - } - else break; - ap++; } + + ap = &argv[optind]; while ((p = *ap++) != NULL) { while ((c = *p++) != '\0') { if (c == '\\' && eflag) { - switch (c = *p++) { - case 'a': c = '\007'; break; - case 'b': c = '\b'; break; - case 'c': exit( 0); /* exit */ - case 'f': c = '\f'; break; - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'v': c = '\v'; break; - case '\\': break; /* c = '\\' */ - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - c -= '0'; - if (*p >= '0' && *p <= '7') - c = c * 8 + (*p++ - '0'); - if (*p >= '0' && *p <= '7') - c = c * 8 + (*p++ - '0'); - break; - default: - p--; - break; - } + if (*p == 'c') + exit(0); + else + c = process_escape_sequence(&p); } putchar(c); } @@ -96,7 +68,7 @@ echo_main(int argc, char** argv) if (! nflag) putchar('\n'); fflush(stdout); - exit( 0); + return( 0); } /*-