1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 22:11:54 +02:00

add $redirections array to completion system parameters, containing information about all redirections on the line; make this and compstate[redirect] contain the file descriptor number (16751)

This commit is contained in:
Sven Wischnowsky 2002-03-01 10:41:59 +00:00
parent 4b98b648df
commit 10490ec499
6 changed files with 82 additions and 25 deletions

View file

@ -1,3 +1,11 @@
2002-03-01 Sven Wischnowsky <wischnow@zsh.org>
* 16751: Src/Zle/comp.h, Src/Zle/compcore.c, Src/Zle/complete.c,
Src/Zle/zle_main.c, Src/Zle/zle_tricky.c: add $redirections
array to completion system parameters, containing information
about all redirections on the line; make this and
compstate[redirect] contain the file descriptor number
2002-02-28 Bart Schaefer <schaefer@zsh.org> 2002-02-28 Bart Schaefer <schaefer@zsh.org>
* 16748: Completion/Zsh/Command/_zle: Fix infinite loop * 16748: Completion/Zsh/Command/_zle: Fix infinite loop

View file

@ -298,25 +298,27 @@ typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int,
#define CPN_WORDS 0 #define CPN_WORDS 0
#define CP_WORDS (1 << CPN_WORDS) #define CP_WORDS (1 << CPN_WORDS)
#define CPN_CURRENT 1 #define CPN_REDIRS 1
#define CP_REDIRS (1 << CPN_REDIRS)
#define CPN_CURRENT 2
#define CP_CURRENT (1 << CPN_CURRENT) #define CP_CURRENT (1 << CPN_CURRENT)
#define CPN_PREFIX 2 #define CPN_PREFIX 3
#define CP_PREFIX (1 << CPN_PREFIX) #define CP_PREFIX (1 << CPN_PREFIX)
#define CPN_SUFFIX 3 #define CPN_SUFFIX 4
#define CP_SUFFIX (1 << CPN_SUFFIX) #define CP_SUFFIX (1 << CPN_SUFFIX)
#define CPN_IPREFIX 4 #define CPN_IPREFIX 5
#define CP_IPREFIX (1 << CPN_IPREFIX) #define CP_IPREFIX (1 << CPN_IPREFIX)
#define CPN_ISUFFIX 5 #define CPN_ISUFFIX 6
#define CP_ISUFFIX (1 << CPN_ISUFFIX) #define CP_ISUFFIX (1 << CPN_ISUFFIX)
#define CPN_QIPREFIX 6 #define CPN_QIPREFIX 7
#define CP_QIPREFIX (1 << CPN_QIPREFIX) #define CP_QIPREFIX (1 << CPN_QIPREFIX)
#define CPN_QISUFFIX 7 #define CPN_QISUFFIX 8
#define CP_QISUFFIX (1 << CPN_QISUFFIX) #define CP_QISUFFIX (1 << CPN_QISUFFIX)
#define CPN_COMPSTATE 8 #define CPN_COMPSTATE 9
#define CP_COMPSTATE (1 << CPN_COMPSTATE) #define CP_COMPSTATE (1 << CPN_COMPSTATE)
#define CP_REALPARAMS 9 #define CP_REALPARAMS 10
#define CP_ALLREALS ((unsigned int) 0x1ff) #define CP_ALLREALS ((unsigned int) 0x3ff)
#define CPN_NMATCHES 0 #define CPN_NMATCHES 0

View file

@ -618,6 +618,13 @@ callcompfunc(char *s, char *fn)
} else } else
compwords = (char **) zcalloc(sizeof(char *)); compwords = (char **) zcalloc(sizeof(char *));
if (compredirs)
freearray(compredirs);
if (rdstrs)
compredirs = bld_list_array(rdstrs);
else
compredirs = (char **) zcalloc(sizeof(char *));
compparameter = ztrdup(compparameter); compparameter = ztrdup(compparameter);
compredirect = ztrdup(compredirect); compredirect = ztrdup(compredirect);
zsfree(compquote); zsfree(compquote);
@ -1459,11 +1466,11 @@ set_comp_sep(void)
return 0; return 0;
} }
/* This stores the strings from the list in an array. */ /* This builds an array from a list of strings. */
/**/ /**/
mod_export void mod_export char **
set_list_array(char *name, LinkList l) bld_list_array(LinkList l)
{ {
char **a, **p; char **a, **p;
LinkNode n; LinkNode n;
@ -1473,7 +1480,16 @@ set_list_array(char *name, LinkList l)
*p++ = ztrdup((char *) getdata(n)); *p++ = ztrdup((char *) getdata(n));
*p = NULL; *p = NULL;
setaparam(name, a); return a;
}
/* This stores the strings from the list in an array. */
/**/
mod_export void
set_list_array(char *name, LinkList l)
{
setaparam(name, bld_list_array(l));
} }
/* Get the words from a variable or a (list of words). */ /* Get the words from a variable or a (list of words). */

