diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-25 19:41:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-25 19:41:05 +0200 |
commit | 78645d8371e69ce82841b66aa5ef69c02055f5bc (patch) | |
tree | 1c8af3c0793d512bc7f930097f07c3346bfc5e9c | |
parent | 8c5da0323bf2da02c40c587c5694b22e3ec623fb (diff) | |
download | busybox-w32-78645d8371e69ce82841b66aa5ef69c02055f5bc.tar.gz busybox-w32-78645d8371e69ce82841b66aa5ef69c02055f5bc.tar.bz2 busybox-w32-78645d8371e69ce82841b66aa5ef69c02055f5bc.zip |
awk: move locals deeper into scopes where they are used, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/editors/awk.c b/editors/awk.c index 1b23c17d2..86076d7b6 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -3254,20 +3254,19 @@ static var *evaluate(node *op, var *res) | |||
3254 | 3254 | ||
3255 | static int awk_exit(int r) | 3255 | static int awk_exit(int r) |
3256 | { | 3256 | { |
3257 | var tv; | ||
3258 | unsigned i; | 3257 | unsigned i; |
3259 | hash_item *hi; | ||
3260 | |||
3261 | zero_out_var(&tv); | ||
3262 | 3258 | ||
3263 | if (!exiting) { | 3259 | if (!exiting) { |
3260 | var tv; | ||
3264 | exiting = TRUE; | 3261 | exiting = TRUE; |
3265 | nextrec = FALSE; | 3262 | nextrec = FALSE; |
3263 | zero_out_var(&tv); | ||
3266 | evaluate(endseq.first, &tv); | 3264 | evaluate(endseq.first, &tv); |
3267 | } | 3265 | } |
3268 | 3266 | ||
3269 | /* waiting for children */ | 3267 | /* waiting for children */ |
3270 | for (i = 0; i < fdhash->csize; i++) { | 3268 | for (i = 0; i < fdhash->csize; i++) { |
3269 | hash_item *hi; | ||
3271 | hi = fdhash->items[i]; | 3270 | hi = fdhash->items[i]; |
3272 | while (hi) { | 3271 | while (hi) { |
3273 | if (hi->data.rs.F && hi->data.rs.is_pipe) | 3272 | if (hi->data.rs.F && hi->data.rs.is_pipe) |
@@ -3348,11 +3347,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
3348 | llist_t *list_e = NULL; | 3347 | llist_t *list_e = NULL; |
3349 | #endif | 3348 | #endif |
3350 | int i; | 3349 | int i; |
3351 | var *v; | ||
3352 | var tv; | 3350 | var tv; |
3353 | char **envp; | ||
3354 | char *vnames = (char *)vNames; /* cheat */ | ||
3355 | char *vvalues = (char *)vValues; | ||
3356 | 3351 | ||
3357 | INIT_G(); | 3352 | INIT_G(); |
3358 | 3353 | ||
@@ -3361,8 +3356,6 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
3361 | if (ENABLE_LOCALE_SUPPORT) | 3356 | if (ENABLE_LOCALE_SUPPORT) |
3362 | setlocale(LC_NUMERIC, "C"); | 3357 | setlocale(LC_NUMERIC, "C"); |
3363 | 3358 | ||
3364 | zero_out_var(&tv); | ||
3365 | |||
3366 | /* allocate global buffer */ | 3359 | /* allocate global buffer */ |
3367 | g_buf = xmalloc(MAXVARFMT + 1); | 3360 | g_buf = xmalloc(MAXVARFMT + 1); |
3368 | 3361 | ||
@@ -3372,16 +3365,21 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
3372 | fnhash = hash_init(); | 3365 | fnhash = hash_init(); |
3373 | 3366 | ||
3374 | /* initialize variables */ | 3367 | /* initialize variables */ |
3375 | for (i = 0; *vnames; i++) { | 3368 | { |
3376 | intvar[i] = v = newvar(nextword(&vnames)); | 3369 | char *vnames = (char *)vNames; /* cheat */ |
3377 | if (*vvalues != '\377') | 3370 | char *vvalues = (char *)vValues; |
3378 | setvar_s(v, nextword(&vvalues)); | 3371 | for (i = 0; *vnames; i++) { |
3379 | else | 3372 | var *v; |
3380 | setvar_i(v, 0); | 3373 | intvar[i] = v = newvar(nextword(&vnames)); |
3381 | 3374 | if (*vvalues != '\377') | |
3382 | if (*vnames == '*') { | 3375 | setvar_s(v, nextword(&vvalues)); |
3383 | v->type |= VF_SPECIAL; | 3376 | else |
3384 | vnames++; | 3377 | setvar_i(v, 0); |
3378 | |||
3379 | if (*vnames == '*') { | ||
3380 | v->type |= VF_SPECIAL; | ||
3381 | vnames++; | ||
3382 | } | ||
3385 | } | 3383 | } |
3386 | } | 3384 | } |
3387 | 3385 | ||
@@ -3393,16 +3391,19 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
3393 | newfile("/dev/stderr")->F = stderr; | 3391 | newfile("/dev/stderr")->F = stderr; |
3394 | 3392 | ||
3395 | /* Huh, people report that sometimes environ is NULL. Oh well. */ | 3393 | /* Huh, people report that sometimes environ is NULL. Oh well. */ |
3396 | if (environ) for (envp = environ; *envp; envp++) { | 3394 | if (environ) { |
3397 | /* environ is writable, thus we don't strdup it needlessly */ | 3395 | char **envp; |
3398 | char *s = *envp; | 3396 | for (envp = environ; *envp; envp++) { |
3399 | char *s1 = strchr(s, '='); | 3397 | /* environ is writable, thus we don't strdup it needlessly */ |
3400 | if (s1) { | 3398 | char *s = *envp; |
3401 | *s1 = '\0'; | 3399 | char *s1 = strchr(s, '='); |
3402 | /* Both findvar and setvar_u take const char* | 3400 | if (s1) { |
3403 | * as 2nd arg -> environment is not trashed */ | 3401 | *s1 = '\0'; |
3404 | setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1 + 1); | 3402 | /* Both findvar and setvar_u take const char* |
3405 | *s1 = '='; | 3403 | * as 2nd arg -> environment is not trashed */ |
3404 | setvar_u(findvar(iamarray(intvar[ENVIRON]), s), s1 + 1); | ||
3405 | *s1 = '='; | ||
3406 | } | ||
3406 | } | 3407 | } |
3407 | } | 3408 | } |
3408 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); | 3409 | opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); |
@@ -3466,6 +3467,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv) | |||
3466 | setari_u(intvar[ARGV], ++i, *argv++); | 3467 | setari_u(intvar[ARGV], ++i, *argv++); |
3467 | setvar_i(intvar[ARGC], i + 1); | 3468 | setvar_i(intvar[ARGC], i + 1); |
3468 | 3469 | ||
3470 | zero_out_var(&tv); | ||
3469 | evaluate(beginseq.first, &tv); | 3471 | evaluate(beginseq.first, &tv); |
3470 | if (!mainseq.first && !endseq.first) | 3472 | if (!mainseq.first && !endseq.first) |
3471 | awk_exit(EXIT_SUCCESS); | 3473 | awk_exit(EXIT_SUCCESS); |