1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-02 13:26:03 +02:00

Revert "41499 (with one further tweak): POSIX_STRINGS behaviour."

This reverts commit 2eacbef919.

Conflicts:
	ChangeLog
This commit is contained in:
Peter Stephenson 2017-08-08 19:04:49 +01:00
parent 2fba415a71
commit a9b579a9d3
4 changed files with 16 additions and 80 deletions

View File

@ -1,3 +1,8 @@
2017-08-08 Peter Stephenson <p.w.stephenson@ntlworld.com>
* unposted: back off 41499 as it has side effects which, while
perfectly logical, are not what POSIX expects.
2017-08-08 Peter Stephenson <p.stephenson@samsung.com> 2017-08-08 Peter Stephenson <p.stephenson@samsung.com>
* 41510: Doc/Zsh/params.yo: update doc for $ZSH_PATCHLEVEL. * 41510: Doc/Zsh/params.yo: update doc for $ZSH_PATCHLEVEL.

View File

@ -2193,16 +2193,16 @@ cindex(discarding embedded nulls in $'...')
cindex(embedded nulls, in $'...') cindex(embedded nulls, in $'...')
cindex(nulls, embedded in $'...') cindex(nulls, embedded in $'...')
item(tt(POSIX_STRINGS) <K> <S>)( item(tt(POSIX_STRINGS) <K> <S>)(
This option affects processing of quoted strings, and also This option affects processing of quoted strings. Currently it only
splitting of strngs. affects the behaviour of null characters, i.e. character 0 in the
portable character set corresponding to US ASCII.
When this option is not set, null characters (character 0 in the When this option is not set, null characters embedded within strings
portable character set coresponding to US ASCII) that are embedded of the form tt($')var(...)tt(') are treated as ordinary characters. The
within strings of the form tt($')var(...)tt(') are treated as ordinary entire string is maintained within the shell and output to files where
characters. The entire string is maintained within the shell and output necessary, although owing to restrictions of the library interface
to files where necessary, although owing to restrictions of the library the string is truncated at the null character in file names, environment
interface the string is truncated at the null character in file names, variables, or in arguments to external programs.
environment variables, or in arguments to external programs.
When this option is set, the tt($')var(...)tt(') expression is truncated at When this option is set, the tt($')var(...)tt(') expression is truncated at
the null character. Note that remaining parts of the same string the null character. Note that remaining parts of the same string
@ -2211,18 +2211,6 @@ beyond the termination of the quotes are not truncated.
For example, the command line argument tt(a$'b\0c'd) is treated with For example, the command line argument tt(a$'b\0c'd) is treated with
the option off as the characters tt(a), tt(b), null, tt(c), tt(d), the option off as the characters tt(a), tt(b), null, tt(c), tt(d),
and with the option on as the characters tt(a), tt(b), tt(d). and with the option on as the characters tt(a), tt(b), tt(d).
Furthermore, when the option is set, a trailing separator followed by an
empty strings does not cause extra fields to be produced when the string
is split. For example,
example(var="foo bar "
print -l "${=var}")
outputs a blank line at the end if tt(POSIXSTRINGS) is not set, but
no blank line if the option is set. Note that empty elements would in
any case be removed if quotation marks were not used. If the separator
is not white space, only the final separator is ignored in this fashion.
) )
pindex(POSIX_TRAPS) pindex(POSIX_TRAPS)
pindex(NO_POSIX_TRAPS) pindex(NO_POSIX_TRAPS)

View File

@ -3500,12 +3500,12 @@ skipwsep(char **s)
mod_export char ** mod_export char **
spacesplit(char *s, int allownull, int heap, int quote) spacesplit(char *s, int allownull, int heap, int quote)
{ {
char *t, **ret, **ptr, **eptr; char *t, **ret, **ptr;
int l = sizeof(*ret) * (wordcount(s, NULL, -!allownull) + 1); int l = sizeof(*ret) * (wordcount(s, NULL, -!allownull) + 1);
char *(*dup)(const char *) = (heap ? dupstring : ztrdup); char *(*dup)(const char *) = (heap ? dupstring : ztrdup);
/* ### TODO: s/calloc/alloc/ */ /* ### TODO: s/calloc/alloc/ */
eptr = ptr = ret = (char **) (heap ? hcalloc(l) : zshcalloc(l)); ptr = ret = (char **) (heap ? hcalloc(l) : zshcalloc(l));
if (quote) { if (quote) {
/* /*
@ -3537,7 +3537,6 @@ spacesplit(char *s, int allownull, int heap, int quote)
if (s > t || allownull) { if (s > t || allownull) {
*ptr = (char *) (heap ? zhalloc((s - t) + 1) : *ptr = (char *) (heap ? zhalloc((s - t) + 1) :
zalloc((s - t) + 1)); zalloc((s - t) + 1));
eptr = ptr;
ztrncpy(*ptr++, t, s - t); ztrncpy(*ptr++, t, s - t);
} else } else
*ptr++ = dup(nulstring); *ptr++ = dup(nulstring);
@ -3546,21 +3545,6 @@ spacesplit(char *s, int allownull, int heap, int quote)
} }
if (!allownull && t != s) if (!allownull && t != s)
*ptr++ = dup(""); *ptr++ = dup("");
if (isset(POSIXSTRINGS) && ptr > eptr + 1) {
/*
* Trailing separators do not generate extra fields in POSIX.
* Note this is only the final separator --- if the
* immediately preceding field was null it is still counted.
* So just back up one.
*/
--ptr;
if (!heap) {
char **ret2 = realloc(ret, sizeof(*ret) * (ptr+1-ret));
ptr -= ret-ret2;
free(ret);
ret = ret2;
}
}
*ptr = NULL; *ptr = NULL;
return ret; return ret;
} }

View File

@ -1339,44 +1339,3 @@
?(anon):4: `break' active at end of function scope ?(anon):4: `break' active at end of function scope
?(anon):4: `break' active at end of function scope ?(anon):4: `break' active at end of function scope
?(anon):4: `break' active at end of function scope ?(anon):4: `break' active at end of function scope
for opt in POSIX_STRINGS NO_POSIX_STRINGS; do
var="foo bar "
(setopt $opt; print -l X "${=var}" Y)
var="foo2::bar2:"
(setopt $opt; IFS=:; print -l X "${=var}" Y)
var="foo3:bar3::"
(setopt $opt; IFS=:; print -l X "${=var}" Y)
done
0:POSIX_STRINGS effect on final delimiters
>X
>foo
>bar
>Y
>X
>foo2
>
>bar2
>Y
>X
>foo3
>bar3
>
>Y
>X
>foo
>bar
>
>Y
>X
>foo2
>
>bar2
>
>Y
>X
>foo3
>bar3
>
>
>Y