hush: delete hush-bugs/glob_and_vars.tests for real
[oweals/busybox.git] / shell / ash.c
index fa063bf2016c080918cfd33c412a47d8db295a9f..b490b69f1c3a52647a8f60dd971cc8da5f4c5fee 100644 (file)
@@ -1258,7 +1258,7 @@ stunalloc(void *p)
 {
 #if DEBUG
        if (!p || (g_stacknxt < (char *)p) || ((char *)p < g_stackp->space)) {
-               write(2, "stunalloc\n", 10);
+               write(STDERR_FILENO, "stunalloc\n", 10);
                abort();
        }
 #endif
@@ -5818,73 +5818,26 @@ parse_sub_pattern(char *arg, int inquotes)
        char *idx, *repl = NULL;
        unsigned char c;
 
-       for (idx = arg; *arg; arg++) {
-               if (*arg == '/') {
-                       /* Only the first '/' seen is our seperator */
+       idx = arg;
+       while (1) {
+               c = *arg;
+               if (!c)
+                       break;
+               if (c == '/') {
+                       /* Only the first '/' seen is our separator */
                        if (!repl) {
-                               *idx++ = '\0';
-                               repl = idx;
-                       } else
-                               *idx++ = *arg;
-                       } else if (*arg != '\\') {
-                               *idx++ = *arg;
-                       } else {
-                               if (inquotes)
-                                       arg++;
-                               else {
-                                       if (*(arg + 1) != '\\')
-                                               goto single_backslash;
-                                       arg += 2;
-                               }
-
-                       switch (*arg) {
-                       case 'n':       c = '\n'; break;
-                       case 'r':       c = '\r'; break;
-                       case 't':       c = '\t'; break;
-                       case 'v':       c = '\v'; break;
-                       case 'f':       c = '\f'; break;
-                       case 'b':       c = '\b'; break;
-                       case 'a':       c = '\a'; break;
-                       case '\\':
-                               if (*(arg + 1) != '\\' && !inquotes)
-                                       goto single_backslash;
-                               arg++;
-                               /* FALLTHROUGH */
-                       case '\0':
-                               /* Trailing backslash, just stuff one in the buffer
-                                * and backup arg so the loop will exit.
-                                */
-                               c = '\\';
-                               if (!*arg)
-                                       arg--;
-                               break;
-                       default:
-                               c = *arg;
-                               if (isdigit(c)) {
-                                       /* It's an octal number, parse it. */
-                                       int i;
-                                       c = 0;
-
-                                       for (i = 0; *arg && i < 3; arg++, i++) {
-                                               if (*arg >= '8' || *arg < '0')
-                                                       ash_msg_and_raise_error("Invalid octal char in pattern");
-// TODO: number() instead? It does error checking...
-                                               c = (c << 3) + atoi(arg);
-                                       }
-                                       /* back off one (so outer loop can do it) */
-                                       arg--;
-                               }
+                               repl = idx + 1;
+                               c = '\0';
                        }
-                       *idx++ = c;
                }
+               *idx++ = c;
+               if (!inquotes && c == '\\' && arg[1] == '\\')
+                       arg++; /* skip both \\, not just first one */
+               arg++;
        }
-       *idx = *arg;
+       *idx = c; /* NUL */
 
        return repl;
-
- single_backslash:
-       ash_msg_and_raise_error("single backslash unexpected");
-       /* NOTREACHED */
 }
 #endif /* ENABLE_ASH_BASH_COMPAT */
 
@@ -8488,17 +8441,18 @@ static int ulimitcmd(int, char **);
  * Apart from the above, [[ expr ]] should work as [ expr ]
  */
 
-#define testcmd test_main
-#define echocmd echo_main
+#define echocmd   echo_main
+#define printfcmd printf_main
+#define testcmd   test_main
 
 /* Keep these in proper order since it is searched via bsearch() */
 static const struct builtincmd builtintab[] = {
        { BUILTIN_SPEC_REG      ".", dotcmd },
        { BUILTIN_SPEC_REG      ":", truecmd },
 #if ENABLE_ASH_BUILTIN_TEST
-       { BUILTIN_REGULAR       "[", testcmd },
+       { BUILTIN_REGULAR       "[", testcmd },
 #if ENABLE_ASH_BASH_COMPAT
-       { BUILTIN_REGULAR       "[[", testcmd },
+       { BUILTIN_REGULAR       "[[", testcmd },
 #endif
 #endif
 #if ENABLE_ASH_ALIAS
@@ -8540,6 +8494,9 @@ static const struct builtincmd builtintab[] = {
        { BUILTIN_NOSPEC        "let", letcmd },
 #endif
        { BUILTIN_ASSIGN        "local", localcmd },
+#if ENABLE_ASH_BUILTIN_PRINTF
+       { BUILTIN_REGULAR       "printf", printfcmd },
+#endif
        { BUILTIN_NOSPEC        "pwd", pwdcmd },
        { BUILTIN_REGULAR       "read", readcmd },
        { BUILTIN_SPEC_REG_ASSG "readonly", exportcmd },
@@ -8548,7 +8505,7 @@ static const struct builtincmd builtintab[] = {
        { BUILTIN_SPEC_REG      "shift", shiftcmd },
        { BUILTIN_SPEC_REG      "source", dotcmd },
 #if ENABLE_ASH_BUILTIN_TEST
-       { BUILTIN_REGULAR       "test", testcmd },
+       { BUILTIN_REGULAR       "test", testcmd },
 #endif
        { BUILTIN_SPEC_REG      "times", timescmd },
        { BUILTIN_SPEC_REG      "trap", trapcmd },
@@ -10761,7 +10718,7 @@ parsesub: {
 #if ENABLE_ASH_MATH_SUPPORT
                        PARSEARITH();
 #else
-                       raise_error_syntax("We unsupport $((arith))");
+                       raise_error_syntax("you disabled math support for $((arith)) syntax");
 #endif
                } else {
                        pungetc();