refactor global(x) into isglobal(x, true)

This commit is contained in:
tg 2017-04-02 16:07:04 +00:00
parent ab976fd8d3
commit fd1dda2401
1 changed files with 17 additions and 8 deletions

25
var.c
View File

@ -28,7 +28,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.211 2017/04/02 15:51:20 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.212 2017/04/02 16:07:04 tg Exp $");
/*- /*-
* Variables * Variables
@ -227,6 +227,13 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
*/ */
struct tbl * struct tbl *
global(const char *n) global(const char *n)
{
return (isglobal(n, true));
}
/* search for variable; if not found, return NULL or create globally */
struct tbl *
isglobal(const char *n, bool docreate)
{ {
struct tbl *vp; struct tbl *vp;
union mksh_cchack vname; union mksh_cchack vname;
@ -294,17 +301,19 @@ global(const char *n)
goto out; goto out;
} }
l = varsearch(e->loc, &vp, vn, h); l = varsearch(e->loc, &vp, vn, h);
if (vp == NULL && docreate)
vp = ktenter(&l->vars, vn, h);
else
docreate = false;
if (vp != NULL) { if (vp != NULL) {
if (array) if (array)
vp = arraysearch(vp, val); vp = arraysearch(vp, val);
goto out; if (docreate) {
vp->flag |= DEFINED;
if (special(vn))
vp->flag |= SPECIAL;
}
} }
vp = ktenter(&l->vars, vn, h);
if (array)
vp = arraysearch(vp, val);
vp->flag |= DEFINED;
if (special(vn))
vp->flag |= SPECIAL;
out: out:
last_lookup_was_array = array; last_lookup_was_array = array;
if (vn != n) if (vn != n)