mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-30 05:40:58 +01:00
25345, 25347: neaten interface from main shell to zle
This commit is contained in:
parent
8a466992da
commit
0c9830d23c
13 changed files with 206 additions and 122 deletions
|
|
@ -1,3 +1,11 @@
|
|||
2008-07-31 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 25345, 25347: Src/builtin.c, Src/exec.c, Src/hist.c, Src/init.c,
|
||||
Src/input.c, Src/jobs.c, Src/loop.c, Src/options.c, Src/signals.c,
|
||||
Src/utils.c, Src/zsh.h, Src/Zle/zle_main.c: Neaten interface
|
||||
from main shell to zle to zleentry() in main shell using
|
||||
single zle_entry_pointer.
|
||||
|
||||
2008-07-30 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* unposted: Doc/Zsh/func.yo: refer to DEBUG_BEFORE_CMD option.
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
11
Src/hist.c
11
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;
|
||||
|
||||
|
|
|
|||
158
Src/init.c
158
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
|
||||
/*
|
||||
* ZLE entry point pointer.
|
||||
* No other source file needs to know which modules are linked in.
|
||||
*/
|
||||
/**/
|
||||
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 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;
|
||||
/**/
|
||||
mod_export ZleReadFn zlereadptr = autoload_zleread;
|
||||
/**/
|
||||
mod_export ZleVoidIntFn zlesetkeymapptr = noop_function_int;
|
||||
|
||||
#else /* !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;
|
||||
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 */
|
||||
|
||||
#endif /* !LINKED_XMOD_zshQszle */
|
||||
|
||||
/**/
|
||||
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);
|
||||
}
|
||||
mod_export int zle_load_state;
|
||||
|
||||
/**/
|
||||
mod_export char *
|
||||
fallback_zleread(char **lp, UNUSED(char **rp), UNUSED(int ha), UNUSED(int con))
|
||||
zleentry(VA_ALIST1(int cmd))
|
||||
VA_DCL
|
||||
{
|
||||
char *pptbuf;
|
||||
int pptlen;
|
||||
char *ret = NULL;
|
||||
va_list ap;
|
||||
VA_DEF_ARG(int cmd);
|
||||
|
||||
pptbuf = unmetafy(promptexpand(lp ? *lp : NULL, 0, NULL, NULL, NULL),
|
||||
&pptlen);
|
||||
write(2, (WRITE_ARG_2_T)pptbuf, pptlen);
|
||||
free(pptbuf);
|
||||
VA_START(ap, cmd);
|
||||
VA_GET_ARG(ap, cmd, int);
|
||||
|
||||
return shingetline();
|
||||
}
|
||||
#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;
|
||||
|
||||
/**/
|
||||
#ifdef UNLINKED_XMOD_zshQszle
|
||||
case 1:
|
||||
ret = zle_entry_ptr(cmd, ap);
|
||||
/* Don't execute fallback code */
|
||||
cmd = -1;
|
||||
break;
|
||||
|
||||
/**/
|
||||
static void
|
||||
autoload_zlesetkeymap(int mode)
|
||||
{
|
||||
zlesetkeymapptr = noop_function_int;
|
||||
(void)load_module("zsh/zle", NULL, 0);
|
||||
(*zlesetkeymapptr)(mode);
|
||||
}
|
||||
|
||||
/**/
|
||||
case 2:
|
||||
/* Execute fallback code */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
lp = va_arg(ap, char **);
|
||||
|
||||
pptbuf = unmetafy(promptexpand(lp ? *lp : NULL, 0, NULL, NULL,
|
||||
NULL),
|
||||
&pptlen);
|
||||
write(2, (WRITE_ARG_2_T)pptbuf, pptlen);
|
||||
free(pptbuf);
|
||||
|
||||
ret = shingetline();
|
||||
break;
|
||||
}
|
||||
|
||||
case ZLE_CMD_GET_LINE:
|
||||
{
|
||||
int *ll, *cs;
|
||||
|
||||
ll = va_arg(ap, int *);
|
||||
cs = va_arg(ap, int *);
|
||||
*ll = *cs = 0;
|
||||
ret = ztrdup("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* compctl entry point pointers. Similar to the ZLE ones. */
|
||||
|
||||
/**/
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
20
Src/zsh.h
20
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. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue