/* * define function. Returns 1 if function is being undefined (t == 0) and * function did not exist, returns 0 otherwise. */ int define(const char *name, struct op *t) { uint32_t nhash; struct tbl *tp; bool was_set = false; nhash = hash(name); if (t != NULL && !tobool(t->u.ksh_func)) { /* drop same-name aliases for POSIX functions */ if ((tp = ktsearch(&aliases, name, nhash))) ktdelete(tp); } while (/* CONSTCOND */ 1) { tp = findfunc(name, nhash, true); /* because findfunc:create=true */ mkssert(tp != NULL); if (tp->flag & ISSET) was_set = true; /* * If this function is currently being executed, we zap * this table entry so findfunc() won't see it */ if (tp->flag & FINUSE) { tp->name[0] = '\0'; /* ensure it won't be found */ tp->flag &= ~DEFINED; tp->flag |= FDELETE; } else break; } if (tp->flag & ALLOC) { tp->flag &= ~(ISSET|ALLOC); tfree(tp->val.t, tp->areap); } if (t == NULL) { /* undefine */ ktdelete(tp); return (was_set ? 0 : 1); } tp->val.t = tcopy(t->left, tp->areap); tp->flag |= (ISSET|ALLOC); if (t->u.ksh_func) tp->flag |= FKSH; return (0); }
/* Make a variable non-special */ static void unspecial(const char *name) { struct tbl *tp; tp = ktsearch(&specials, name, hash(name)); if (tp) ktdelete(tp); }