awk: move locals deeper into scopes where they are used, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
@@ -3254,20 +3254,19 @@ static var *evaluate(node *op, var *res)
|
|||||||
|
|
||||||
static int awk_exit(int r)
|
static int awk_exit(int r)
|
||||||
{
|
{
|
||||||
var tv;
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
hash_item *hi;
|
|
||||||
|
|
||||||
zero_out_var(&tv);
|
|
||||||
|
|
||||||
if (!exiting) {
|
if (!exiting) {
|
||||||
|
var tv;
|
||||||
exiting = TRUE;
|
exiting = TRUE;
|
||||||
nextrec = FALSE;
|
nextrec = FALSE;
|
||||||
|
zero_out_var(&tv);
|
||||||
evaluate(endseq.first, &tv);
|
evaluate(endseq.first, &tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* waiting for children */
|
/* waiting for children */
|
||||||
for (i = 0; i < fdhash->csize; i++) {
|
for (i = 0; i < fdhash->csize; i++) {
|
||||||
|
hash_item *hi;
|
||||||
hi = fdhash->items[i];
|
hi = fdhash->items[i];
|
||||||
while (hi) {
|
while (hi) {
|
||||||
if (hi->data.rs.F && hi->data.rs.is_pipe)
|
if (hi->data.rs.F && hi->data.rs.is_pipe)
|
||||||
@@ -3348,11 +3347,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
llist_t *list_e = NULL;
|
llist_t *list_e = NULL;
|
||||||
#endif
|
#endif
|
||||||
int i;
|
int i;
|
||||||
var *v;
|
|
||||||
var tv;
|
var tv;
|
||||||
char **envp;
|
|
||||||
char *vnames = (char *)vNames; /* cheat */
|
|
||||||
char *vvalues = (char *)vValues;
|
|
||||||
|
|
||||||
INIT_G();
|
INIT_G();
|
||||||
|
|
||||||
@@ -3361,8 +3356,6 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (ENABLE_LOCALE_SUPPORT)
|
if (ENABLE_LOCALE_SUPPORT)
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
|
|
||||||
zero_out_var(&tv);
|
|
||||||
|
|
||||||
/* allocate global buffer */
|
/* allocate global buffer */
|
||||||
g_buf = xmalloc(MAXVARFMT + 1);
|
g_buf = xmalloc(MAXVARFMT + 1);
|
||||||
|
|
||||||
@@ -3372,7 +3365,11 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
fnhash = hash_init();
|
fnhash = hash_init();
|
||||||
|
|
||||||
/* initialize variables */
|
/* initialize variables */
|
||||||
|
{
|
||||||
|
char *vnames = (char *)vNames; /* cheat */
|
||||||
|
char *vvalues = (char *)vValues;
|
||||||
for (i = 0; *vnames; i++) {
|
for (i = 0; *vnames; i++) {
|
||||||
|
var *v;
|
||||||
intvar[i] = v = newvar(nextword(&vnames));
|
intvar[i] = v = newvar(nextword(&vnames));
|
||||||
if (*vvalues != '\377')
|
if (*vvalues != '\377')
|
||||||
setvar_s(v, nextword(&vvalues));
|
setvar_s(v, nextword(&vvalues));
|
||||||
@@ -3384,6 +3381,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
vnames++;
|
vnames++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handle_special(intvar[FS]);
|
handle_special(intvar[FS]);
|
||||||
handle_special(intvar[RS]);
|
handle_special(intvar[RS]);
|
||||||
@@ -3393,7 +3391,9 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
newfile("/dev/stderr")->F = stderr;
|
newfile("/dev/stderr")->F = stderr;
|
||||||
|
|
||||||
/* Huh, people report that sometimes environ is NULL. Oh well. */
|
/* Huh, people report that sometimes environ is NULL. Oh well. */
|
||||||
if (environ) for (envp = environ; *envp; envp++) {
|
if (environ) {
|
||||||
|
char **envp;
|
||||||
|
for (envp = environ; *envp; envp++) {
|
||||||
/* environ is writable, thus we don't strdup it needlessly */
|
/* environ is writable, thus we don't strdup it needlessly */
|
||||||
char *s = *envp;
|
char *s = *envp;
|
||||||
char *s1 = strchr(s, '=');
|
char *s1 = strchr(s, '=');
|
||||||
@@ -3405,6 +3405,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
*s1 = '=';
|
*s1 = '=';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL);
|
opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL);
|
||||||
argv += optind;
|
argv += optind;
|
||||||
//argc -= optind;
|
//argc -= optind;
|
||||||
@@ -3466,6 +3467,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
setari_u(intvar[ARGV], ++i, *argv++);
|
setari_u(intvar[ARGV], ++i, *argv++);
|
||||||
setvar_i(intvar[ARGC], i + 1);
|
setvar_i(intvar[ARGC], i + 1);
|
||||||
|
|
||||||
|
zero_out_var(&tv);
|
||||||
evaluate(beginseq.first, &tv);
|
evaluate(beginseq.first, &tv);
|
||||||
if (!mainseq.first && !endseq.first)
|
if (!mainseq.first && !endseq.first)
|
||||||
awk_exit(EXIT_SUCCESS);
|
awk_exit(EXIT_SUCCESS);
|
||||||
|
|||||||
Reference in New Issue
Block a user