zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Standard IFS
@ 2010-03-11 22:04 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2010-03-11 22:04 UTC (permalink / raw)
  To: Zsh hackers list

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/


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-03-11 22:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-11 22:04 PATCH: Standard IFS Peter Stephenson

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).