From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20412 invoked by alias); 19 Aug 2012 19:21:07 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30633 Received: (qmail 7642 invoked from network); 19 Aug 2012 19:20:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.171 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:x-mailer :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=8sLE++kUq3zvTY3zUzKLhnRWd34AMcf2+ePuMz6WMPs=; b=VXl1Hy9N1w+tdgW1ofE+RdaEi5OpZkG0VQJ8f1zahHP1iO0plP6bKQQMDsXiondEuP OOSaDogdsvl7kMP/0YS9MOfv8e35V8JHOdxxBcNCginwwNaqojjzMde0sSm71F7RO+gr 10oF+q4QUqEaq6bYLal8yKcy763fsb+6Tfn22mXA9XexTx60xJ/MNFZrwtw8onwJ3grX /Ce9bZYUw0ATZvCs4rWuTdtHMqDJGaJsioOKRXTlg//pxr//AZSUkQuF+t/cP+ixlVie k7KjKa00Q03QRjcvYMkKsrg9HEnO/UUeuKgVh9Q3xuXthMVKFADVKGiuTZclPJRIUzYa r0/Q== X-ProxyUser-IP: 86.6.16.18 Date: Sun, 19 Aug 2012 20:20:41 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: functions -T does tracing for current function only Message-ID: <20120819202041.7091ed97@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQneQHE2tc0xktSg0enwb3oTigZE0xIZpEn0+SLMJu/dzyAt3wE+MWaSPSUI3xpfE4hf4149 It's been annoying me for a good few years that I can't make the shell trace a specific function without it turning on tracing for functions called from that. This makes the flag -T do that. We're in luck that although typeset -T without the -f requires a specific number of arguments that test isn't applied in the code common the cases with and without the -f. (Obviously the meaning of typeset -T for variables doesn't apply to functions.) I'm sure you'll tell me if it doesn't work. (I thought a bit about making the called functions explicit turn tracing off; there's some logic in that, but it's much less convenient, since I'd have to find out what functions were called from the function I was tracing and set the flag for all of them.) Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.139 diff -p -u -r1.139 builtins.yo --- Doc/Zsh/builtins.yo 16 Aug 2012 14:00:11 -0000 1.139 +++ Doc/Zsh/builtins.yo 19 Aug 2012 19:15:52 -0000 @@ -620,7 +620,7 @@ Equivalent to tt(typeset -E), except tha point numbers are not permitted. ) findex(functions) -xitem(tt(functions) [ {tt(PLUS())|tt(-)}tt(UXkmtuz) ] [ var(name) ... ]) +xitem(tt(functions) [ {tt(PLUS())|tt(-)}tt(UXkmtTuz) ] [ var(name) ... ]) xitem(tt(functions -M) var(mathfn) [ var(min) [ var(max) [ var(shellfn) ] ] ]) xitem(tt(functions -M) [ tt(-m) var(pattern) ... ]) item(tt(functions +M) [ tt(-m) ] var(mathfn))( @@ -1555,6 +1555,7 @@ export. Setting the value using the sca separators (which cannot be quoted). It is possible to use the same two tied variables with a different separator character in which case the variables remain joined as before but the separator is changed. +This flag has a different meaning when used with tt(-f); see below. The tt(-g) (global) flag is treated specially: it means that any resulting parameter will not be restricted to local scope. Note that this @@ -1652,16 +1653,18 @@ shown. ) item(tt(-f))( The names refer to functions rather than parameters. No assignments -can be made, and the only other valid flags are tt(-t), tt(-k), tt(-u), -tt(-U) and tt(-z). The flag tt(-t) turns on execution tracing for this -function. The tt(-u) and tt(-U) flags cause the function to be -marked for autoloading; tt(-U) also causes alias expansion to be -suppressed when the function is loaded. The tt(fpath) parameter -will be searched to find the function definition when the function -is first referenced; see noderef(Functions). The tt(-k) and tt(-z) flags -make the function be loaded using ksh-style or zsh-style autoloading -respectively. If neither is given, the setting of the KSH_AUTOLOAD option -determines how the function is loaded. +can be made, and the only other valid flags are tt(-t), tt(-T), tt(-k), +tt(-u), tt(-U) and tt(-z). The flag tt(-t) turns on execution tracing +for this function; the flag tt(-T) does the same, but turns off tracing +on any function called from the present one, unless that function also +has the tt(-t) or tt(-T) flag. The tt(-u) and tt(-U) flags cause the +function to be marked for autoloading; tt(-U) also causes alias +expansion to be suppressed when the function is loaded. The tt(fpath) +parameter will be searched to find the function definition when the +function is first referenced; see noderef(Functions). The tt(-k) and +tt(-z) flags make the function be loaded using ksh-style or zsh-style +autoloading respectively. If neither is given, the setting of the +KSH_AUTOLOAD option determines how the function is loaded. ) item(tt(-h))( Hide: only useful for special parameters (those marked `' in the table in Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.260 diff -p -u -r1.260 builtin.c --- Src/builtin.c 16 Aug 2012 14:00:11 -0000 1.260 +++ Src/builtin.c 19 Aug 2012 19:15:53 -0000 @@ -46,7 +46,7 @@ static struct builtin builtins[] = BUILTIN(".", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL), BUILTIN(":", BINF_PSPECIAL, bin_true, 0, -1, 0, NULL, NULL), BUILTIN("alias", BINF_MAGICEQUALS | BINF_PLUSOPTS, bin_alias, 0, -1, 0, "Lgmrs", NULL), - BUILTIN("autoload", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "ktUwXz", "u"), + BUILTIN("autoload", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "ktTUwXz", "u"), BUILTIN("bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL), BUILTIN("break", BINF_PSPECIAL, bin_break, 0, 1, BIN_BREAK, NULL, NULL), BUILTIN("bye", 0, bin_break, 0, 1, BIN_EXIT, NULL, NULL), @@ -72,7 +72,7 @@ static struct builtin builtins[] = BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlmnpPrRt:W", NULL), BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL), BUILTIN("float", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "E:%F:%HL:%R:%Z:%ghlprtux", "E"), - BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "kmMtuUz", NULL), + BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "kmMtTuUz", NULL), BUILTIN("getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"), BUILTIN("getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL), BUILTIN("hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "Ldfmrv", NULL), @@ -2685,6 +2685,10 @@ bin_functions(char *name, char **argv, O on |= PM_TAGGED; else if (OPT_PLUS(ops,'t')) off |= PM_TAGGED; + if (OPT_MINUS(ops,'T')) + on |= PM_TAGGED_LOCAL; + else if (OPT_PLUS(ops,'T')) + on |= PM_TAGGED_LOCAL; if (OPT_MINUS(ops,'z')) { on |= PM_ZSHSTORED; off |= PM_KSHSTORED; Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.210 diff -p -u -r1.210 exec.c --- Src/exec.c 5 Mar 2012 10:06:29 -0000 1.210 +++ Src/exec.c 19 Aug 2012 19:15:53 -0000 @@ -4484,11 +4484,12 @@ doshfunc(Shfunc shfunc, LinkList dosharg int *oldpipestats = NULL; char saveopts[OPT_SIZE], *oldscriptname = scriptname; char *name = shfunc->node.nam; - int flags = shfunc->node.flags; + int flags = shfunc->node.flags, ooflags; char *fname = dupstring(name); int obreaks, saveemulation, savesticky_emulation, restore_sticky; Eprog prog; struct funcstack fstack; + static int oflags; #ifdef MAX_FUNCTION_DEPTH static int funcdepth; #endif @@ -4547,8 +4548,17 @@ doshfunc(Shfunc shfunc, LinkList dosharg } else restore_sticky = 0; - if (flags & PM_TAGGED) + if (flags & (PM_TAGGED|PM_TAGGED_LOCAL)) opts[XTRACE] = 1; + else if (oflags & PM_TAGGED_LOCAL) + opts[XTRACE] = 0; + ooflags = oflags; + /* + * oflags is static, because we compare it on the next recursive + * call. Hence also we maintain ooflags for restoring the previous + * value of oflags after the call. + */ + oflags = flags; opts[PRINTEXITVALUE] = 0; if (doshargs) { LinkNode node; @@ -4633,6 +4643,7 @@ doshfunc(Shfunc shfunc, LinkList dosharg optcind = oldoptcind; zoptind = oldzoptind; scriptname = oldscriptname; + oflags = ooflags; if (restore_sticky) { /* Index: Src/hashtable.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/hashtable.c,v retrieving revision 1.36 diff -p -u -r1.36 hashtable.c --- Src/hashtable.c 1 Mar 2012 03:35:04 -0000 1.36 +++ Src/hashtable.c 19 Aug 2012 19:15:53 -0000 @@ -923,12 +923,13 @@ printshfuncnode(HashNode hn, int printfl printf("%c undefined\n\t", hashchar); else t = getpermtext(f->funcdef, NULL, 1); - if (f->node.flags & PM_TAGGED) + if (f->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL)) printf("%c traced\n\t", hashchar); if (!t) { - char *fopt = "Utkz"; + char *fopt = "UtTkz"; int flgs[] = { - PM_UNALIASED, PM_TAGGED, PM_KSHSTORED, PM_ZSHSTORED, 0 + PM_UNALIASED, PM_TAGGED, PM_TAGGED_LOCAL, + PM_KSHSTORED, PM_ZSHSTORED, 0 }; int fl;; Index: Src/options.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/options.c,v retrieving revision 1.61 diff -p -u -r1.61 options.c --- Src/options.c 7 Mar 2012 06:10:42 -0000 1.61 +++ Src/options.c 19 Aug 2012 19:15:53 -0000 @@ -532,7 +532,7 @@ emulate(const char *zsh_name, int fully) * close enough. */ Shfunc shf = (Shfunc)shfunctab->getnode(shfunctab, funcstack->name); - if (shf && (shf->node.flags & PM_TAGGED)) { + if (shf && (shf->node.flags & (PM_TAGGED|PM_TAGGED_LOCAL))) { /* Tracing is on, so set xtrace */ opts[XTRACE] = 1; } Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.137 diff -p -u -r1.137 subst.c --- Src/subst.c 22 Apr 2012 20:49:40 -0000 1.137 +++ Src/subst.c 19 Aug 2012 19:15:53 -0000 @@ -2314,6 +2314,8 @@ paramsubst(LinkList l, LinkNode n, char val = dyncat(val, "-readonly"); if (f & PM_TAGGED) val = dyncat(val, "-tag"); + if (f & PM_TAGGED_LOCAL) + val = dyncat(val, "-tag_local"); if (f & PM_EXPORTED) val = dyncat(val, "-export"); if (f & PM_UNIQUE) Index: Src/zsh.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v retrieving revision 1.182 diff -p -u -r1.182 zsh.h --- Src/zsh.h 16 Aug 2012 19:12:27 -0000 1.182 +++ Src/zsh.h 19 Aug 2012 19:15:53 -0000 @@ -1554,6 +1554,7 @@ struct tieddata { #define PM_HIDE (1<<14) /* Special behaviour hidden by local */ #define PM_HIDEVAL (1<<15) /* Value not shown in `typeset' commands */ #define PM_TIED (1<<16) /* array tied to colon-path or v.v. */ +#define PM_TAGGED_LOCAL (1<<16) /* (function): non-recursive PM_TAGGED */ #define PM_KSHSTORED (1<<17) /* function stored in ksh form */ #define PM_ZSHSTORED (1<<18) /* function stored in zsh form */ -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/