* PATCH: tricky.c and completion functions
@ 1999-08-13 12:16 Sven Wischnowsky
1999-08-13 15:14 ` Tanaka Akira
0 siblings, 1 reply; 6+ messages in thread
From: Sven Wischnowsky @ 1999-08-13 12:16 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: tricky.c and completion functions
1999-08-13 12:16 PATCH: tricky.c and completion functions Sven Wischnowsky
@ 1999-08-13 15:14 ` Tanaka Akira
1999-08-13 15:55 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Tanaka Akira @ 1999-08-13 15:14 UTC (permalink / raw)
To: zsh-workers
In article <199908131216.OAA11188@beta.informatik.hu-berlin.de>,
Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> 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
> + file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt )
Hm.
Index: Completion/User/_colors
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_colors,v
retrieving revision 1.1.1.3
diff -u -F^( -r1.1.1.3 _colors
--- _colors 1999/08/13 12:34:21 1.1.1.3
+++ _colors 1999/08/13 15:08:23
@@ -5,7 +5,7 @@
# Cache of color names doesn't exist yet, create it.
- file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt )
+ file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt(N) )
if (( $#file )); then
_color_cache=( "${(@)${(@f)$(< $file[1])}[2,-1]##* }" )
--
Tanaka Akira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: tricky.c and completion functions
1999-08-13 15:14 ` Tanaka Akira
@ 1999-08-13 15:55 ` Bart Schaefer
1999-08-13 16:07 ` Tanaka Akira
0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 1999-08-13 15:55 UTC (permalink / raw)
To: Tanaka Akira, zsh-workers
On Aug 14, 12:14am, Tanaka Akira wrote:
} Subject: Re: PATCH: tricky.c and completion functions
}
} Hm.
}
} - file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt )
} + file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt(N) )
That (N) shouldn't be necessary -- brace expansion does not test for the
exsistence of any files, it just pastes together the strings in all the
possible combinations. Did it actually fail for you somehow?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: tricky.c and completion functions
1999-08-13 15:55 ` Bart Schaefer
@ 1999-08-13 16:07 ` Tanaka Akira
0 siblings, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 1999-08-13 16:07 UTC (permalink / raw)
To: zsh-workers
In article <990813155515.ZM5338@candle.brasslantern.com>,
"Bart Schaefer" <schaefer@candle.brasslantern.com> writes:
> That (N) shouldn't be necessary -- brace expansion does not test for the
> exsistence of any files, it just pastes together the strings in all the
> possible combinations. Did it actually fail for you somehow?
It is required for removing non-existing files from the result of
the brace expansion.
For example, under SunOS 5.7:
Z(2):akr@is27e1u11% print -l /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt
/usr/lib/X11/rgb.txt
/usr/X11R6/lib/X11/rgb.txt
/usr/openwin/lib/X11/rgb.txt
/usr/local/lib/X11/rgb.txt
/usr/local/X11/lib/X11/rgb.txt
/usr/local/X11R6/lib/X11/rgb.txt
Z(2):akr@is27e1u11% print -l /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt(N)
/usr/openwin/lib/X11/rgb.txt
Z(2):akr@is27e1u11%
So, $(<$files[1]) causes an error if (N) is not used.
Also, I suppose that (N) was intended by Sven because
Completion/User/_cursors use same method for cursorfont.h.
--
Tanaka Akira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: tricky.c and completion functions
@ 1999-08-17 8:10 Sven Wischnowsky
0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-08-17 8:10 UTC (permalink / raw)
To: zsh-workers
Tanaka Akira wrote:
> Also, I suppose that (N) was intended by Sven because
> Completion/User/_cursors use same method for cursorfont.h.
That's right. Sorry! Thanks.
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: tricky.c and completion functions
@ 1999-08-17 8:20 Sven Wischnowsky
0 siblings, 0 replies; 6+ messages in thread
From: Sven Wischnowsky @ 1999-08-17 8:20 UTC (permalink / raw)
To: zsh-workers
I wrote:
> There was a bug with matching control (it didn't compare the strings
> for the anchors on the line and in the word).
Here is a fix for another bug: if you have `-M "r:|[-.]=*"' and the
matches `a-b.c' and `a.c' doing `a.<TAB>' removed the dot because it
didn't look ahead for matching anchors in both strings (only in one).
Bye
Sven
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Fri Aug 13 14:16:37 1999
+++ Src/Zle/zle_tricky.c Tue Aug 17 10:15:46 1999
@@ -2147,7 +2147,7 @@
wl = m->llen; w = l;
}
if (wl) {
- /* Probably resie the buffer. */
+ /* Probably resize the buffer. */
if (matchbuflen - matchbufadded <= wl) {
int blen = matchbuflen + wl + 20;
char *buf;
@@ -3458,21 +3458,35 @@
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;
+ o->flags |= CLF_MISS;
continue;
} else {
- if (o->flags & CLF_SUF)
- break;
+ for (t = o; (tn = t->next) && !cmp_anchors(n, tn, 1);
+ t = tn);
- o->word = o->line = o->orig = NULL;
- o->wlen = 0;
- free_cline(o->next);
- o->next = NULL;
- o->flags |= CLF_MISS;
+ if (tn) {
+ t = tn->prefix; tn->prefix = o->prefix; o->prefix = t;
+ t = tn->suffix; tn->suffix = o->suffix; o->suffix = t;
+ if (po)
+ po->next = tn;
+ else
+ oo = tn;
+ o = tn;
+ o->flags |= CLF_MISS;
+ continue;
+ } else {
+ if (o->flags & CLF_SUF)
+ break;
+
+ o->word = o->line = o->orig = NULL;
+ o->wlen = 0;
+ free_cline(o->next);
+ o->next = NULL;
+ o->flags |= CLF_MISS;
+ }
}
}
/* Ok, they are equal, now join the sub-lists. */
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1999-08-17 8:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-13 12:16 PATCH: tricky.c and completion functions Sven Wischnowsky
1999-08-13 15:14 ` Tanaka Akira
1999-08-13 15:55 ` Bart Schaefer
1999-08-13 16:07 ` Tanaka Akira
1999-08-17 8:10 Sven Wischnowsky
1999-08-17 8:20 Sven Wischnowsky
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).