From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10458 invoked by alias); 11 Mar 2010 22:05:19 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27785 Received: (qmail 26191 invoked from network); 11 Mar 2010 22:05:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.48 as permitted sender) From: Peter Stephenson To: zsh-workers@zsh.org (Zsh hackers list) Subject: PATCH: Standard IFS X-Mailer: MH-E 8.2; nmh 1.3; GNU Emacs 23.1.1 Date: Thu, 11 Mar 2010 22:04:51 +0000 Message-ID: <5092.1268345091@pws-pc> X-Cloudmark-Analysis: v=1.1 cv=W3tOLUehizD4qj6VhtReFuw5MKb8d+XqjIxlDsIazEA= c=1 sm=0 a=DogomfpGjd0A:10 a=NLZqzBF-AAAA:8 a=5eNmfCWiVUoO4XCcJbAA:9 a=-b1DjHxpBYFwtzQF3lgA:7 a=R8VGrgE50IoNQdTthZpG2EiYV68A:4 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/