hush: remove useless ESC_GLOB_CHARS clears/resotres
authorDenys Vlasenko <dvlasenk@redhat.com>
Fri, 10 Sep 2010 08:12:34 +0000 (10:12 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Fri, 10 Sep 2010 08:12:34 +0000 (10:12 +0200)
function                                             old     new   delta
o_addQstr                                             43     165    +122
expand_on_ifs                                        210     189     -21
expand_vars_to_list                                 1122    1094     -28
o_addqblock                                          139       -    -139
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 122/-188)          Total: -66 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
shell/hush.c

index 9c615275c086260999e126be11a9885ecbbbbe9d..b7aeab28cac91eb02b0ccb2798abbd9b9116ac6f 100644 (file)
@@ -4353,13 +4353,12 @@ static int expand_on_ifs(o_string *output, int n, const char *str)
        while (1) {
                int word_len = strcspn(str, G.ifs);
                if (word_len) {
-                       if (output->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)
-                               o_addqblock(output, str, word_len);
-                       else if (!(output->o_expflags & EXP_FLAG_GLOB))
+                       if (!(output->o_expflags & EXP_FLAG_GLOB))
                                o_addblock(output, str, word_len);
-                       else /* if (!escape && glob) */ {
+                       else {
                                /* Protect backslashes against globbing up :)
-                                * Example: "v='\*'; echo b$v"
+                                * Example: "v='\*'; echo b$v" prints "b\*"
+                                * (and does not try to glob on "*")
                                 */
                                o_addblock_duplicate_backslash(output, str, word_len);
                                /*/ Why can't we do it easier? */
@@ -4819,10 +4818,6 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
                        i = 1;
                        cant_be_null |= first_ch; /* do it for "$@" _now_, when we know it's not empty */
                        if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
-                               int sv = output->o_expflags;
-                               /* unquoted var's contents should be globbed, so don't escape */
-//TODO: make _caller_ set EXP_FLAG_ESC_GLOB_CHARS properly
-                               output->o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS;
                                while (G.global_argv[i]) {
                                        n = expand_on_ifs(output, n, G.global_argv[i]);
                                        debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, G.global_argc - 1);
@@ -4835,7 +4830,6 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
                                                debug_print_list("expand_vars_to_list[3]", output, n);
                                        }
                                }
-                               output->o_expflags = sv;
                        } else
                        /* If EXP_FLAG_SINGLEWORD, we handle assignment 'a=....$@.....'
                         * and in this case should treat it like '$*' - see 'else...' below */
@@ -4917,13 +4911,8 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
                                debug_printf_expand("unquoted '%s', output->o_escape:%d\n", val,
                                                !!(output->o_expflags & EXP_FLAG_ESC_GLOB_CHARS));
                                if (val && val[0]) {
-                                       /* unquoted var's contents should be globbed, so don't escape */
-                                       int sv = output->o_expflags;
-//TODO: make _caller_ set EXP_FLAG_ESC_GLOB_CHARS properly
-                                       output->o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS;
                                        n = expand_on_ifs(output, n, val);
                                        val = NULL;
-                                       output->o_expflags = sv;
                                }
                        } else { /* quoted $VAR, val will be appended below */
                                debug_printf_expand("quoted '%s', output->o_escape:%d\n", val,