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

PATCH Re: Another uncommitted patch



On May 8,  6:42pm, Peter Stephenson wrote:
} Subject: Re: Another uncommitted patch
}
} On Fri, 06 May 2011 08:22:28 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > Should I commit users/15442 ("SH_WORD_SPLIT, $* and null IFS")?
} > 
} > I remember seeing something from someone about the "YUK" comment,
} > but whatever it was is not linked as a followup in the archive.

(That's because the discussion moved to zsh-workers.)

} I think the fix is probably reasonable, however I believe I suggested
} just sticking with basing it on SH_WORD_SPLIT to reduce the number of
} different behaviours; having three is probably more confusing than
} just changing the behaviour which isn't obviously correct anyway.

Revised patch below.  This made the patch a bit more convoluted as it
now needs to deal with the case of ${(@)==var} where shwordsplit is
explicitly turned off but array preservation is turned on.
 
} I suspect the YUK chunk went with Wayne's fix to multsub.

Indeed, I finally tracked that down.  Although that chunk is no longer
quite so yucky, I marked it in the patch for reference.  If someone else
wants to clean up all the cross-referential comments, please do.

I also fixed some indentation that I got wrong 10 years ago.


Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.119
diff -u -r1.119 subst.c
--- Src/subst.c	21 Mar 2011 11:09:51 -0000	1.119
+++ Src/subst.c	18 May 2011 01:32:47 -0000
@@ -1611,7 +1611,7 @@
      * This is one of the things that decides whether multsub
      * will produce an array, but in an extremely indirect fashion.
      */
-    int nojoin = 0;
+    int nojoin = isset(SHWORDSPLIT) ? !(ifs && *ifs) : 0;
     /*
      * != 0 means ${...}, otherwise $...  What works without braces
      * is largely a historical artefact (everything works with braces,
@@ -1717,7 +1717,7 @@
 		    ++arrasg;
 		    break;
 		case '@':
-		    nojoin = 1;
+		    nojoin = 2;	/* nojoin = 2 means force */
 		    break;
 		case 'M':
 		    flags |= SUB_MATCH;
@@ -2033,9 +2033,14 @@
 	    /* SH_WORD_SPLIT on or off (doubled). spbreak = 2 means force */
 	    if ((c = *++s) == '=' || c == Equals) {
 		spbreak = 0;
+		if (nojoin < 2)
+		    nojoin = 0;
 		s++;
-	    } else
+	    } else {
 		spbreak = 2;
+		if (nojoin < 2)
+		    nojoin = !(ifs && *ifs);
+	    }
 	} else if ((c == '#' || c == Pound) &&
 		   (itype_end(s+1, IIDENT, 0) != s + 1
 		    || (cc = s[1]) == '*' || cc == Star || cc == '@'
@@ -2653,14 +2658,14 @@
 		*idend = sav;
 		copied = 1;
 		if (isarr) {
-		  if (nojoin)
-		    isarr = -1;
-		  if (qt && !getlen && isarr > 0 && !spsep && spbreak < 2) {
-		    val = sepjoin(aval, sep, 1);
-		    isarr = 0;
-		  }
-		  sep = spsep = NULL;
-		  spbreak = 0;
+		    if (nojoin)
+			isarr = -1;
+		    if (qt && !getlen && isarr > 0 && !spsep && spbreak < 2) {
+			val = sepjoin(aval, sep, 1);
+			isarr = 0;
+		    }
+		    sep = spsep = NULL;
+		    spbreak = 0;
 		}
 	    }
 	    break;
@@ -3018,7 +3023,7 @@
     /* At this point we make sure that our arrayness has affected the
      * arrayness of the linked list.  Then, we can turn our value into
      * a scalar for convenience sake without affecting the arrayness
-     * of the resulting value. */
+     * of the resulting value.  ## This is the YUK chunk. ## */
     if (isarr)
 	l->list.flags |= LF_ARRAY;
     else
@@ -3040,7 +3045,7 @@
      * done any requested splitting of the word value with quoting preserved.
      * "ssub" is true when we are called from singsub (via prefork):
      * it means that we must join arrays and should not split words. */
-    if (ssub || spbreak || spsep || sep) {
+    if (ssub || (spbreak && isarr >= 0) || spsep || sep) {
 	if (isarr) {
 	    val = sepjoin(aval, sep, 1);
 	    isarr = 0;



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