static int wrap_private(Eprog prog, FuncWrap w, char *name) { static int wraplevel = 0; if (wraplevel < locallevel /* && strcmp(name, "(anon)") != 0 */) { int owl = wraplevel; wraplevel = locallevel; scanhashtable(paramtab, 0, 0, 0, scopeprivate, PM_UNSET); runshfunc(prog, w, name); scanhashtable(paramtab, 0, 0, 0, scopeprivate, 0); wraplevel = owl; return 0; } return 1; }
static int bin_private(char *nam, char **args, LinkList assigns, Options ops, int func) { int from_typeset = 1; makeprivate_error = 0; if (!OPT_ISSET(ops, 'P')) return bin_typeset(nam, args, assigns, ops, func); else if (OPT_ISSET(ops, 'T')) { zwarn("bad option: -T"); return 1; } if (locallevel == 0) { if (isset(WARNCREATEGLOBAL)) zwarnnam(nam, "invalid local scope, using globals"); return bin_typeset("private", args, assigns, ops, func); } ops->ind['g'] = 2; /* force bin_typeset() to behave as "local" */ queue_signals(); fakelevel = locallevel; startparamscope(); from_typeset = bin_typeset("private", args, assigns, ops, func); scanhashtable(paramtab, 0, 0, 0, makeprivate, 0); endparamscope(); fakelevel = 0; unqueue_signals(); return makeprivate_error | from_typeset; }
void installemulation(int new_emulation, char *new_opts) { setemulate_emulation = new_emulation; setemulate_opts = new_opts; scanhashtable(optiontab, 0, 0, 0, setemulate, !!(new_emulation & EMULATE_FULLY)); }
void printoptionlist(void) { short *lp; char c; printf("\nNamed options:\n"); scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionlist_printoption, 0); printf("\nOption aliases:\n"); scanhashtable(optiontab, 1, OPT_ALIAS, 0, printoptionlist_printoption, 0); printf("\nOption letters:\n"); for(lp = optletters, c = FIRST_OPT; c <= LAST_OPT; lp++, c++) { if(!*lp) continue; printf(" -%c ", c); printoptionlist_printequiv(*lp); } }
static void emptythingytab(UNUSED(HashTable ht)) { /* This will only be called when deleting the thingy table, which * * is only done to unload the zle module. A normal emptytable() * * function would free all the thingies, but we don't want to do * * that because some of them are the known thingies in the fixed * * `thingies' table. As the module cleanup code deletes all the * * keymaps and so on before deleting the thingy table, we can * * just remove the user-defined widgets and then be sure that * * *all* the thingies left are the fixed ones. This has the side * * effect of freeing all resources used by user-defined widgets. */ scanhashtable(thingytab, 0, 0, DISABLED, scanemptythingies, 0); }
void emulate(const char *zsh_name, int fully) { char ch = *zsh_name; if (ch == 'r') ch = zsh_name[1]; /* Work out the new emulation mode */ if (ch == 'c') emulation = EMULATE_CSH; else if (ch == 'k') emulation = EMULATE_KSH; else if (ch == 's' || ch == 'b') emulation = EMULATE_SH; else emulation = EMULATE_ZSH; scanhashtable(optiontab, 0, 0, 0, setemulate, fully); }
Thingy executenamedcommand(char *prmt) { Thingy cmd, retval = NULL; int l, len, feep = 0, listed = 0, curlist = 0; int ols = (listshown && validlist), olll = lastlistlen; char *cmdbuf, *ptr; char *okeymap = ztrdup(curkeymapname); clearlist = 1; /* prmt may be constant */ prmt = ztrdup(prmt); l = strlen(prmt); cmdbuf = (char *)zhalloc(l + NAMLEN + 2 #ifdef MULTIBYTE_SUPPORT + 2 * MB_CUR_MAX #endif ); strcpy(cmdbuf, prmt); zsfree(prmt); statusline = cmdbuf; selectlocalmap(command_keymap); selectkeymap("main", 1); ptr = cmdbuf += l; len = 0; for (;;) { *ptr = '_'; ptr[1] = '\0'; zrefresh(); if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) { statusline = NULL; selectkeymap(okeymap, 1); zsfree(okeymap); if ((listshown = ols)) { showinglist = -2; lastlistlen = olll; } else if (listed) clearlist = listshown = 1; retval = NULL; goto done; } if(cmd == Th(z_clearscreen)) { clearscreen(zlenoargs); if (curlist) { int zmultsav = zmult; zmult = 1; listlist(namedcmdll); showinglist = 0; zmult = zmultsav; } } else if(cmd == Th(z_redisplay)) { redisplay(zlenoargs); if (curlist) { int zmultsav = zmult; zmult = 1; listlist(namedcmdll); showinglist = 0; zmult = zmultsav; } } else if(cmd == Th(z_viquotedinsert)) { *ptr = '^'; zrefresh(); getfullchar(0); if(LASTFULLCHAR == ZLEEOF || !LASTFULLCHAR || len >= NAMLEN) feep = 1; else { int ret = zlecharasstring(LASTFULLCHAR, ptr); len += ret; ptr += ret; curlist = 0; } } else if(cmd == Th(z_quotedinsert)) { if(getfullchar(0) == ZLEEOF || !LASTFULLCHAR || len == NAMLEN) feep = 1; else { int ret = zlecharasstring(LASTFULLCHAR, ptr); len += ret; ptr += ret; curlist = 0; } } else if(cmd == Th(z_backwarddeletechar) || cmd == Th(z_vibackwarddeletechar)) { if (len) { ptr = backwardmetafiedchar(cmdbuf, ptr, NULL); len = ptr - cmdbuf; curlist = 0; } } else if(cmd == Th(z_killregion) || cmd == Th(z_backwardkillword) || cmd == Th(z_vibackwardkillword)) { if (len) curlist = 0; while (len) { convchar_t cc; ptr = backwardmetafiedchar(cmdbuf, ptr, &cc); len = ptr - cmdbuf; if (cc == ZWC('-')) break; } } else if(cmd == Th(z_killwholeline) || cmd == Th(z_vikillline) || cmd == Th(z_backwardkillline)) { len = 0; ptr = cmdbuf; if (listed) clearlist = listshown = 1; curlist = 0; } else if (cmd == Th(z_bracketedpaste)) { char *insert = bracketedstring(); size_t inslen = strlen(insert); if (len + inslen > NAMLEN) feep = 1; else { strcpy(ptr, insert); len += inslen; ptr += inslen; if (listed) { clearlist = listshown = 1; listed = 0; } else curlist = 0; } free(insert); } else { if(cmd == Th(z_acceptline) || cmd == Th(z_vicmdmode)) { Thingy r; unambiguous: *ptr = 0; r = rthingy(cmdbuf); if (!(r->flags & DISABLED)) { unrefthingy(r); statusline = NULL; selectkeymap(okeymap, 1); zsfree(okeymap); if ((listshown = ols)) { showinglist = -2; lastlistlen = olll; } else if (listed) clearlist = listshown = 1; retval = r; goto done; } unrefthingy(r); } if(cmd == Th(z_selfinsertunmeta)) { fixunmeta(); cmd = Th(z_selfinsert); } if (cmd == Th(z_listchoices) || cmd == Th(z_deletecharorlist) || cmd == Th(z_expandorcomplete) || cmd == Th(z_completeword) || cmd == Th(z_expandorcompleteprefix) || cmd == Th(z_vicmdmode) || cmd == Th(z_acceptline) || lastchar == ' ' || lastchar == '\t') { namedcmdambig = 100; namedcmdll = newlinklist(); *ptr = '\0'; namedcmdstr = cmdbuf; scanhashtable(thingytab, 1, 0, DISABLED, scancompcmd, 0); namedcmdstr = NULL; if (empty(namedcmdll)) { feep = 1; if (listed) clearlist = listshown = 1; curlist = 0; } else if (cmd == Th(z_listchoices) || cmd == Th(z_deletecharorlist)) { int zmultsav = zmult; *ptr = '_'; ptr[1] = '\0'; zmult = 1; listlist(namedcmdll); listed = curlist = 1; showinglist = 0; zmult = zmultsav; } else if (!nextnode(firstnode(namedcmdll))) { strcpy(ptr = cmdbuf, peekfirst(namedcmdll)); len = strlen(ptr); ptr += len; if (cmd == Th(z_acceptline) || cmd == Th(z_vicmdmode)) goto unambiguous; } else { strcpy(cmdbuf, peekfirst(namedcmdll)); ptr = cmdbuf + namedcmdambig; *ptr = '_'; ptr[1] = '\0'; if (isset(AUTOLIST) && !(isset(LISTAMBIGUOUS) && namedcmdambig > len)) { int zmultsav = zmult; if (isset(LISTBEEP)) feep = 1; zmult = 1; listlist(namedcmdll); listed = curlist = 1; showinglist = 0; zmult = zmultsav; } len = namedcmdambig; } } else { if (len == NAMLEN || cmd != Th(z_selfinsert)) feep = 1; else { #ifdef MULTIBYTE_SUPPORT if (!lastchar_wide_valid) getrestchar(lastchar, NULL, NULL); if (lastchar_wide == WEOF) feep = 1; else #endif if (ZC_icntrl(LASTFULLCHAR)) feep = 1; else { int ret = zlecharasstring(LASTFULLCHAR, ptr); len += ret; ptr += ret; if (listed) { clearlist = listshown = 1; listed = 0; } else curlist = 0; } } } } if (feep) handlefeep(zlenoargs); feep = 0; } done: selectlocalmap(NULL); return retval; }
void list_emulate_options(char *cmdopts, int fully) { print_emulate_opts = cmdopts; scanhashtable(optiontab, 1, 0, 0, print_emulate_option, fully); }
void printoptionstates(int hadplus) { scanhashtable(optiontab, 1, 0, OPT_ALIAS, printoptionnodestate, hadplus); }
int bin_setopt(char *nam, char **args, UNUSED(Options ops), int isun) { int action, optno, match = 0; /* With no arguments or options, display options. */ if (!*args) { scanhashtable(optiontab, 1, 0, OPT_ALIAS, optiontab->printnode, !isun); return 0; } /* loop through command line options (begins with "-" or "+") */ while (*args && (**args == '-' || **args == '+')) { action = (**args == '-') ^ isun; if(!args[0][1]) *args = "--"; while (*++*args) { if(**args == Meta) *++*args ^= 32; /* The pseudo-option `--' signifies the end of options. */ if (**args == '-') { args++; goto doneoptions; } else if (**args == 'o') { if (!*++*args) args++; if (!*args) { zwarnnam(nam, "string expected after -o"); inittyptab(); return 1; } if(!(optno = optlookup(*args))) zwarnnam(nam, "no such option: %s", *args); else if(dosetopt(optno, action, 0, opts)) zwarnnam(nam, "can't change option: %s", *args); break; } else if(**args == 'm') { match = 1; } else { if (!(optno = optlookupc(**args))) zwarnnam(nam, "bad option: -%c", **args); else if(dosetopt(optno, action, 0, opts)) zwarnnam(nam, "can't change option: -%c", **args); } } args++; } doneoptions: if (!match) { /* Not globbing the arguments -- arguments are simply option names. */ while (*args) { if(!(optno = optlookup(*args++))) zwarnnam(nam, "no such option: %s", args[-1]); else if(dosetopt(optno, !isun, 0, opts)) zwarnnam(nam, "can't change option: %s", args[-1]); } } else { /* Globbing option (-m) set. */ while (*args) { Patprog pprog; char *s, *t; t = s = dupstring(*args); while (*t) if (*t == '_') chuck(t); else { /* See comment in optlookup() */ if (*t >= 'A' && *t <= 'Z') *t = (*t - 'A') + 'a'; t++; } /* Expand the current arg. */ tokenize(s); if (!(pprog = patcompile(s, PAT_STATIC, NULL))) { zwarnnam(nam, "bad pattern: %s", *args); continue; } /* Loop over expansions. */ scanmatchtable(optiontab, pprog, 0, 0, OPT_ALIAS, setoption, !isun); args++; } } inittyptab(); return 0; }
void installemulation(void) { scanhashtable(optiontab, 0, 0, 0, setemulate, !!(emulation & EMULATE_FULLY)); }