Comment on kernel stuff
[oweals/busybox.git] / coreutils / echo.c
index 91f17aa0f4b51a9b8302ec6f54e544dfe7f284fb..6e279d1c6d332431249039bc7909ed76be635049 100644 (file)
 #include "internal.h"
 #include <stdio.h>
 
+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;
+       char *p;
        register char c;
        int nflag = 0;
        int eflag = 0;
@@ -45,34 +56,19 @@ echo_main(int argc, char** argv)
                } else if (strcmp(p, "-E")==0) {
                        eflag = 0;
                }
+               else if (strncmp(p, "--", 2)==0) {
+                       usage( uname_usage);
+               } 
                else break;
                ap++;
        }
        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);
                }
@@ -82,7 +78,7 @@ echo_main(int argc, char** argv)
        if (! nflag)
                putchar('\n');
        fflush(stdout);
-       exit( 0);
+       return( 0);
 }
 
 /*-