Changeset 2859 in MondoRescue for branches/2.2.9/mindi-busybox/shell/hush.c


Ignore:
Timestamp:
Jul 26, 2011, 1:25:42 AM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update to upstream busybox 1.18.5
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/shell/hush.c

    r2725 r2859  
    428428#define NULL_O_STRING { NULL }
    429429
     430#ifndef debug_printf_parse
     431static const char *const assignment_flag[] = {
     432    "MAYBE_ASSIGNMENT",
     433    "DEFINITELY_ASSIGNMENT",
     434    "NOT_ASSIGNMENT",
     435    "WORD_IS_KEYWORD",
     436};
     437#endif
     438
    430439/* I can almost use ordinary FILE*.  Is open_memstream() universally
    431440 * available?  Where is it documented? */
     
    28862895    static const struct reserved_combo reserved_list[] = {
    28872896# if ENABLE_HUSH_IF
    2888         { "!",     RES_NONE,  NOT_ASSIGNMENT , 0 },
    2889         { "if",    RES_IF,    WORD_IS_KEYWORD, FLAG_THEN | FLAG_START },
    2890         { "then",  RES_THEN,  WORD_IS_KEYWORD, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
    2891         { "elif",  RES_ELIF,  WORD_IS_KEYWORD, FLAG_THEN },
    2892         { "else",  RES_ELSE,  WORD_IS_KEYWORD, FLAG_FI   },
    2893         { "fi",    RES_FI,    NOT_ASSIGNMENT , FLAG_END  },
     2897        { "!",     RES_NONE,  NOT_ASSIGNMENT  , 0 },
     2898        { "if",    RES_IF,    MAYBE_ASSIGNMENT, FLAG_THEN | FLAG_START },
     2899        { "then",  RES_THEN,  MAYBE_ASSIGNMENT, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
     2900        { "elif",  RES_ELIF,  MAYBE_ASSIGNMENT, FLAG_THEN },
     2901        { "else",  RES_ELSE,  MAYBE_ASSIGNMENT, FLAG_FI   },
     2902        { "fi",    RES_FI,    NOT_ASSIGNMENT  , FLAG_END  },
    28942903# endif
    28952904# if ENABLE_HUSH_LOOPS
    2896         { "for",   RES_FOR,   NOT_ASSIGNMENT , FLAG_IN | FLAG_DO | FLAG_START },
    2897         { "while", RES_WHILE, WORD_IS_KEYWORD, FLAG_DO | FLAG_START },
    2898         { "until", RES_UNTIL, WORD_IS_KEYWORD, FLAG_DO | FLAG_START },
    2899         { "in",    RES_IN,    NOT_ASSIGNMENT , FLAG_DO   },
    2900         { "do",    RES_DO,    WORD_IS_KEYWORD, FLAG_DONE },
    2901         { "done",  RES_DONE,  NOT_ASSIGNMENT , FLAG_END  },
     2905        { "for",   RES_FOR,   NOT_ASSIGNMENT  , FLAG_IN | FLAG_DO | FLAG_START },
     2906        { "while", RES_WHILE, MAYBE_ASSIGNMENT, FLAG_DO | FLAG_START },
     2907        { "until", RES_UNTIL, MAYBE_ASSIGNMENT, FLAG_DO | FLAG_START },
     2908        { "in",    RES_IN,    NOT_ASSIGNMENT  , FLAG_DO   },
     2909        { "do",    RES_DO,    MAYBE_ASSIGNMENT, FLAG_DONE },
     2910        { "done",  RES_DONE,  NOT_ASSIGNMENT  , FLAG_END  },
    29022911# endif
    29032912# if ENABLE_HUSH_CASE
    2904         { "case",  RES_CASE,  NOT_ASSIGNMENT , FLAG_MATCH | FLAG_START },
    2905         { "esac",  RES_ESAC,  NOT_ASSIGNMENT , FLAG_END  },
     2913        { "case",  RES_CASE,  NOT_ASSIGNMENT  , FLAG_MATCH | FLAG_START },
     2914        { "esac",  RES_ESAC,  NOT_ASSIGNMENT  , FLAG_END  },
    29062915# endif
    29072916    };
     
    29692978    ctx->old_flag = r->flag;
    29702979    word->o_assignment = r->assignment_flag;
     2980    debug_printf_parse("word->o_assignment='%s'\n", assignment_flag[word->o_assignment]);
    29712981
    29722982    if (ctx->old_flag & FLAG_END) {
     
    30353045        ctx->pending_redirect = NULL;
    30363046    } else {
    3037         /* If this word wasn't an assignment, next ones definitely
    3038          * can't be assignments. Even if they look like ones. */
    3039         if (word->o_assignment != DEFINITELY_ASSIGNMENT
    3040          && word->o_assignment != WORD_IS_KEYWORD
    3041         ) {
    3042             word->o_assignment = NOT_ASSIGNMENT;
    3043         } else {
    3044             if (word->o_assignment == DEFINITELY_ASSIGNMENT)
    3045                 command->assignment_cnt++;
    3046             word->o_assignment = MAYBE_ASSIGNMENT;
    3047         }
    3048 
    30493047#if HAS_KEYWORDS
    30503048# if ENABLE_HUSH_CASE
     
    30663064# endif
    30673065        ) {
    3068             debug_printf_parse("checking '%s' for reserved-ness\n", word->data);
    3069             if (reserved_word(word, ctx)) {
     3066            int reserved = reserved_word(word, ctx);
     3067            debug_printf_parse("checking for reserved-ness: %d\n", reserved);
     3068            if (reserved) {
    30703069                o_reset_to_empty_unquoted(word);
    30713070                debug_printf_parse("done_word return %d\n",
     
    30883087            return 1;
    30893088        }
     3089
     3090        /* If this word wasn't an assignment, next ones definitely
     3091         * can't be assignments. Even if they look like ones. */
     3092        if (word->o_assignment != DEFINITELY_ASSIGNMENT
     3093         && word->o_assignment != WORD_IS_KEYWORD
     3094        ) {
     3095            word->o_assignment = NOT_ASSIGNMENT;
     3096        } else {
     3097            if (word->o_assignment == DEFINITELY_ASSIGNMENT) {
     3098                command->assignment_cnt++;
     3099                debug_printf_parse("++assignment_cnt=%d\n", command->assignment_cnt);
     3100            }
     3101            debug_printf_parse("word->o_assignment was:'%s'\n", assignment_flag[word->o_assignment]);
     3102            word->o_assignment = MAYBE_ASSIGNMENT;
     3103        }
     3104        debug_printf_parse("word->o_assignment='%s'\n", assignment_flag[word->o_assignment]);
     3105
    30903106        if (word->has_quoted_part
    30913107         /* optimization: and if it's ("" or '') or ($v... or `cmd`...): */
     
    41064122            ) {
    41074123                dest.o_assignment = DEFINITELY_ASSIGNMENT;
     4124                debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]);
    41084125            }
    41094126            continue;
     
    41554172                }
    41564173                dest.o_assignment = MAYBE_ASSIGNMENT;
     4174                debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]);
    41574175                ch = ';';
    41584176                /* note: if (is_blank) continue;
     
    42044222            done_pipe(&ctx, PIPE_SEQ);
    42054223            dest.o_assignment = MAYBE_ASSIGNMENT;
     4224            debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]);
    42064225            /* Do we sit outside of any if's, loops or case's? */
    42074226            if (!HAS_KEYWORDS
     
    43104329             * cannot be an assignment */
    43114330            dest.o_assignment = NOT_ASSIGNMENT;
     4331            debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]);
    43124332        }
    43134333
     
    44074427             * with an assignment */
    44084428            dest.o_assignment = MAYBE_ASSIGNMENT;
     4429            debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]);
    44094430            break;
    44104431        case '&':
     
    72937314#if ENABLE_HUSH_LOOPS
    72947315        /* Beware of "while false; true; do ..."! */
    7295         if (pi->next && pi->next->res_word == RES_DO) {
     7316        if (pi->next
     7317         && (pi->next->res_word == RES_DO || pi->next->res_word == RES_DONE)
     7318        /* (the second check above is needed for "while ...; do \n done" case) */
     7319        ) {
    72967320            if (rword == RES_WHILE) {
    72977321                if (rcode) {
Note: See TracChangeset for help on using the changeset viewer.