From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: PATCH: Standard IFS
Date: Thu, 11 Mar 2010 22:04:51 +0000 [thread overview]
Message-ID: <5092.1268345091@pws-pc> (raw)
I keep meaning to post this.
POSIX requires that IFS be set to a particular value if it's not in the
environment (which we ignore anyway, that's explicitly allowed). We
should use this value in sh and ksh emulation.
You'd be surprised how long it took me to realise why 'echo $IFS | xxd'
didn't do what I expected in sh mode. (You need double quotes because
of word splitting.)
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.111
diff -p -u -r1.111 init.c
--- Src/init.c 9 Feb 2010 13:58:33 -0000 1.111
+++ Src/init.c 11 Mar 2010 22:02:46 -0000
@@ -815,7 +815,8 @@ setupvals(void)
? ztrdup("+ ") : ztrdup("+%N:%i> ");
sprompt = ztrdup("zsh: correct '%R' to '%r' [nyae]? ");
- ifs = ztrdup(DEFAULT_IFS);
+ ifs = EMULATION(EMULATE_KSH|EMULATE_SH) ?
+ ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS);
wordchars = ztrdup(DEFAULT_WORDCHARS);
postedit = ztrdup("");
zunderscore = (char *) zalloc(underscorelen = 32);
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.240
diff -p -u -r1.240 utils.c
--- Src/utils.c 24 Feb 2010 21:38:10 -0000 1.240
+++ Src/utils.c 11 Mar 2010 22:02:48 -0000
@@ -3271,7 +3271,8 @@ inittyptab(void)
typtab[t0] |= ITOK | IMETA;
for (t0 = (int)STOUC(Snull); t0 <= (int)STOUC(Nularg); t0++)
typtab[t0] |= ITOK | IMETA | INULL;
- for (s = ifs ? ifs : DEFAULT_IFS; *s; s++) {
+ for (s = ifs ? ifs : EMULATION(EMULATE_KSH|EMULATE_SH) ?
+ ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS); *s; s++) {
int c = STOUC(*s == Meta ? *++s ^ 32 : *s);
#ifdef MULTIBYTE_SUPPORT
if (!isascii(c)) {
@@ -3305,7 +3306,8 @@ inittyptab(void)
}
#ifdef MULTIBYTE_SUPPORT
set_widearray(wordchars, &wordchars_wide);
- set_widearray(ifs ? ifs : DEFAULT_IFS, &ifs_wide);
+ set_widearray(ifs ? ifs : EMULATION(EMULATE_KSH|EMULATE_SH) ?
+ ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS), &ifs_wide);
#endif
for (s = SPECCHARS; *s; s++)
typtab[STOUC(*s)] |= ISPECIAL;
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.163
diff -p -u -r1.163 zsh.h
--- Src/zsh.h 24 Feb 2010 21:38:10 -0000 1.163
+++ Src/zsh.h 11 Mar 2010 22:02:48 -0000
@@ -127,6 +127,10 @@ struct mathfunc {
#define DEFAULT_IFS " \t\n\203 "
+/* As specified in the standard (POSIX 2008) */
+
+#define DEFAULT_IFS_SH " \t\n"
+
/*
* Character tokens.
* These should match the characters in ztokens, defined in lex.c
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
reply other threads:[~2010-03-11 22:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5092.1268345091@pws-pc \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).