about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2024-01-24 17:32:45 -0800
committerBart Schaefer <schaefer@zsh.org>2024-01-24 17:32:45 -0800
commitc72b4a74ef3e5031a72cab13d7d6365e8d7ef0fc (patch)
tree11f76c400568fd7805a900a841762fce492e1cfe /Src
parent3406089647393c7593e37ee0661a179a9d848c49 (diff)
downloadzsh-c72b4a74ef3e5031a72cab13d7d6365e8d7ef0fc.tar.gz
zsh-c72b4a74ef3e5031a72cab13d7d6365e8d7ef0fc.tar.xz
zsh-c72b4a74ef3e5031a72cab13d7d6365e8d7ef0fc.zip
52473: zstyle -q for testing existence of a zstyle setting
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/zutil.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 8b863d5c8..293a62dcf 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -462,6 +462,28 @@ lookupstyle(char *ctxt, char *style)
 }
 
 static int
+testforstyle(char *ctxt, char *style)
+{
+    Style s;
+    Stypat p;
+    int found = 0;
+
+    s = (Style)zstyletab->getnode2(zstyletab, style);
+    if (s) {
+	MatchData match;
+	savematch(&match);
+	for (p = s->pats; p; p = p->next)
+	    if (pattry(p->prog, ctxt)) {
+		found = 1;
+		break;
+	    }
+	restorematch(&match);
+    }
+
+    return !found;	/* 0 == success */
+}
+
+static int
 bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 {
     int min, max, n, add = 0, list = ZSLIST_NONE, eval = 0;
@@ -570,6 +592,7 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
     case 't': min = 2; max = -1; break;
     case 'T': min = 2; max = -1; break;
     case 'm': min = 3; max =  3; break;
+    case 'q': min = 2; max =  2; break;
     case 'g': min = 1; max =  3; break;
     default:
 	zwarnnam(nam, "invalid option: %s", args[0]);
@@ -723,6 +746,15 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 	    return 1;
 	}
 	break;
+    case 'q':
+	{
+	    int success;
+	    queue_signals();	/* Protect PAT_STATIC */
+	    success = testforstyle(args[1], args[2]);
+	    unqueue_signals();
+	    return success;
+	}
+	break;
     case 'g':
 	{
 	    int ret = 1;