diff options
author | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-02-13 09:44:44 +0000 |
commit | dc19a361bd6c6df30338371532691bbc7f7126bb (patch) | |
tree | 1fb2cd646d54b5f8e425c4f11f3e09fc21d1966b /editors | |
parent | 096aee2bb468d1ab044de36e176ed1f6c7e3674d (diff) | |
parent | 3459024bf404af814cacfe90a0deb719e282ae62 (diff) | |
download | busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.gz busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.tar.bz2 busybox-w32-dc19a361bd6c6df30338371532691bbc7f7126bb.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/editors/awk.c b/editors/awk.c index 1a273ff2e..9d74d931d 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2518,6 +2518,32 @@ static var *evaluate(node *op, var *res) | |||
2518 | op1 = op->l.n; | 2518 | op1 = op->l.n; |
2519 | debug_printf_eval("opinfo:%08x opn:%08x\n", opinfo, opn); | 2519 | debug_printf_eval("opinfo:%08x opn:%08x\n", opinfo, opn); |
2520 | 2520 | ||
2521 | /* "delete" is special: | ||
2522 | * "delete array[var--]" must evaluate index expr only once, | ||
2523 | * must not evaluate it in "execute inevitable things" part. | ||
2524 | */ | ||
2525 | if (XC(opinfo & OPCLSMASK) == XC(OC_DELETE)) { | ||
2526 | uint32_t info = op1->info & OPCLSMASK; | ||
2527 | var *v; | ||
2528 | |||
2529 | debug_printf_eval("DELETE\n"); | ||
2530 | if (info == OC_VAR) { | ||
2531 | v = op1->l.v; | ||
2532 | } else if (info == OC_FNARG) { | ||
2533 | v = &fnargs[op1->l.aidx]; | ||
2534 | } else { | ||
2535 | syntax_error(EMSG_NOT_ARRAY); | ||
2536 | } | ||
2537 | if (op1->r.n) { /* array ref? */ | ||
2538 | const char *s; | ||
2539 | s = getvar_s(evaluate(op1->r.n, v1)); | ||
2540 | hash_remove(iamarray(v), s); | ||
2541 | } else { | ||
2542 | clear_array(iamarray(v)); | ||
2543 | } | ||
2544 | goto next; | ||
2545 | } | ||
2546 | |||
2521 | /* execute inevitable things */ | 2547 | /* execute inevitable things */ |
2522 | if (opinfo & OF_RES1) | 2548 | if (opinfo & OF_RES1) |
2523 | L.v = evaluate(op1, v1); | 2549 | L.v = evaluate(op1, v1); |
@@ -2625,28 +2651,7 @@ static var *evaluate(node *op, var *res) | |||
2625 | break; | 2651 | break; |
2626 | } | 2652 | } |
2627 | 2653 | ||
2628 | case XC( OC_DELETE ): { | 2654 | /* case XC( OC_DELETE ): - moved to happen before arg evaluation */ |
2629 | uint32_t info = op1->info & OPCLSMASK; | ||
2630 | var *v; | ||
2631 | |||
2632 | if (info == OC_VAR) { | ||
2633 | v = op1->l.v; | ||
2634 | } else if (info == OC_FNARG) { | ||
2635 | v = &fnargs[op1->l.aidx]; | ||
2636 | } else { | ||
2637 | syntax_error(EMSG_NOT_ARRAY); | ||
2638 | } | ||
2639 | |||
2640 | if (op1->r.n) { | ||
2641 | const char *s; | ||
2642 | clrvar(L.v); | ||
2643 | s = getvar_s(evaluate(op1->r.n, v1)); | ||
2644 | hash_remove(iamarray(v), s); | ||
2645 | } else { | ||
2646 | clear_array(iamarray(v)); | ||
2647 | } | ||
2648 | break; | ||
2649 | } | ||
2650 | 2655 | ||
2651 | case XC( OC_NEWSOURCE ): | 2656 | case XC( OC_NEWSOURCE ): |
2652 | g_progname = op->l.new_progname; | 2657 | g_progname = op->l.new_progname; |
@@ -2670,12 +2675,14 @@ static var *evaluate(node *op, var *res) | |||
2670 | /* -- recursive node type -- */ | 2675 | /* -- recursive node type -- */ |
2671 | 2676 | ||
2672 | case XC( OC_VAR ): | 2677 | case XC( OC_VAR ): |
2678 | debug_printf_eval("VAR\n"); | ||
2673 | L.v = op->l.v; | 2679 | L.v = op->l.v; |
2674 | if (L.v == intvar[NF]) | 2680 | if (L.v == intvar[NF]) |
2675 | split_f0(); | 2681 | split_f0(); |
2676 | goto v_cont; | 2682 | goto v_cont; |
2677 | 2683 | ||
2678 | case XC( OC_FNARG ): | 2684 | case XC( OC_FNARG ): |
2685 | debug_printf_eval("FNARG[%d]\n", op->l.aidx); | ||
2679 | L.v = &fnargs[op->l.aidx]; | 2686 | L.v = &fnargs[op->l.aidx]; |
2680 | v_cont: | 2687 | v_cont: |
2681 | res = op->r.n ? findvar(iamarray(L.v), R.s) : L.v; | 2688 | res = op->r.n ? findvar(iamarray(L.v), R.s) : L.v; |
@@ -3039,7 +3046,8 @@ static var *evaluate(node *op, var *res) | |||
3039 | 3046 | ||
3040 | default: | 3047 | default: |
3041 | syntax_error(EMSG_POSSIBLE_ERROR); | 3048 | syntax_error(EMSG_POSSIBLE_ERROR); |
3042 | } | 3049 | } /* switch */ |
3050 | next: | ||
3043 | if ((opinfo & OPCLSMASK) <= SHIFT_TIL_THIS) | 3051 | if ((opinfo & OPCLSMASK) <= SHIFT_TIL_THIS) |
3044 | op = op->a.n; | 3052 | op = op->a.n; |
3045 | if ((opinfo & OPCLSMASK) >= RECUR_FROM_THIS) | 3053 | if ((opinfo & OPCLSMASK) >= RECUR_FROM_THIS) |
@@ -3145,7 +3153,7 @@ static rstream *next_input_file(void) | |||
3145 | } | 3153 | } |
3146 | 3154 | ||
3147 | int awk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 3155 | int awk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
3148 | int awk_main(int argc, char **argv) | 3156 | int awk_main(int argc UNUSED_PARAM, char **argv) |
3149 | { | 3157 | { |
3150 | unsigned opt; | 3158 | unsigned opt; |
3151 | char *opt_F; | 3159 | char *opt_F; |
@@ -3214,7 +3222,7 @@ int awk_main(int argc, char **argv) | |||
3214 | } | 3222 | } |
3215 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); | 3223 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); |
3216 | argv += optind; | 3224 | argv += optind; |
3217 | argc -= optind; | 3225 | //argc -= optind; |
3218 | if (opt & OPT_W) | 3226 | if (opt & OPT_W) |
3219 | bb_error_msg("warning: option -W is ignored"); | 3227 | bb_error_msg("warning: option -W is ignored"); |
3220 | if (opt & OPT_F) { | 3228 | if (opt & OPT_F) { |
@@ -3251,15 +3259,14 @@ int awk_main(int argc, char **argv) | |||
3251 | if (!*argv) | 3259 | if (!*argv) |
3252 | bb_show_usage(); | 3260 | bb_show_usage(); |
3253 | parse_program(*argv++); | 3261 | parse_program(*argv++); |
3254 | argc--; | ||
3255 | } | 3262 | } |
3256 | 3263 | ||
3257 | /* fill in ARGV array */ | 3264 | /* fill in ARGV array */ |
3258 | setvar_i(intvar[ARGC], argc + 1); | ||
3259 | setari_u(intvar[ARGV], 0, "awk"); | 3265 | setari_u(intvar[ARGV], 0, "awk"); |
3260 | i = 0; | 3266 | i = 0; |
3261 | while (*argv) | 3267 | while (*argv) |
3262 | setari_u(intvar[ARGV], ++i, *argv++); | 3268 | setari_u(intvar[ARGV], ++i, *argv++); |
3269 | setvar_i(intvar[ARGC], i + 1); | ||
3263 | 3270 | ||
3264 | evaluate(beginseq.first, &tv); | 3271 | evaluate(beginseq.first, &tv); |
3265 | if (!mainseq.first && !endseq.first) | 3272 | if (!mainseq.first && !endseq.first) |