Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=from:to:subject:date:message-id:in-reply-to:references;
        bh=d98ndQIpUz+6Hi8HHjuoctydt6a7+b1InMckBmdh7sg=;
        b=W3a232V2OBmzt8fIu2JX+c3OPIodRSQm2tEAJJwWNGSmOQTcrLAmMANHC6AVH6ohgs
         1lv5tvRFJSyqjl7z0JdBDETSgZKXfv80y+40EkesgEdiUCDi6MOk+Abies7i+30PbEWt
         UcG8N/RcyMtcZN+RBxSpNLaHr5exnqnTzSa26g/FiOgp/0E9YW0hiNXENRnIIgQFMBDo
         p3ap4PXcgobUxsJpaDeSemToOVVZTpr85Y4dRweEQcdOjb4oWvM48w8A61lliux2E6bl
         +/kUyr4KRvodj9ulQrAZE2hErDQhM4WXoX70AIqTEyWXP3H5pefBHc+eV8vLbPuMEWbc
         S/Ow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references;
        bh=d98ndQIpUz+6Hi8HHjuoctydt6a7+b1InMckBmdh7sg=;
        b=fCnV6ODTa++cDdxvVJLWhDuzcGKPQrAn/L4YG14Bmv7F9al2II0dAT6NlKg7F2ks1M
         NRp+isjdbGQLLQ64eJAFTWT/xH87V6kGx8zy0Wonm7/KTa1zFpGBQ6Y3002LwC5hsZTa
         VxELBx0ObwlJAx3Lr90RINyloq7fiO9MQOzwZPlRhT7THzPQvKk6wm9GhfPRmBi0NWU0
         FVbemS+RrPcrPYu1zuN+a3rYxZOxp07TbITfZOWcy+5Fa8xKKPSVdxDl1i122pDrbGyF
         n0KQirnHRlQquAyCW2dvHBoL+3EDpzwVG3GoEPnn8vxAi5uCkSaRna/D9G8FGNF38OXs
         PEzQ==
X-Gm-Message-State: AD7BkJJWu3I1gMEOr1+qZlUeVsQWmY2bE/BvW/d/7DXJ+h1fiN4mNnAqH0unGQ/J+OiVqw==
X-Received: by 10.28.213.66 with SMTP id m63mr18631202wmg.2.1460376381435;
        Mon, 11 Apr 2016 05:06:21 -0700 (PDT)
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Allow / in full pattern alternations
Date: Mon, 11 Apr 2016 14:06:14 +0200
Message-Id: <1460376374-9081-1-git-send-email-mikachu@gmail.com>
X-Mailer: git-send-email 2.6.1
In-Reply-To: <CAHYJk3SEeghkbpLCE26bG_76nM5PYp9MF68AO1ue00DHTwRV6A@mail.gmail.com>
References: <CAHYJk3SEeghkbpLCE26bG_76nM5PYp9MF68AO1ue00DHTwRV6A@mail.gmail.com>
X-Seq: zsh-workers 38275

Well, it was a bit easier than I thought.

% print -l (${(~j:|:)${:-$^fpath/rep*}})
/home/mikaelh/.zsh/functions/repoint
/home/mikaelh/.zsh/functions/repointmany
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-argument
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-string
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-string-again

This patch is obviously pretty ugly, and just intended as a proof of
concept / pile of crap, and it will leak stuff / do weird things if
there was an error in a sub-globpattern.

It is also obviously not intended for inclusion, I just wanted to see
what the code might look like and what would be needed. But if someone
is struck by some inspiration about how to implement this in a way that
is less horrible, feel free to say how :).

---
 Src/glob.c | 47 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 11 deletions(-)

diff --git a/Src/glob.c b/Src/glob.c
index 7848598..610396d 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1829,17 +1829,27 @@ zglob(LinkList list, LinkNode np, int nountok)
 	    quals = newquals;
     }
     q = parsepat(str);
+    int specialhack = 0;
     if (!q || errflag) {	/* if parsing failed */
-	restore_globstate(saved);
-	if (unset(BADPATTERN)) {
-	    if (!nountok)
-		untokenize(ostr);
-	    insertlinknode(list, node, ostr);
+	char *par = str;
+	if (*str == zpc_special[ZPC_INPAR] &&
+	    !skipparens(Inpar, Outpar, (char **)&par) &&
+	    !*par && zpc_special[ZPC_BAR] && strchr(str, zpc_special[ZPC_BAR]))
+	{
+	    specialhack = 1;
+	    errflag &= ~ERRFLAG_ERROR;
+	} else {
+	    restore_globstate(saved);
+	    if (unset(BADPATTERN)) {
+		if (!nountok)
+		    untokenize(ostr);
+		insertlinknode(list, node, ostr);
+		return;
+	    }
+	    errflag &= ~ERRFLAG_ERROR;
+	    zerr("bad pattern: %s", ostr);
 	    return;
 	}
-	errflag &= ~ERRFLAG_ERROR;
-	zerr("bad pattern: %s", ostr);
-	return;
     }
     if (!gf_nsorts) {
 	gf_sortlist[0].tp = gf_sorts = (shortcircuit ? GS_NONE : GS_NAME);
@@ -1852,9 +1862,24 @@ zglob(LinkList list, LinkNode np, int nountok)
     matchct = 0;
     pattrystart();
 
-    /* The actual processing takes place here: matches go into  *
-     * matchbuf.  This is the only top-level call to scanner(). */
-    scanner(q, shortcircuit);
+    if (!specialhack) {
+	/* The actual processing takes place here: matches go into  *
+	 * matchbuf.  This is the only top-level call to scanner(). */
+	scanner(q, shortcircuit);
+    } else {
+	str++;
+	while (*str) {
+	    char *next = strchr(str, zpc_special[ZPC_BAR]);
+	    if (!next) next = strchr(str, Outpar);
+	    if (!next) break;
+	    *next = '\0';
+	    q = parsepat(str);
+	    // XXX handle errors magically
+	    scanner(q, shortcircuit);
+	    str = next+1;
+	}
+    }
+
 
     /* Deal with failures to match depending on options */
     if (matchct)
-- 
2.6.1

