diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Zle/zle_main.c | 88 | ||||
-rw-r--r-- | Src/builtin.c | 19 | ||||
-rw-r--r-- | Src/exec.c | 2 | ||||
-rw-r--r-- | Src/hist.c | 11 | ||||
-rw-r--r-- | Src/init.c | 154 | ||||
-rw-r--r-- | Src/input.c | 3 | ||||
-rw-r--r-- | Src/jobs.c | 4 | ||||
-rw-r--r-- | Src/loop.c | 5 | ||||
-rw-r--r-- | Src/options.c | 2 | ||||
-rw-r--r-- | Src/signals.c | 2 | ||||
-rw-r--r-- | Src/utils.c | 6 | ||||
-rw-r--r-- | Src/zsh.h | 20 |
12 files changed, 196 insertions, 120 deletions
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index f564b84ee..0825e162b 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1809,6 +1809,72 @@ zleaftertrap(UNUSED(Hookdef dummy), UNUSED(void *dat)) return 0; } +static char * +zle_main_entry(int cmd, va_list ap) +{ + switch (cmd) { + case ZLE_CMD_GET_LINE: + { + int *ll, *cs; + ll = va_arg(ap, int *); + cs = va_arg(ap, int *); + return zlegetline(ll, cs); + } + + case ZLE_CMD_READ: + { + char **lp, **rp; + int flags, context; + + lp = va_arg(ap, char **); + rp = va_arg(ap, char **); + flags = va_arg(ap, int); + context = va_arg(ap, int); + + return zleread(lp, rp, flags, context); + } + + case ZLE_CMD_ADD_TO_LINE: + zleaddtoline(va_arg(ap, int)); + break; + + case ZLE_CMD_TRASH: + trashzle(); + break; + + case ZLE_CMD_RESET_PROMPT: + zle_resetprompt(); + break; + + case ZLE_CMD_REFRESH: + zrefresh(); + break; + + case ZLE_CMD_SET_KEYMAP: + zlesetkeymap(va_arg(ap, int)); + break; + + case ZLE_CMD_GET_KEY: + { + long do_keytmout; + int *timeout, *chrp; + + do_keytmout = va_arg(ap, long); + timeout = va_arg(ap, int *); + chrp = va_arg(ap, int *); + *chrp = getbyte(do_keytmout, timeout); + break; + } + + default: +#ifdef DEBUG + dputs("Bad command %d in zle_main_entry", cmd); +#endif + break; + } + return NULL; +} + static struct builtin bintab[] = { BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL), BUILTIN("vared", 0, bin_vared, 1, 1, 0, "aAcehM:m:p:r:", NULL), @@ -1849,15 +1915,8 @@ int setup_(UNUSED(Module m)) { /* Set up editor entry points */ - trashzleptr = trashzle; - zle_resetpromptptr = zle_resetprompt; - zrefreshptr = zrefresh; - zleaddtolineptr = zleaddtoline; - zlegetlineptr = zlegetline; - zlereadptr = zleread; - zlesetkeymapptr = zlesetkeymap; - - getkeyptr = getbyte; + zle_entry_ptr = zle_main_entry; + zle_load_state = 1; /* initialise the thingies */ init_thingies(); @@ -1949,15 +2008,8 @@ finish_(UNUSED(Module m)) zfree(vibuf[i].buf, vibuf[i].len); /* editor entry points */ - trashzleptr = noop_function; - zle_resetpromptptr = noop_function; - zrefreshptr = noop_function; - zleaddtolineptr = noop_function_int; - zlegetlineptr = NULL; - zlereadptr = fallback_zleread; - zlesetkeymapptr= noop_function_int; - - getkeyptr = NULL; + zle_entry_ptr = (ZleEntryPoint)0; + zle_load_state = 0; zfree(clwords, clwsize * sizeof(char *)); zle_refresh_finish(); diff --git a/Src/builtin.c b/Src/builtin.c index 19423fb63..99daf866b 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4754,7 +4754,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) char *reply, *readpmpt; int bsiz, c = 0, gotnl = 0, al = 0, first, nchars = 1, bslash, keys = 0; int haso = 0; /* true if /dev/tty has been opened specially */ - int isem = !strcmp(term, "emacs"), izle = zleactive && getkeyptr; + int isem = !strcmp(term, "emacs"), izle = zleactive; char *buf, *bptr, *firstarg, *zbuforig; LinkList readll = newlinklist(); FILE *oshout = NULL; @@ -4964,7 +4964,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) do { if (izle) { - if ((val = getkeyptr(izle_timeout, NULL)) < 0) { + zleentry(ZLE_CMD_GET_KEY, izle_timeout, NULL, &val); + if (val < 0) { eof = 1; break; } @@ -5069,9 +5070,13 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) if (izle) { #ifdef MULTIBYTE_SUPPORT int key; + char c; - while ((key = getkeyptr(izle_timeout, NULL)) >= 0) { - char c = (char)key; + for (;;) { + zleentry(ZLE_CMD_GET_KEY, izle_timeout, NULL, &key); + if (key < 0) + break; + c = (char)key; /* * If multibyte, it can't be y, so we don't care * what key gets set to; just read to end of character. @@ -5081,7 +5086,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) break; } #else - int key = getkeyptr(izle_timeout, NULL); + int key; + zleentry(ZLE_CMD_GET_KEY, izle_timeout, NULL, &key); #endif readbuf[0] = (key == 'y' ? 'y' : 'n'); @@ -5461,7 +5467,8 @@ zread(int izle, int *readchar, long izle_timeout) int ret; if (izle) { - int c = getkeyptr(izle_timeout, NULL); + int c; + zleentry(ZLE_CMD_GET_KEY, izle_timeout, NULL, &c); return (c < 0 ? EOF : c); } diff --git a/Src/exec.c b/Src/exec.c index 437a45c37..8edbf1dc9 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -1376,7 +1376,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) pipe(synch); if ((pid = zfork(&bgtime)) == -1) { - trashzleptr(); + zleentry(ZLE_CMD_TRASH); close(synch[0]); close(synch[1]); fprintf(stderr, "zsh: job can't be suspended\n"); diff --git a/Src/hist.c b/Src/hist.c index f856eedff..85c0e9983 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -243,7 +243,7 @@ iaddtoline(int c) return; if (qbang && c == bangchar && stophist < 2) { exlast--; - zleaddtolineptr('\\'); + zleentry(ZLE_CMD_ADD_TO_LINE, '\\'); } if (excs > zlemetacs) { excs += 1 + inbufct - exlast; @@ -253,7 +253,7 @@ iaddtoline(int c) excs = zlemetacs; } exlast = inbufct; - zleaddtolineptr(itok(c) ? ztokens[c - Pound] : c); + zleentry(ZLE_CMD_ADD_TO_LINE, itok(c) ? ztokens[c - Pound] : c); } @@ -2565,12 +2565,7 @@ bufferwords(LinkList list, char *buf, int *index) int ll, cs; char *linein; - if (zlegetlineptr) { - linein = (char *)zlegetlineptr(&ll, &cs); - } else { - linein = ztrdup(""); - ll = cs = 0; - } + linein = zleentry(ZLE_CMD_GET_LINE, &ll, &cs); zlemetall = ll + 1; /* length of line plus space added below */ zlemetacs = cs; diff --git a/Src/init.c b/Src/init.c index 7a64df17e..cf6164321 100644 --- a/Src/init.c +++ b/Src/init.c @@ -84,11 +84,6 @@ mod_export int hasam, hasxn; /**/ mod_export int tccolours; -/* Pointer to read-key function from zle */ - -/**/ -mod_export int (*getkeyptr) _((long, int *)); - /* SIGCHLD mask */ /**/ @@ -717,8 +712,6 @@ setupvals(void) zero_mnumber.type = MN_INTEGER; zero_mnumber.u.l = 0; - getkeyptr = NULL; - lineno = 1; noeval = 0; curhist = 0; @@ -1181,85 +1174,102 @@ noop_function_int(UNUSED(int nothing)) /* do nothing */ } -/* ZLE entry point pointers. They are defined here because the initial * - * values depend on whether ZLE is linked in or not -- if it is, we * - * avoid wasting space with the fallback functions. No other source * - * file needs to know which modules are linked in. */ - -#ifdef LINKED_XMOD_zshQszle - -/**/ -mod_export ZleVoidFn trashzleptr = noop_function; -/**/ -mod_export ZleVoidFn zle_resetpromptptr = noop_function; -/**/ -mod_export ZleVoidFn zrefreshptr = noop_function; -/**/ -mod_export ZleVoidIntFn zleaddtolineptr = noop_function_int; +/* + * ZLE entry point pointer. + * No other source file needs to know which modules are linked in. + */ /**/ -mod_export ZleGetLineFn zlegetlineptr = NULL; +mod_export ZleEntryPoint zle_entry_ptr; + +/* + * State of loading of zle. + * 0 = Not loaded, not attempted. + * 1 = Loaded successfully + * 2 = Failed to load. + */ /**/ -mod_export ZleReadFn zlereadptr = autoload_zleread; +mod_export int zle_load_state; + /**/ -mod_export ZleVoidIntFn zlesetkeymapptr = noop_function_int; +mod_export char * +zleentry(VA_ALIST1(int cmd)) +VA_DCL +{ + char *ret = NULL; + va_list ap; + VA_DEF_ARG(int cmd); + + VA_START(ap, cmd); + VA_GET_ARG(ap, cmd, int); + +#if defined(LINKED_XMOD_zshQszle) || defined(UNLINKED_XMOD_zshQszle) + /* autoload */ + switch (zle_load_state) { + case 0: + if (load_module("zsh/zle", NULL, 0) != 1) { + (void)load_module("zsh/compctl", NULL, 0); + ret = zle_entry_ptr(cmd, ap); + /* Don't execute fallback code */ + cmd = -1; + } else { + zle_load_state = 2; + /* Execute fallback code below */ + } + break; -#else /* !LINKED_XMOD_zshQszle */ + case 1: + ret = zle_entry_ptr(cmd, ap); + /* Don't execute fallback code */ + cmd = -1; + break; -mod_export ZleVoidFn trashzleptr = noop_function; -mod_export ZleVoidFn zle_resetpromptptr = noop_function; -mod_export ZleVoidFn zrefreshptr = noop_function; -mod_export ZleVoidIntFn zleaddtolineptr = noop_function_int; -mod_export ZleGetLineFn zlegetlineptr = NULL; -# ifdef UNLINKED_XMOD_zshQszle -mod_export ZleReadFn zlereadptr = autoload_zleread; -mod_export ZleVoidIntFn zlesetkeymapptr = autoload_zlesetkeymap; -# else /* !UNLINKED_XMOD_zshQszle */ -mod_export ZleReadFn zlereadptr = fallback_zleread; -mod_export ZleVoidIntFn zlesetkeymapptr = noop_function_int; -# endif /* !UNLINKED_XMOD_zshQszle */ + case 2: + /* Execute fallback code */ + break; + } +#endif -#endif /* !LINKED_XMOD_zshQszle */ + switch (cmd) { + /* + * Only the read command really needs a fallback if zle + * is not available. ZLE_CMD_GET_LINE has traditionally + * had local code in bufferwords() to do this, but that' + * probably only because bufferwords() is part of completion + * and so everything to do with it is horribly complicated. + */ + case ZLE_CMD_READ: + { + char *pptbuf, **lp; + int pptlen; -/**/ -char * -autoload_zleread(char **lp, char **rp, int ha, int con) -{ - zlereadptr = fallback_zleread; - if (load_module("zsh/zle", NULL, 0) != 1) - (void)load_module("zsh/compctl", NULL, 0); - return zlereadptr(lp, rp, ha, con); -} + lp = va_arg(ap, char **); -/**/ -mod_export char * -fallback_zleread(char **lp, UNUSED(char **rp), UNUSED(int ha), UNUSED(int con)) -{ - char *pptbuf; - int pptlen; + pptbuf = unmetafy(promptexpand(lp ? *lp : NULL, 0, NULL, NULL, + NULL), + &pptlen); + write(2, (WRITE_ARG_2_T)pptbuf, pptlen); + free(pptbuf); - pptbuf = unmetafy(promptexpand(lp ? *lp : NULL, 0, NULL, NULL, NULL), - &pptlen); - write(2, (WRITE_ARG_2_T)pptbuf, pptlen); - free(pptbuf); + ret = shingetline(); + break; + } - return shingetline(); -} + case ZLE_CMD_GET_LINE: + { + int *ll, *cs; -/**/ -#ifdef UNLINKED_XMOD_zshQszle + ll = va_arg(ap, int *); + cs = va_arg(ap, int *); + *ll = *cs = 0; + ret = ztrdup(""); + break; + } + } -/**/ -static void -autoload_zlesetkeymap(int mode) -{ - zlesetkeymapptr = noop_function_int; - (void)load_module("zsh/zle", NULL, 0); - (*zlesetkeymapptr)(mode); + va_end(ap); + return ret; } -/**/ -#endif - /* compctl entry point pointers. Similar to the ZLE ones. */ /**/ diff --git a/Src/input.c b/Src/input.c index a721eba9b..5d780f3c4 100644 --- a/Src/input.c +++ b/Src/input.c @@ -275,7 +275,8 @@ inputline(void) int flags = ZLRF_HISTORY|ZLRF_NOSETTY; if (isset(IGNOREEOF)) flags |= ZLRF_IGNOREEOF; - ingetcline = zlereadptr(ingetcpmptl, ingetcpmptr, flags, context); + ingetcline = zleentry(ZLE_CMD_READ, ingetcpmptl, ingetcpmptr, + flags, context); histdone |= HISTFLAG_SETTY; } if (!ingetcline) { diff --git a/Src/jobs.c b/Src/jobs.c index a8767ac39..5edeecde6 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -459,7 +459,7 @@ update_job(Job jn) if ((isset(NOTIFY) || job == thisjob) && (jn->stat & STAT_LOCKED)) { if (printjob(jn, !!isset(LONGLISTJOBS), 0) && zleactive) - zrefreshptr(); + zleentry(ZLE_CMD_REFRESH); } if (sigtrapped[SIGCHLD] && job != thisjob) dotrap(SIGCHLD); @@ -895,7 +895,7 @@ printjob(Job jn, int lng, int synch) Process qn; if (!synch) - trashzleptr(); + zleentry(ZLE_CMD_TRASH); if (doputnl && !synch) { doneprint = 1; putc('\n', fout); diff --git a/Src/loop.c b/Src/loop.c index 9533ba186..40dbe6f8f 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -245,7 +245,8 @@ execselect(Estate state, UNUSED(int do_exec)) int oef = errflag; isfirstln = 1; - str = zlereadptr(&prompt3, NULL, 0, ZLCON_SELECT); + str = zleentry(ZLE_CMD_READ, &prompt3, NULL, + 0, ZLCON_SELECT); if (errflag) str = NULL; errflag = oef; @@ -313,7 +314,7 @@ selectlist(LinkList l, size_t start) size_t longest = 1, fct, fw = 0, colsz, t0, t1, ct; char **arr, **ap; - trashzleptr(); + zleentry(ZLE_CMD_TRASH); arr = hlinklist2array(l, 0); for (ap = arr; *ap; ap++) if (strlen(*ap) > longest) diff --git a/Src/options.c b/Src/options.c index e59736153..bb99ba1e5 100644 --- a/Src/options.c +++ b/Src/options.c @@ -724,7 +724,7 @@ dosetopt(int optno, int value, int force) return -1; #endif /* GETPWNAM_FAKED */ } else if ((optno == EMACSMODE || optno == VIMODE) && value) { - (*zlesetkeymapptr)(optno); + zleentry(ZLE_CMD_SET_KEYMAP, optno); opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0; } opts[optno] = value; diff --git a/Src/signals.c b/Src/signals.c index 317df59b8..022ee8fb5 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -1213,7 +1213,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) * need to restore the display. */ if (zleactive && resetneeded) - zrefreshptr(); + zleentry(ZLE_CMD_REFRESH); if (*sigtr != ZSIG_IGNORED) *sigtr &= ~ZSIG_IGNORED; diff --git a/Src/utils.c b/Src/utils.c index ae0d43876..ec2df7cd0 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -108,7 +108,7 @@ static void zwarning(const char *cmd, const char *fmt, va_list ap) { if (isatty(2)) - trashzleptr(); + zleentry(ZLE_CMD_TRASH); if (cmd) { if (unset(SHINSTDIN) || locallevel) { @@ -1573,8 +1573,8 @@ adjustwinsize(int from) winchanged = #endif /* TIOCGWINSZ */ resetneeded = 1; - zrefreshptr(); - zle_resetpromptptr(); + zleentry(ZLE_CMD_REFRESH); + zleentry(ZLE_CMD_RESET_PROMPT); } } diff --git a/Src/zsh.h b/Src/zsh.h index da9664ef5..d245a416a 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2373,12 +2373,22 @@ enum { typedef int (*CompctlReadFn) _((char *, char **, Options, char *)); -/* ZLE entry point pointers */ +/* ZLE entry point pointer */ -typedef void (*ZleVoidFn) _((void)); -typedef void (*ZleVoidIntFn) _((int)); -typedef char *(*ZleReadFn) _((char **, char **, int, int)); -typedef char *(*ZleGetLineFn) _((int *, int *)); +typedef char * (*ZleEntryPoint)(int cmd, va_list ap); + +/* Commands to pass to entry point */ + +enum { + ZLE_CMD_GET_LINE, + ZLE_CMD_READ, + ZLE_CMD_ADD_TO_LINE, + ZLE_CMD_TRASH, + ZLE_CMD_RESET_PROMPT, + ZLE_CMD_REFRESH, + ZLE_CMD_SET_KEYMAP, + ZLE_CMD_GET_KEY +}; /***************************************/ /* Hooks in core. */ |