Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: problem with compctl -M
- X-seq: zsh-workers 4975
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: problem with compctl -M
- Date: Mon, 25 Jan 1999 10:57:42 +0100 (MET)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Matcher definitions with `*'s where to eager to let the other matchers
take over again, sometimes rejecting possible matches (e.g. with
`l:|=* r:|=*' the string `tu' didn't match `ftp.tu-berlin.de' since
the `t' in `ftp' where matched by the `t' in `tu' and then the
matching code gave up).
This patch may make things a bit slower (shouldn't be noticeable) but
it also makes the code smaller and cleaner (that's what makes the
patch look big).
Again this should work with 3.1.5-pws versions before pws-5.
Bye
Sven
diff -c os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
*** os/Zle/zle_tricky.c Mon Jan 25 10:23:16 1999
--- Src/Zle/zle_tricky.c Mon Jan 25 10:26:51 1999
***************
*** 1859,1865 ****
/* Do the matching for a prefix. */
static char *
! match_pfx(char *l, char *w, Cline *nlp, int *lp, Cline *rlp, int *bplp)
{
static unsigned char *ea;
static int ealen = 0;
--- 1859,1866 ----
/* Do the matching for a prefix. */
static char *
! match_pfx(char *l, char *w, Cline *nlp, int *lp, Cline *rlp, int *bplp,
! Cmatcher nm)
{
static unsigned char *ea;
static int ealen = 0;
***************
*** 1867,1927 ****
static int rwlen;
int ll = strlen(l), lw = strlen(w), mlw;
! int il = 0, iw = 0, t, stil, stiw, std, bc = brpl;
! char *nw = rw, *stl = NULL, *stw;
Cmlist ms;
! Cmatcher mp, stm;
Cline lr = NULL;
! *nlp = NULL;
! if (ll > ealen) {
! /* This is the `in'/`out' string for pattern matching. */
! if (ealen)
! zfree(ea, ealen);
! ea = (unsigned char *) zalloc(ealen = ll + 20);
}
while (ll && lw) {
- if (*l == *w) {
- /* Same character, take it. */
-
- if (stl) {
- /* But first check, if we were collecting characters *
- * for a `*'. */
- int sl = iw - stiw;
-
- nw = addtoword(&rw, &rwlen, nw, stm, stl, stw, sl, 0);
-
- addtocline(nlp, &lr, stl, stm->llen,
- stw, sl, stm, (std ? CLF_SUF : 0));
-
- stl = NULL;
-
- if (bc <= 0 && bplp) {
- *bplp = nw - rw;
- bplp = NULL;
- }
- }
- nw = addtoword(&rw, &rwlen, nw, NULL, NULL, l, 1, 0);
-
- addtocline(nlp, &lr, l, 1, NULL, 0, NULL, 0);
-
- l++;
- w++;
- il++;
- iw++;
- ll--;
- lw--;
- bc--;
-
- if (bc <= 0 && bplp) {
- *bplp = nw - rw;
- bplp = NULL;
- }
- continue;
- }
for (ms = mstack; ms; ms = ms->next) {
for (mp = ms->matcher; mp; mp = mp->next) {
t = 1;
/* Try to match the prefix, if any. */
if (mp->flags & CMF_LEFT) {
--- 1868,1894 ----
static int rwlen;
int ll = strlen(l), lw = strlen(w), mlw;
! int il = 0, iw = 0, t, bc = brpl;
! char *nw = rw;
Cmlist ms;
! Cmatcher mp;
Cline lr = NULL;
! if (nlp) {
! *nlp = NULL;
! if (ll > ealen) {
! /* This is the `in'/`out' string for pattern matching. */
! if (ealen)
! zfree(ea, ealen);
! ea = (unsigned char *) zalloc(ealen = ll + 20);
! }
}
while (ll && lw) {
for (ms = mstack; ms; ms = ms->next) {
for (mp = ms->matcher; mp; mp = mp->next) {
+ if (nm == mp)
+ continue;
t = 1;
/* Try to match the prefix, if any. */
if (mp->flags & CMF_LEFT) {
***************
*** 1947,1968 ****
else
t = 0;
}
! if (t && !stl) {
! /* We simply keep the current position *
! * and start collecting characters until *
! * another matcher matches. */
! std = (mp->flags & CMF_LEFT);
! stl = l;
! stil = il;
! stw = w;
! stiw = iw;
! stm = mp;
! t = 0;
! l += mp->llen;
! il += mp->llen;
! ll -= mp->llen;
!
! break;
}
else
t = 0;
--- 1914,1954 ----
else
t = 0;
}
! if (t) {
! int i = 0, j = iw, k = lw;
! int jj = il + mp->llen, kk = ll - mp->llen;
! char *p = l + mp->llen, *q = w;
!
! for (; k; i++, j++, k--, q++) {
! if (match_pfx(p, q, NULL, NULL,
! NULL, NULL, mp))
! break;
! }
! if (k) {
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, mp,
! l, w, i, 0);
! addtocline(nlp, &lr, l, mp->llen,
! w, i, mp,
! ((mp->flags & CMF_LEFT) ?
! CLF_SUF : 0));
! }
! w = q;
! iw = j;
! lw = k;
! l = p;
! il = jj;
! ll = kk;
! bc -= i;
!
! if (bc <= 0 && bplp) {
! *bplp = nw - rw;
! bplp = NULL;
! }
! break;
! }
! else
! t = 0;
}
else
t = 0;
***************
*** 1988,2013 ****
if (t) {
/* If it matched, build a new chunk on the Cline list *
* and add the string to the built match. */
! if (stl) {
! int sl = iw - stiw;
!
! nw = addtoword(&rw, &rwlen, nw, stm, stl, stw, sl, 0);
!
! addtocline(nlp, &lr,
! stl, stm->llen, stw, sl, stm,
! (std ? CLF_SUF : 0));
!
! stl = NULL;
!
! if (bc <= 0 && bplp) {
! *bplp = nw - rw;
! bplp = NULL;
! }
}
- nw = addtoword(&rw, &rwlen, nw, mp, l, w, mlw, 0);
-
- addtocline(nlp, &lr, l, mp->llen, w, mlw, mp, 0);
-
l += mp->llen;
w += mlw;
ll -= mp->llen;
--- 1974,1983 ----
if (t) {
/* If it matched, build a new chunk on the Cline list *
* and add the string to the built match. */
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, mp, l, w, mlw, 0);
! addtocline(nlp, &lr, l, mp->llen, w, mlw, mp, 0);
}
l += mp->llen;
w += mlw;
ll -= mp->llen;
***************
*** 2026,2061 ****
if (mp)
break;
}
! if (!stl && !t) {
! if (*nlp) {
lr->next = freecl;
freecl = *nlp;
}
return NULL;
}
- if (stl) {
- /* We are collecting characters, just skip over. */
- w++;
- lw--;
- iw++;
- }
}
! *lp = iw;
if (lw) {
! /* There is a unmatched portion in the word, keep it. */
! if (rlp) {
! w = dupstring(w);
! addtocline(nlp, &lr, w, lw, w, -1, NULL, CLF_MID);
!
! *rlp = lr;
! } else {
! addtocline(nlp, &lr, l, 0, dupstring(w), lw, NULL, CLF_END);
! nw = addtoword(&rw, &rwlen, nw, NULL, NULL, w, lw, 0);
}
! }
! else if (rlp) {
! if (lr) {
lr->next = freecl;
freecl = *nlp;
}
--- 1996,2046 ----
if (mp)
break;
}
! if (t)
! continue;
! if (*l == *w) {
! /* Same character, take it. */
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, NULL, NULL, l, 1, 0);
! addtocline(nlp, &lr, l, 1, NULL, 0, NULL, 0);
! }
! l++;
! w++;
! il++;
! iw++;
! ll--;
! lw--;
! bc--;
!
! if (bc <= 0 && bplp) {
! *bplp = nw - rw;
! bplp = NULL;
! }
! } else {
! if (nlp && *nlp) {
lr->next = freecl;
freecl = *nlp;
}
return NULL;
}
}
! if (lp)
! *lp = iw;
if (lw) {
! if (nlp) {
! /* There is a unmatched portion in the word, keep it. */
! if (rlp) {
! w = dupstring(w);
! addtocline(nlp, &lr, w, lw, w, -1, NULL, CLF_MID);
! *rlp = lr;
! } else {
! addtocline(nlp, &lr, l, 0, dupstring(w), lw, NULL, CLF_END);
! nw = addtoword(&rw, &rwlen, nw, NULL, NULL, w, lw, 0);
! }
}
! } else if (rlp) {
! if (nlp && lr) {
lr->next = freecl;
freecl = *nlp;
}
***************
*** 2065,2084 ****
*nw = '\0';
if (ll) {
! if (*nlp) {
lr->next = freecl;
freecl = *nlp;
}
! return 0;
}
! /* Finally, return the built match string. */
! return dupstring(rw);
}
/* Do the matching for a suffix. */
static char *
! match_sfx(char *l, char *w, Cline *nlp, int *lp, int *bslp)
{
static unsigned char *ea;
static int ealen = 0;
--- 2050,2072 ----
*nw = '\0';
if (ll) {
! if (nlp && *nlp) {
lr->next = freecl;
freecl = *nlp;
}
! return NULL;
}
! if (nlp)
! /* Finally, return the built match string. */
! return dupstring(rw);
!
! return ((char *) 1);
}
/* Do the matching for a suffix. */
static char *
! match_sfx(char *l, char *w, Cline *nlp, int *lp, int *bslp, Cmatcher nm)
{
static unsigned char *ea;
static int ealen = 0;
***************
*** 2086,2143 ****
static int rwlen;
int ll = strlen(l), lw = strlen(w), mlw;
! int il = 0, iw = 0, t, stil, stiw, std, bc = brsl;
! char *nw = rw, *stl = NULL, *stw;
Cmlist ms;
! Cmatcher mp, stm;
Cline lr = NULL;
l += ll;
w += lw;
! *nlp = NULL;
! if (ll > ealen) {
! if (ealen)
! zfree(ea, ealen);
! ea = (unsigned char *) zalloc(ealen = ll + 20);
}
while (ll && lw) {
- if (l[-1] == w[-1]) {
- if (stl) {
- int sl = iw - stiw;
-
- stl -= stm->llen;
- stw -= sl;
- nw = addtoword(&rw, &rwlen, nw, stm, stl, stw, sl, 1);
-
- addtocline(nlp, &lr, stl, stm->llen,
- stw, sl, stm, (std ? CLF_SUF : 0));
-
- stl = NULL;
-
- if (bc <= 0 && bslp) {
- *bslp = nw - rw;
- bslp = NULL;
- }
- }
- nw = addtoword(&rw, &rwlen, nw, NULL, NULL, l - 1, 1, 1);
-
- addtocline(nlp, &lr, l - 1, 1, NULL, 0, NULL, 0);
-
- l--;
- w--;
- il++;
- iw++;
- ll--;
- lw--;
- bc--;
- if (bc <= 0 && bslp) {
- *bslp = nw - rw;
- bslp = NULL;
- }
- continue;
- }
for (ms = mstack; ms; ms = ms->next) {
for (mp = ms->matcher; mp; mp = mp->next) {
t = 1;
--- 2074,2098 ----
static int rwlen;
int ll = strlen(l), lw = strlen(w), mlw;
! int il = 0, iw = 0, t, bc = brsl;
! char *nw = rw;
Cmlist ms;
! Cmatcher mp;
Cline lr = NULL;
l += ll;
w += lw;
! if (nlp) {
! *nlp = NULL;
! if (ll > ealen) {
! if (ealen)
! zfree(ea, ealen);
! ea = (unsigned char *) zalloc(ealen = ll + 20);
! }
}
while (ll && lw) {
for (ms = mstack; ms; ms = ms->next) {
for (mp = ms->matcher; mp; mp = mp->next) {
t = 1;
***************
*** 2164,2185 ****
else
t = 0;
}
! if (t && !stl) {
! std = (mp->flags & CMF_LEFT);
! stl = l;
! stil = il;
! stw = w;
! stiw = iw;
! stm = mp;
! t = 0;
! l -= mp->llen;
! il += mp->llen;
! ll -= mp->llen;
!
! break;
}
- else
- t = 0;
}
} else {
t = pattern_match(mp->line, l - mp->llen, NULL, ea) &&
--- 2119,2160 ----
else
t = 0;
}
! if (t) {
! int i = 0, j = iw, k = lw;
! int jj = il + mp->llen, kk = ll - mp->llen;
! char *p = l - mp->llen, *q = w;
!
! for (; k; i++, j++, k--, q--)
! if (match_sfx(p, q, NULL, NULL,
! NULL, mp))
! break;
! if (k) {
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, mp,
! l - mp->llen, w - i,
! i, 1);
! addtocline(nlp, &lr, l - mp->llen,
! mp->llen, w - i, i, mp,
! ((mp->flags & CMF_LEFT) ?
! CLF_SUF : 0));
! }
! w = q;
! iw = j;
! lw = k;
! l = p;
! il = jj;
! ll = kk;
! bc -= i;
!
! if (bc <= 0 && bslp) {
! *bslp = nw - rw;
! bslp = NULL;
! }
! break;
! }
! else
! t = 0;
}
}
} else {
t = pattern_match(mp->line, l - mp->llen, NULL, ea) &&
***************
*** 2199,2228 ****
t = 0;
}
if (t) {
! if (stl) {
! int sl = iw - stiw;
!
! stl -= stm->llen;
! stw -= sl;
!
! nw = addtoword(&rw, &rwlen, nw, stm, stl, stw, sl, 1);
!
! addtocline(nlp, &lr,
! stl, stm->llen, stw, sl, stm,
! (std ? CLF_SUF : 0));
!
! stl = NULL;
!
! if (bc <= 0 && bslp) {
! *bslp = nw - rw;
! bslp = NULL;
! }
}
- nw = addtoword(&rw, &rwlen, nw, mp, l, w, mlw, 1);
-
- addtocline(nlp, &lr, l - mp->llen, mp->llen,
- w - mlw, mlw, mp, 0);
-
l -= mp->llen;
w -= mlw;
ll -= mp->llen;
--- 2174,2184 ----
t = 0;
}
if (t) {
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, mp, l, w, mlw, 1);
! addtocline(nlp, &lr, l - mp->llen, mp->llen,
! w - mlw, mlw, mp, 0);
}
l -= mp->llen;
w -= mlw;
ll -= mp->llen;
***************
*** 2240,2270 ****
if (mp)
break;
}
! if (!stl && !t) {
! if (*nlp) {
lr->next = freecl;
freecl = *nlp;
}
return NULL;
}
- if (stl) {
- w--;
- lw--;
- iw++;
- }
}
! *lp = iw;
if (nw)
*nw = '\0';
if (ll) {
! if (*nlp) {
lr->next = freecl;
freecl = *nlp;
}
! return 0;
}
! return dupstring(rw);
}
/* Check if the word `w' matches. */
--- 2196,2243 ----
if (mp)
break;
}
! if (t)
! continue;
! if (l[-1] == w[-1]) {
! if (nlp) {
! nw = addtoword(&rw, &rwlen, nw, NULL, NULL, l - 1, 1, 1);
! addtocline(nlp, &lr, l - 1, 1, NULL, 0, NULL, 0);
! }
! l--;
! w--;
! il++;
! iw++;
! ll--;
! lw--;
! bc--;
! if (bc <= 0 && bslp) {
! *bslp = nw - rw;
! bslp = NULL;
! }
! } else {
! if (nlp && *nlp) {
lr->next = freecl;
freecl = *nlp;
}
return NULL;
}
}
! if (lp)
! *lp = iw;
if (nw)
*nw = '\0';
if (ll) {
! if (nlp && *nlp) {
lr->next = freecl;
freecl = *nlp;
}
! return NULL;
}
! if (nlp)
! return dupstring(rw);
!
! return ((char *) 1);
}
/* Check if the word `w' matches. */
***************
*** 2283,2290 ****
int sl;
Cline sli, last;
! if ((p = match_pfx(pfx, w, &pli, &pl, &last, bpl))) {
! if ((s = match_sfx(sfx, w + pl, &sli, &sl, bsl))) {
int pml, sml;
last->llen -= sl;
--- 2256,2263 ----
int sl;
Cline sli, last;
! if ((p = match_pfx(pfx, w, &pli, &pl, &last, bpl, NULL))) {
! if ((s = match_sfx(sfx, w + pl, &sli, &sl, bsl, NULL))) {
int pml, sml;
last->llen -= sl;
***************
*** 2305,2311 ****
}
else
return NULL;
! } else if (!(r = match_pfx(pfx, w, &pli, &pl, NULL, bpl)))
return NULL;
if (lppre && *lppre) {
--- 2278,2284 ----
}
else
return NULL;
! } else if (!(r = match_pfx(pfx, w, &pli, &pl, NULL, bpl, NULL)))
return NULL;
if (lppre && *lppre) {
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author