diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-11-21 15:09:55 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-11-21 15:09:55 +0100 |
commit | bd0e221620eb725043b4e748248046ece996a393 (patch) | |
tree | 54d12beebe19b7c50c6b14b15ad18c302fa0eff9 | |
parent | 2635369a92db338321b2ba38e73539992967357c (diff) | |
download | busybox-w32-bd0e221620eb725043b4e748248046ece996a393.tar.gz busybox-w32-bd0e221620eb725043b4e748248046ece996a393.tar.bz2 busybox-w32-bd0e221620eb725043b4e748248046ece996a393.zip |
awk: fix a bug in argc counting in recent change
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 16 | ||||
-rwxr-xr-x | testsuite/awk.tests | 14 |
2 files changed, 21 insertions, 9 deletions
diff --git a/editors/awk.c b/editors/awk.c index 29fb2e782..d0e3781e7 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -3204,15 +3204,17 @@ int awk_main(int argc, char **argv) | |||
3204 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); | 3204 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); |
3205 | argv += optind; | 3205 | argv += optind; |
3206 | argc -= optind; | 3206 | argc -= optind; |
3207 | if (opt & OPT_F) { /* -F */ | 3207 | if (opt & OPT_W) |
3208 | bb_error_msg("warning: option -W is ignored"); | ||
3209 | if (opt & OPT_F) { | ||
3208 | unescape_string_in_place(opt_F); | 3210 | unescape_string_in_place(opt_F); |
3209 | setvar_s(intvar[FS], opt_F); | 3211 | setvar_s(intvar[FS], opt_F); |
3210 | } | 3212 | } |
3211 | while (list_v) { /* -v */ | 3213 | while (list_v) { |
3212 | if (!is_assignment(llist_pop(&list_v))) | 3214 | if (!is_assignment(llist_pop(&list_v))) |
3213 | bb_show_usage(); | 3215 | bb_show_usage(); |
3214 | } | 3216 | } |
3215 | while (list_f) { /* -f */ | 3217 | while (list_f) { |
3216 | char *s = NULL; | 3218 | char *s = NULL; |
3217 | FILE *from_file; | 3219 | FILE *from_file; |
3218 | 3220 | ||
@@ -3230,7 +3232,7 @@ int awk_main(int argc, char **argv) | |||
3230 | } | 3232 | } |
3231 | g_progname = "cmd. line"; | 3233 | g_progname = "cmd. line"; |
3232 | #if ENABLE_FEATURE_AWK_GNU_EXTENSIONS | 3234 | #if ENABLE_FEATURE_AWK_GNU_EXTENSIONS |
3233 | while (list_e) { /* -e */ | 3235 | while (list_e) { |
3234 | parse_program(llist_pop(&list_e)); | 3236 | parse_program(llist_pop(&list_e)); |
3235 | } | 3237 | } |
3236 | #endif | 3238 | #endif |
@@ -3238,13 +3240,11 @@ int awk_main(int argc, char **argv) | |||
3238 | if (!*argv) | 3240 | if (!*argv) |
3239 | bb_show_usage(); | 3241 | bb_show_usage(); |
3240 | parse_program(*argv++); | 3242 | parse_program(*argv++); |
3241 | argc++; | 3243 | argc--; |
3242 | } | 3244 | } |
3243 | if (opt & OPT_W) // -W | ||
3244 | bb_error_msg("warning: option -W is ignored"); | ||
3245 | 3245 | ||
3246 | /* fill in ARGV array */ | 3246 | /* fill in ARGV array */ |
3247 | setvar_i(intvar[ARGC], argc); | 3247 | setvar_i(intvar[ARGC], argc + 1); |
3248 | setari_u(intvar[ARGV], 0, "awk"); | 3248 | setari_u(intvar[ARGV], 0, "awk"); |
3249 | i = 0; | 3249 | i = 0; |
3250 | while (*argv) | 3250 | while (*argv) |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index a02302405..50b2a8328 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -275,10 +275,22 @@ testing "awk large integer" \ | |||
275 | "" "" | 275 | "" "" |
276 | 276 | ||
277 | testing "awk length(array)" \ | 277 | testing "awk length(array)" \ |
278 | "awk 'BEGIN{ A[1]=2; A["qwe"]="asd"; print length(A)}'" \ | 278 | "awk 'BEGIN{ A[1]=2; A[\"qwe\"]=\"asd\"; print length(A)}'" \ |
279 | "2\n" \ | 279 | "2\n" \ |
280 | "" "" | 280 | "" "" |
281 | 281 | ||
282 | testing "awk -f and ARGC" \ | ||
283 | "awk -f - input" \ | ||
284 | "re\n2\n" \ | ||
285 | "do re mi\n" \ | ||
286 | '{print $2; print ARGC;}' \ | ||
287 | |||
288 | testing "awk -e and ARGC" \ | ||
289 | "awk -e '{print \$2; print ARGC;}' input" \ | ||
290 | "re\n2\n" \ | ||
291 | "do re mi\n" \ | ||
292 | "" \ | ||
293 | |||
282 | # testing "description" "command" "result" "infile" "stdin" | 294 | # testing "description" "command" "result" "infile" "stdin" |
283 | 295 | ||
284 | exit $FAILCOUNT | 296 | exit $FAILCOUNT |