Changeset 2859 in MondoRescue for branches/2.2.9/mindi-busybox/shell
- Timestamp:
- Jul 26, 2011, 1:25:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/shell/hush.c
r2725 r2859 428 428 #define NULL_O_STRING { NULL } 429 429 430 #ifndef debug_printf_parse 431 static const char *const assignment_flag[] = { 432 "MAYBE_ASSIGNMENT", 433 "DEFINITELY_ASSIGNMENT", 434 "NOT_ASSIGNMENT", 435 "WORD_IS_KEYWORD", 436 }; 437 #endif 438 430 439 /* I can almost use ordinary FILE*. Is open_memstream() universally 431 440 * available? Where is it documented? */ … … 2886 2895 static const struct reserved_combo reserved_list[] = { 2887 2896 # 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 }, 2894 2903 # endif 2895 2904 # 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 }, 2902 2911 # endif 2903 2912 # 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 }, 2906 2915 # endif 2907 2916 }; … … 2969 2978 ctx->old_flag = r->flag; 2970 2979 word->o_assignment = r->assignment_flag; 2980 debug_printf_parse("word->o_assignment='%s'\n", assignment_flag[word->o_assignment]); 2971 2981 2972 2982 if (ctx->old_flag & FLAG_END) { … … 3035 3045 ctx->pending_redirect = NULL; 3036 3046 } else { 3037 /* If this word wasn't an assignment, next ones definitely3038 * can't be assignments. Even if they look like ones. */3039 if (word->o_assignment != DEFINITELY_ASSIGNMENT3040 && word->o_assignment != WORD_IS_KEYWORD3041 ) {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 3049 3047 #if HAS_KEYWORDS 3050 3048 # if ENABLE_HUSH_CASE … … 3066 3064 # endif 3067 3065 ) { 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) { 3070 3069 o_reset_to_empty_unquoted(word); 3071 3070 debug_printf_parse("done_word return %d\n", … … 3088 3087 return 1; 3089 3088 } 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 3090 3106 if (word->has_quoted_part 3091 3107 /* optimization: and if it's ("" or '') or ($v... or `cmd`...): */ … … 4106 4122 ) { 4107 4123 dest.o_assignment = DEFINITELY_ASSIGNMENT; 4124 debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); 4108 4125 } 4109 4126 continue; … … 4155 4172 } 4156 4173 dest.o_assignment = MAYBE_ASSIGNMENT; 4174 debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); 4157 4175 ch = ';'; 4158 4176 /* note: if (is_blank) continue; … … 4204 4222 done_pipe(&ctx, PIPE_SEQ); 4205 4223 dest.o_assignment = MAYBE_ASSIGNMENT; 4224 debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); 4206 4225 /* Do we sit outside of any if's, loops or case's? */ 4207 4226 if (!HAS_KEYWORDS … … 4310 4329 * cannot be an assignment */ 4311 4330 dest.o_assignment = NOT_ASSIGNMENT; 4331 debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); 4312 4332 } 4313 4333 … … 4407 4427 * with an assignment */ 4408 4428 dest.o_assignment = MAYBE_ASSIGNMENT; 4429 debug_printf_parse("dest.o_assignment='%s'\n", assignment_flag[dest.o_assignment]); 4409 4430 break; 4410 4431 case '&': … … 7293 7314 #if ENABLE_HUSH_LOOPS 7294 7315 /* 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 ) { 7296 7320 if (rword == RES_WHILE) { 7297 7321 if (rcode) {
Note:
See TracChangeset
for help on using the changeset viewer.