awk: support for ENVIRON
This commit is contained in:
parent
88f7b63019
commit
708929bc32
2 changed files with 18 additions and 4 deletions
|
@ -36,7 +36,7 @@ char *cmd;
|
|||
int iflg; /* interactive mode */
|
||||
#endif
|
||||
|
||||
main(argc, argv) char **argv;
|
||||
main(argc, argv, envp) char **argv, *envp;
|
||||
{
|
||||
char *s, *strpbrk(), *strchr();
|
||||
void onint();
|
||||
|
@ -98,7 +98,7 @@ main(argc, argv) char **argv;
|
|||
xargc--;
|
||||
}
|
||||
|
||||
initarg(cmd, xargc, xargv);
|
||||
initarg(cmd, xargc, xargv, envp);
|
||||
if (xargc == 0) {
|
||||
ifp = stdin; *FILENAME = "-";
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ extern prmflg;
|
|||
SYMBOL *hashtab[HASHSIZE];
|
||||
SYMBOL *funtab[HASHSIZE];
|
||||
SYMBOL *argtab[HASHSIZE];
|
||||
SYMBOL *envtab[HASHSIZE];
|
||||
|
||||
char *strsave(), *emalloc(), *strchr();
|
||||
CELL *lookup(), *install(), *_install(), *mkcell(), *mktmp(), *getvar();
|
||||
|
@ -86,11 +87,11 @@ setvar(s) char *s;
|
|||
}
|
||||
}
|
||||
|
||||
initarg(arg0, argc, argv) char *arg0, **argv;
|
||||
initarg(arg0, argc, argv, envp) char *arg0, **argv, **envp;
|
||||
{
|
||||
CELL *u;
|
||||
register int i;
|
||||
register char str[4];
|
||||
register char str[4], *p;
|
||||
|
||||
ARGC = &install("ARGC", VAR|NUM, (char *)NULL, (double)argc+1, hashtab)->c_fval;
|
||||
u = install("ARGV", ARR, (char *)NULL, 0.0, hashtab);
|
||||
|
@ -103,6 +104,19 @@ initarg(arg0, argc, argv) char *arg0, **argv;
|
|||
else
|
||||
install(str, VAR|STR, argv[i], 0.0, argtab);
|
||||
}
|
||||
|
||||
u = install("ENVIRON", ARR, (char *)NULL, 0.0, hashtab);
|
||||
u->c_sval = (char *) envtab;
|
||||
for (i = 0; envp[i] && *envp[i]; i++) {
|
||||
if ((p = strchr(envp[i], '=')) != NULL) {
|
||||
*p = 0;
|
||||
if (isnum(p+1))
|
||||
install(envp[i], VAR|STR|NUM, p+1, atof(p+1), envtab);
|
||||
else
|
||||
install(envp[i], VAR|STR, p+1, 0.0, envtab);
|
||||
*p = '=';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
|
|
Loading…
Reference in a new issue