about summary refs log tree commit diff
path: root/Src/pattern.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2013-06-13 18:40:36 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2013-06-13 18:40:36 +0100
commit347a63da0cf1c681ac97c21a107b4722abf449b2 (patch)
treeeb91735a2bb171a5f092c374e5a84f3e1ad7008f /Src/pattern.c
parentfdf2867e5f08809ff3fccc78fb6df13a196e3efc (diff)
downloadzsh-347a63da0cf1c681ac97c21a107b4722abf449b2.tar.gz
zsh-347a63da0cf1c681ac97c21a107b4722abf449b2.tar.xz
zsh-347a63da0cf1c681ac97c21a107b4722abf449b2.zip
31465: fix basic completion and globbing uses of disabled patterns
Diffstat (limited to 'Src/pattern.c')
-rw-r--r--Src/pattern.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/Src/pattern.c b/Src/pattern.c
index a90d3cddc..b7897e75c 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -3966,3 +3966,78 @@ clearpatterndisables(void)
 {
     memset(zpc_disables, 0, ZPC_COUNT);
 }
+
+
+/* Check to see if str is eligible for filename generation. */
+
+/**/
+mod_export int
+haswilds(char *str)
+{
+    char *start;
+
+    /* `[' and `]' are legal even if bad patterns are usually not. */
+    if ((*str == Inbrack || *str == Outbrack) && !str[1])
+	return 0;
+
+    /* If % is immediately followed by ?, then that ? is     *
+     * not treated as a wildcard.  This is so you don't have *
+     * to escape job references such as %?foo.               */
+    if (str[0] == '%' && str[1] == Quest)
+	str[1] = '?';
+
+    /*
+     * Note that at this point zpc_special has not been set up.
+     */
+    start = str;
+    for (; *str; str++) {
+	switch (*str) {
+	    case Inpar:
+		if ((!isset(SHGLOB) && !zpc_disables[ZPC_INPAR]) ||
+		    (str > start && isset(KSHGLOB) &&
+		     ((str[-1] == Quest && !zpc_disables[ZPC_KSH_QUEST]) ||
+		      (str[-1] == Star && !zpc_disables[ZPC_KSH_STAR]) ||
+		      (str[-1] == '+' && !zpc_disables[ZPC_KSH_PLUS]) ||
+		      (str[-1] == '!' && !zpc_disables[ZPC_KSH_BANG]) ||
+		      (str[-1] == '@' && !zpc_disables[ZPC_KSH_AT]))))
+		    return 1;
+		break;
+
+	    case Bar:
+		if (!zpc_disables[ZPC_BAR])
+		    return 1;
+		break;
+
+	    case Star:
+		if (!zpc_disables[ZPC_STAR])
+		    return 1;
+		break;
+
+	    case Inbrack:
+		if (!zpc_disables[ZPC_INBRACK])
+		    return 1;
+		break;
+
+	    case Inang:
+		if (!zpc_disables[ZPC_INANG])
+		    return 1;
+		break;
+
+	    case Quest:
+		if (!zpc_disables[ZPC_QUEST])
+		    return 1;
+		break;
+
+	    case Pound:
+		if (isset(EXTENDEDGLOB) && !zpc_disables[ZPC_HASH])
+		    return 1;
+		break;
+
+	    case Hat:
+		if (isset(EXTENDEDGLOB) && !zpc_disables[ZPC_HAT])
+		    return 1;
+		break;
+	}
+    }
+    return 0;
+}