Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Standard IFS



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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author