diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2008-09-16 15:02:01 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2008-09-16 15:02:01 +0000 |
commit | 2920c227d3f8e6d8af1f2b0c3163badb95cde9b5 (patch) | |
tree | 854021a4e3cfa7a72bf67a364ce55e6803ca800b /Src | |
parent | 14905ddc74f78b54c75434c8a4d7e029b1933280 (diff) | |
download | zsh-2920c227d3f8e6d8af1f2b0c3163badb95cde9b5.tar.gz zsh-2920c227d3f8e6d8af1f2b0c3163badb95cde9b5.tar.xz zsh-2920c227d3f8e6d8af1f2b0c3163badb95cde9b5.zip |
25677: add %x and %I prompt escapes for shell source code debugging
tidy up interface to doshfunc()
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Modules/zftp.c | 30 | ||||
-rw-r--r-- | Src/Zle/compcore.c | 6 | ||||
-rw-r--r-- | Src/Zle/compctl.c | 12 | ||||
-rw-r--r-- | Src/Zle/zle_main.c | 5 | ||||
-rw-r--r-- | Src/Zle/zle_misc.c | 6 | ||||
-rw-r--r-- | Src/exec.c | 22 | ||||
-rw-r--r-- | Src/init.c | 2 | ||||
-rw-r--r-- | Src/math.c | 6 | ||||
-rw-r--r-- | Src/prompt.c | 26 | ||||
-rw-r--r-- | Src/signals.c | 27 | ||||
-rw-r--r-- | Src/utils.c | 21 |
11 files changed, 97 insertions, 66 deletions
diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index 4679c56a6..0d5e58e56 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -1469,9 +1469,9 @@ zfsenddata(char *name, int recv, int progress, off_t startat) char lsbuf[ZF_BUFSIZE], *ascbuf = NULL, *optr; off_t sofar = 0, last_sofar = 0; readwrite_t read_ptr = zfread, write_ptr = zfwrite; - Eprog prog; + Shfunc shfunc; - if (progress && (prog = getshfunc("zftp_progress")) != &dummy_eprog) { + if (progress && (shfunc = getshfunc("zftp_progress"))) { /* * progress to set up: ZFTP_COUNT is zero. * We do this here in case we needed to wait for a RETR @@ -1480,7 +1480,7 @@ zfsenddata(char *name, int recv, int progress, off_t startat) int osc = sfcontext; sfcontext = SFC_HOOK; - doshfunc("zftp_progress", prog, NULL, 0, 1); + doshfunc(shfunc, NULL, 0, 1); sfcontext = osc; /* Now add in the bit of the file we've got/sent already */ sofar = last_sofar = startat; @@ -1608,12 +1608,12 @@ zfsenddata(char *name, int recv, int progress, off_t startat) } else break; if (!ret && sofar != last_sofar && progress && - (prog = getshfunc("zftp_progress")) != &dummy_eprog) { + (shfunc = getshfunc("zftp_progress"))) { int osc = sfcontext; zfsetparam("ZFTP_COUNT", &sofar, ZFPM_READONLY|ZFPM_INTEGER); sfcontext = SFC_HOOK; - doshfunc("zftp_progress", prog, NULL, 0, 1); + doshfunc(shfunc, NULL, 0, 1); sfcontext = osc; last_sofar = sofar; } @@ -2364,7 +2364,7 @@ zfgetcwd(void) { char *ptr, *eptr; int endc; - Eprog prog; + Shfunc shfunc; if (zfprefs & ZFPF_DUMB) return 1; @@ -2391,11 +2391,11 @@ zfgetcwd(void) * front end. By putting it here, and in close when ZFTP_PWD is unset, * we at least cover the bases. */ - if ((prog = getshfunc("zftp_chpwd")) != &dummy_eprog) { + if ((shfunc = getshfunc("zftp_chpwd"))) { int osc = sfcontext; sfcontext = SFC_HOOK; - doshfunc("zftp_chpwd", prog, NULL, 0, 1); + doshfunc(shfunc, NULL, 0, 1); sfcontext = osc; } return 0; @@ -2549,7 +2549,7 @@ zftp_getput(char *name, char **args, int flags) { int ret = 0, recv = (flags & ZFTP_RECV), getsize = 0, progress = 1; char *cmd = recv ? "RETR " : (flags & ZFTP_APPE) ? "APPE " : "STOR "; - Eprog prog; + Shfunc shfunc; /* * At this point I'd like to set progress to 0 if we're @@ -2567,7 +2567,7 @@ zftp_getput(char *name, char **args, int flags) for (; *args; args++) { char *ln, *rest = NULL; off_t startat = 0; - if (progress && (prog = getshfunc("zftp_progress")) != &dummy_eprog) { + if (progress && (shfunc = getshfunc("zftp_progress"))) { off_t sz = -1; /* * This calls the SIZE command to get the size for remote @@ -2608,14 +2608,14 @@ zftp_getput(char *name, char **args, int flags) * if and only if we called zfsenddata(); */ if (progress && ret != 2 && - (prog = getshfunc("zftp_progress")) != &dummy_eprog) { + (shfunc = getshfunc("zftp_progress"))) { /* progress to finish: ZFTP_TRANSFER set to GF or PF */ int osc = sfcontext; zfsetparam("ZFTP_TRANSFER", ztrdup(recv ? "GF" : "PF"), ZFPM_READONLY); sfcontext = SFC_HOOK; - doshfunc("zftp_progress", prog, NULL, 0, 1); + doshfunc(shfunc, NULL, 0, 1); sfcontext = osc; } if (rest) { @@ -2715,7 +2715,7 @@ static void zfclose(int leaveparams) { char **aptr; - Eprog prog; + Shfunc shfunc; if (!zfsess->control) return; @@ -2766,11 +2766,11 @@ zfclose(int leaveparams) zfunsetparam(*aptr); /* Now ZFTP_PWD is unset. It's up to zftp_chpwd to notice. */ - if ((prog = getshfunc("zftp_chpwd")) != &dummy_eprog) { + if ((shfunc = getshfunc("zftp_chpwd"))) { int osc = sfcontext; sfcontext = SFC_HOOK; - doshfunc("zftp_chpwd", prog, NULL, 0, 1); + doshfunc(shfunc, NULL, 0, 1); sfcontext = osc; } } diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index e66cf8890..9f97779ff 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -540,13 +540,13 @@ static int parwb, parwe, paroffs; static void callcompfunc(char *s, char *fn) { - Eprog prog; + Shfunc shfunc; int lv = lastval; char buf[20]; METACHECK(); - if ((prog = getshfunc(fn)) != &dummy_eprog) { + if ((shfunc = getshfunc(fn))) { char **p, *tmp; int aadd = 0, usea = 1, icf = incompfunc, osc = sfcontext; unsigned int rset, kset; @@ -814,7 +814,7 @@ callcompfunc(char *s, char *fn) while (*p) addlinknode(largs, dupstring(*p++)); } - doshfunc(fn, prog, largs, 0, 0); + doshfunc(shfunc, largs, 0, 0); cfret = lastval; lastval = olv; } OLDHEAPS; diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 57bfccd49..9d03635ff 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -3635,12 +3635,12 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) } if (cc->func) { /* This handles the compctl -K flag. */ - Eprog prog; + Shfunc shfunc; char **r; int lv = lastval; /* Get the function. */ - if ((prog = getshfunc(cc->func)) != &dummy_eprog) { + if ((shfunc = getshfunc(cc->func))) { /* We have it, so build a argument list. */ LinkList args = newlinklist(); int osc = sfcontext; @@ -3664,7 +3664,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) incompctlfunc = 1; sfcontext = SFC_COMPLETE; /* Call the function. */ - doshfunc(cc->func, prog, args, 0, 1); + doshfunc(shfunc, args, 0, 1); sfcontext = osc; incompctlfunc = 0; /* And get the result from the reply parameter. */ @@ -3809,12 +3809,12 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) /* generate the user-defined display list: if anything fails, * * we silently allow the normal completion list to be used. */ char **yaptr = NULL, *uv = NULL; - Eprog prog; + Shfunc shfunc; if (cc->ylist[0] == '$' || cc->ylist[0] == '(') { /* from variable */ uv = cc->ylist + (cc->ylist[0] == '$'); - } else if ((prog = getshfunc(cc->ylist)) != &dummy_eprog) { + } else if ((shfunc = getshfunc(cc->ylist))) { /* from function: pass completions as arg list */ LinkList args = newlinklist(); LinkNode ln; @@ -3839,7 +3839,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) if (incompfunc != 1) incompctlfunc = 1; sfcontext = SFC_COMPLETE; - doshfunc(cc->ylist, prog, args, 0, 1); + doshfunc(shfunc, args, 0, 1); sfcontext = osc; incompctlfunc = 0; uv = "reply"; diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 4bccf2d46..dc6e07f2b 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1304,9 +1304,8 @@ execzlefunc(Thingy func, char **args, int set_bindk) r = 1; } else { Shfunc shf = (Shfunc) shfunctab->getnode(shfunctab, w->u.fnnam); - Eprog prog = (shf ? shf->funcdef : &dummy_eprog); - if(prog == &dummy_eprog) { + if (!shf) { /* the shell function doesn't exist */ char *nm = nicedup(w->u.fnnam, 0); char *msg = tricat("No such shell function `", nm, "'"); @@ -1330,7 +1329,7 @@ execzlefunc(Thingy func, char **args, int set_bindk) makezleparams(0); sfcontext = SFC_WIDGET; opts[XTRACE] = 0; - ret = doshfunc(w->u.fnnam, prog, largs, shf->node.flags, 1); + ret = doshfunc(shf, largs, shf->node.flags, 1); opts[XTRACE] = oxt; sfcontext = osc; endparamscope(); diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index a6f7e803b..c34db2970 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -1358,9 +1358,9 @@ mod_export void iremovesuffix(ZLE_INT_T c, int keep) { if (suffixfunc) { - Eprog prog = getshfunc(suffixfunc); + Shfunc shfunc = getshfunc(suffixfunc); - if (prog != &dummy_eprog) { + if (shfunc) { LinkList args = newlinklist(); char buf[20]; int osc = sfcontext; @@ -1384,7 +1384,7 @@ iremovesuffix(ZLE_INT_T c, int keep) startparamscope(); makezleparams(0); sfcontext = SFC_COMPLETE; - doshfunc(suffixfunc, prog, args, 0, 1); + doshfunc(shfunc, args, 0, 1); sfcontext = osc; endparamscope(); diff --git a/Src/exec.c b/Src/exec.c index a8098e5f8..781598cc1 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -518,7 +518,7 @@ commandnotfound(char *arg0, LinkList args) return 127; pushnode(args, arg0); - return doshfunc(shf->node.nam, shf->funcdef, args, shf->node.flags, 1); + return doshfunc(shf, args, shf->node.flags, 1); } /* execute an external command */ @@ -4064,7 +4064,7 @@ execshfunc(Shfunc shf, LinkList args) cmdsp = 0; if ((osfc = sfcontext) == SFC_NONE) sfcontext = SFC_DIRECT; - doshfunc(shf->node.nam, shf->funcdef, args, shf->node.flags, 0); + doshfunc(shf, args, shf->node.flags, 0); sfcontext = osfc; free(cmdstack); cmdstack = ocs; @@ -4200,18 +4200,20 @@ loadautofn(Shfunc shf, int fksh, int autol) /**/ mod_export int -doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval) +doshfunc(Shfunc shfunc, LinkList doshargs, int flags, int noreturnval) { char **tab, **x, *oargv0; int oldzoptind, oldlastval, oldoptcind, oldnumpipestats, ret; int *oldpipestats = NULL; - char saveopts[OPT_SIZE], *oldscriptname = scriptname, *fname = dupstring(name); + char saveopts[OPT_SIZE], *oldscriptname = scriptname; + char *name = shfunc->node.nam; + char *fname = dupstring(name); int obreaks, saveemulation ; + Eprog prog; struct funcstack fstack; #ifdef MAX_FUNCTION_DEPTH static int funcdepth; #endif - Shfunc shf; pushheap(); @@ -4291,14 +4293,10 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval) fstack.tp = FS_FUNC; funcstack = &fstack; - if ((shf = (Shfunc) shfunctab->getnode(shfunctab, name))) { - fstack.flineno = shf->lineno; - fstack.filename = dupstring(shf->filename); - } else { - fstack.flineno = 0; - fstack.filename = dupstring(fstack.caller); - } + fstack.flineno = shfunc->lineno; + fstack.filename = dupstring(shfunc->filename); + prog = shfunc->funcdef; if (prog->flags & EF_RUN) { Shfunc shf; diff --git a/Src/init.c b/Src/init.c index 4c08c8c65..215514f6d 100644 --- a/Src/init.c +++ b/Src/init.c @@ -149,7 +149,7 @@ loop(int toplevel, int justonce) int toksav = tok; if (toplevel && - (getshfunc("preexec") != &dummy_eprog || + (getshfunc("preexec") || paramtab->getnode(paramtab, "preexec_functions"))) { LinkList args; char *cmdstr; diff --git a/Src/math.c b/Src/math.c index 1aedcde28..78f7572a5 100644 --- a/Src/math.c +++ b/Src/math.c @@ -868,11 +868,11 @@ callmathfunc(char *o) argc <= f->maxargs)) { if (f->flags & MFF_USERFUNC) { char *shfnam = f->module ? f->module : n; - Eprog prog = getshfunc(shfnam); - if (prog == &dummy_eprog) + Shfunc shfunc = getshfunc(shfnam); + if (!shfunc) zerr("no such function: %s", shfnam); else { - doshfunc(n, prog, l, 0, 1); + doshfunc(shfunc, l, 0, 1); return lastmathval; } } else { diff --git a/Src/prompt.c b/Src/prompt.c index 36eaca3e9..7bba51c61 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -725,11 +725,37 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep) if(Rstring) stradd(Rstring); break; + case 'I': + if (funcstack && funcstack->tp != FS_SOURCE) { + /* + * We're in a function or an eval with + * EVALLINENO. Calculate the line number in + * the file. + */ + zlong flineno = lineno + funcstack->flineno; + /* take account of eval line nos. starting at 1 */ + if (funcstack->tp == FS_EVAL) + lineno--; + addbufspc(DIGBUFSIZE); + sprintf(bp, "%ld", (long)flineno); + bp += strlen(bp); + break; + } + /* else we're in a file and lineno is already correct */ + /* FALLTHROUGH */ case 'i': addbufspc(DIGBUFSIZE); sprintf(bp, "%ld", (long)lineno); bp += strlen(bp); break; + case 'x': + if (funcstack && funcstack->tp != FS_SOURCE) + promptpath(funcstack->filename ? funcstack->filename : "", + arg, 0); + else + promptpath(scriptfilename ? scriptfilename : argzero, + arg, 0); + break; case '\0': return 0; case Meta: diff --git a/Src/signals.c b/Src/signals.c index b794f1527..ba5777524 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -963,8 +963,7 @@ endtrapscope(void) } if (exittr) { - dotrapargs(SIGEXIT, &exittr, (exittr & ZSIG_FUNC) ? - ((Shfunc)exitfn)->funcdef : (Eprog) exitfn); + dotrapargs(SIGEXIT, &exittr, exitfn); if (exittr & ZSIG_FUNC) shfunctab->freenode((HashNode)exitfn); else @@ -1077,8 +1076,16 @@ int intrap; /**/ int trapisfunc; +/* + * sig is the signal number. + * *sigtr is the value to be taken as the field in sigtrapped (since + * that may have changed by this point if we are exiting). + * sigfn is an Eprog with a non-function eval list, or a Shfunc + * with a function trap. It may be NULL with an ignored signal. + */ + /**/ -void +static void dotrapargs(int sig, int *sigtr, void *sigfn) { LinkList args; @@ -1153,7 +1160,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) trapisfunc = isfunc = 1; sfcontext = SFC_SIGNAL; - doshfunc(name, sigfn, args, 0, 1); + doshfunc((Shfunc)sigfn, args, 0, 1); sfcontext = osc; freelinklist(args, (FreeFunc) NULL); zsfree(name); @@ -1162,7 +1169,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn) trap_state = TRAP_STATE_PRIMED; trapisfunc = isfunc = 0; - execode(sigfn, 1, 0); + execode((Eprog)sigfn, 1, 0); } runhookdef(AFTERTRAPHOOK, NULL); @@ -1215,12 +1222,12 @@ dotrapargs(int sig, int *sigtr, void *sigfn) void dotrap(int sig) { - Eprog funcprog; + void *funcprog; if (sigtrapped[sig] & ZSIG_FUNC) { HashNode hn = gettrapnode(sig, 0); if (hn) - funcprog = ((Shfunc)hn)->funcdef; + funcprog = hn; else { #ifdef DEBUG dputs("BUG: running function trap which has escaped."); @@ -1230,7 +1237,11 @@ dotrap(int sig) } else funcprog = siglists[sig]; - /* Copied from dotrapargs(). */ + /* + * Copied from dotrapargs(). + * (In fact, the gain from duplicating this appears to be virtually + * zero. Not sure why it's here.) + */ if ((sigtrapped[sig] & ZSIG_IGNORED) || !funcprog || errflag) return; diff --git a/Src/utils.c b/Src/utils.c index dfece68a8..748c62920 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -35,6 +35,8 @@ /**/ mod_export char *scriptname; /* is sometimes a function name */ +/* filename of script or other file containing code source e.g. autoload */ + /**/ mod_export char *scriptfilename; @@ -1134,7 +1136,7 @@ time_t lastwatch; mod_export int callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval) { - Eprog prog; + Shfunc shfunc; /* * Save stopmsg, since user doesn't get a chance to respond * to a list of jobs generated in a hook. @@ -1143,8 +1145,8 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval) sfcontext = SFC_HOOK; - if ((prog = getshfunc(name)) != &dummy_eprog) { - ret = doshfunc(name, prog, lnklst, 0, 1); + if ((shfunc = getshfunc(name))) { + ret = doshfunc(shfunc, lnklst, 0, 1); stat = 0; } @@ -1159,8 +1161,8 @@ callhookfunc(char *name, LinkList lnklst, int arrayp, int *retval) if ((arrptr = getaparam(arrnam))) { for (; *arrptr; arrptr++) { - if ((prog = getshfunc(*arrptr)) != &dummy_eprog) { - int newret = doshfunc(arrnam, prog, lnklst, 0, 1); + if ((shfunc = getshfunc(*arrptr))) { + int newret = doshfunc(shfunc, lnklst, 0, 1); if (!ret) ret = newret; stat = 0; @@ -2893,15 +2895,10 @@ sepsplit(char *s, char *sep, int allownull, int heap) /* Get the definition of a shell function */ /**/ -mod_export Eprog +mod_export Shfunc getshfunc(char *nam) { - Shfunc shf; - - if (!(shf = (Shfunc) shfunctab->getnode(shfunctab, nam))) - return &dummy_eprog; - - return shf->funcdef; + return (Shfunc) shfunctab->getnode(shfunctab, nam); } /**/ |