From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3/2) with ESMTP id AAA10409 for ; Fri, 19 Jul 1996 00:41:57 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id KAA03657; Thu, 18 Jul 1996 10:24:01 -0400 (EDT) Resent-Date: Thu, 18 Jul 1996 10:24:01 -0400 (EDT) From: Zefram Message-Id: <11879.199607181423@granite.dcs.warwick.ac.uk> Subject: more dependencies on emulation To: zsh-workers@math.gatech.edu (Z Shell workers mailing list) Date: Thu, 18 Jul 1996 15:23:02 +0100 (BST) X-Patch: 118 X-Loop: zefram@dcs.warwick.ac.uk X-Stardate: [-31]7827.99 X-US-Congress: Moronic fuckers MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"Z-IfR2.0.3v.0aaxn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1695 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- Continuing on from my FUNCTION_ARGZERO patch in article 1669, this patch removes some direct dependencies on emulation from subst.c. After this, the only use of emulation is in the emulate builtin itself, and in initialisation (where it's difficult to avoid). There are two distinct uses of emulation addressed here. One affects the position of filename expansion in the order of expansion; I add a new option, SH_FILE_SUBST, to control this. This option is affected by changing emulation mode, so the current behaviour will be unchanged except where the new option is explicitly used. The second use of emulation is to control whether the $foo[2] subscript placement will work; sh and ksh don't recognise it as a subscript. The patch makes this be controlled by the KSH_ARRAYS option, as it should have been all along. The KSH_ARRAYS option is also changed to be set by default when emulating sh, which was previously not essential. Both of the above optional behaviours are also documented by this patch. Previously they were totally undocumented. My comments in article 1669 about the option patch in article 1275 apply here also. Applying this patch by hand if you don't have the option patch applied is not difficult. If anyone wants an updated copy of the option patch, mail me. -zefram Index: Doc/zshexpn.man =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshexpn.man,v retrieving revision 1.9 diff -c -r1.9 zshexpn.man *** zshexpn.man 1996/07/16 14:26:42 1.9 --- zshexpn.man 1996/07/18 11:36:36 *************** *** 25,30 **** --- 25,40 ---- .BR ' , and \fB"\fP are removed and the result is subjected to \fIfilename expansion\fP followed by \fIfilename generation\fP. + .PP + If the + .B SH_FILE_SUBST + option is set, the order of expansion is modified + for compatibility with sh and ksh. + .I Filename expansion + is performed immediately after + .IR "alias substitution" , + preceding the set of five substitutions mentioned above. + is .SH FILENAME EXPANSION Each word is checked to see if it begins with an unquoted .BR ~ . Index: Doc/zshoptions.man =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshoptions.man,v retrieving revision 1.11 diff -c -r1.11 zshoptions.man *** zshoptions.man 1996/07/16 16:35:47 1.11 --- zshoptions.man 1996/07/18 11:32:19 *************** *** 292,299 **** .TP \fBKSH_ARRAYS\fP Emulate \fIksh\fP array handling as closely as possible. If this option ! is set, array elements are numbered from zero and an array parameter ! without subscript refers to the first element instead of the whole array. .TP \fBKSH_OPTION_PRINT\fP Alters the way options settings are printed. --- 292,301 ---- .TP \fBKSH_ARRAYS\fP Emulate \fIksh\fP array handling as closely as possible. If this option ! is set, array elements are numbered from zero, an array parameter ! without subscript refers to the first element instead of the whole array, ! and braces are required to delimit a subscript (``${path[2]}'' rather ! than just ``$path[2]''). .TP \fBKSH_OPTION_PRINT\fP Alters the way options settings are printed. *************** *** 448,453 **** --- 450,464 ---- .TP \fBRM_STAR_SILENT\fP (\-\fBH\fP) Do not query the user before executing "rm *" or "rm path/*". + .TP + \fBSH_FILE_SUBST\fP + Perform filename expansion (e.g., ~ expansion) + .I before + parateter expansion, command substitution, arithmetic expansion + and brace expansion. + If this option is unset, it is performed + .I after + brace expansion, so things like ``~$USERNAME'' ``~{pfalstad,rc}'' will work. .TP \fBSH_GLOB\fP Disables the special meaning of `(', `|', `)' and '<' for globbing the Index: Doc/zshparam.man =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Doc/zshparam.man,v retrieving revision 1.8 diff -c -r1.8 zshparam.man *** zshparam.man 1996/07/16 14:26:43 1.8 --- zshparam.man 1996/07/18 11:36:18 *************** *** 33,43 **** --- 33,45 ---- expansion as if it were surrounded by "$((...))". The elements are numbered beginning with 1 unless the \fBKSH_ARRAYS\fP option is set when they are numbered from zero. + .PP A subscript of the form \fB[*]\fP or \fB[@]\fP evaluates to all elements of an array; there is no difference between the two except when they appear within double quotes. "$foo[*]" evaluates to "$foo[1] $foo[2] ...", while "$foo[@]" evaluates to "$foo[1]" "$foo[2]", etc. + .PP A subscript of the form \fB[\fIexp1\fP,\fIexp2\fB]\fR selects all elements in the range \fIexp1\fP to \fIexp2\fP, inclusive. *************** *** 51,56 **** --- 53,67 ---- case the subscripts specify a substring to be extracted. For example, if \fBFOO\fP is set to \fBfoobar\fP, then \fBecho $FOO[2,5]\fP prints \fBooba\fP. + .PP + Subscripts may be used inside braces used to delimit a parameter name, thus + .B ${foo[2]} + is equivalent to + .BR $foo[2] . + If the + .B KSH_ARRAYS + option is set, the braced form is the only one that will + work, the subscript otherwise not being treated specially. .PP If a subscript is used on the left side of an assignment the selected range is replaced by the expression on the right side. Index: Src/globals.h =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/globals.h,v retrieving revision 1.11 diff -c -r1.11 globals.h *** globals.h 1996/07/16 16:35:55 1.11 --- globals.h 1996/07/18 11:43:38 *************** *** 717,723 **** {"ignoreeof", '7', 0, 0}, {"interactive", 'i', 'i', OPT_SPECIAL}, {"interactivecomments", 'k', 0, OPT_EMULATE|OPT_BOURNE}, ! {"ksharrays", 0, 0, OPT_EMULATE|OPT_KSH}, {"kshoptionprint", 0, 0, OPT_EMULATE|OPT_KSH}, {"listambiguous", 0, 0, 0}, {"listbeep", 0, 0, OPT_ALL}, --- 717,723 ---- {"ignoreeof", '7', 0, 0}, {"interactive", 'i', 'i', OPT_SPECIAL}, {"interactivecomments", 'k', 0, OPT_EMULATE|OPT_BOURNE}, ! {"ksharrays", 0, 0, OPT_EMULATE|OPT_BOURNE}, {"kshoptionprint", 0, 0, OPT_EMULATE|OPT_KSH}, {"listambiguous", 0, 0, 0}, {"listbeep", 0, 0, OPT_ALL}, *************** *** 750,755 **** --- 750,756 ---- {"rcs", x'f', 0, OPT_ALL}, {"recexact", 'S', 0, 0}, {"rmstarsilent", 'H', 0, OPT_BOURNE}, + {"shfilesubst", 0, 0, OPT_EMULATE|OPT_BOURNE}, {"shglob", 0, 0, OPT_EMULATE|OPT_BOURNE}, {"shinstdin", 's', 's', OPT_SPECIAL}, {"shortloops", 0, 0, OPT_ALL}, Index: Src/subst.c =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/subst.c,v retrieving revision 1.10 diff -c -r1.10 subst.c *** subst.c 1996/07/16 14:26:58 1.10 --- subst.c 1996/07/18 11:30:07 *************** *** 66,74 **** setdata(node, (void *) getoutputfile(str)); /* =(...) */ if (!getdata(node)) return; ! } ! else { ! if (emulation == EMULATE_SH || emulation == EMULATE_KSH) filesub((char **)getaddrdata(node), flags & 3); if (!(node = stringsubst(list, node, flags & 4))) return; --- 66,73 ---- setdata(node, (void *) getoutputfile(str)); /* =(...) */ if (!getdata(node)) return; ! } else { ! if (isset(SHFILESUBST)) filesub((char **)getaddrdata(node), flags & 3); if (!(node = stringsubst(list, node, flags & 4))) return; *************** *** 80,86 **** if (unset(IGNOREBRACES) && !(flags & 4)) while (hasbraces(getdata(node))) xpandbraces(list, &node); ! if (emulation != EMULATE_SH && emulation != EMULATE_KSH) filesub((char **)getaddrdata(node), flags & 3); } else if (!(flags & 4)) uremnode(list, node); --- 79,85 ---- if (unset(IGNOREBRACES) && !(flags & 4)) while (hasbraces(getdata(node))) xpandbraces(list, &node); ! if (unset(SHFILESUBST)) filesub((char **)getaddrdata(node), flags & 3); } else if (!(flags & 4)) uremnode(list, node); *************** *** 970,978 **** copied = 1; *s = sav; v = (Value) NULL; ! } else if (!(v = getvalue(&s, (emulation != EMULATE_KSH && ! emulation != EMULATE_SH) || ! inbrace ? 1 : -1))) { vunset = 1; } else if ((isarr = v->isarr)) { aval = getarrvalue(v); --- 969,975 ---- copied = 1; *s = sav; v = (Value) NULL; ! } else if (!(v = getvalue(&s, (unset(KSHARRAYS) || inbrace) ? 1 : -1))) { vunset = 1; } else if ((isarr = v->isarr)) { aval = getarrvalue(v); *************** *** 1209,1216 **** } if (colf) { s--; ! if (((emulation != EMULATE_KSH && ! emulation != EMULATE_SH) || inbrace)) { if (!isarr) modify(&val, &s); else { --- 1206,1212 ---- } if (colf) { s--; ! if (unset(KSHARRAYS) || inbrace) { if (!isarr) modify(&val, &s); else { Index: Src/zsh.h =================================================================== RCS file: /home/zefram/usr/cvsroot/zsh/Src/zsh.h,v retrieving revision 1.14 diff -c -r1.14 zsh.h *** zsh.h 1996/07/16 16:35:56 1.14 --- zsh.h 1996/07/18 10:57:22 *************** *** 1132,1137 **** --- 1132,1138 ---- RCS, RECEXACT, RMSTARSILENT, + SHFILESUBST, SHGLOB, SHINSTDIN, SHORTLOOPS, -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBMe4oBXD/+HJTpU/hAQFajAP/SZugoTHBNnfyAnuG+7od5QVY7qUSfvy4 Ojv5UL0d0oTNePQzPgvu0m1JuJWO5QnJJBWnurwN70utjueWNEzxRAhVnOPO9Wb/ 9jt6yy528wtGOZ17+ausyZvhoyvmkORNT/z+iuTOFhKwvEONTyrQspRwpO6xA1kd 91Bl91xrLes= =Y2Nd -----END PGP SIGNATURE-----