From dda51b9dbbfa6b3f7b8b99124b0a2a504521eb2c Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 6 Jan 2013 18:55:00 +0000 Subject: 30949: restore "read -q" behavior lost by 27188 --- Src/builtin.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 90fe1a6c5..f5c727f47 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5490,6 +5490,9 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) eof = 2; else eof = (bptr - buf != 1 || (buf[0] != 'y' && buf[0] != 'Y')); + buf[0] = eof ? 'n' : 'y'; + buf[1] = 0; + bptr = buf+2; } if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) fwrite(buf, bptr - buf, 1, stdout); -- cgit v1.2.3 From 3ed9e4d1b9bc97a577df3d9679959ad7e839cd9d Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Tue, 8 Jan 2013 07:18:50 +0000 Subject: unposted: tweak 30949 to fix buffer pointer --- ChangeLog | 7 ++++++- Src/builtin.c | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 14ff3458b..9a3c20ecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-01-07 Bart Schaefer + + * unposted (see 30952): Src/builtin.c: tweak to 30949 to fix the + buffer pointer. + 2013-01-06 Bart Schaefer * 30949: Src/builtin.c: restore "read -q" behavior lost by 27188. @@ -435,5 +440,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5783 $ +* $Revision: 1.5784 $ ***************************************************** diff --git a/Src/builtin.c b/Src/builtin.c index f5c727f47..f13167f33 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5491,8 +5491,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) else eof = (bptr - buf != 1 || (buf[0] != 'y' && buf[0] != 'Y')); buf[0] = eof ? 'n' : 'y'; - buf[1] = 0; - bptr = buf+2; + bptr = buf + 1; } if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) fwrite(buf, bptr - buf, 1, stdout); -- cgit v1.2.3 From 555b95c5f39bb3221ad3a54e583ec643aa2ce516 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 22 Feb 2013 20:26:32 +0000 Subject: 31060:"+" before a flag for "functions" or "autoload" should suppress display of function body. --- ChangeLog | 7 ++++++- Src/builtin.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 04a051add..afcb54c76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-02-22 Peter Stephenson + + * 31060: Src/builtin.c: "+" before a flag for "functions" or + "autoload" should suppress display of function body. + 2013-02-21 Oliver Kiddle * 31058: Completion/Zsh/Command/_fc, Completion/Unix/Command/_cut, @@ -532,5 +537,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5804 $ +* $Revision: 1.5805 $ ***************************************************** diff --git a/Src/builtin.c b/Src/builtin.c index f13167f33..d91c2d944 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2680,7 +2680,7 @@ bin_functions(char *name, char **argv, Options ops, int func) Patprog pprog; Shfunc shf; int i, returnval = 0; - int on = 0, off = 0, pflags = 0; + int on = 0, off = 0, pflags = 0, roff; /* Do we have any flags defined? */ if (OPT_PLUS(ops,'u')) @@ -2699,16 +2699,21 @@ bin_functions(char *name, char **argv, Options ops, int func) on |= PM_TAGGED_LOCAL; else if (OPT_PLUS(ops,'T')) off |= PM_TAGGED_LOCAL; + roff = off; if (OPT_MINUS(ops,'z')) { on |= PM_ZSHSTORED; off |= PM_KSHSTORED; - } else if (OPT_PLUS(ops,'z')) + } else if (OPT_PLUS(ops,'z')) { off |= PM_ZSHSTORED; + roff |= PM_ZSHSTORED; + } if (OPT_MINUS(ops,'k')) { on |= PM_KSHSTORED; off |= PM_ZSHSTORED; - } else if (OPT_PLUS(ops,'k')) + } else if (OPT_PLUS(ops,'k')) { off |= PM_KSHSTORED; + roff |= PM_KSHSTORED; + } if ((off & PM_UNDEFINED) || (OPT_ISSET(ops,'k') && OPT_ISSET(ops,'z')) || (OPT_MINUS(ops,'X') && (OPT_ISSET(ops,'m') || *argv || !scriptname))) { @@ -2716,7 +2721,7 @@ bin_functions(char *name, char **argv, Options ops, int func) return 1; } - if (OPT_PLUS(ops,'f') || OPT_ISSET(ops,'+')) + if (OPT_PLUS(ops,'f') || roff || OPT_ISSET(ops,'+')) pflags |= PRINT_NAMEONLY; if (OPT_MINUS(ops,'M') || OPT_PLUS(ops,'M')) { -- cgit v1.2.3 From 424ff5644b2a06b18e8e431ecb555502eea1ae41 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 10 Apr 2013 18:10:45 +0100 Subject: users/17754: failing to retie an array and colon-separated scalar shouldn't be a fatal error --- ChangeLog | 5 +++++ Src/builtin.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 28b5174c4..9963a0da8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-04-10 Peter Stephenson + + * users/17754: Src/builtin.c: failing to retie an array + and colon-separated scalar shouldn't be a fatal error. + 2013-04-09 Peter Stephenson * 31246: Makefile.in, Src/zsh.mdd: make a separate patch level diff --git a/Src/builtin.c b/Src/builtin.c index d91c2d944..cd886437b 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2470,7 +2470,7 @@ bin_typeset(char *name, char **argv, Options ops, int func) setsparam(asg0.name, ztrdup(asg0.value)); return 0; } else { - zerrnam(name, "can't tie already tied scalar: %s", + zwarnnam(name, "can't tie already tied scalar: %s", asg0.name); } return 1; -- cgit v1.2.3 From 1182a75e1b4d46a42935a217e80a2955b76be1a5 Mon Sep 17 00:00:00 2001 From: Barton Schaefer Date: Mon, 20 May 2013 22:44:03 -0700 Subject: upon "read" of a short line, assign all variables passed as arguments. It was noted that (print 1 2 | read one two three four) assigned values only to $one and $two except in the case where EOF was reached. --- ChangeLog | 5 +++++ Src/builtin.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 6cdb25ae9..4ce49d11b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-05-20 Barton Schaefer + + * 31416: Src/builtin.c: upon "read" of a short line, assign all + variables passed as arguments. + 2013-05-14 Peter Stephenson * unposted: Completion/Unix/Command/_perforce: Improve diff --git a/Src/builtin.c b/Src/builtin.c index cd886437b..bc91578b3 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5674,7 +5674,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) zputs(buf, stdout); putchar('\n'); } - if (!OPT_ISSET(ops,'e') && (*buf || first)) { + if (!OPT_ISSET(ops,'e') && (*buf || first || gotnl)) { if (OPT_ISSET(ops,'A')) { addlinknode(readll, buf); al++; -- cgit v1.2.3 From fdf2867e5f08809ff3fccc78fb6df13a196e3efc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 13 Jun 2013 18:38:33 +0100 Subject: 31444: Basic code for enable/disable -p --- Doc/Zsh/builtins.yo | 102 +++++++++++++++++++++++++++++--- Doc/Zsh/options.yo | 13 ++++ Doc/zmacros.yo | 1 + Src/builtin.c | 20 +++++-- Src/exec.c | 5 ++ Src/options.c | 1 + Src/pattern.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Src/zsh.h | 16 +++++ 8 files changed, 313 insertions(+), 12 deletions(-) (limited to 'Src/builtin.c') diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index f3a7f6a97..3623f9bb9 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -291,8 +291,8 @@ enditem() findex(disable) cindex(disabling commands) cindex(commands, disabling) -item(tt(disable) [ tt(-afmrs) ] var(name) ...)( -Temporarily disable the var(name)d hash table elements. The default +item(tt(disable) [ tt(-afmprs) ] var(name) ...)( +Temporarily disable the var(name)d hash table elements or patterns. The default is to disable builtin commands. This allows you to use an external command with the same name as a builtin command. The tt(-a) option causes tt(disable) to act on regular or global aliases. The tt(-s) @@ -305,6 +305,80 @@ quoted to prevent them from undergoing filename expansion), and all hash table elements from the corresponding hash table matching these patterns are disabled. Disabled objects can be enabled with the tt(enable) command. + +With the option tt(-p), var(name) ... refer to elements of the +shell's pattern syntax as described in noderef(Filename Generation). +Certain elements can be disabled separately, as given below. + +Note that patterns +not allowed by the current settings for the options tt(EXTENDED_GLOB), +tt(KSH_GLOB) and tt(SH_GLOB) are never enabled, regardless of the +setting here. For example, if tt(EXTENDED_GLOB) is not active, +the pattern tt(^) is ineffective even if `tt(disable -p "^")' has +not been issued. The list below indicates any option settings +that restrict the use of the pattern. It should be noted that +setting tt(SH_GLOB) has a wider effect then merely disabling patterns +as certain expressions, in particular those involving parentheses, +are parsed differently. + +The following patterns may be disabled; all +the strings need quoting on the command line to prevent them from +being interpreted immediately as patterns and the patterns are +shown below in single quotes as a reminder. +startitem() +item(tt('?'))( +The pattern character tt(?) wherever it occurs, including when preceding +a parenthesis with tt(KSH_GLOB). +) +item(tt('*'))( +The pattern character tt(*) wherever it occurs, including recursive +globbing and when preceding a parenthesis with tt(KSH_GLOB). +) +item('LSQUARE()')( +Character classes. +) +item(tt('<') (tt(NO_SH_GLOB)))( +Numeric ranges. +) +item(tt('|') (tt(NO_SH_GLOB)))( +Alternation in grouped patterns, case statements, or KSH_GLOB +parenthesised expressions. +) +item(tt('LPAR()') (tt(NO_SH_GLOB)))( +Grouping using single parentheses. Disabling this does not disable the +use of parentheses for tt(KSH_GLOB) where they are introduced by a +special character, nor for glob qualifiers (use `tt(setopt +NO_BARE_GLOB_QUAL)' to disable glob qualifiers that use parentheses +only). +) +item(tt('~') (tt(EXTENDED_GLOB)))( +Exclusion in the form var(A)tt(~)var(B). +) +item(tt('^') (tt(EXTENDED_GLOB)))( +Exclusion in the form var(A)tt(^)var(B). +) +item(tt('#') (tt(EXTENDED_GLOB)))( +The pattern character tt(#) wherever it occurs, both for +repetition of a previous pattern and for indicating globbing flags. +) +item(tt('?LPAR()') (tt(KSH_GLOB)))( +The grouping form tt(?LPAR())var(...)tt(RPAR()). Note this is also +disabled if tt('?') is disabled. +) +item(tt('*LPAR()') (tt(KSH_GLOB)))( +The grouping form tt(*LPAR())var(...)tt(RPAR()). Note this is also +disabled if tt('*') is disabled. +) +item(tt('PLUS()LPAR()') (tt(KSH_GLOB)))( +The grouping form tt(PLUS()LPAR())var(...)tt(RPAR()). +) +item(tt('!LPAR()') (tt(KSH_GLOB)))( +The grouping form tt(!LPAR())var(...)tt(RPAR()). +) +item(tt('@LPAR()') (tt(KSH_GLOB)))( +The grouping form tt(@LPAR())var(...)tt(RPAR()). +) +enditem() ) findex(disown) cindex(jobs, disowning) @@ -376,7 +450,9 @@ the section COMPATIBILITY in zmanref(zsh) ifnzman(\ noderef(Compatibility) )\ -. +. In addition to setting shell options, the command also restores +the pristine state of pattern enables, as if all patterns had been +enabled using tt(enable -p). If the tt(emulate) command occurs inside a function that has been marked for execution tracing with tt(functions -t) then the tt(xtrace) @@ -390,9 +466,11 @@ are reset to their default value corresponding to the specified emulation mode, except for certain options describing the interactive environment; otherwise, only those options likely to cause portability problems in scripts and functions are altered. If the tt(-L) switch is given, -the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set as -well, causing the effects of the tt(emulate) command and any tt(setopt) and -tt(trap) commands to be local to the immediately surrounding shell +the options tt(LOCAL_OPTIONS), tt(LOCAL_PATTERNS) and tt(LOCAL_TRAPS) +will be set as +well, causing the effects of the tt(emulate) command and any tt(setopt), +tt(disable -p) or tt(enable -b), and tt(trap) commands to be local to +the immediately surrounding shell function, if any; normally these options are turned off in all emulation modes except tt(ksh). The tt(-L) switch is mutually exclusive with the use of tt(-c) in var(flags). @@ -414,7 +492,8 @@ Use of tt(-c) enables `sticky' emulation mode for functions defined within the evaluated expression: the emulation mode is associated thereafter with the function so that whenever the function is executed the emulation (respecting the tt(-R) switch, if present) and all -options are set before entry to the function, and restored after exit. +options are set (and pattern disables cleared) +before entry to the function, and the state is restored after exit. If the function is called when the sticky emulation is already in effect, either within an `tt(emulate) var(shell) tt(-c)' expression or within another function with the same sticky emulation, entry and exit @@ -471,7 +550,7 @@ endsitem() findex(enable) cindex(enabling commands) cindex(commands, enabling) -item(tt(enable) [ tt(-afmrs) ] var(name) ...)( +item(tt(enable) [ tt(-afmprs) ] var(name) ...)( Enable the var(name)d hash table elements, presumably disabled earlier with tt(disable). The default is to enable builtin commands. The tt(-a) option causes tt(enable) to act on regular or global aliases. @@ -483,6 +562,13 @@ printed. With the tt(-m) flag the arguments are taken as patterns (should be quoted) and all hash table elements from the corresponding hash table matching these patterns are enabled. Enabled objects can be disabled with the tt(disable) builtin command. + +tt(enable -p) reenables patterns disabled with tt(disable -p). Note +that it does not override globbing options; for example, `tt(enable -p +"~")' does not cause the pattern character tt(~) to be active unless +the tt(EXTENDED_GLOB) option is also set. To enable all possible +patterns (so that they may be invidually disabled with tt(disable -p)), +use `tt(setopt EXTENDED_GLOB KSH_GLOB NO_SH_GLOB)'. ) findex(eval) cindex(evaluating arguments as commands) diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 60892dd8b..ec862321e 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1618,6 +1618,19 @@ A shell function can also guarantee itself a known shell configuration with a formulation like `tt(emulate -L zsh)'; the tt(-L) activates tt(LOCAL_OPTIONS). ) +pindex(LOCAL_PATTERNS) +pindex(NO_LOCAL_PATTERNS) +pindex(LOCALPATTERNS) +pindex(NOLOCALPATTERNS) +item(tt(LOCAL_PATTERNS))( +If this option is set at the point of return from a shell function, +the state of pattern disables, as set with the builtin command +`tt(disable -p)', is restored to what it was when the function was +entered. The behaviour of this option is similar to the effect +of tt(LOCAL_OPTIONS) on options; hence `tt(emulate -L sh)' (or +indeed any other emulation with the tt(-L) option) activates +tt(LOCAL_PATTERNS). +) pindex(LOCAL_TRAPS) pindex(NO_LOCAL_TRAPS) pindex(LOCALTRAPS) diff --git a/Doc/zmacros.yo b/Doc/zmacros.yo index 19506d222..aed5bd8a7 100644 --- a/Doc/zmacros.yo +++ b/Doc/zmacros.yo @@ -33,6 +33,7 @@ DEFINEMACRO(RQUOTE)(0)(CHAR(39)) DEFINEMACRO(LPAR)(0)(CHAR(40)) DEFINEMACRO(RPAR)(0)(CHAR(41)) DEFINEMACRO(PLUS)(0)(CHAR(43)) +DEFINEMACRO(LSQUARE)(0)(CHAR(91)) DEFINEMACRO(DASH)(0)(ifztexi(--)ifnztexi(-)) diff --git a/Src/builtin.c b/Src/builtin.c index bc91578b3..8516acd81 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -55,11 +55,11 @@ static struct builtin builtins[] = BUILTIN("continue", BINF_PSPECIAL, bin_break, 0, 1, BIN_CONTINUE, NULL, NULL), BUILTIN("declare", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%klmprtuxz", NULL), BUILTIN("dirs", 0, bin_dirs, 0, -1, 0, "clpv", NULL), - BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmrs", NULL), + BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmprs", NULL), BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL), BUILTIN("echo", BINF_SKIPINVALID, bin_print, 0, -1, BIN_ECHO, "neE", "-"), BUILTIN("emulate", 0, bin_emulate, 0, -1, 0, "LR", NULL), - BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmrs", NULL), + BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmprs", NULL), BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL), BUILTIN("exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL), BUILTIN("export", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, BIN_EXPORT, "E:%F:%HL:%R:%TUZ:%afhi:%lprtu", "xg"), @@ -467,7 +467,9 @@ bin_enable(char *name, char **argv, Options ops, int func) int match = 0, returnval = 0; /* Find out which hash table we are working with. */ - if (OPT_ISSET(ops,'f')) + if (OPT_ISSET(ops,'p')) { + return pat_enables(name, argv, func == BIN_ENABLE); + } else if (OPT_ISSET(ops,'f')) ht = shfunctab; else if (OPT_ISSET(ops,'r')) ht = reswdtab; @@ -5020,6 +5022,7 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) int opt_R = OPT_ISSET(ops, 'R'); int saveemulation, savehackchar; int ret = 1, new_emulation; + unsigned int savepatterns; char saveopts[OPT_SIZE], new_opts[OPT_SIZE]; char *cmd = 0; const char *shname = *argv; @@ -5061,7 +5064,8 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) if (!argv[1]) { emulate(shname, OPT_ISSET(ops,'R'), &emulation, opts); if (OPT_ISSET(ops,'L')) - opts[LOCALOPTIONS] = opts[LOCALTRAPS] = 1; + opts[LOCALOPTIONS] = opts[LOCALTRAPS] = opts[LOCALPATTERNS] = 1; + clearpatterndisables(); return 0; } @@ -5082,6 +5086,13 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) goto restore; } + savepatterns = savepatterndisables(); + /* + * All emulations start with an empty set of pattern disables, + * hence no special "sticky" behaviour is required. + */ + clearpatterndisables(); + saveemulation = emulation; emulation = new_emulation; memcpy(opts, new_opts, sizeof(opts)); @@ -5131,6 +5142,7 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) sticky = save_sticky; emulation = saveemulation; memcpy(opts, saveopts, sizeof(opts)); + restorepatterndisables(savepatterns); restore: keyboardhackchar = savehackchar; inittyptab(); /* restore banghist */ diff --git a/Src/exec.c b/Src/exec.c index 14c2ba003..75805d3f5 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4627,6 +4627,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) } starttrapscope(); + startpatternscope(); pptab = pparams; if (!(flags & PM_UNDEFINED)) @@ -4674,6 +4675,8 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) offptr++) opts[*offptr] = 0; } + /* All emulations start with pattern disables clear */ + clearpatterndisables(); } else restore_sticky = 0; @@ -4774,6 +4777,8 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) scriptname = oldscriptname; oflags = ooflags; + endpatternscope(); /* before restoring old LOCALPATTERNS */ + if (restore_sticky) { /* * If we switched to an emulation environment just for diff --git a/Src/options.c b/Src/options.c index 480fccd57..ad869b253 100644 --- a/Src/options.c +++ b/Src/options.c @@ -179,6 +179,7 @@ static struct optname optns[] = { {{NULL, "listrowsfirst", 0}, LISTROWSFIRST}, {{NULL, "listtypes", OPT_ALL}, LISTTYPES}, {{NULL, "localoptions", OPT_EMULATE|OPT_KSH}, LOCALOPTIONS}, +{{NULL, "localpatterns", OPT_EMULATE}, LOCALPATTERNS}, {{NULL, "localtraps", OPT_EMULATE|OPT_KSH}, LOCALTRAPS}, {{NULL, "login", OPT_SPECIAL}, LOGINSHELL}, {{NULL, "longlistjobs", 0}, LONGLISTJOBS}, diff --git a/Src/pattern.c b/Src/pattern.c index 54d6e7cb3..a90d3cddc 100644 --- a/Src/pattern.c +++ b/Src/pattern.c @@ -232,6 +232,27 @@ static const char zpc_chars[ZPC_COUNT] = { Hat, Pound, Bnullkeep, Quest, Star, '+', '!', '@' }; +/* + * Corresponding strings used in enable/disable -p. + * NULL means no way of turning this on or off. + */ +static const char *zpc_strings[ZPC_COUNT] = { + NULL, NULL, "|", NULL, "~", "(", "?", "*", "[", "<", + "^", "#", NULL, "?(", "*(", "+(", "!(", "@(" +}; + +/* + * Corresponding array of pattern disables as set by the user + * using "disable -p". + */ +static char zpc_disables[ZPC_COUNT]; + +/* + * Stack of saved (compressed) zpc_disables for function scope. + */ + +static struct zpc_disables_save *zpc_disables_stack; + /* * Characters which terminate a simple string (ZPC_COUNT) or * an entire pattern segment (the first ZPC_SEG_COUNT). @@ -414,7 +435,19 @@ static long rn_offs; static void patcompcharsset(void) { + char *spp, *disp; + int i; + + /* Initialise enabled special characters */ memcpy(zpc_special, zpc_chars, ZPC_COUNT); + /* Apply user disables from disable -p */ + for (i = 0, spp = zpc_special, disp = zpc_disables; + i < ZPC_COUNT; + i++, spp++, disp++) { + if (*disp) + *spp = Marker; + } + if (!isset(EXTENDEDGLOB)) { /* Extended glob characters are not active */ zpc_special[ZPC_TILDE] = zpc_special[ZPC_HAT] = @@ -3799,3 +3832,137 @@ freepatprog(Patprog prog) if (prog && prog != dummy_patprog1 && prog != dummy_patprog2) zfree(prog, prog->size); } + +/* Disable or reenable a pattern character */ + +/**/ +int +pat_enables(const char *cmd, char **patp, int enable) +{ + int ret = 0; + const char **stringp; + char *disp; + + if (!*patp) { + int done = 0; + for (stringp = zpc_strings, disp = zpc_disables; + stringp < zpc_strings + ZPC_COUNT; + stringp++, disp++) { + if (!*stringp) + continue; + if (enable ? *disp : !*disp) + continue; + if (done) + putc(' ', stdout); + printf("'%s'", *stringp); + done = 1; + } + if (done) + putc('\n', stdout); + return 0; + } + + for (; *patp; patp++) { + for (stringp = zpc_strings, disp = zpc_disables; + stringp < zpc_strings + ZPC_COUNT; + stringp++, disp++) { + if (*stringp && !strcmp(*stringp, *patp)) { + *disp = (char)!enable; + break; + } + } + if (stringp == zpc_strings + ZPC_COUNT) { + zerrnam(cmd, "invalid pattern: %s", *patp); + ret = 1; + } + } + + return ret; +} + +/* + * Save the current state of pattern disables, returning the saved value. + */ + +/**/ +unsigned int +savepatterndisables(void) +{ + unsigned int disables, bit; + char *disp; + + disables = 0; + for (bit = 1, disp = zpc_disables; + disp < zpc_disables + ZPC_COUNT; + bit <<= 1, disp++) { + if (*disp) + disables |= bit; + } + return disables; +} + +/* + * Function scope saving pattern enables. + */ + +/**/ +void +startpatternscope(void) +{ + Zpc_disables_save newdis; + + newdis = (Zpc_disables_save)zalloc(sizeof(*newdis)); + newdis->next = zpc_disables_stack; + newdis->disables = savepatterndisables(); + + zpc_disables_stack = newdis; +} + +/* + * Restore completely the state of pattern disables. + */ + +/**/ +void +restorepatterndisables(unsigned int disables) +{ + char *disp; + unsigned int bit; + + for (bit = 1, disp = zpc_disables; + disp < zpc_disables + ZPC_COUNT; + bit <<= 1, disp++) { + if (disables & bit) + *disp = 1; + else + *disp = 0; + } +} + +/* + * Function scope to restore pattern enables if localpatterns is turned on. + */ + +/**/ +void +endpatternscope(void) +{ + Zpc_disables_save olddis; + + olddis = zpc_disables_stack; + zpc_disables_stack = olddis->next; + + if (isset(LOCALPATTERNS)) + restorepatterndisables(olddis->disables); + + zfree(olddis, sizeof(*olddis)); +} + +/* Reinitialise pattern disables */ + +/**/ +void +clearpatterndisables(void) +{ + memset(zpc_disables, 0, ZPC_COUNT); +} diff --git a/Src/zsh.h b/Src/zsh.h index 639c2b746..299357de8 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1413,6 +1413,21 @@ enum zpc_chars { ZPC_COUNT /* Number of special chararacters */ }; +/* + * Structure to save disables special characters for function scope. + */ +struct zpc_disables_save { + struct zpc_disables_save *next; + /* + * Bit vector of ZPC_COUNT disabled characters. + * We'll live dangerously and assumed ZPC_COUNT is no greater + * than the number of bits an an unsigned int. + */ + unsigned int disables; +}; + +typedef struct zpc_disables_save *Zpc_disables_save; + /* * Special match types used in character classes. These * are represented as tokens, with Meta added. The character @@ -2074,6 +2089,7 @@ enum { LISTROWSFIRST, LISTTYPES, LOCALOPTIONS, + LOCALPATTERNS, LOCALTRAPS, LOGINSHELL, LONGLISTJOBS, -- cgit v1.2.3 From 9d32c82da323982610dacc2562b1135dbb2079af Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 29 Jul 2013 10:44:07 +0100 Subject: 17591: fix error message for invalid fd in print -u --- ChangeLog | 5 +++++ Src/builtin.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 6c6dbef92..0c04ac112 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-07-29 Peter Stephenson + + * 17891: Src/builtin.c: fix error message for invalid file + descriptor in "print -u". + 2013-07-28 Peter Stephenson * Manuel Presnitz: 31592 (with minor changes of phrasing): diff --git a/Src/builtin.c b/Src/builtin.c index 8516acd81..ae2e9f676 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3792,11 +3792,11 @@ bin_print(char *name, char **args, Options ops, int func) /* -u and -p -- output to other than standard output */ if (OPT_HASARG(ops,'u') || OPT_ISSET(ops,'p')) { - int fd; + int fdarg, fd; if (OPT_ISSET(ops, 'p')) { - fd = coprocout; - if (fd < 0) { + fdarg = coprocout; + if (fdarg < 0) { zwarnnam(name, "-p: no coprocess"); return 1; } @@ -3804,13 +3804,13 @@ bin_print(char *name, char **args, Options ops, int func) char *argptr = OPT_ARG(ops,'u'), *eptr; /* Handle undocumented feature that -up worked */ if (!strcmp(argptr, "p")) { - fd = coprocout; - if (fd < 0) { + fdarg= coprocout; + if (fdarg < 0) { zwarnnam(name, "-p: no coprocess"); return 1; } } else { - fd = (int)zstrtol(argptr, &eptr, 10); + fdarg = (int)zstrtol(argptr, &eptr, 10); if (*eptr) { zwarnnam(name, "number expected after -%c: %s", 'u', argptr); @@ -3819,8 +3819,8 @@ bin_print(char *name, char **args, Options ops, int func) } } - if ((fd = dup(fd)) < 0) { - zwarnnam(name, "bad file number: %d", fd); + if ((fd = dup(fdarg)) < 0) { + zwarnnam(name, "bad file number: %d", fdarg); return 1; } if ((fout = fdopen(fd, "w")) == 0) { -- cgit v1.2.3 From 9ebf22b34b5e8d4b8bd147a038458d82735d9d2e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 5 Aug 2013 19:55:15 +0100 Subject: 31631: Use cygwin_conv_path if available. Prefer it to cygwin_conv_to_posix_path. --- ChangeLog | 5 +++++ Src/builtin.c | 5 +++++ configure.ac | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 21c0cef7c..b6ff9fcef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-08-05 Peter Stephenson + + * 31631: configure.ac, Src/builtin.c: use cygwin_conv_path in + preference to cygwin_conv_to_posix_path if available. + 2013-08-04 Peter Stephenson * Yuusuke Yoshimoto: 31632: Completion/Unix/Type/_java_class: diff --git a/Src/builtin.c b/Src/builtin.c index ae2e9f676..3159975e3 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -939,11 +939,16 @@ cd_do_chdir(char *cnam, char *dest, int hard) * DOS style names with drives in them */ static char buf[PATH_MAX]; +#ifdef HAVE_CYGWIN_CONV_PATH + cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, dest, buf, + PATH_MAX); +#else #ifndef _SYS_CYGWIN_H void cygwin_conv_to_posix_path(const char *, char *); #endif cygwin_conv_to_posix_path(dest, buf); +#endif dest = buf; #endif nocdpath = dest[0] == '.' && diff --git a/configure.ac b/configure.ac index 5528597ba..c3debd8ad 100644 --- a/configure.ac +++ b/configure.ac @@ -1237,7 +1237,8 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \ regcomp regexec regerror regfree \ gdbm_open getxattr \ realpath canonicalize_file_name \ - symlink getcwd) + symlink getcwd \ + cygwin_conv_path) AC_FUNC_STRCOLL if test x$enable_cap = xyes; then -- cgit v1.2.3 From 935758ab7febbf1c46323d530fae2bae1dfd23d5 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 18 Aug 2013 20:24:45 -0700 Subject: 31637: be more selective about retry of lchdir() in cd_do_chdir() Change of directory should not be retried relative to the current directory when it has already failed along some path that does not refer to the current directory. --- ChangeLog | 6 ++++++ Src/builtin.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index d27000788..74e0ebeb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-08-17 Barton E. Schaefer + + * 31637: Src/builtin.c: change of directory should not be retried + relative to the current directory when it has already failed along + some path that does not refer to the current directory. + 2013-08-11 Peter Stephenson * 31650: Src/utils.c: use zlong for mailcheck parameters to diff --git a/Src/builtin.c b/Src/builtin.c index 3159975e3..f8be4acc9 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1125,7 +1125,8 @@ cd_try_chdir(char *pfix, char *dest, int hard) * argument to cd relatively. This is useful if the cwd * or a parent directory is renamed in the interim. */ - if (lchdir(buf, NULL, hard) && lchdir(dest, NULL, hard)) { + if (lchdir(buf, NULL, hard) && + (pfix || *dest == '/' || lchdir(dest, NULL, hard))) { free(buf); return NULL; } -- cgit v1.2.3 From c866657a3cfd8a82d3c6ee06ff193a0c927b299f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 6 Sep 2013 20:37:40 +0100 Subject: 31706: standardize handling of "test ! " --- ChangeLog | 5 +++++ Src/builtin.c | 13 ++++++++++--- Test/C02cond.ztst | 6 +++++- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 72fc65195..0e8809ad3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-09-06 Peter Stephenson + + * 31706: Src/builtin.c, Test/C02cond.ztst: standardise + handling of "test ! ". + 2013-09-04 Peter Stephenson * 31696: Src/parse.c, Test/C02cond.ztst: in "test", no one diff --git a/Src/builtin.c b/Src/builtin.c index f8be4acc9..c3f0169c7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5995,7 +5995,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) char **s; Eprog prog; struct estate state; - int nargs; + int nargs, sense = 0, ret; /* if "test" was invoked as "[", it needs a matching "]" * * which is subsequently ignored */ @@ -6014,7 +6014,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) /* * Implement some XSI extensions to POSIX here. * See - * http://www.opengroup.org/onlinepubs/009695399/utilities/test.html. + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html */ nargs = arrlen(argv); if (nargs == 3 || nargs == 4) @@ -6023,6 +6023,10 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) argv[nargs-1] = NULL; argv++; } + if (nargs == 4 && !strcmp("!", argv[0])) { + sense = 1; + argv++; + } } lexsave(); @@ -6057,8 +6061,11 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) state.pc = prog->prog; state.strs = prog->strs; + ret = evalcond(&state, name); + if (ret < 2 && sense) + ret = ! ret; - return evalcond(&state, name); + return ret; } /* display a time, provided in units of 1/60s, as minutes and seconds */ diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 856251923..94fca8b68 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -331,7 +331,9 @@ F:Failures in these cases do not indicate a problem in the shell. '! -o' '! -a ! -a !' '! = !' - '! !') + '! !' + '= -a o' + '! = -a o') for w in $weirdies; do eval test $w print $? @@ -344,6 +346,8 @@ F:Failures in these cases do not indicate a problem in the shell. >0 >0 >1 +>0 +>1 %clean # This works around a bug in rm -f in some versions of Cygwin -- cgit v1.2.3