View file

@ -43,6 +43,7 @@ zlong complistlines,
/**/ /**/
mod_export mod_export
char **compwords, char **compwords,
**compredirs,
*compprefix, *compprefix,
*compsuffix, *compsuffix,
*compisuffix, *compisuffix,
@ -948,6 +949,7 @@ struct compparam {
static struct compparam comprparams[] = { static struct compparam comprparams[] = {
{ "words", PM_ARRAY, VAL(compwords), NULL, NULL }, { "words", PM_ARRAY, VAL(compwords), NULL, NULL },
{ "redirections", PM_ARRAY, VAL(compredirs), NULL, NULL },
{ "CURRENT", PM_INTEGER, VAL(compcurrent), NULL, NULL }, { "CURRENT", PM_INTEGER, VAL(compcurrent), NULL, NULL },
{ "PREFIX", PM_SCALAR, VAL(compprefix), NULL, NULL }, { "PREFIX", PM_SCALAR, VAL(compprefix), NULL, NULL },
{ "SUFFIX", PM_SCALAR, VAL(compsuffix), NULL, NULL }, { "SUFFIX", PM_SCALAR, VAL(compsuffix), NULL, NULL },
@ -1239,13 +1241,13 @@ comp_wrapper(Eprog prog, FuncWrap w, char *name)
if (incompfunc != 1) if (incompfunc != 1)
return 1; return 1;
else { else {
char *orest, *opre, *osuf, *oipre, *oisuf, **owords; char *orest, *opre, *osuf, *oipre, *oisuf, **owords, **oredirs;
char *oqipre, *oqisuf, *oq, *oqi, *oqs, *oaq; char *oqipre, *oqisuf, *oq, *oqi, *oqs, *oaq;
zlong ocur; zlong ocur;
unsigned int runset = 0, kunset = 0, m, sm; unsigned int runset = 0, kunset = 0, m, sm;
Param *pp; Param *pp;
m = CP_WORDS | CP_CURRENT | CP_PREFIX | CP_SUFFIX | m = CP_WORDS | CP_REDIRS | CP_CURRENT | CP_PREFIX | CP_SUFFIX |
CP_IPREFIX | CP_ISUFFIX | CP_QIPREFIX | CP_QISUFFIX; CP_IPREFIX | CP_ISUFFIX | CP_QIPREFIX | CP_QISUFFIX;
for (pp = comprpms, sm = 1; m; pp++, m >>= 1, sm <<= 1) { for (pp = comprpms, sm = 1; m; pp++, m >>= 1, sm <<= 1) {
if ((m & 1) && ((*pp)->flags & PM_UNSET)) if ((m & 1) && ((*pp)->flags & PM_UNSET))
@ -1267,6 +1269,7 @@ comp_wrapper(Eprog prog, FuncWrap w, char *name)
oqs = ztrdup(compqstack); oqs = ztrdup(compqstack);
oaq = ztrdup(autoq); oaq = ztrdup(autoq);
owords = zarrdup(compwords); owords = zarrdup(compwords);
oredirs = zarrdup(compredirs);
runshfunc(prog, w, name); runshfunc(prog, w, name);
@ -1293,9 +1296,12 @@ comp_wrapper(Eprog prog, FuncWrap w, char *name)
zsfree(autoq); zsfree(autoq);
autoq = oaq; autoq = oaq;
freearray(compwords); freearray(compwords);
freearray(compredirs);
compwords = owords; compwords = owords;
compredirs = oredirs;
comp_setunset(CP_COMPSTATE | comp_setunset(CP_COMPSTATE |
(~runset & (CP_WORDS | CP_CURRENT | CP_PREFIX | (~runset & (CP_WORDS | CP_REDIRS |
CP_CURRENT | CP_PREFIX |
CP_SUFFIX | CP_IPREFIX | CP_ISUFFIX | CP_SUFFIX | CP_IPREFIX | CP_ISUFFIX |
CP_QIPREFIX | CP_QISUFFIX)), CP_QIPREFIX | CP_QISUFFIX)),
(runset & CP_ALLREALS), (runset & CP_ALLREALS),
@ -1390,7 +1396,7 @@ setup_(Module m)
hasperm = 0; hasperm = 0;
comprpms = compkpms = NULL; comprpms = compkpms = NULL;
compwords = NULL; compwords = compredirs = NULL;
compprefix = compsuffix = compiprefix = compisuffix = compprefix = compsuffix = compiprefix = compisuffix =
compqiprefix = compqisuffix = compqiprefix = compqisuffix =
compcontext = compparameter = compredirect = compquote = compcontext = compparameter = compredirect = compquote =
@ -1447,6 +1453,8 @@ finish_(Module m)
{ {
if (compwords) if (compwords)
freearray(compwords); freearray(compwords);
if (compredirs)
freearray(compredirs);
zsfree(compprefix); zsfree(compprefix);
zsfree(compsuffix); zsfree(compsuffix);
zsfree(compiprefix); zsfree(compiprefix);

View file

@ -1138,6 +1138,7 @@ setup_(Module m)
stackhist = stackcs = -1; stackhist = stackcs = -1;
kungetbuf = (char *) zalloc(kungetsz = 32); kungetbuf = (char *) zalloc(kungetsz = 32);
comprecursive = 0; comprecursive = 0;
rdstrs = NULL;
/* initialise the keymap system */ /* initialise the keymap system */
init_keymaps(); init_keymaps();
@ -1192,7 +1193,8 @@ finish_(Module m)
zfree(vichgbuf, vichgbufsz); zfree(vichgbuf, vichgbufsz);
zfree(kungetbuf, kungetsz); zfree(kungetbuf, kungetsz);
free_isrch_spots(); free_isrch_spots();
if (rdstrs)
freelinklist(rdstrs, freestr);
zfree(cutbuf.buf, cutbuf.len); zfree(cutbuf.buf, cutbuf.len);
for(i = KRINGCT; i--; ) for(i = KRINGCT; i--; )
zfree(kring[i].buf, kring[i].len); zfree(kring[i].buf, kring[i].len);

View file

@ -346,6 +346,13 @@ mod_export int lincmd, linredir, linarr;
/**/ /**/
mod_export char *rdstr; mod_export char *rdstr;
static char rdstrbuf[20];
/* The list of redirections on the line. */
/**/
mod_export LinkList rdstrs;
/* This holds the name of the current command (used to find the right * /* This holds the name of the current command (used to find the right *
* compctl). */ * compctl). */
@ -978,7 +985,7 @@ get_comp_string(void)
{ {
int t0, tt0, i, j, k, cp, rd, sl, ocs, ins, oins, ia, parct, varq = 0; int t0, tt0, i, j, k, cp, rd, sl, ocs, ins, oins, ia, parct, varq = 0;
int ona = noaliases; int ona = noaliases;
char *s = NULL, *linptr, *tmp, *p, *tt = NULL; char *s = NULL, *linptr, *tmp, *p, *tt = NULL, rdop[20];
freebrinfo(brbeg); freebrinfo(brbeg);
freebrinfo(brend); freebrinfo(brend);
@ -987,6 +994,11 @@ get_comp_string(void)
zsfree(lastprebr); zsfree(lastprebr);
zsfree(lastpostbr); zsfree(lastpostbr);
lastprebr = lastpostbr = NULL; lastprebr = lastpostbr = NULL;
if (rdstrs)
freelinklist(rdstrs, freestr);
rdstrs = znewlinklist();
rdop[0] = '\0';
rdstr = NULL;
/* This global flag is used to signal the lexer code if it should * /* This global flag is used to signal the lexer code if it should *
* expand aliases or not. */ * expand aliases or not. */
@ -1074,8 +1086,14 @@ get_comp_string(void)
else else
linarr = 0; linarr = 0;
} }
if (inredir) if (inredir) {
rdstr = tokstrings[tok]; rdstr = rdstrbuf;
if (tokfd >= 0)
sprintf(rdop, "%d%s", tokfd, tokstrings[tok]);
else
strcpy(rdop, tokstrings[tok]);
strcpy(rdstr, rdop);
}
if (tok == DINPAR) if (tok == DINPAR)
tokstr = NULL; tokstr = NULL;
@ -1118,8 +1136,11 @@ get_comp_string(void)
ia = linarr; ia = linarr;
if (inwhat == IN_NOTHING && incond) if (inwhat == IN_NOTHING && incond)
inwhat = IN_COND; inwhat = IN_COND;
} else if (linredir) } else if (linredir) {
if (rdop[0] && tokstr)
zaddlinknode(rdstrs, tricat(rdop, ":", tokstr));
continue; continue;
}
if (incond) { if (incond) {
if (tok == DBAR) if (tok == DBAR)
tokstr = "||"; tokstr = "||";