about summary refs log tree commit diff
path: root/Src/Zle/compctl.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-10-12 09:32:45 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-10-12 09:32:45 +0000
commit0f076fcde8a342c081b8eab0a2f135335d552d79 (patch)
tree13bf91d328057d7b41df879e7ad80128f70baeab /Src/Zle/compctl.c
parent0749034911b1e28d4d9abba5472201972a5e37ce (diff)
downloadzsh-0f076fcde8a342c081b8eab0a2f135335d552d79.tar.gz
zsh-0f076fcde8a342c081b8eab0a2f135335d552d79.tar.xz
zsh-0f076fcde8a342c081b8eab0a2f135335d552d79.zip
manual/8219
Diffstat (limited to 'Src/Zle/compctl.c')
-rw-r--r--Src/Zle/compctl.c91
1 files changed, 58 insertions, 33 deletions
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index 0f42372f0..ce80bbee5 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -1919,50 +1919,75 @@ bin_compadd(char *name, char **argv, char *ops, int func)
 #define CVT_SUFNUM   4
 #define CVT_SUFPAT   5
 
-static void
+/**/
+void
 ignore_prefix(int l)
 {
-    char *tmp, sav = compprefix[l];
-
-    compprefix[l] = '\0';
-    tmp = tricat(compiprefix, compprefix, "");
-    zsfree(compiprefix);
-    compiprefix = tmp;
-    compprefix[l] = sav;
-    tmp = ztrdup(compprefix + l);
-    zsfree(compprefix);
-    compprefix = tmp;
+    if (l) {
+	char *tmp, sav;
+	int pl = strlen(compprefix);
+
+	if (l > pl)
+	    l = pl;
+
+	sav = compprefix[l];
+
+	compprefix[l] = '\0';
+	tmp = tricat(compiprefix, compprefix, "");
+	zsfree(compiprefix);
+	compiprefix = tmp;
+	compprefix[l] = sav;
+	tmp = ztrdup(compprefix + l);
+	zsfree(compprefix);
+	compprefix = tmp;
+    }
 }
 
-static void
+/**/
+void
 ignore_suffix(int l)
 {
-    char *tmp, sav;
-
-    l = strlen(compsuffix) - l;
-    tmp = tricat(compsuffix + l, compisuffix, "");
-    zsfree(compisuffix);
-    compisuffix = tmp;
-    sav = compsuffix[l];
-    compsuffix[l] = '\0';
-    tmp = ztrdup(compsuffix);
-    compsuffix[l] = sav;
-    zsfree(compsuffix);
-    compsuffix = tmp;
+    if (l) {
+	char *tmp, sav;
+	int sl = strlen(compsuffix);
+
+	if ((l = sl - l) < 0)
+	    l = 0;
+
+	tmp = tricat(compsuffix + l, compisuffix, "");
+	zsfree(compisuffix);
+	compisuffix = tmp;
+	sav = compsuffix[l];
+	compsuffix[l] = '\0';
+	tmp = ztrdup(compsuffix);
+	compsuffix[l] = sav;
+	zsfree(compsuffix);
+	compsuffix = tmp;
+    }
 }
 
 /**/
-static void
+void
 restrict_range(int b, int e)
 {
-    int i = e - b + 1;
-    char **p = (char **) zcalloc((i + 1) * sizeof(char *)), **q, **pp;
-
-    for (q = p, pp = compwords + b; i; i--, q++, pp++)
-	*q = ztrdup(*pp);
-    freearray(compwords);
-    compwords = p;
-    compcurrent -= b;
+    int wl = arrlen(compwords) - 1;
+
+    if (wl && b >= 0 && e >= 0 && (b > 0 || e < wl)) {
+	int i;
+	char **p, **q, **pp;
+
+	if (e > wl)
+	    e = wl;
+
+	i = e - b + 1;
+	p = (char **) zcalloc((i + 1) * sizeof(char *));
+
+	for (q = p, pp = compwords + b; i; i--, q++, pp++)
+	    *q = ztrdup(*pp);
+	freearray(compwords);
+	compwords = p;
+	compcurrent -= b;
+    }
 }
 
 static int