From acb7209f06f532b7682aaf9f329993756493c2ee Mon Sep 17 00:00:00 2001 From: Geoff Wing Date: Mon, 23 Jul 2012 03:45:40 +0000 Subject: Remove unavailable sites --- Doc/Zsh/ftp_sites.yo | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'Doc/Zsh') diff --git a/Doc/Zsh/ftp_sites.yo b/Doc/Zsh/ftp_sites.yo index 3ed675ab1..62c1bff06 100644 --- a/Doc/Zsh/ftp_sites.yo +++ b/Doc/Zsh/ftp_sites.yo @@ -5,24 +5,11 @@ tt(http://www.zsh.org/pub/)) ) item(Australia)( nofill(tt(ftp://ftp.zsh.org/pub/) -tt(http://www.zsh.org/pub/)) -) -item(Denmark)( -nofill(tt(ftp://mirrors.dotsrc.org/zsh/)) -) -item(Finland)( -nofill(tt(ftp://ftp.funet.fi/pub/unix/shells/zsh/)) -) -item(France)( -nofill(tt(ftp://nephtys.lip6.fr/pub/unix/shells/zsh/)) -) -item(Germany)( -nofill(tt(ftp://ftp.fu-berlin.de/pub/unix/shells/zsh/)) +tt(http://www.zsh.org/pub/) +tt(http://mirror.dejanseo.com.au/pub/zsh/)) ) item(Hungary)( -nofill(tt(ftp://ftp.kfki.hu/pub/packages/zsh/)) -) -item(Poland)( -nofill(tt(ftp://sunsite.icm.edu.pl/pub/unix/shells/zsh/)) +nofill(tt(ftp://ftp.cs.elte.hu/pub/zsh/) +tt(http://www.cs.elte.hu/pub/zsh/)) ) enditem() -- cgit v1.2.3 From 268e56a1446af3ca6df84789180b87ac4f57d1d3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 16 Aug 2012 14:00:11 +0000 Subject: 30169: repeat "typeset -T" with same two first arguments is not an error --- ChangeLog | 6 +++++- Doc/Zsh/builtins.yo | 4 +++- Src/builtin.c | 15 ++++++++++++++- Test/B02typeset.ztst | 9 +++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 424c6c83c..41172b1c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-08-16 Peter Stephenson + * 30619: Doc/Zsh/builtins.yo, Src/builtin.c, + Test/B02typeset.ztst: repeat "typeset -T" with same two first + arguments is not an error. + * 30617: Src/prototypes.h, Src/zsh_system.h: rationalise replacement of tgoto() prototype which could appear twice inconsistently. @@ -57,5 +61,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5695 $ +* $Revision: 1.5696 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 98c470a54..5c133a856 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1552,7 +1552,9 @@ an array to var(SCALAR) is an error, and assigning a scalar to var(array) sets it to be a single-element array. Note that both `tt(typeset -xT ...)' and `tt(export -T ...)' work, but only the scalar will be marked for export. Setting the value using the scalar version causes a split on all -separators (which cannot be quoted). +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. The tt(-g) (global) flag is treated specially: it means that any resulting parameter will not be restricted to local scope. Note that this diff --git a/Src/builtin.c b/Src/builtin.c index b5a98cbd2..ce7d6a563 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2449,7 +2449,20 @@ bin_typeset(char *name, char **argv, Options ops, int func) && (locallevel == pm->level || !(on & PM_LOCAL))) { if (pm->node.flags & PM_TIED) { unqueue_signals(); - zerrnam(name, "can't tie already tied scalar: %s", asg0.name); + if (!strcmp(asg->name, pm->ename)) { + /* + * Already tied in the fashion requested. + */ + struct tieddata *tdp = (struct tieddata*)pm->u.data; + /* Update join character */ + tdp->joinchar = joinchar; + if (asg0.value) + setsparam(asg0.name, ztrdup(asg0.value)); + return 0; + } else { + zerrnam(name, "can't tie already tied scalar: %s", + asg0.name); + } return 1; } if (!asg0.value && !(PM_TYPE(pm->node.flags) & (PM_ARRAY|PM_HASHED))) diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 7a9928abe..51ebc6535 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -459,3 +459,12 @@ silent2(){ local silence; silent1; } silent2 0:typeset -g should be silent even without TYPESET_SILENT + + typeset -T TIED_SCALAR tied_array + TIED_SCALAR=foo:bar + print $tied_array + typeset -T TIED_SCALAR=goo:car tied_array + print $tied_array +0:retying arrays to same array works +>foo bar +>goo car -- cgit v1.2.3 From 3aae0ef8fecd69c983e6452a6b4f9c641cac9ab1 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Fri, 17 Aug 2012 08:22:52 +0000 Subject: Stepan Koltsov: vcs_info: %a to output number of all patches in (no)?patch-format styles --- ChangeLog | 10 +++++++++- Doc/Zsh/contrib.yo | 1 + Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 7 ++++--- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 4 ++-- Functions/VCS_Info/VCS_INFO_quilt | 8 +++++--- 5 files changed, 21 insertions(+), 9 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index b870fa618..825b6bb58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-08-17 Frank Terbeck + + * Stepan Koltsov: Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_git, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, + Functions/VCS_Info/VCS_INFO_quilt: vcs_info: %a to output number + of all patches in (no)?patch-format styles + 2012-08-16 Peter Stephenson * Hiramatsu Yoshifumi: 30621 patch-ac (from NetBSD pkgsrc) @@ -70,5 +78,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5698 $ +* $Revision: 1.5699 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 139a68150..24aafc331 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1003,6 +1003,7 @@ sitem(tt(%p))(The name of the top-most applied patch (tt(applied-string)).) sitem(tt(%u))(The number of unapplied patches (tt(unapplied-string)).) sitem(tt(%n))(The number of applied patches.) sitem(tt(%c))(The number of unapplied patches.) +sitem(tt(%a))(The number of all patches.) sitem(tt(%g))(The names of active tt(mq) guards (tt(hg) backend).) sitem(tt(%G))(The number of active tt(mq) guards (tt(hg) backend).) endsitem() diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 9364fd021..e40571a0e 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -129,12 +129,13 @@ rrn=${gitbase:t} local patchdir=${gitdir}/patches/${gitbranch} if [[ -d $patchdir ]] ; then - local -a stgit_applied stgit_unapplied + local -a stgit_applied stgit_unapplied stgit_all stgit_applied=(${(f)"$(< "${patchdir}/applied")"}) stgit_applied=( ${(Oa)stgit_applied} ) stgit_unapplied=(${(f)"$(< "${patchdir}/unapplied")"}) stgit_unapplied=( ${(oa)stgit_unapplied} ) + stgit_all=( ${(Oa)stgit_applied} ${stgit_unapplied} ) if VCS_INFO_hook 'gen-applied-string' "${stgit_applied[@]}"; then if (( ${#stgit_applied} )); then @@ -158,10 +159,10 @@ if [[ -d $patchdir ]] ; then zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" nopatch-format stgitmsg || stgitmsg="no patch applied" fi hook_com=( applied "${stgitpatch}" unapplied "${stgitunapplied}" - applied-n ${#stgit_applied} unapplied-n ${#stgit_unapplied} ) + applied-n ${#stgit_applied} unapplied-n ${#stgit_unapplied} all-n ${#stgit_all} ) if VCS_INFO_hook 'set-patch-format' "${stgitmsg}"; then zformat -f stgitmsg "${stgitmsg}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ - "n:${#stgit_applied}" "c:${#stgit_unapplied}" + "n:${#stgit_applied}" "c:${#stgit_unapplied}" "a:${#stgit_all}" else stgitmsg=${hook_com[patch-replace]} fi diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index a1b87f59e..48e385c97 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -213,13 +213,13 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ fi hook_com=( applied "${applied_string}" unapplied "${unapplied_string}" - applied-n ${#mqpatches} unapplied-n ${#mqunapplied} + applied-n ${#mqpatches} unapplied-n ${#mqunapplied} all-n ${#mqseries} guards "${guards_string}" guards-n ${#mqguards} ) if VCS_INFO_hook 'set-patch-format' ${qstring}; then zformat -f hgmqstring "${hgmqstring}" \ "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ - "n:${#mqpatches}" "c:${#mqunapplied}" \ + "n:${#mqpatches}" "c:${#mqunapplied}" "a:${#mqseries}" \ "g:${hook_com[guards]}" "G:${#mqguards}" else hgmqstring=${hook_com[patch-replace]} diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index fc127c23b..7001eca07 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -89,7 +89,7 @@ function VCS_INFO_quilt() { local patches pc tmp qstring root local -i ret local -x context - local -a applied unapplied applied_string unapplied_string quiltcommand + local -a applied unapplied all applied_string unapplied_string quiltcommand local -Ax hook_com context=":vcs_info:${vcs}.quilt-${mode}:${usercontext}:${rrn}" @@ -142,6 +142,8 @@ function VCS_INFO_quilt() { unapplied=() fi + all=( ${(Oa)applied} ${unapplied} ) + if VCS_INFO_hook 'gen-applied-string' "${applied[@]}"; then if (( ${#applied} )); then applied_string=${applied[1]} @@ -164,10 +166,10 @@ function VCS_INFO_quilt() { zstyle -s "${context}" nopatch-format qstring || qstring="no patch applied" fi hook_com=( applied "${applied_string}" unapplied "${unapplied_string}" - applied-n ${#applied} unapplied-n ${#unapplied} ) + applied-n ${#applied} unapplied-n ${#unapplied} all-n ${#all} ) if VCS_INFO_hook 'set-patch-format' ${qstring}; then zformat -f qstring "${qstring}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ - "n:${#applied}" "c:${#unapplied}" + "n:${#applied}" "c:${#unapplied}" "a:${#all}" else qstring=${hook_com[patch-replace]} fi -- cgit v1.2.3 From 9fdcd824d8df307081723ec5f0ae04c838b2b7b8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 17 Aug 2012 11:12:34 +0000 Subject: 30627: support RLIMIT_NTHR as on NetBSD --- ChangeLog | 21 +++++---------------- Doc/Zsh/builtins.yo | 8 ++++++-- Src/Builtins/rlimits.awk | 1 + Src/Builtins/rlimits.c | 11 +++++++++++ configure.ac | 1 + 5 files changed, 24 insertions(+), 18 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 825b6bb58..97c1efe27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,19 +1,8 @@ -2012-08-17 Frank Terbeck +2012-08-17 Peter Stephenson - * Stepan Koltsov: Doc/Zsh/contrib.yo, - Functions/VCS_Info/Backends/VCS_INFO_get_data_git, - Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, - Functions/VCS_Info/VCS_INFO_quilt: vcs_info: %a to output number - of all patches in (no)?patch-format styles - -2012-08-16 Peter Stephenson - - * Hiramatsu Yoshifumi: 30621 patch-ac (from NetBSD pkgsrc) - backported to configure.ac: compilation on interix, also - change linker flags for NetBSD. - - * Hiramatsu Yoshifumi: 30621 patch-ab (from NetBSD pkgsrc): - Src/zsh.h: compilation on __INTERIX + * 30627: configure.ac, Doc/Zsh/builtins.yo, + Src/Builtins/rlimits.awk, Src/Builtins/rlimits.c: + support RLIMIT_NTHR as on NetBSD. 2012-08-16 Peter Stephenson @@ -78,5 +67,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5699 $ +* $Revision: 1.5700 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 5c133a856..f0af72085 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1738,7 +1738,7 @@ enditem() findex(ulimit) cindex(resource limits) cindex(limits, resource) -item(tt(ulimit) [ [ tt(-SHacdfilmnpqstvx) | tt(-N) var(resource) [ var(limit) ] ... ])( +item(tt(ulimit) [ [ tt(-SHacdfilmnpqrstvx) | tt(-N) var(resource) [ var(limit) ] ... ])( Set or display resource limits of the shell and the processes started by the shell. The value of var(limit) can be a number in the unit specified below or one of the values `tt(unlimited)', which removes the limit on the @@ -1759,6 +1759,9 @@ When looping over multiple resources, the shell will abort immediately if it detects a badly formed argument. However, if it fails to set a limit for some other reason it will continue trying to set the remaining limits. +Not all the following resources are supported on all systems. Running +tt(ulimit -a) will show which are supported. + startsitem() sitem(tt(-a))(Lists all of the current resource limits.) sitem(tt(-c))(512-byte blocks on the size of core dumps.) @@ -1771,7 +1774,8 @@ sitem(tt(-n))(open file descriptors.) sitem(tt(-q))(Bytes in POSIX message queues.) sitem(tt(-s))(K-bytes on the size of the stack.) sitem(tt(-t))(CPU seconds to be used.) -sitem(tt(-u))(processes available to the user.) +sitem(tt(-r))(The number of simultaneous threads available to the user.) +sitem(tt(-u))(The number of processes available to the user.) sitem(tt(-v))(K-bytes on the size of virtual memory. On some systems this refers to the limit called `address space'.) sitem(tt(-x))(The number of locks on files.) diff --git a/Src/Builtins/rlimits.awk b/Src/Builtins/rlimits.awk index 418206a66..bf914814d 100644 --- a/Src/Builtins/rlimits.awk +++ b/Src/Builtins/rlimits.awk @@ -42,6 +42,7 @@ BEGIN {limidx = 0} if (limnam == "MEMLOCK") { msg[limnum] = "Mmemorylocked" } if (limnam == "NOFILE") { msg[limnum] = "Ndescriptors" } if (limnam == "NPROC") { msg[limnum] = "Nmaxproc" } + if (limnam == "NTHR") { msg[limnum] = "Nmaxthr" } if (limnam == "OFILE") { msg[limnum] = "Ndescriptors" } if (limnam == "PTHREAD") { msg[limnum] = "Nmaxpthreads" } if (limnam == "RSS") { msg[limnum] = "Mresident" } diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index 670516169..45d5b2dea 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -314,6 +314,12 @@ printulimit(char *nam, int lim, int hard, int head) printf("-u: processes "); break; # endif /* HAVE_RLIMIT_NPROC */ +# ifdef HAVE_RLIMIT_NTHR + case RLIMIT_NTHR: + if (head) + printf("-r: threads "); + break; +#endif /* HAVE_RLIMIT_NTHR */ # if defined(HAVE_RLIMIT_VMEM) && (!defined(HAVE_RLIMIT_RSS) || !defined(RLIMIT_VMEM_IS_RSS)) case RLIMIT_VMEM: if (head) @@ -791,6 +797,11 @@ bin_ulimit(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) res = RLIMIT_NOFILE; break; # endif /* HAVE_RLIMIT_NOFILE */ +# ifdef HAVE_RLIMIT_NTHR + case 'r': + res = RLIMIT_NTHR; + break; +# endif /* HAVE_RLIMIT_NTHR */ # ifdef HAVE_RLIMIT_NPROC case 'u': res = RLIMIT_NPROC; diff --git a/configure.ac b/configure.ac index 04b2ce21a..986ef3a33 100644 --- a/configure.ac +++ b/configure.ac @@ -1799,6 +1799,7 @@ zsh_LIMIT_PRESENT(RLIMIT_AS) zsh_LIMIT_PRESENT(RLIMIT_LOCKS) zsh_LIMIT_PRESENT(RLIMIT_MEMLOCK) zsh_LIMIT_PRESENT(RLIMIT_NPROC) +zsh_LIMIT_PRESENT(RLIMIT_NTHR) zsh_LIMIT_PRESENT(RLIMIT_NOFILE) zsh_LIMIT_PRESENT(RLIMIT_PTHREAD) zsh_LIMIT_PRESENT(RLIMIT_RSS) -- cgit v1.2.3 From e92a823a4b143f42dcb867f74f25b074cd991666 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 17 Aug 2012 13:26:22 +0000 Subject: 30629 plus unposted formatting changes: support socket buffer size limit properly in ulimit; improve consistency of output and documentation and tweak formatting appropriately --- ChangeLog | 8 ++++++- Doc/Zsh/builtins.yo | 11 +++++---- Src/Builtins/rlimits.c | 63 ++++++++++++++++++++++++++------------------------ 3 files changed, 46 insertions(+), 36 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 97c1efe27..2a95245a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-08-17 Peter Stephenson + * 30629 plus unposted formatting improvements: + Doc/Zsh/builtins.yo, Src/Builtins/rlimits.c: more complete + handling for socket buffer size limit (NetBSD) plus formatting + and consistency changes (kb -> kbytes everywhere in ulimit + output, K-bytes to kilobytes everywhere in documentation). + * 30627: configure.ac, Doc/Zsh/builtins.yo, Src/Builtins/rlimits.awk, Src/Builtins/rlimits.c: support RLIMIT_NTHR as on NetBSD. @@ -67,5 +73,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5700 $ +* $Revision: 1.5701 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index f0af72085..894f65a3e 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1764,19 +1764,20 @@ tt(ulimit -a) will show which are supported. startsitem() sitem(tt(-a))(Lists all of the current resource limits.) +sitem(tt(-b))(Socket buffer size in bytes LPAR()N.B. not kilobytes+RPAR()) sitem(tt(-c))(512-byte blocks on the size of core dumps.) -sitem(tt(-d))(K-bytes on the size of the data segment.) +sitem(tt(-d))(Kilobytes on the size of the data segment.) sitem(tt(-f))(512-byte blocks on the size of files written.) sitem(tt(-i))(The number of pending signals.) -sitem(tt(-l))(K-bytes on the size of locked-in memory.) -sitem(tt(-m))(K-bytes on the size of physical memory.) +sitem(tt(-l))(Kilobytes on the size of locked-in memory.) +sitem(tt(-m))(Kilobytes on the size of physical memory.) sitem(tt(-n))(open file descriptors.) sitem(tt(-q))(Bytes in POSIX message queues.) -sitem(tt(-s))(K-bytes on the size of the stack.) +sitem(tt(-s))(Kilobytes on the size of the stack.) sitem(tt(-t))(CPU seconds to be used.) sitem(tt(-r))(The number of simultaneous threads available to the user.) sitem(tt(-u))(The number of processes available to the user.) -sitem(tt(-v))(K-bytes on the size of virtual memory. On some systems this +sitem(tt(-v))(Kilobytes on the size of virtual memory. On some systems this refers to the limit called `address space'.) sitem(tt(-x))(The number of locks on files.) endsitem() diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index 45d5b2dea..eedfa969c 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -238,32 +238,32 @@ printulimit(char *nam, int lim, int hard, int head) switch (lim) { case RLIMIT_CORE: if (head) - printf("-c: core file size (blocks) "); + printf("-c: core file size (blocks) "); if (limit != RLIM_INFINITY) limit /= 512; break; case RLIMIT_DATA: if (head) - printf("-d: data seg size (kbytes) "); + printf("-d: data seg size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; case RLIMIT_FSIZE: if (head) - printf("-f: file size (blocks) "); + printf("-f: file size (blocks) "); if (limit != RLIM_INFINITY) limit /= 512; break; # ifdef HAVE_RLIMIT_SIGPENDING case RLIMIT_SIGPENDING: if (head) - printf("-i: pending signals "); + printf("-i: pending signals "); break; # endif # ifdef HAVE_RLIMIT_MEMLOCK case RLIMIT_MEMLOCK: if (head) - printf("-l: locked-in-memory size (kb) "); + printf("-l: locked-in-memory size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -273,7 +273,7 @@ printulimit(char *nam, int lim, int hard, int head) # if defined(HAVE_RLIMIT_RSS) && !defined(RLIMIT_VMEM_IS_RSS) && !defined(RLIMIT_RSS_IS_AS) case RLIMIT_RSS: if (head) - printf("-m: resident set size (kbytes) "); + printf("-m: resident set size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -281,7 +281,7 @@ printulimit(char *nam, int lim, int hard, int head) # if defined(HAVE_RLIMIT_VMEM) && defined(HAVE_RLIMIT_RSS) && defined(RLIMIT_VMEM_IS_RSS) case RLIMIT_VMEM: if (head) - printf("-m: memory size (kb) "); + printf("-m: memory size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -289,41 +289,41 @@ printulimit(char *nam, int lim, int hard, int head) # ifdef HAVE_RLIMIT_NOFILE case RLIMIT_NOFILE: if (head) - printf("-n: file descriptors "); + printf("-n: file descriptors "); break; # endif /* HAVE_RLIMIT_NOFILE */ # ifdef HAVE_RLIMIT_MSGQUEUE case RLIMIT_MSGQUEUE: if (head) - printf("-q: bytes in POSIX msg queues "); + printf("-q: bytes in POSIX msg queues "); break; # endif case RLIMIT_STACK: if (head) - printf("-s: stack size (kbytes) "); + printf("-s: stack size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; case RLIMIT_CPU: if (head) - printf("-t: cpu time (seconds) "); + printf("-t: cpu time (seconds) "); break; # ifdef HAVE_RLIMIT_NPROC case RLIMIT_NPROC: if (head) - printf("-u: processes "); + printf("-u: processes "); break; # endif /* HAVE_RLIMIT_NPROC */ # ifdef HAVE_RLIMIT_NTHR case RLIMIT_NTHR: if (head) - printf("-r: threads "); + printf("-r: threads "); break; #endif /* HAVE_RLIMIT_NTHR */ # if defined(HAVE_RLIMIT_VMEM) && (!defined(HAVE_RLIMIT_RSS) || !defined(RLIMIT_VMEM_IS_RSS)) case RLIMIT_VMEM: if (head) - printf("-v: virtual memory size (kb) "); + printf("-v: virtual memory size (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -331,7 +331,7 @@ printulimit(char *nam, int lim, int hard, int head) # if defined HAVE_RLIMIT_AS && !defined(RLIMIT_VMEM_IS_AS) case RLIMIT_AS: if (head) - printf("-v: address space (kb) "); + printf("-v: address space (kbytes) "); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -339,13 +339,13 @@ printulimit(char *nam, int lim, int hard, int head) # ifdef HAVE_RLIMIT_LOCKS case RLIMIT_LOCKS: if (head) - printf("-x: file locks "); + printf("-x: file locks "); break; # endif /* HAVE_RLIMIT_LOCKS */ # ifdef HAVE_RLIMIT_AIO_MEM case RLIMIT_AIO_MEM: if (head) - printf("-N %2d: AIO locked-in-memory (kb) ", RLIMIT_AIO_MEM); + printf("-N %2d: AIO locked-in-memory (kbytes)", RLIMIT_AIO_MEM); if (limit != RLIM_INFINITY) limit /= 1024; break; @@ -353,44 +353,42 @@ printulimit(char *nam, int lim, int hard, int head) # ifdef HAVE_RLIMIT_AIO_OPS case RLIMIT_AIO_OPS: if (head) - printf("-N %2d: AIO operations ", RLIMIT_AIO_OPS); + printf("-N %2d: AIO operations ", RLIMIT_AIO_OPS); break; # endif /* HAVE_RLIMIT_AIO_OPS */ # ifdef HAVE_RLIMIT_TCACHE case RLIMIT_TCACHE: if (head) - printf("-N %2d: cached threads ", RLIMIT_TCACHE); + printf("-N %2d: cached threads ", RLIMIT_TCACHE); break; # endif /* HAVE_RLIMIT_TCACHE */ # ifdef HAVE_RLIMIT_SBSIZE case RLIMIT_SBSIZE: if (head) - printf("-N %2d: socket buffer size (kb) ", RLIMIT_SBSIZE); - if (limit != RLIM_INFINITY) - limit /= 1024; + printf("-b: socket buffer size (bytes) ", RLIMIT_SBSIZE); break; # endif /* HAVE_RLIMIT_SBSIZE */ # ifdef HAVE_RLIMIT_PTHREAD case RLIMIT_PTHREAD: if (head) - printf("-N %2d: threads per process ", RLIMIT_PTHREAD); + printf("-N %2d: threads per process ", RLIMIT_PTHREAD); break; # endif /* HAVE_RLIMIT_PTHREAD */ # ifdef HAVE_RLIMIT_NICE case RLIMIT_NICE: if (head) - printf("-e: max nice "); + printf("-e: max nice "); break; # endif /* HAVE_RLIMIT_NICE */ # ifdef HAVE_RLIMIT_RTPRIO case RLIMIT_RTPRIO: if (head) - printf("-r: max rt priority "); + printf("-r: max rt priority "); break; # endif /* HAVE_RLIMIT_RTPRIO */ default: if (head) - printf("-N %2d: ", lim); + printf("-N %2d: ", lim); break; } /* display the limit */ @@ -782,16 +780,21 @@ bin_ulimit(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) case 'c': res = RLIMIT_CORE; break; -# ifdef HAVE_RLIMIT_RSS - case 'm': - res = RLIMIT_RSS; +# ifdef HAVE_RLIMIT_SBSIZE + case 'b': + res = RLIMIT_SBSIZE; break; -# endif /* HAVE_RLIMIT_RSS */ +# endif /* HAVE_RLIMIT_SBSIZE */ # ifdef HAVE_RLIMIT_MEMLOCK case 'l': res = RLIMIT_MEMLOCK; break; # endif /* HAVE_RLIMIT_MEMLOCK */ +# ifdef HAVE_RLIMIT_RSS + case 'm': + res = RLIMIT_RSS; + break; +# endif /* HAVE_RLIMIT_RSS */ # ifdef HAVE_RLIMIT_NOFILE case 'n': res = RLIMIT_NOFILE; -- cgit v1.2.3 From 6f3ff6b653ca5e6f528bc46ec6295cb6d263a9fd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 21 Aug 2012 18:03:01 +0000 Subject: 30633: "functions -T" only traces marked function, not called functions --- ChangeLog | 9 ++++++++- Doc/Zsh/builtins.yo | 25 ++++++++++++++----------- Src/builtin.c | 8 ++++++-- Src/exec.c | 15 +++++++++++++-- Src/hashtable.c | 7 ++++--- Src/options.c | 2 +- Src/subst.c | 2 ++ Src/zsh.h | 1 + 8 files changed, 49 insertions(+), 20 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index a2b415d83..78e4f92f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-08-21 Peter Stephenson + + * 30633: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c, + Src/hashtable.c, Src/options.c, Src/subst.c, Src/zsh.h: + "functions -T" traces only marked function and not called + functions unless also marked. + 2012-08-20 Peter Stephenson * Stepan Koltsov: 30634: Functions/Misc/zmv: use (q-) quoting @@ -88,5 +95,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5704 $ +* $Revision: 1.5705 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 894f65a3e..0e5353633 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -620,7 +620,7 @@ Equivalent to tt(typeset -E), except that options irrelevant to floating 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 scalar version causes a split on all 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 diff --git a/Src/builtin.c b/Src/builtin.c index ce7d6a563..3925edd10 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -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, Options ops, int func) 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; diff --git a/Src/exec.c b/Src/exec.c index 6ebc9c014..a40838f91 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4484,11 +4484,12 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) 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 doshargs, int noreturnval) } 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 doshargs, int noreturnval) optcind = oldoptcind; zoptind = oldzoptind; scriptname = oldscriptname; + oflags = ooflags; if (restore_sticky) { /* diff --git a/Src/hashtable.c b/Src/hashtable.c index be71a1cc9..b472e40b9 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -923,12 +923,13 @@ printshfuncnode(HashNode hn, int printflags) 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;; diff --git a/Src/options.c b/Src/options.c index c6db75372..609c28fd1 100644 --- a/Src/options.c +++ b/Src/options.c @@ -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; } diff --git a/Src/subst.c b/Src/subst.c index 932f41287..b0c15d048 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2314,6 +2314,8 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) 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) diff --git a/Src/zsh.h b/Src/zsh.h index 946102528..b9f2846f7 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -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 */ -- cgit v1.2.3 From 76091a6995f7a567651232e2d164f6ea91462b05 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 21 Aug 2012 18:45:31 +0000 Subject: users/17211: new recursive-files style --- ChangeLog | 5 ++++- Completion/Unix/Type/_files | 18 ++++++++++++++++-- Doc/Zsh/compsys.yo | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 78e4f92f4..e4077cd1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-08-21 Peter Stephenson + * users/17211: Completion/Unix/Type/_files, Doc/Zsh/compsys.yo: + new recursive-files style. + * 30633: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c, Src/hashtable.c, Src/options.c, Src/subst.c, Src/zsh.h: "functions -T" traces only marked function and not called @@ -95,5 +98,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5705 $ +* $Revision: 1.5706 $ ***************************************************** diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files index f21d7bc3b..0a2715814 100644 --- a/Completion/Unix/Type/_files +++ b/Completion/Unix/Type/_files @@ -1,7 +1,7 @@ #compdef -redirect-,-default-,-default- local opts tmp glob pat pats expl tag i def descr end ign ret=1 match tried -local type sdef ignvars ignvar +local type sdef ignvars ignvar prepath oprefix rfiles rfile zparseopts -a opts \ '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+: @@ -118,7 +118,21 @@ for def in "$pats[@]"; do while _next_label "$tag" expl "$descr"; do _comp_ignore=( $_comp_ignore $ign ) if [[ -n "$end" ]]; then - _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0 + if _path_files -g "$pat" "$opts[@]" "$expl[@]"; then + ret=0 + elif [[ $PREFIX$SUFFIX != */* ]] && zstyle -a ":completion:${curcontext}:$tag" recursive-files rfiles; then + for rfile in $rfiles; do + if [[ $PWD/ = ${~rfile} ]]; then + for prepath in **/*(/); do + oprefix=$PREFIX + PREFIX=$prepath/$PREFIX + _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0 + PREFIX=$oprefix + done + break + fi + done + fi else _path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0 fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 135a60a41..2787f66a7 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2355,6 +2355,28 @@ found, or var(max) words have been tried. The default is to complete all words from the history at once. ) +kindex(recursive-files, completion style) +item(tt(recursive-files))( +If this style is set, its value is an array of patterns to be +tested against `tt($PWD/)': note the trailing slash, which allows +directories in the pattern to be delimited unambiguously by including +slashes on both sides. If an ordinary file completion fails +and the word on the command line does not yet have a directory part to its +name, the style is retrieved using the same tag as for the completion +just attempted, then the elements tested against tt($PWD/) in turn. +If one matches, then the shell reattempts completion by prepending the word +on the command line with each directory in the expansion of tt(**/*(/)) +in turn. Typically the elements of the style will be set to restrict +the number of directories beneath the current one to a manageable +number, for example `tt(*/.git/*)'. + +For example, + +example(zstyle ':completion:*' recursive-files '*/zsh/*') + +If the current directory is tt(/home/pws/zsh/Src), then +tt(zle_tr)em(TAB) can be completed to tt(Zle/zle_tricky.c). +) kindex(regular, completion style) item(tt(regular))( This style is used by the tt(_expand_alias) completer and bindable -- cgit v1.2.3 From d3891edfca77ce587585990135242247a48595fc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 3 Sep 2012 11:12:15 +0000 Subject: users/12713: returning REPLY to _user_expand sets description for expansion --- ChangeLog | 8 +++++++- Completion/Base/Completer/_user_expand | 13 +++++++------ Doc/Zsh/compsys.yo | 4 +++- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index c7dbbecf8..a2f9e8ac2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-03 Peter Stephenson + + * users/17213: Completion/Base/Completer/_user_expand, + Doc/Zsh/compsys.yo: allow REPLY to pass a description for an + expansion. + 2012-08-27 Peter Stephenson * Oliver (olipro): 30643: Completion/Linux/Command/_ipset: @@ -124,5 +130,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5712 $ +* $Revision: 1.5713 $ ***************************************************** diff --git a/Completion/Base/Completer/_user_expand b/Completion/Base/Completer/_user_expand index 049cc31ef..cf3d172f0 100644 --- a/Completion/Base/Completer/_user_expand +++ b/Completion/Base/Completer/_user_expand @@ -12,7 +12,7 @@ setopt localoptions nonomatch [[ _matcher_num -gt 1 ]] && return 1 -local exp word sort expr expl subd suf=" " asp tmp spec +local exp word sort expr expl subd suf=" " asp tmp spec REPLY local -a specs reply if [[ "$funcstack[2]" = _prefix ]]; then @@ -30,6 +30,7 @@ exp=("$word") zstyle -a ":completion:${curcontext}" user-expand specs || return 1 for spec in $specs; do + REPLY= case $spec in ('$'[[:IDENT:]]##) # Spec is an associative array with explicit keys. @@ -85,9 +86,9 @@ fi if [[ -z "$compstate[insert]" ]] ;then if [[ "$sort" = menu ]]; then - _description expansions expl expansions "o:$word" + _description expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" else - _description -V expansions expl expansions "o:$word" + _description -V expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" fi compadd "$expl[@]" -UQ -qS "$suf" -a exp @@ -98,9 +99,9 @@ else local i j normal space dir if [[ "$sort" = menu ]]; then - _description expansions expl expansions "o:$word" + _description expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" else - _description -V expansions expl expansions "o:$word" + _description -V expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" fi normal=() space=() @@ -120,7 +121,7 @@ else (( $#space )) && compadd "$expl[@]" -UQ -qS " " -a space (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal fi - if _requested all-expansions expl 'all expansions'; then + if _requested all-expansions expl "all expansions${REPLY:+: $REPLY}"; then local disp dstr if [[ "${#${exp}}" -ge COLUMNS ]]; then diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 2787f66a7..2991c1f4a 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3180,7 +3180,9 @@ var(_func) is the name of a shell function whose name must begin with tt(_) but is not otherwise special to the completion system. The function is called with the trial word as an argument. If the word is to be expanded, the function should set the array tt(reply) to a list of -expansions. The return status of the function is irrelevant. +expansions. Optionally, it can set tt(REPLY) to a word that will +be used as a description for the set of expansions. +The return status of the function is irrelevant. ) endsitem() ) -- cgit v1.2.3 From e550c98d69a270a9c6623fe1fd602b5081f4b46c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 11 Sep 2012 16:02:41 +0000 Subject: 30647, 30649: allow underscores in numeric constants --- ChangeLog | 8 +++++++- Doc/Zsh/arith.yo | 10 +++++++++- NEWS | 23 +++++++++++++++++++++-- Src/math.c | 39 +++++++++++++++++++++++++++++++++------ Src/utils.c | 28 +++++++++++++++++++--------- Test/C01arith.ztst | 23 +++++++++++++++++++++++ 6 files changed, 112 insertions(+), 19 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index cf53ffbe6..c9339beb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-11 Peter Stephenson + + * 30647, 30649: Doc/Zsh/arith.yo, Src/math.c, Src/utils.c, + Test/C01arith.ztst: allow underscores in numeric constants + within math evaluation. + 2012-09-09 Peter Stephenson * Jun T.: 30664: configure.ac: fix some Yodl version issues. @@ -151,5 +157,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5718 $ +* $Revision: 1.5719 $ ***************************************************** diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo index dd18ee720..2674c7817 100644 --- a/Doc/Zsh/arith.yo +++ b/Doc/Zsh/arith.yo @@ -48,6 +48,12 @@ The var(base)tt(#) may also be omitted, in which case base 10 is used. For backwards compatibility the form `tt([)var(base)tt(])var(n)' is also accepted. +An integer expression or a base given in the form +`var(base)tt(#)var(n)' may contain underscores (`tt(_)') after the +leading digit for visual guidance; these are ignored in computation. +Examples are tt(1_000_000) or tt(0xffff_ffff) which are equivalent to +tt(1000000) and tt(0xffffffff) respectively. + It is also possible to specify a base to be used for output in the form `tt([#)var(base)tt(])', for example `tt([#16])'. This is used when outputting arithmetical substitutions or when assigning to scalar @@ -87,7 +93,9 @@ output is valid syntax for input. If the tt(#) is doubled, for example Floating point constants are recognized by the presence of a decimal point or an exponent. The decimal point may be the first character of the constant, but the exponent character tt(e) or tt(E) may not, as it will be -taken for a parameter name. +taken for a parameter name. All numeric parts (before and after the +decimal point and in the exponent) may contain underscores after the +leading digit for visual guidance; these are ignored in computation. cindex(arithmetic operators) cindex(operators, arithmetic) diff --git a/NEWS b/NEWS index 23097b6aa..68d4ad657 100644 --- a/NEWS +++ b/NEWS @@ -4,8 +4,27 @@ CHANGES FROM PREVIOUS VERSIONS OF ZSH Note also the list of incompatibilities in the README file. -Changes between 4.2 and 5.0 ---------------------------- +Changes since 5.0.0 +------------------- + +"functions -T" turns on tracing for the specified function(s) only, +similar to "functions -t" except that tracing is turned off for any +functions called from the specified one(s) that don't also have the -t +or -T flag. + +In file completion, the recursive-files style can be set to an array of +patterns to matche against "$PWD/". In any matched location, it is +possibly to complete files in arbitrarily deep subdirectories without +needing to type the directory prefix. See example in the zshcompsys +manual. + +The _user_expand completer now allows expansion functions in the +user-expand files to return a string in REPLY that will be used to name +the set of expansions returned. + + +Changes between 4.2 and 5.0.0 +----------------------------- The following changes first appeared in the 4.3 series of releases; see also the file Etc/NEWS-4.3. diff --git a/Src/math.c b/Src/math.c index c7d384019..abc5f994e 100644 --- a/Src/math.c +++ b/Src/math.c @@ -452,7 +452,7 @@ lexconstant(void) nptr++; if (*nptr == 'x' || *nptr == 'X') { /* Let zstrtol parse number with base */ - yyval.u.l = zstrtol(ptr, &ptr, 0); + yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); /* Should we set lastbase here? */ lastbase = 16; return NUM; @@ -466,13 +466,13 @@ lexconstant(void) * it can't be a base indication (always decimal) * or a floating point number. */ - for (ptr2 = nptr; idigit(*ptr2); ptr2++) + for (ptr2 = nptr; idigit(*ptr2) || *ptr2 == '_'; ptr2++) ; if (ptr2 > nptr && *ptr2 != '.' && *ptr2 != 'e' && *ptr2 != 'E' && *ptr2 != '#') { - yyval.u.l = zstrtol(ptr, &ptr, 0); + yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); lastbase = 8; return NUM; } @@ -481,17 +481,43 @@ lexconstant(void) } else { - while (idigit(*nptr)) + while (idigit(*nptr) || *nptr == '_') nptr++; } if (*nptr == '.' || *nptr == 'e' || *nptr == 'E') { + char *ptr2; /* it's a float */ yyval.type = MN_FLOAT; #ifdef USE_LOCALE prev_locale = dupstring(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); #endif + if (*nptr == '.') { + nptr++; + while (idigit(*nptr) || *nptr == '_') + nptr++; + } + if (*nptr == 'e' || *nptr == 'E') { + nptr++; + if (*nptr == '+' || *nptr == '-') + nptr++; + while (idigit(*nptr) || *nptr == '_') + nptr++; + } + for (ptr2 = ptr; ptr2 < nptr; ptr2++) { + if (*ptr2 == '_') { + int len = nptr - ptr; + ptr = strdup(ptr); + for (ptr2 = ptr; len; len--) { + if (*ptr2 == '_') + chuck(ptr2); + else + ptr2++; + } + break; + } + } yyval.u.d = strtod(ptr, &nptr); #ifdef USE_LOCALE if (prev_locale) setlocale(LC_NUMERIC, prev_locale); @@ -503,11 +529,12 @@ lexconstant(void) ptr = nptr; } else { /* it's an integer */ - yyval.u.l = zstrtol(ptr, &ptr, 10); + yyval.u.l = zstrtol_underscore(ptr, &ptr, 10, 1); if (*ptr == '#') { ptr++; - yyval.u.l = zstrtol(ptr, &ptr, lastbase = yyval.u.l); + lastbase = yyval.u.l; + yyval.u.l = zstrtol_underscore(ptr, &ptr, lastbase, 1); } } return NUM; diff --git a/Src/utils.c b/Src/utils.c index d35ca1dfd..cadb06f61 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2030,13 +2030,20 @@ skipparens(char inpar, char outpar, char **s) return level; } +/**/ +mod_export zlong +zstrtol(const char *s, char **t, int base) +{ + return zstrtol_underscore(s, t, base, 0); +} + /* Convert string to zlong (see zsh.h). This function (without the z) * * is contained in the ANSI standard C library, but a lot of them seem * * to be broken. */ /**/ mod_export zlong -zstrtol(const char *s, char **t, int base) +zstrtol_underscore(const char *s, char **t, int base, int underscore) { const char *inp, *trunc = NULL; zulong calc = 0, newcalc = 0; @@ -2062,22 +2069,24 @@ zstrtol(const char *s, char **t, int base) if (base < 2 || base > 36) { zerr("invalid base (must be 2 to 36 inclusive): %d", base); return (zlong)0; - } else if (base <= 10) - for (; *s >= '0' && *s < ('0' + base); s++) { - if (trunc) + } else if (base <= 10) { + for (; (*s >= '0' && *s < ('0' + base)) || + (underscore && *s == '_'); s++) { + if (trunc || *s == '_') continue; newcalc = calc * base + *s - '0'; if (newcalc < calc) { - trunc = s; - continue; + trunc = s; + continue; } calc = newcalc; } - else + } else { for (; idigit(*s) || (*s >= 'a' && *s < ('a' + base - 10)) - || (*s >= 'A' && *s < ('A' + base - 10)); s++) { - if (trunc) + || (*s >= 'A' && *s < ('A' + base - 10)) + || (underscore && *s == '_'); s++) { + if (trunc || *s == '_') continue; newcalc = calc*base + (idigit(*s) ? (*s - '0') : (*s & 0x1f) + 9); if (newcalc < calc) @@ -2087,6 +2096,7 @@ zstrtol(const char *s, char **t, int base) } calc = newcalc; } + } /* * Special case: check for a number that was just too long for diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index 1f0d2d0f3..e5845d37f 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -210,3 +210,26 @@ print $x 0:double increment for repeated expression >2 + + # Floating point. Default precision should take care of rounding errors. + print $(( 1_0.000_000e0_1 )) + # Integer. + print $(( 0x_ff_ff_ )) + # _ are parts of variable names that don't start with a digit + __myvar__=42 + print $(( __myvar__ + $__myvar__ )) + # _ is not part of variable name that does start with a digit + # (which are substituted before math eval) + set -- 6 + print $(( $1_000_000 )) + # Underscores in expressions with no whitespace + print $(( 3_000_+4_000_/2 )) + # Underscores may appear in the base descriptor, for what it's worth... + print $(( 1_6_#f_f_ )) +0:underscores in math constants +>100. +>65535 +>84 +>6000000 +>5000 +>255 -- cgit v1.2.3 From 8e43f7f3c839429849cb36ea0c84cdc05d40ad1d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 21 Sep 2012 12:45:12 +0000 Subject: 30687 with typo corrected: don't REPORTTIME if zleactive --- ChangeLog | 7 ++++++- Doc/Zsh/params.yo | 5 ++++- Src/jobs.c | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index bd8629898..67695c12c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-09-21 Peter Stephenson + + * 30687 (typo fixed): Doc/Zsh/params.yo, Src/jobs.c: don't + REPORTTIME if zleactive (but time keyword is allowed). + 2012-09-15 Peter Stephenson * Александр Балезин: 30667: Completion/Unix/Command/_ip: add @@ -164,5 +169,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5721 $ +* $Revision: 1.5722 $ ***************************************************** diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 5991921f8..bf9a68ba8 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1225,7 +1225,10 @@ vindex(REPORTTIME) item(tt(REPORTTIME))( If nonnegative, commands whose combined user and system execution times (measured in seconds) are greater than this value have timing -statistics printed for them. +statistics printed for them. Output is suppressed for commands +executed within the line editor, including completion; commands +explicitly marked with the tt(time) keyword still cause the summary +to be printed in this case. ) vindex(REPLY) item(tt(REPLY))( diff --git a/Src/jobs.c b/Src/jobs.c index c9c549e1e..ddd997c49 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -868,6 +868,8 @@ should_report_time(Job j) /* can this ever happen? */ if (!j->procs) return 0; + if (zleactive) + return 0; #ifdef HAVE_GETRUSAGE reporttime -= j->procs->ti.ru_utime.tv_sec + j->procs->ti.ru_stime.tv_sec; -- cgit v1.2.3 From dbec4fa6ccccb717608498b83989b21967948bde Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 21 Sep 2012 19:08:35 +0000 Subject: 30692: allow autoload +X -m to work change to _path_files to make it load in that fashion --- ChangeLog | 8 +++++++- Completion/Unix/Type/_path_files | 2 +- Doc/Zsh/builtins.yo | 5 ++++- Src/builtin.c | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 67695c12c..231f3b143 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-21 Peter Stephenson + + * 30692: Completion/Unix/Type/_path_files, Doc/Zsh/builtins.yo, + Src/builtin.c: allow autoload +X -m to work; change _path_files + so it works on that. + 2012-09-21 Peter Stephenson * 30687 (typo fixed): Doc/Zsh/params.yo, Src/jobs.c: don't @@ -169,5 +175,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5722 $ +* $Revision: 1.5723 $ ***************************************************** diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files index a170983ba..aa58ea09b 100644 --- a/Completion/Unix/Type/_path_files +++ b/Completion/Unix/Type/_path_files @@ -198,7 +198,7 @@ zstyle -T ":completion:${curcontext}:paths" path-completion && path_completion=1 if [[ -n "$compstate[pattern_match]" ]]; then - if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete } || + if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete; } || _have_glob_qual "$SUFFIX" complete; then # Copy all glob qualifiers from the line to # the patterns used when generating matches diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 0e5353633..75745028f 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -108,7 +108,7 @@ ifnzman(noderef(Aliasing)). findex(autoload) cindex(functions, autoloading) cindex(autoloading functions) -item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXktz) ] [ tt(-w) ] [ var(name) ... ])( +item(tt(autoload) [ {tt(PLUS())|tt(-)}tt(UXkmtz) ] [ tt(-w) ] [ var(name) ... ])( Equivalent to tt(functions -u), with the exception of tt(-X)/tt(+X) and tt(-w). @@ -129,6 +129,9 @@ undefined and marked for autoloading. If ksh-style autoloading is enabled, the function created will contain the contents of the file plus a call to the function itself appended to it, thus giving normal ksh autoloading behaviour on the first call to the function. +If the tt(-m) flag is also given each var(name) is treated as a +pattern and all functions already marked for autoload that match the +pattern are loaded. With the tt(-w) flag, the var(name)s are taken as names of files compiled with the tt(zcompile) builtin, and all functions defined in them are diff --git a/Src/builtin.c b/Src/builtin.c index d8493bb8a..51ddce18c 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -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, "ktTUwXz", "u"), + BUILTIN("autoload", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "mktTUwXz", "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), @@ -2882,7 +2882,7 @@ bin_functions(char *name, char **argv, Options ops, int func) if ((pprog = patcompile(*argv, PAT_STATIC, 0))) { /* with no options, just print all functions matching the glob pattern */ queue_signals(); - if (!(on|off)) { + if (!(on|off) && !OPT_ISSET(ops,'X')) { scanmatchtable(shfunctab, pprog, 1, 0, DISABLED, shfunctab->printnode, pflags); } else { -- cgit v1.2.3 From feb6169bcd8920ccda0ee20b8089d9f3ca8010ba Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Fri, 28 Sep 2012 22:07:29 +0000 Subject: Seth House: 30702: contrib.yo, VCS_INFO_get_data_hg: Removed --debug flag from the hg vcs_info backend --- ChangeLog | 8 +++++++- Doc/Zsh/contrib.yo | 7 +++++-- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 9 ++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 27ee25112..f98b6c925 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-09-29 Frank Terbeck + + * Seth House: 30702: Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg: Removed --debug + flag from the hg vcs_info backend + 2012-09-28 Oliver Kiddle * 30697: Completion/Unix/Command/_dbus: new completion definition @@ -179,5 +185,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5724 $ +* $Revision: 1.5725 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 24aafc331..8dbc095fd 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -768,7 +768,10 @@ item(tt(hgrevformat))( tt(hg) uses both a hash and a revision number to reference a specific changeset in a repository. With this style you can format the revision string (see tt(branchformat)) to include either or both. It's only -useful when tt(get-revision) is true. +useful when tt(get-revision) is true. Note, the full 40-character revision id +is not available (except when using the tt(use-simple) option) because +executing hg more than once per prompt is too slow; you may customize this +behavior using hooks. ) kindex(max-exports) item(tt(max-exports))( @@ -993,7 +996,7 @@ In tt(hgrevformat) these replacements are done: startsitem() sitem(tt(%r))(The current local revision number.) -sitem(tt(%h))(The current 40-character changeset ID hash identifier.) +sitem(tt(%h))(The current global revision identifier.) endsitem() In tt(patch-format) and tt(nopatch-format) these replacements are done: diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 48e385c97..cedaf5676 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -37,12 +37,15 @@ VCS_INFO_adjust # Calling the 'hg' program is quite a bit too slow for prompts. # Disabled by default anyway, so no harm done. if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then - # Calling hexdump is (much) faster than hg but doesn't get the local rev if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple \ && ( VCS_INFO_check_com hexdump ) && [[ -r ${dirstatefile} ]] ; then + # Calling hexdump is (much) faster than hg but doesn't get the local rev r_csetid=$(hexdump -n 20 -e '1/1 "%02x"' ${dirstatefile}) else - hgid_args=( --debug id -i -n -b ) + # Settling for a short (but unique!) hash because getting the full + # 40-char hash in addition to all the other info we want isn't + # available in a single hg invocation + hgid_args=( id -i -n -b ) # Looking for changes is a tad bit slower since the dirstate cache must # first be refreshed before being read @@ -119,7 +122,7 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-bookmarks \ && [[ -r "${bmfile}" ]] && [[ -n "$r_csetid" ]] ; then while read -r i_bmhash i_bmname ; do # Compare hash in bookmarks file with changeset id - [[ $r_csetid == $i_bmhash ]] && hgbmarks+=( $i_bmname ) + [[ $i_bmhash == $r_csetid* ]] && hgbmarks+=( $i_bmname ) done < ${bmfile} if VCS_INFO_hook 'gen-hg-bookmark-string' "${hgbmarks[@]}"; then -- cgit v1.2.3 From 61b9529ff848d6758b498389256111984bda1437 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Oct 2012 18:11:12 +0000 Subject: users/17310: we can't treat < after [ as a normal character. Document problem and test for case that needs to work. --- ChangeLog | 9 ++++++++- Doc/Zsh/params.yo | 5 ++++- Src/lex.c | 4 ++-- Test/A04redirect.ztst | 3 +++ Test/D06subscript.ztst | 20 -------------------- 5 files changed, 17 insertions(+), 24 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 681fd10e9..0d68f729f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-10-03 Peter Stephenson + + * users/17310: Doc/Zsh/params.yo, Src/lex.c, Test/A04redirect.ztst, + Test/D06subscript.ztst: back off users/17304 owing to problem + with [ command, document problem, and test the case that needs + to work. + 2012-10-02 Peter Stephenson * users/17304: Src/lex.c, Test/D06subscript.ztst: angle brackets @@ -207,5 +214,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5731 $ +* $Revision: 1.5732 $ ***************************************************** diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index bf9a68ba8..b7b7750ff 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -182,7 +182,10 @@ to the matching closing one is considered to be a list of flags, as in The flags tt(s), tt(n) and tt(b) take an argument; the delimiter is shown below as `tt(:)', but any character, or the matching pairs `tt(LPAR())...tt(RPAR())', `tt({)...tt(})', `tt([)...tt(])', or -`tt(<)...tt(>)', may be used. +`tt(<)...tt(>)', may be used, but note that `tt(<)...tt(>)' can only be +used if the subscript is inside a double quoted expression or a +parameter substitution enclosed in braces as otherwise the expression is +interpreted as a redirection. The flags currently understood are: diff --git a/Src/lex.c b/Src/lex.c index d02b3885a..1cf3611c9 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1218,7 +1218,7 @@ gettokstr(int c, int sub) c = Comma; break; case LX2_OUTANG: - if (in_brace_param || sub || brct) + if (in_brace_param || sub) break; e = hgetc(); if (e != '(') { @@ -1255,7 +1255,7 @@ gettokstr(int c, int sub) break; } lexstop = 0; - if (in_brace_param || sub || brct) + if (in_brace_param || sub) break; goto brk; case LX2_EQUALS: diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst index 3911b0629..d3c0a4a99 100644 --- a/Test/A04redirect.ztst +++ b/Test/A04redirect.ztst @@ -441,3 +441,6 @@ 0:failed assignment on non-posix-special, POSIX_BUILTINS >output ?zsh: read-only variable: foo + + ["; do - eval 'print ${string[(ws'$delims[1]'+'$delims[2]')2]}' - eval 'print $string[(ws'$delims[1]'+'$delims[2]')3]' - eval 'print "$string[(ws'$delims[1]'+'$delims[2]')4]"' - done -0:Check matched delimiters in subscripts ->like ->a ->dome ->like ->a ->dome ->like ->a ->dome ->like ->a ->dome -- cgit v1.2.3 From 325c3864c67a3e7dfd949727a229adaa961c3d95 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Oct 2012 18:12:47 +0000 Subject: users/17305: fix doc of ordering of word splitting improve (z) and (Z) doc --- ChangeLog | 5 ++++- Doc/Zsh/expn.yo | 67 +++++++++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 0d68f729f..de241b8ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-10-03 Peter Stephenson + * users/17305: Doc/Zsh/expn.yo: fix documentation for ordering + of word splitting and improve (z) and (Z) documentation. + * users/17310: Doc/Zsh/params.yo, Src/lex.c, Test/A04redirect.ztst, Test/D06subscript.ztst: back off users/17304 owing to problem with [ command, document problem, and test the case that needs @@ -214,5 +217,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5732 $ +* $Revision: 1.5733 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 8afd92532..7362c9c52 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1051,12 +1051,13 @@ item(tt(z))( Split the result of the expansion into words using shell parsing to find the words, i.e. taking into account any quoting in the value. Comments are not treated specially but as ordinary strings, similar -to interactive shells with the tt(INTERACTIVE_COMMENTS) option unset. +to interactive shells with the tt(INTERACTIVE_COMMENTS) option unset +(however, see the tt(Z) flag below for related options) -Note that this is done very late, as for the `tt((s))' flag. So to -access single words in the result, one has to use nested expansions as +Note that this is done very late, even later than the `tt((s))' flag. So to +access single words in the result use nested expansions as in `tt(${${(z)foo}[2]})'. Likewise, to remove the quotes in the -resulting words one would do: `tt(${(Q)${(z)foo}})'. +resulting words use `tt(${(Q)${(z)foo}})'. ) item(tt(0))( Split the result of the expansion on null bytes. This is a shorthand @@ -1165,7 +1166,8 @@ i.e. tt("${(@s.:.)line}"). ) item(tt(Z:)var(opts)tt(:))( As tt(z) but takes a combination of option letters between a following -pair of delimiter characters. tt(LPAR()Z+PLUS()c+PLUS()RPAR()) +pair of delimiter characters. With no options the effect is identical +to tt(z). tt(LPAR()Z+PLUS()c+PLUS()RPAR()) causes comments to be parsed as a string and retained; any field in the resulting array beginning with an unquoted comment character is a comment. tt(LPAR()Z+PLUS()C+PLUS()RPAR()) causes comments to be parsed @@ -1248,7 +1250,7 @@ em(no responsibility) for any brain damage which may occur during the reading of the following rules. startitem() -item(tt(1.) em(Nested Substitution))( +item(tt(1.) em(Nested substitution))( If multiple nested tt(${...}) forms are present, substitution is performed from the inside outwards. At each level, the substitution takes account of whether the current value is a scalar or an array, whether the @@ -1272,12 +1274,12 @@ which is expanded by filename expansion to a full path; the outer substitution then applies the modifier tt(:h) and takes the directory part of the path.) ) -item(tt(2.) em(Internal Parameter Flags))( +item(tt(2.) em(Internal parameter flags))( Any parameter flags set by one of the tt(typeset) family of commands, in particular the tt(L), tt(R), tt(Z), tt(u) and tt(l) flags for padding and capitalization, are applied directly to the parameter value. ) -item(tt(3.) em(Parameter Subscripting))( +item(tt(3.) em(Parameter subscripting))( If the value is a raw parameter reference with a subscript, such as tt(${)var(var)tt([3]}), the effect of subscripting is applied directly to the parameter. Subscripts are evaluated left to right; subsequent @@ -1287,11 +1289,11 @@ character of the first word, but tt(${var[2,4][2]}) is the entire third word (the second word of the range of words two through four of the original array). Any number of subscripts may appear. ) -item(tt(4.) em(Parameter Name Replacement))( +item(tt(4.) em(Parameter name replacement))( The effect of any tt((P)) flag, which treats the value so far as a parameter name and replaces it with the corresponding value, is applied. ) -item(tt(5.) em(Double-Quoted Joining))( +item(tt(5.) em(Double-quoted joining))( If the value after this process is an array, and the substitution appears in double quotes, and no tt((@)) flag is present at the current level, the words of the value are joined with the first character of the @@ -1299,7 +1301,7 @@ parameter tt($IFS), by default a space, between each word (single word arrays are not modified). If the tt((j)) flag is present, that is used for joining instead of tt($IFS). ) -item(tt(6.) em(Nested Subscripting))( +item(tt(6.) em(Nested subscripting))( Any remaining subscripts (i.e. of a nested substitution) are evaluated at this point, based on whether the value is an array or a scalar. As with tt(3.), multiple subscripts can appear. Note that tt(${foo[2,4][2]}) is @@ -1322,7 +1324,7 @@ item(tt(9.) em(Length))( Any initial tt(#) modifier, i.e. in the form tt(${#)var(var)tt(}), is used to evaluate the length of the expression so far. ) -item(tt(10.) em(Forced Joining))( +item(tt(10.) em(Forced joining))( If the `tt((j))' flag is present, or no `tt((j))' flag is present but the string is to be split as given by rules tt(16.) or tt(17.), and joining did not take place at step tt(5.), any words in the value are joined @@ -1330,36 +1332,41 @@ together using the given string or the first character of tt($IFS) if none. Note that the `tt((F))' flag implicitly supplies a string for joining in this manner. ) -item(tt(11.) em(Case modification))( +item(tt(11.) em(Simple word splitting))( +If one of the `tt((s))' or `tt((f))' flags are present, or the `tt(=)' +specifier was present (e.g. tt(${=)var(var)tt(})), the word is split on +occurrences of the specified string, or (for tt(=) with neither of the two +flags present) any of the characters in tt($IFS). + +If no `tt((s))', `tt((f))' or `tt(=)' was given, but the word is not +quoted and the option tt(SH_WORD_SPLIT) is set, the word is split on +occurrences of any of the characters in tt($IFS). Note this step, too, +takes place at all levels of a nested substitution. +) +item(tt(12.) em(Case modification))( Any case modification from one of the flags tt((L)), tt((U)) or tt((C)) is applied. ) -item(tt(12.) em(Escape sequence replacement))( +item(tt(13.) em(Escape sequence replacement))( First any replacements from the tt((g)) flag are performed, then any prompt-style formatting from the tt((%)) family of flags is applied. ) -item(tt(13.) em(Quote application))( +item(tt(14.) em(Quote application))( Any quoting or unquoting using tt((q)) and tt((Q)) and related flags is applied. ) -item(tt(14.) em(Directory naming))( +item(tt(15.) em(Directory naming))( Any directory name substitution using tt((D)) flag is applied. ) -item(tt(15.) em(Visibility enhancment))( +item(tt(16.) em(Visibility enhancment))( Any modifications to make characters visible using the tt((V)) flag are applied. ) -item(tt(16.) em(Forced Splitting))( -If one of the `tt((s))', `tt((f))' or `tt((z))' flags are present, or the `tt(=)' -specifier was present (e.g. tt(${=)var(var)tt(})), the word is split on -occurrences of the specified string, or (for tt(=) with neither of the two -flags present) any of the characters in tt($IFS). -) -item(tt(17.) em(Shell Word Splitting))( -If no `tt((s))', `tt((f))' or `tt(=)' was given, but the word is not -quoted and the option tt(SH_WORD_SPLIT) is set, the word is split on -occurrences of any of the characters in tt($IFS). Note this step, too, -takes place at all levels of a nested substitution. +item(tt(17.) em(Lexical word splitting))( +If the 'tt((z))' flag or one of the forms of the 'tt((Z))' flag is +present, the word is split as if it were a shell command line, so that +quotation marks and other metacharacters are used to decide what +constitutes a word. ) item(tt(18.) em(Uniqueness))( If the result is an array and the `tt((u))' flag was present, duplicate @@ -1369,7 +1376,7 @@ item(tt(19.) em(Ordering))( If the result is still an array and one of the `tt((o))' or `tt((O))' flags was present, the array is reordered. ) -item(tt(20.) em(Re-Evaluation))( +item(tt(20.) em(Re-evaluation))( Any `tt((e))' flag is applied to the value, forcing it to be re-examined for new parameter substitutions, but also for command and arithmetic substitutions. @@ -1378,7 +1385,7 @@ item(tt(21.) em(Padding))( Any padding of the value by the `tt(LPAR()l.)var(fill)tt(.RPAR())' or `tt(LPAR()r.)var(fill)tt(.RPAR())' flags is applied. ) -item(tt(22.) em(Semantic Joining))( +item(tt(22.) em(Semantic joining))( In contexts where expansion semantics requires a single word to result, all words are rejoined with the first character of tt(IFS) between. So in `tt(${LPAR()P)tt(RPAR()${LPAR()f)tt(RPAR()lines}})' -- cgit v1.2.3 From 8781aad44870da32b3c59f5faa8a5a3e01a7027d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 5 Oct 2012 13:31:58 +0000 Subject: additional split change fixes --- Doc/Zsh/expn.yo | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 7362c9c52..8ee72bbdb 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1176,7 +1176,8 @@ starting with the third character of tt($HISTCHARS), default tt(#), up to the next newline is a comment. tt(LPAR()Z+PLUS()n+PLUS()RPAR()) causes unquoted newlines to be treated as ordinary whitespace, else they are treated as if they are shell code delimiters and converted to -semicolons. +semicolons. Options are combined within the same set of delimiters, +e.g. tt(LPAR()Z+PLUS()Cn+PLUS()RPAR()). ) item(tt(_:)var(flags)tt(:))( The underscore (tt(_)) flag is reserved for future use. As of this @@ -1278,6 +1279,8 @@ item(tt(2.) em(Internal parameter flags))( Any parameter flags set by one of the tt(typeset) family of commands, in particular the tt(L), tt(R), tt(Z), tt(u) and tt(l) flags for padding and capitalization, are applied directly to the parameter value. +Note these flags are options to the command, e.g. `tt(typeset -Z)'; +they are not the same as the flags used within parameter substitutions. ) item(tt(3.) em(Parameter subscripting))( If the value is a raw parameter reference with a subscript, such as @@ -1358,7 +1361,7 @@ is applied. item(tt(15.) em(Directory naming))( Any directory name substitution using tt((D)) flag is applied. ) -item(tt(16.) em(Visibility enhancment))( +item(tt(16.) em(Visibility enhancement))( Any modifications to make characters visible using the tt((V)) flag are applied. ) -- cgit v1.2.3 From 321471891e259c7b406f3cfaf1c076b28ae16a5f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 7 Oct 2012 17:50:18 +0000 Subject: 30718: emulate command evaluations should apply sticky emulation to autoloads, too --- ChangeLog | 8 +++++++- Doc/Zsh/builtins.yo | 23 ++++++++++++++++++----- README | 34 ++++++++++++++++++++++++++++++++-- Src/builtin.c | 3 +-- Test/C04funcdef.ztst | 17 +++++++++++++++++ 5 files changed, 75 insertions(+), 10 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 37dce9bf9..31896e953 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-10-07 Peter Stephenson + + * 30718: README, Doc/Zsh/builtins.yo, Src/builtin.c, + Test/C04funcdef.ztst: emulate command evaluations should apply + sticky emulation to autoloads, too. + 2012-10-07 Oliver Kiddle * unposted: Completion/Unix/Command/_webbrowser, @@ -233,5 +239,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5737 $ +* $Revision: 1.5738 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 75745028f..f7924a072 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -137,10 +137,19 @@ With the tt(-w) flag, the var(name)s are taken as names of files compiled with the tt(zcompile) builtin, and all functions defined in them are marked for autoloading. -The flags tt(-z) and tt(-k) mark the function to be autoloaded in -native or ksh emulation, as if the option tt(KSH_AUTOLOAD) were -unset or were set, respectively. The flags override the setting of -the option at the time the function is loaded. +The flags tt(-z) and tt(-k) mark the function to be autoloaded using the +zsh or ksh style, as if the option tt(KSH_AUTOLOAD) were unset or were +set, respectively. The flags override the setting of the option at the +time the function is loaded. + +Note that the tt(autoload) command makes no attempt to ensure the +shell options set during the loading or execution of the file have +any particular value. For this, the tt(emulate) command can be used: + +example(emulate zsh -c 'autoload -Uz var(func)') + +arranges that when var(func) is loaded the shell is in native tt(zsh) +emulation, and this emulation is also applied when var(func) is run. ) findex(bg) cindex(jobs, backgrounding) @@ -393,6 +402,7 @@ ifnzman(noderef(Invocation))\ ifzman(the section INVOCATION in zmanref(zsh)), except that `tt(-o EMACS)' and `tt(-o VI)' may not be used. Flags such as `tt(+r)'/`tt(+o RESTRICTED)' may be prohibited in some circumstances. + If tt(-c) var(arg) appears in var(flags), var(arg) is evaluated while the requested emulation is temporarily in effect. In this case the emulation mode and all options are restored to their previous values before @@ -409,7 +419,10 @@ 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 from the function do not cause options to be altered (except due to -standard processing such as the tt(LOCAL_OPTIONS) option). +standard processing such as the tt(LOCAL_OPTIONS) option). This also +applies to functions marked for autoload within the sticky emulation; +the appropriate set of options will be applied at the point the +function is loaded as well as when it is run. For example: diff --git a/README b/README index c5c18a90d..7542f8d35 100644 --- a/README +++ b/README @@ -30,8 +30,38 @@ Zsh is a shell with lots of features. For a list of some of these, see the file FEATURES, and for the latest changes see NEWS. For more details, see the documentation. -Possible incompatibilities ---------------------------- +Incompatibilities between 5.0.0 and 5.0.1 +----------------------------------------- + +In 5.0.0, the new "sticky" emulation feature was applied to functions +explicitly declared within an expression following `emulate ... -c', but +did not apply to functions marked for autoload in that expression. This +was not documented and experience suggests it was inconvenient, so in +5.0.1 autoloads also have the sticky property. + +In other words, + + emulate zsh -c 'func() { ... }' + +behaves the same way in 5.0.0 and 5.0.1, with the function func always being +run in native zsh emulation regardless of the current option settings. +However, + + emulate zsh -c 'autoload -Uz func' + +behaves differently: in 5.0.0, func was loaded with the options in +effect at the point where it was first run, and subsequently run with +whatever options were in effect at that point; in 5.0.1, func is loaded +with native zsh emulation options and run with those same options. This +is now the recommended way of ensuring a function is loaded and run with +a consistent set of options. + +Note that the `autoload -z' has never affected the options applied when +the function is loaded or run, only the effect of the KSH_AUTOLOAD +option at the point the function is loaded. + +Possible incompatibilities between 4.2 and 5.0 +---------------------------------------------- Here are some incompatibilities in the shell since the 4.2 series of releases. It is hoped most users will not be adversely affected by these. diff --git a/Src/builtin.c b/Src/builtin.c index 51ddce18c..e9ad8f3de 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2944,8 +2944,7 @@ bin_functions(char *name, char **argv, Options ops, int func) shf = (Shfunc) zshcalloc(sizeof *shf); shf->node.flags = on; shf->funcdef = mkautofn(shf); - /* No sticky emulation for autoloaded functions */ - shf->emulation = 0; + shf->emulation = sticky_emulation; shfunctab->addnode(shfunctab, ztrdup(*argv), shf); if (signum != -1) { diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 90f01e397..706aa28c2 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -251,6 +251,23 @@ >foo1 >bar2 + ( + setopt ignorebraces + fpath=(.) + print "{ echo OK }\n[[ -o ignorebraces ]] || print 'ignorebraces is off'" \ + >emufunctest + (autoload -z emufunctest; emufunctest) 2>&1 + emulate zsh -c 'autoload -Uz emufunctest' + emufunctest + [[ -o ignorebraces ]] && print 'ignorebraces is still on here' + ) +0:sticky emulation applies to autoloads and autoloaded function execution +>emufunctest:3: parse error near `\n' +>OK +>ignorebraces is off +>ignorebraces is still on here + + %clean rm -f file.in file.out -- cgit v1.2.3 From 4b86cc48f704152ccca13c50bc3acd59b4217ecc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 11 Oct 2012 20:14:01 +0000 Subject: 30726: make shell options passed to emulate stick along with the emulation --- ChangeLog | 11 ++++- Doc/Zsh/builtins.yo | 4 ++ Src/Modules/parameter.c | 2 +- Src/builtin.c | 50 +++++++++++++++++----- Src/exec.c | 107 +++++++++++++++++++++++++++++++++++++++++++++--- Src/hashtable.c | 9 ++++ Src/init.c | 44 ++++++++++++++++---- Src/options.c | 18 +++----- Src/parse.c | 2 +- Src/signals.c | 5 ++- Src/zsh.h | 30 +++++++++++++- Test/B07emulate.ztst | 46 +++++++++++++++++++++ 12 files changed, 287 insertions(+), 41 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 5a69f0174..4b1508a47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-10-11 Peter Stephenson + + * 30726: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c, + Src/hashtable.c, Src/init.c, Src/options.c, Src/parse.c, + Src/signals.c, Src/zsh.h, Src/Modules/parameter.c, + Test/B07emulate.ztst: extend 30722 to handle the case + where shell options passed to the emulate command need + propagating to sticky emulation. + 2012-10-11 Peter Stephenson * 30724: Src/exec.c, Src/jobs.c: shell code optimised to use @@ -260,5 +269,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5744 $ +* $Revision: 1.5745 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index f7924a072..37319c9b0 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -462,6 +462,10 @@ sitem(4.)(The presence or absence of the tt(-R) switch to tt(emulate) corresponds to different sticky emulation modes, so for example `tt(emulate sh -c)', `tt(emulate -R sh -c)' and `tt(emulate csh -c)' are treated as three distinct sticky emulations.) +sitem(5.)(Difference in shell options supplied in addition to the +basic emulation also mean the sticky emulations are different, so for +example `tt(emulate zsh -c)' and `tt(emulate zsh -o cbases -c)' are +treated as distinct sticky emulations.) endsitem() ) findex(enable) diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index f19dfce4f..a029c9cb4 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -289,7 +289,7 @@ setfunction(char *name, char *val, int dis) shf = (Shfunc) zshcalloc(sizeof(*shf)); shf->funcdef = dupeprog(prog, 0); shf->node.flags = dis; - shf->emulation = sticky_emulation; + shfunc_set_sticky(shf); if (!strncmp(name, "TRAP", 4) && (sn = getsignum(name + 4)) != -1) { diff --git a/Src/builtin.c b/Src/builtin.c index 5cb643f23..8a83df711 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2944,7 +2944,7 @@ bin_functions(char *name, char **argv, Options ops, int func) shf = (Shfunc) zshcalloc(sizeof *shf); shf->node.flags = on; shf->funcdef = mkautofn(shf); - shf->emulation = sticky_emulation; + shfunc_set_sticky(shf); shfunctab->addnode(shfunctab, ztrdup(*argv), shf); if (signum != -1) { @@ -5007,11 +5007,15 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) { int opt_L = OPT_ISSET(ops, 'L'); int opt_R = OPT_ISSET(ops, 'R'); - int saveemulation, savesticky_emulation, savehackchar; + int saveemulation, savehackchar; int ret = 1, new_emulation; - char saveopts[OPT_SIZE], new_opts[OPT_SIZE], savesticky_opts[OPT_SIZE]; + char saveopts[OPT_SIZE], new_opts[OPT_SIZE]; char *cmd = 0; const char *shname = *argv; + LinkList optlist; + LinkNode optnode; + Emulation_options save_sticky; + OptIndex *on_ptr, *off_ptr; /* without arguments just print current emulation */ if (!shname) { @@ -5055,7 +5059,8 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) memcpy(new_opts, opts, sizeof(opts)); savehackchar = keyboardhackchar; emulate(shname, OPT_ISSET(ops,'R'), &new_emulation, new_opts); - if (parseopts("emulate", &argv, new_opts, &cmd)) { + optlist = newlinklist(); + if (parseopts("emulate", &argv, new_opts, &cmd, optlist)) { ret = 1; goto restore; } @@ -5081,15 +5086,40 @@ bin_emulate(UNUSED(char *nam), char **argv, Options ops, UNUSED(int func)) } else return 0; - savesticky_emulation = sticky_emulation; - sticky_emulation = emulation; - memcpy(savesticky_opts, sticky_opts, sizeof(opts)); - memcpy(sticky_opts, opts, sizeof(opts)); + save_sticky = sticky; + sticky = hcalloc(sizeof(*sticky)); + sticky->emulation = emulation; + for (optnode = firstnode(optlist); optnode; incnode(optnode)) { + /* Data is index into new_opts */ + char *optptr = (char *)getdata(optnode); + if (*optptr) + sticky->n_on_opts++; + else + sticky->n_off_opts++; + } + if (sticky->n_on_opts) + on_ptr = sticky->on_opts = + zhalloc(sticky->n_on_opts * sizeof(*sticky->on_opts)); + else + on_ptr = NULL; + if (sticky->n_off_opts) + off_ptr = sticky->off_opts = zhalloc(sticky->n_off_opts * + sizeof(*sticky->off_opts)); + else + off_ptr = NULL; + for (optnode = firstnode(optlist); optnode; incnode(optnode)) { + /* Data is index into new_opts */ + char *optptr = (char *)getdata(optnode); + int optno = optptr - new_opts; + if (*optptr) + *on_ptr++ = optno; + else + *off_ptr++ = optno; + } ret = eval(argv); - sticky_emulation = savesticky_emulation; + sticky = save_sticky; emulation = saveemulation; memcpy(opts, saveopts, sizeof(opts)); - memcpy(sticky_opts, savesticky_opts, sizeof(opts)); restore: keyboardhackchar = savehackchar; inittyptab(); /* restore banghist */ diff --git a/Src/exec.c b/Src/exec.c index b2224cfb3..74b14d54d 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4267,7 +4267,7 @@ execfuncdef(Estate state, UNUSED(int do_exec)) shf->node.flags = 0; shf->filename = ztrdup(scriptfilename); shf->lineno = lineno; - shf->emulation = sticky_emulation; + shfunc_set_sticky(shf); if (!names) { /* @@ -4319,6 +4319,46 @@ execfuncdef(Estate state, UNUSED(int do_exec)) return ret; } +/* Duplicate a sticky emulation */ + +/**/ + +mod_export Emulation_options +sticky_emulation_dup(Emulation_options src, int useheap) +{ + Emulation_options newsticky = useheap ? + hcalloc(sizeof(*src)) : zshcalloc(sizeof(*src)); + newsticky->emulation = src->emulation; + if (src->n_on_opts) { + size_t sz = src->n_on_opts * sizeof(*src->on_opts); + newsticky->n_on_opts = src->n_on_opts; + newsticky->on_opts = useheap ? zhalloc(sz) : zalloc(sz); + memcpy(newsticky->on_opts, src->on_opts, sz); + } + if (src->n_off_opts) { + size_t sz = src->n_off_opts * sizeof(*src->off_opts); + newsticky->n_off_opts = src->n_off_opts; + newsticky->off_opts = useheap ? zhalloc(sz) : zalloc(sz); + memcpy(newsticky->off_opts, src->off_opts, sz); + } + + return newsticky; +} + +/* Set the sticky emulation attributes for a shell function */ + +/**/ + +mod_export void +shfunc_set_sticky(Shfunc shf) +{ + if (sticky) + shf->sticky = sticky_emulation_dup(sticky, 0); + else + shf->sticky = NULL; +} + + /* Main entry point to execute a shell function. */ /**/ @@ -4478,6 +4518,45 @@ loadautofn(Shfunc shf, int fksh, int autol) return shf; } +/* + * Check if a sticky emulation differs from the current one. + */ + +/**/ + +int sticky_emulation_differs(Emulation_options sticky2) +{ + /* If no new sticky emulation, not a different emulation */ + if (!sticky2) + return 0; + /* If no current sticky emulation, different */ + if (!sticky) + return 1; + /* If basic emulation different, different */ + if (sticky->emulation != sticky2->emulation) + return 1; + /* If differing numbers of options, different */ + if (sticky->n_on_opts != sticky2->n_on_opts || + sticky->n_off_opts != sticky2->n_off_opts) + return 1; + /* + * We need to compare option arrays, if non-null. + * We made parseopts() create the list of options in option + * order to make this easy. + */ + /* If different options turned on, different */ + if (sticky->n_on_opts && + memcmp(sticky->on_opts, sticky2->on_opts, + sticky->n_on_opts * sizeof(*sticky->on_opts)) != 0) + return 1; + /* If different options turned on, different */ + if (sticky->n_off_opts && + memcmp(sticky->off_opts, sticky2->off_opts, + sticky->n_off_opts * sizeof(*sticky->off_opts)) != 0) + return 1; + return 0; +} + /* * execute a shell function * @@ -4507,10 +4586,11 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) char *name = shfunc->node.nam; int flags = shfunc->node.flags, ooflags; char *fname = dupstring(name); - int obreaks, saveemulation, savesticky_emulation, restore_sticky; + int obreaks, saveemulation, restore_sticky; Eprog prog; struct funcstack fstack; static int oflags; + Emulation_options save_sticky = NULL; #ifdef MAX_FUNCTION_DEPTH static int funcdepth; #endif @@ -4548,9 +4628,9 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) * function we need to restore the original options on exit. */ memcpy(saveopts, opts, sizeof(opts)); saveemulation = emulation; - savesticky_emulation = sticky_emulation; + save_sticky = sticky; - if (shfunc->emulation && sticky_emulation != shfunc->emulation) { + if (sticky_emulation_differs(shfunc->sticky)) { /* * Function is marked for sticky emulation. * Enable it now. @@ -4563,9 +4643,24 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) * * This propagates the sticky emulation to subfunctions. */ - emulation = sticky_emulation = shfunc->emulation; + sticky = sticky_emulation_dup(shfunc->sticky, 1); + emulation = sticky->emulation; restore_sticky = 1; installemulation(emulation, opts); + if (sticky->n_on_opts) { + OptIndex *onptr; + for (onptr = sticky->on_opts; + onptr < sticky->on_opts + sticky->n_on_opts; + onptr++) + opts[*onptr] = 1; + } + if (sticky->n_off_opts) { + OptIndex *offptr; + for (offptr = sticky->off_opts; + offptr < sticky->off_opts + sticky->n_off_opts; + offptr++) + opts[*offptr] = 0; + } } else restore_sticky = 0; @@ -4674,7 +4769,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) */ memcpy(opts, saveopts, sizeof(opts)); emulation = saveemulation; - sticky_emulation = savesticky_emulation; + sticky = save_sticky; } else if (isset(LOCALOPTIONS)) { /* restore all shell options except PRIVILEGED and RESTRICTED */ saveopts[PRIVILEGED] = opts[PRIVILEGED]; diff --git a/Src/hashtable.c b/Src/hashtable.c index b472e40b9..ef187927b 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -888,6 +888,15 @@ freeshfuncnode(HashNode hn) if (shf->funcdef) freeeprog(shf->funcdef); zsfree(shf->filename); + if (shf->sticky) { + if (shf->sticky->n_on_opts) + zfree(shf->sticky->on_opts, + shf->sticky->n_on_opts * sizeof(*shf->sticky->on_opts)); + if (shf->sticky->n_off_opts) + zfree(shf->sticky->off_opts, + shf->sticky->n_off_opts * sizeof(*shf->sticky->off_opts)); + zfree(shf->sticky, sizeof(*shf->sticky)); + } zfree(shf, sizeof(struct shfunc)); } diff --git a/Src/init.c b/Src/init.c index 8f6c0ec6d..6c2ba13e4 100644 --- a/Src/init.c +++ b/Src/init.c @@ -246,7 +246,7 @@ parseargs(char **argv, char **runscript) opts[SHINSTDIN] = 0; opts[SINGLECOMMAND] = 0; - if (parseopts(NULL, &argv, opts, &cmd)) + if (parseopts(NULL, &argv, opts, &cmd, NULL)) exit(1); paramlist = znewlinklist(); @@ -277,15 +277,37 @@ parseargs(char **argv, char **runscript) argzero = ztrdup(argzero); } +/* Insert into list in order of pointer value */ + +/**/ +static void +parseopts_insert(LinkList optlist, void *ptr) +{ + LinkNode node; + + for (node = firstnode(optlist); node; incnode(node)) { + if (ptr < getdata(node)) { + insertlinknode(optlist, prevnode(node), ptr); + return; + } + } + + addlinknode(optlist, ptr); +} + /* * Parse shell options. * If nam is not NULL, this is called from a command; don't * exit on failure. + * + * If optlist is not NULL, it used to form a list of pointers + * into new_opts indicating which options have been changed. */ /**/ mod_export int -parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp) +parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp, + LinkList optlist) { int optionbreak = 0; int action, optno; @@ -364,8 +386,12 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp) restricted = action; } else if ((optno == EMACSMODE || optno == VIMODE) && nam) { WARN_OPTION("can't change option: %s", *argv); - } else if (dosetopt(optno, action, !nam, new_opts) && nam) { - WARN_OPTION("can't change option: %s", *argv); + } else { + if (dosetopt(optno, action, !nam, new_opts) && nam) { + WARN_OPTION("can't change option: %s", *argv); + } else if (optlist) { + parseopts_insert(optlist, new_opts+optno); + } } break; } else if (isspace(STOUC(**argv))) { @@ -385,8 +411,12 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp) restricted = action; } else if ((optno == EMACSMODE || optno == VIMODE) && nam) { WARN_OPTION("can't change option: %s", *argv); - } else if (dosetopt(optno, action, !nam, new_opts) && nam) { - WARN_OPTION("can't change option: -%c", **argv); + } else { + if (dosetopt(optno, action, !nam, new_opts) && nam) { + WARN_OPTION("can't change option: -%c", **argv); + } else if (optlist) { + parseopts_insert(optlist, new_opts+optno); + } } } } @@ -396,7 +426,7 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp) if (*cmdp) { if (!*argv) { WARN_OPTION("string expected after -%s", *cmdp); - exit(1); + return 1; } *cmdp = *argv++; } diff --git a/Src/options.c b/Src/options.c index 87e9abe2d..80fef3d00 100644 --- a/Src/options.c +++ b/Src/options.c @@ -35,29 +35,21 @@ /**/ mod_export int emulation; -/* current sticky emulation: 0 means none */ +/* current sticky emulation: sticky = NULL means none */ /**/ -mod_export int sticky_emulation; +mod_export Emulation_options sticky; /* the options; e.g. if opts[SHGLOB] != 0, SH_GLOB is turned on */ - + /**/ mod_export char opts[OPT_SIZE]; -/* - * the options that need setting for current sticky emulation, if any: - * same format as opts. - */ - -/**/ -mod_export char sticky_opts[OPT_SIZE]; - /* Option name hash table */ /**/ mod_export HashTable optiontab; - + /* The canonical option name table */ #define OPT_CSH EMULATE_CSH @@ -786,7 +778,7 @@ dosetopt(int optno, int value, int force, char *new_opts) return -1; #endif /* GETPWNAM_FAKED */ } else if ((optno == EMACSMODE || optno == VIMODE) && value) { - if (sticky_emulation) + if (sticky && sticky->emulation) return -1; zleentry(ZLE_CMD_SET_KEYMAP, optno); new_opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0; diff --git a/Src/parse.c b/Src/parse.c index 8d2878cd7..096faa072 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -3482,7 +3482,7 @@ dump_autoload(char *nam, char *file, int on, Options ops, int func) shf = (Shfunc) zshcalloc(sizeof *shf); shf->node.flags = on; shf->funcdef = mkautofn(shf); - shf->emulation = 0; + shf->sticky = NULL; shfunctab->addnode(shfunctab, ztrdup(fdname(n) + fdhtail(n)), shf); if (OPT_ISSET(ops,'X') && eval_autoload(shf, shf->node.nam, ops, func)) ret = 1; diff --git a/Src/signals.c b/Src/signals.c index ad688094b..046ee6a4a 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -755,7 +755,10 @@ dosavetrap(int sig, int level) newshf->node.flags = shf->node.flags; newshf->funcdef = dupeprog(shf->funcdef, 0); newshf->filename = ztrdup(shf->filename); - newshf->emulation = shf->emulation; + if (shf->sticky) { + newshf->sticky = sticky_emulation_dup(shf->sticky, 0); + } else + newshf->sticky = 0; if (shf->node.flags & PM_UNDEFINED) newshf->funcdef->shf = newshf; } diff --git a/Src/zsh.h b/Src/zsh.h index fee27ac10..e51572bcf 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -407,6 +407,7 @@ typedef struct cmdnam *Cmdnam; typedef struct complist *Complist; typedef struct conddef *Conddef; typedef struct dirsav *Dirsav; +typedef struct emulation_options *Emulation_options; typedef struct features *Features; typedef struct feature_enables *Feature_enables; typedef struct funcstack *Funcstack; @@ -1099,7 +1100,7 @@ struct shfunc { char *filename; /* Name of file located in */ zlong lineno; /* line number in above file */ Eprog funcdef; /* function definition */ - int emulation; /* sticky emulation for function */ + Emulation_options sticky; /* sticky emulation definitions, if any */ }; /* Shell function context types. */ @@ -2104,6 +2105,12 @@ enum { OPT_SIZE }; +/* + * Size required to fit an option number. + * If OPT_SIZE goes above 256 this will need to expand. + */ +typedef unsigned char OptIndex; + #undef isset #define isset(X) (opts[X]) #define unset(X) (!opts[X]) @@ -2112,6 +2119,27 @@ enum { #define jobbing (isset(MONITOR)) #define islogin (isset(LOGINSHELL)) +/* + * Record of emulation and options that need to be set + * for a full "emulate". + */ +struct emulation_options { + /* The emulation itself */ + int emulation; + /* The number of options in on_opts. */ + int n_on_opts; + /* The number of options in off_opts. */ + int n_off_opts; + /* + * Array of options to be turned on. + * Only options specified explicitly in the emulate command + * are recorded. Null if n_on_opts is zero. + */ + OptIndex *on_opts; + /* Array of options to be turned off, similar. */ + OptIndex *off_opts; +}; + /***********************************************/ /* Definitions for terminal and display control */ /***********************************************/ diff --git a/Test/B07emulate.ztst b/Test/B07emulate.ztst index 569640bb4..315206a20 100644 --- a/Test/B07emulate.ztst +++ b/Test/B07emulate.ztst @@ -201,3 +201,49 @@ emulate zsh -o fixallmybugs 'print This was executed, bad' 1:emulate -c with incorrect options ?(eval):emulate:1: no such option: fixallmybugs + + emulate zsh -c ' + func() { [[ -o extendedglob ]] || print extendedglob is off } + ' + func + emulate zsh -o extendedglob -c ' + func() { [[ -o extendedglob ]] && print extendedglob is on } + ' + func +0:options specified alongside emulation are also sticky +>extendedglob is off +>extendedglob is on + + emulate zsh -o extendedglob -c ' + func_inner() { setopt nobareglobqual } + ' + emulate zsh -o extendedglob -c ' + func_outer() { + func_inner + [[ -o bareglobqual ]] || print bareglobqual was turned off + [[ -o extendedglob ]] && print extendedglob is on, though + } + ' + [[ -o extendedglob ]] || print extendedglob is initially off + func_outer +0:options propagate between identical emulations +>extendedglob is initially off +>bareglobqual was turned off +>extendedglob is on, though + + emulate zsh -o extendedglob -c ' + func_inner() { setopt nobareglobqual } + ' + emulate zsh -o extendedglob -o cbases -c ' + func_outer() { + func_inner + [[ -o bareglobqual ]] && print bareglobqual is still on + [[ -o extendedglob ]] && print extendedglob is on, too + } + ' + [[ -o extendedglob ]] || print extendedglob is initially off + func_outer +0:options do not propagate between different emulations +>extendedglob is initially off +>bareglobqual is still on +>extendedglob is on, too -- cgit v1.2.3 From a02f3b69102b0e1d0541eeb5715197e08e1d21ab Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 18 Oct 2012 08:28:46 +0000 Subject: c.f. users/17330: fix reference to splitting rule in parameter expn rules --- ChangeLog | 7 ++++++- Doc/Zsh/expn.yo | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 4b1508a47..d70dc1d51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-10-18 Peter Stephenson + + * c.f. users/17330: Doc/Zsh/expn.yo: fix reference to splitting + rule in parameter expansion rules. + 2012-10-11 Peter Stephenson * 30726: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c, @@ -269,5 +274,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5745 $ +* $Revision: 1.5746 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 8ee72bbdb..18d0447f3 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1329,7 +1329,7 @@ used to evaluate the length of the expression so far. ) item(tt(10.) em(Forced joining))( If the `tt((j))' flag is present, or no `tt((j))' flag is present but -the string is to be split as given by rules tt(16.) or tt(17.), and joining +the string is to be split as given by rules tt(11.), and joining did not take place at step tt(5.), any words in the value are joined together using the given string or the first character of tt($IFS) if none. Note that the `tt((F))' flag implicitly supplies a string for joining in this -- cgit v1.2.3 From 02225925efc7152b52045049e33ceb76b12819dc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 18 Oct 2012 16:18:57 +0000 Subject: 30740: add example of process substitution using anonymous function --- ChangeLog | 5 ++++- Doc/Zsh/expn.yo | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d70dc1d51..5118cace6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2012-10-18 Peter Stephenson + * 30740: Doc/Zsh/expn.yo: add example of process substitution + with anonymous function. + * c.f. users/17330: Doc/Zsh/expn.yo: fix reference to splitting rule in parameter expansion rules. @@ -274,5 +277,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5746 $ +* $Revision: 1.5747 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 18d0447f3..9d6b5c3b5 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -483,6 +483,24 @@ example(LPAR()mycmd =(myoutput)RPAR() &!) as the forked subshell will wait for the command to finish then remove the temporary file. +A general workaround to ensure a process substitution endures for +an appropriate length of time is to pass it as a parameter to +an anonymous shell function (a piece of shell code that is run +immediately with function scope). For example, this code: + +example(LPAR()RPAR() { + print File $1: + cat $1 +} =+LPAR()print This be the verse+RPAR()) + +outputs something resembling the following + +example(File /tmp/zsh6nU0kS: +This be the verse) + +The temporary file created by the process substitution will be deleted +when the function exits. + texinode(Parameter Expansion)(Command Substitution)(Process Substitution)(Expansion) sect(Parameter Expansion) cindex(parameter expansion) -- cgit v1.2.3 From f91707eda1e4dde21f5451c4e8e83612b889ed38 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 19 Oct 2012 09:19:05 +0000 Subject: unposted: further parameter splitting clarifications --- ChangeLog | 6 +++++- Doc/Zsh/expn.yo | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 5118cace6..79e6c0102 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-10-19 Peter Stephenson + + * unposted: Doc/Zsh/expn.yo: further splitting clarifications. + 2012-10-18 Peter Stephenson * 30740: Doc/Zsh/expn.yo: add example of process substitution @@ -277,5 +281,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5747 $ +* $Revision: 1.5748 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 9d6b5c3b5..da68b4ff7 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1347,7 +1347,7 @@ used to evaluate the length of the expression so far. ) item(tt(10.) em(Forced joining))( If the `tt((j))' flag is present, or no `tt((j))' flag is present but -the string is to be split as given by rules tt(11.), and joining +the string is to be split as given by rule tt(11.), and joining did not take place at step tt(5.), any words in the value are joined together using the given string or the first character of tt($IFS) if none. Note that the `tt((F))' flag implicitly supplies a string for joining in this @@ -1387,7 +1387,9 @@ item(tt(17.) em(Lexical word splitting))( If the 'tt((z))' flag or one of the forms of the 'tt((Z))' flag is present, the word is split as if it were a shell command line, so that quotation marks and other metacharacters are used to decide what -constitutes a word. +constitutes a word. Note this form of splitting is entirely distinct +from that described by rule tt(11.): it does not use tt($IFS), and +does not cause forced joining. ) item(tt(18.) em(Uniqueness))( If the result is an array and the `tt((u))' flag was present, duplicate -- cgit v1.2.3 From 7f767568a6490b0a34d35d8db7bb0fcd3da797b6 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 8 Nov 2012 12:24:48 +0000 Subject: 30780: document that set -o failures are hard but setopt failures are soft --- ChangeLog | 7 ++++++- Doc/Zsh/builtins.yo | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index 7fbcf51ee..2742f59cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-11-08 Peter Stephenson + + * 30780: Doc/Zsh/builds.yo: document that set -o failures are + hard but setopt failures are soft. + 2012-11-07 Oliver Kiddle * Benjamin R. Haskell: 30737: Completion/Unix/Command/_git: @@ -302,5 +307,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5753 $ +* $Revision: 1.5754 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 37319c9b0..f3a7f6a97 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1361,6 +1361,11 @@ or without the tt(no) prefix remains the same in this case. If the tt(-m) flag is given the arguments are taken as patterns (which should be quoted to protect them from filename expansion), and all options with names matching these patterns are set. + +Note that a bad option name does not cause execution of subsequent shell +code to be aborted; this is behaviour is different from that of `tt(set +-o)'. This is because tt(set) is regarded as a special builtin by the +POSIX standard, but tt(setopt) is not. ) findex(shift) cindex(parameters, positional) -- cgit v1.2.3 From 7c56d771840a9f335b2e21290c8cbf714264bc66 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 15 Nov 2012 21:08:15 +0000 Subject: 30789: Add CONTINUE_ON_ERROR for old behaviour. New behaviour is for scripts to exit on error instead of returning to top level and executing the next command. --- ChangeLog | 8 +++++++- Doc/Zsh/grammar.yo | 53 +++++++++++++++++++++++++++++++++++++++++++++++++-- Doc/Zsh/options.yo | 16 ++++++++++++++++ Src/hist.c | 2 +- Src/init.c | 9 +++++++-- Src/options.c | 1 + Src/zsh.h | 1 + Test/A04redirect.ztst | 12 ++++++------ 8 files changed, 90 insertions(+), 12 deletions(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index d65cfa957..36bac2884 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2012-11-15 Peter Stephenson + * 30789: Doc/Zsh/grammar.yo, Doc/Zsh/options.yo, Src/hist.c, + Src/init.c, Src/options.c, Src/zsh.h, Test/A04redirect.zsh: add + CONTINUE_ON_ERROR option for compatibility but turn it off: + scripts exit on an error instead of returning to the top-level + like interactive shells. + * 30800: Michal Halenka: Completion/Unix/Command/_arping: fix option. @@ -335,5 +341,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5760 $ +* $Revision: 1.5761 $ ***************************************************** diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 1eb358ea3..e1b2f0ea6 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -438,7 +438,7 @@ where var(term) is at least one newline or tt(;). A short form of tt(select). ) enditem() -texinode(Reserved Words)(Comments)(Alternate Forms For Complex Commands)(Shell Grammar) +texinode(Reserved Words)(Errors)(Alternate Forms For Complex Commands)(Shell Grammar) sect(Reserved Words) cindex(reserved words) findex(disable, use of) @@ -451,7 +451,56 @@ select coproc nocorrect foreach end ! [[ { }) Additionally, `tt(})' is recognized in any position if neither the tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. -texinode(Comments)(Aliasing)(Reserved Words)(Shell Grammar) +texinode(Errors)(Comments)(Reserved Words)(Shell Grammar) +sect(Errors) +cindex(errors, handling of) +Certain errors are treated as fatal by the shell: in an interactive +shell, they cause control to return to the command line, and in a +non-interactive shell they cause the shell to be aborted. In older +versions of zsh, a non-interactive shell running a script would not +abort completely, but would resume execution at the next command to be +read from the script, skipping the remainder of any functions or +shell constructs such as loops or conditions; this somewhat illogical +behaviour can be recovered by setting the option tt(CONTINUE_ON_ERROR). + +Fatal errors found in non-interactive shells include: +startlist() +list(Failure to parse shell options passed when invoking the shell) +list(Failure to change options with the tt(set) builtin) +list(Parse errors of all sorts, including failures to parse +mathematical expressions) +list(Failures to set or modify variable behaviour with tt(typeset), +tt(local), tt(declare), tt(export), tt(integer), tt(float)) +list(Execution of incorrectly positioned loop control structures +(tt(continue), tt(break))) +list(Attempts to use regular expression with no regular expression +module available) +list(Disallowed operations when the tt(RESTRICTED) options is set) +list(Failure to create a pipe needed for a pipeline) +list(Failure to create a multio) +list(Failure to autoload a module needed for a declared shell feature) +list(Errors creating command or process substitutions) +list(Syntax errors in glob qualifiers) +list(File generation errors where not caught by the option tt(BAD_PATTERN)) +list(All bad patterns used for matching within case statements) +list(File generation failures where not caused by tt(NO_MATCH) or +list(All file generation errors where the pattern was used to create a +multio) +list(Memory errors where detected by the shell) +list(Invalid subscripts to shell variables) +list(Attempts to assign read-only variables) +list(Logical errors with variables such as assignment to the wrong type) +list(Use of invalid variable names) +list(Errors in variable substitution syntax) +list(Failure to convert characters in tt($')...tt(') expressions) +similar options) +endlist() + +If the tt(POSIX_BUILTINS) option is set, more errors associated with +shell builtin commands are treated as fatal, as specified by the POSIX +standard. + +texinode(Comments)(Aliasing)(Errors)(Shell Grammar) sect(Comments) cindex(comments) pindex(INTERACTIVE_COMMENTS, use of) diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 3114ecc05..6c8d423cb 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1733,6 +1733,22 @@ Make the tt(echo) builtin compatible with the BSD manref(echo)(1) command. This disables backslashed escape sequences in echo strings unless the tt(-e) option is specified. ) +pindex(CONTINUE_ON_ERROR) +pindex(NO_CONTINUE_ON_ERROR) +pindex(CONTINUEONERROR) +pindex(NOCONTINUEONERROR) +cindex(error, option to continue script on) +item(tt(CONTINUE_ON_ERROR))( +If a fatal error is encountered (see +ifnzman(noderef(Errors))\ +ifzman(the section ERRORS in zmanref(zshmisc))), and the code is running +in a script, the shell will resume execution at the next statement +in the script at the top level, in other words outside all functions +or shell constructs such as loops and conditions. This mimics the +behaviour of interactive shells, where the shell returns to the +line editor to read a new command; it was the normal behaviour in versions +of zsh before 5.0.1. +) pindex(CSH_JUNKIE_HISTORY) pindex(NO_CSH_JUNKIE_HISTORY) pindex(CSHJUNKIEHISTORY) diff --git a/Src/hist.c b/Src/hist.c index 0e63dca37..561e2acd5 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -573,7 +573,7 @@ histsubchar(int c) } else { herrflush(); unqueue_signals(); - zerr("Ambiguous history reference"); + zerr("ambiguous history reference"); return -1; } diff --git a/Src/init.c b/Src/init.c index 6c2ba13e4..8467a739c 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1608,15 +1608,20 @@ zsh_main(UNUSED(int argc), char **argv) * We only do this at top level, because if we are * executing stuff we may refer to them by job pointer. */ + int errexit = 0; maybeshrinkjobtab(); do { /* Reset return from top level which gets us back here */ retflag = 0; loop(1,0); + if (errflag && !interact && !isset(CONTINUEONERROR)) { + errexit = 1; + break; + } } while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN))); - if (tok == LEXERR) { - /* Make sure a parse error exits with non-zero status */ + if (tok == LEXERR || errexit) { + /* Make sure a fatal error exits with non-zero status */ if (!lastval) lastval = 1; stopmsg = 1; diff --git a/Src/options.c b/Src/options.c index 80fef3d00..b36bd9944 100644 --- a/Src/options.c +++ b/Src/options.c @@ -113,6 +113,7 @@ static struct optname optns[] = { {{NULL, "combiningchars", 0}, COMBININGCHARS}, {{NULL, "completealiases", 0}, COMPLETEALIASES}, {{NULL, "completeinword", 0}, COMPLETEINWORD}, +{{NULL, "continueonerror", 0}, CONTINUEONERROR}, {{NULL, "correct", 0}, CORRECT}, {{NULL, "correctall", 0}, CORRECTALL}, {{NULL, "cshjunkiehistory", OPT_EMULATE|OPT_CSH}, CSHJUNKIEHISTORY}, diff --git a/Src/zsh.h b/Src/zsh.h index e51572bcf..207ef1836 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1971,6 +1971,7 @@ enum { COMPLETEINWORD, CORRECT, CORRECTALL, + CONTINUEONERROR, CPRECEDENCES, CSHJUNKIEHISTORY, CSHJUNKIELOOPS, diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst index d3c0a4a99..b8086e724 100644 --- a/Test/A04redirect.ztst +++ b/Test/A04redirect.ztst @@ -419,26 +419,26 @@ >output ?zsh:.:2: no such file or directory: /nonexistent/nonexistent - $ZTST_testdir/../Src/zsh -f <<<' + $ZTST_testdir/../Src/zsh -f -o CONTINUE_ON_ERROR <<<' readonly foo foo=bar set output echo output' -0:failed assignment on posix special, NO_POSIX_BUILTINS +0:failed assignment on posix special, CONTINUE_ON_ERROR >output ?zsh: read-only variable: foo - $ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS <<<' + $ZTST_testdir/../Src/zsh -f <<<' readonly foo foo=bar set output echo output' -1:failed assignment on posix special, POSIX_BUILTINS +1:failed assignment on posix special, NO_CONTINUE_ON_ERROR ?zsh: read-only variable: foo - $ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS <<<' + $ZTST_testdir/../Src/zsh -f -o CONTINUE_ON_ERROR <<<' readonly foo foo=bar echo output echo output' -0:failed assignment on non-posix-special, POSIX_BUILTINS +0:failed assignment on non-posix-special, CONTINUE_ON_ERROR >output ?zsh: read-only variable: foo -- cgit v1.2.3 From 27a41679b61ed558f55b013e906d2a3b7e4adebb Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 18 Nov 2012 18:45:39 +0000 Subject: 30803: Vin Shelton: missing menu entry in grammar.yo --- ChangeLog | 6 +++++- Doc/Zsh/grammar.yo | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh') diff --git a/ChangeLog b/ChangeLog index f9198cb98..95218c308 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-11-16 Vin Shelton + + * Doc/Zsh/grammar.yo: users/16865: Added missing menu item for Errors. + 2012-11-18 Bart Schaefer * users/17042: Src/jobs.c: don't stomp the environment in "jobs -Z" @@ -353,5 +357,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5763 $ +* $Revision: 1.5764 $ ***************************************************** diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index e1b2f0ea6..b452e4cc9 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -8,6 +8,7 @@ menu(Precommand Modifiers) menu(Complex Commands) menu(Alternate Forms For Complex Commands) menu(Reserved Words) +menu(Errors) menu(Comments) menu(Aliasing) menu(Quoting) -- cgit v1.2.3