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

PATCH: tricky.c and completion functions



There was a bug with matching control (it didn't compare the strings
for the anchors on the line and in the word).

I discovered this when playing with _colors and when implementing the
function for xsetroot (and the _cursors utility function).

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Wed Aug 11 15:50:27 1999
+++ Src/Zle/zle_tricky.c	Fri Aug 13 13:46:43 1999
@@ -2294,7 +2294,7 @@
 	for (mp = NULL, ms = mstack; !mp && ms; ms = ms->next) {
 	    for (mp = ms->matcher; mp; mp = mp->next) {
 		t = 1;
-		if (lm == mp ||
+		if ((lm && lm == mp) ||
 		    ((oll == ll || olw == lw) && test && mp->wlen < 0))
 		    /* If we were called recursively, don't use `*' patterns
 		     * at the beginning (avoiding infinite recursion). */
@@ -2335,8 +2335,9 @@
 			continue;
 		    if (ap) {
 			if (!pattern_match(ap, l + aoff, NULL, NULL) ||
-			    (both && !pattern_match(ap, w + aoff, NULL, NULL)))
-			    continue;
+			    (both && (!pattern_match(ap, w + aoff, NULL, NULL) ||
+				      !match_parts(l + aoff, w + aoff, alen))))
+				continue;
 		    } else if (!both || il || iw)
 			continue;
 
@@ -2346,11 +2347,12 @@
 			savl = l[-(llen + zoff)];
 			l[-(llen + zoff)] = '\0';
 		    }
-		    for (t = 0, tp = w, ct = 0, ict = lw - alen;
+		    for (t = 0, tp = w, ct = 0, ict = lw - alen + 1;
 			 ict;
 			 tp += add, ct++, ict--) {
 			if (both ||
-			    pattern_match(ap, tp - moff, NULL, NULL)) {
+			    (pattern_match(ap, tp - moff, NULL, NULL) &&
+			     match_parts(l + aoff , tp - moff, alen))) {
 			    if (sfx) {
 				savw = tp[-zoff];
 				tp[-zoff] = '\0';
@@ -2598,6 +2600,24 @@
     return iw;
 }
 
+/* Wrapper for match_str(), only for a certain length and only doing
+ * the test. */
+
+/**/
+static int
+match_parts(char *l, char *w, int n)
+{
+    char lsav = l[n], wsav = w[n];
+    int ret;
+
+    l[n] = w[n] = '\0';
+    ret = match_str(l, w, NULL, NULL, 0, 1);
+    l[n] = lsav;
+    w[n] = wsav;
+
+    return ret;
+}
+
 /* Check if the word w is matched by the strings in pfx and sfx (the prefix
  * and the suffix from the line) or the pattern cp. In clp a cline list for
  * w is returned.
@@ -2928,7 +2948,7 @@
 	return 1;
     }
     /* Didn't work, try to build a string matching both anchors. */
-    if (join && !(o->flags & CLF_JOIN) &&
+    if (join && !(o->flags & CLF_JOIN) && o->word && n->word &&
 	(j = join_strs(o->wlen, o->word, n->wlen, n->word))) {
 	o->flags |= CLF_JOIN;
 	o->wlen = strlen(j);
@@ -3397,6 +3417,10 @@
 			 (o->flags  & (CLF_SUF | CLF_MID));
 		     t = tn);
 		if (tn && cmp_anchors(o, tn, 1)) {
+		    Cline t;
+
+		    t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
+		    t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
 		    n = tn;
 		    continue;
 		}
@@ -3429,20 +3453,18 @@
 	    }
 	    /* Now see if they have matching anchors. If not, cut the list. */
 	    if (!(o->flags & CLF_MID) && !cmp_anchors(o, n, 1)) {
-#if 0
-		/* This used to search forward for matching anchors.
-		 * Unfortunately this does the wrong thing if the prefixes
-		 * before the differing anchors match nicely. */
-
 		Cline t, tn;
 
 		for (t = n; (tn = t->next) && !cmp_anchors(o, tn, 1); t = tn);
 
 		if (tn) {
+		    Cline t;
+
+		    t = tn->prefix; tn->prefix = n->prefix; n->prefix = t;
+		    t = tn->suffix; tn->suffix = n->suffix; n->suffix = t;
 		    n = tn;
 		    continue;
 		} else {
-#endif
 		    if (o->flags & CLF_SUF)
 			break;
 
@@ -3451,9 +3473,7 @@
 		    free_cline(o->next);
 		    o->next = NULL;
 		    o->flags |= CLF_MISS;
-#if 0
 		}
-#endif
 	    }
 	    /* Ok, they are equal, now join the sub-lists. */
 	    if (o->flags & CLF_MID)
diff -u -r oc/User/_colors Completion/User/_colors
--- oc/User/_colors	Fri Aug 13 09:20:59 1999
+++ Completion/User/_colors	Fri Aug 13 13:53:39 1999
@@ -5,16 +5,10 @@
 
   # Cache of color names doesn't exist yet, create it.
 
-  for f in /usr/{,local/,X11R6/,openwin/}lib/X11/rgb.txt
-  do
-    if [[ -f $f ]]; then
-      file=$f
-      break;
-    fi
-  done
+  file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt )
 
-  if [[ -n "$file" ]]; then
-    _color_cache=( "${(@)${(@f)$(< $file)}[2,-1]##*		}" )
+  if (( $#file )); then
+    _color_cache=( "${(@)${(@f)$(< $file[1])}[2,-1]##*		}" )
   else
 
     # Stupid default value.
@@ -23,4 +17,4 @@
   fi
 fi
 
-compadd - "$_color_cache[@]"
+compadd -M 'm:{a-z}={A-Z} m:-=\  r:|[ A-Z0-9]=* r:|=*' - "$_color_cache[@]"
diff -u -r oc/User/_cursors Completion/User/_cursors
--- oc/User/_cursors	Fri Aug 13 11:34:59 1999
+++ Completion/User/_cursors	Fri Aug 13 11:37:05 1999
@@ -0,0 +1,15 @@
+#autoload
+
+if (( ! $+_cursor_cache )); then
+  local file
+
+  file=( /usr/{include,{{X11R6,openwin},local{,/X11{,R6}}}/include}/X11/cursorfont.h(N) )
+
+  if (( $#file )); then
+    _cursor_cache=( "${(@)${(@)${(M@)${(@f)$(< $file[1])}:#*XC_*}[2,-1]#* XC_}% *}" )
+  else
+    _cursor_cache=( X_cursor )
+  fi
+fi
+
+compadd -M 'm:-=_ r:|_=*' - "$_cursor_cache[@]"
diff -u -r oc/User/_x_options Completion/User/_x_options
--- oc/User/_x_options	Fri Aug 13 09:21:02 1999
+++ Completion/User/_x_options	Fri Aug 13 10:56:32 1999
@@ -4,7 +4,7 @@
 
 if [ "$words[CURRENT-1]" = "-display" ]; then
   _compskip=all
-  _hosts -S :0
+  _hosts -S ':0 ' -r :
 else
-  compadd -P- -J options - display name xrm
+  compadd -J options - -display -name -xrm
 fi
diff -u -r oc/User/_xsetroot Completion/User/_xsetroot
--- oc/User/_xsetroot	Fri Aug 13 11:28:36 1999
+++ Completion/User/_xsetroot	Fri Aug 13 11:35:36 1999
@@ -0,0 +1,15 @@
+#compdef xsetroot
+
+case "$words[CURRENT-1]" in
+-cursor) _files -/g '*.(#i)(xbm|curs(|or))'; return;;
+-cursor_name) _cursors; return;;
+-bitmap) _files -/g '*.(#i)xbm'; return;;
+-([fb]g|solid)) _colors; return;;
+esac
+
+if [[ CURRENT -gt 2 && "$words[CURRENT-2]" = -cursor ]]; then
+  _files -/g '*.(#i)(xbm|curs(|or)|mask)'
+else
+  compadd -M 'm:-=_ r:|_=*' - -help -def -cursor -cursor_name -bitmap -mod -gray -grey \
+                       -fg -bg -rv -solid -name
+fi

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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