From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: return value for comp{add,gen}
Date: Thu, 4 Mar 1999 10:21:15 +0100 (MET) [thread overview]
Message-ID: <199903040921.KAA02212@beta.informatik.hu-berlin.de> (raw)
The patch below makes `compadd' and `compgen' return zero if matches
were added and non-zero otherwise. With that Andrej's proposed
compgen -g '*.c' || compgen -f
works.
Bye
Sven
diff -u os/Zle/comp1.c Src/Zle/comp1.c
--- os/Zle/comp1.c Wed Mar 3 17:22:41 1999
+++ Src/Zle/comp1.c Thu Mar 4 10:10:59 1999
@@ -52,7 +52,7 @@
/* pointers to functions required by compctl and defined by zle */
/**/
-void (*addmatchesptr) _((char *, char *, char *, char *, char *, char *, char *, char *, char *, char *, int, int, Cmatcher, char *, char **));
+int (*addmatchesptr) _((char *, char *, char *, char *, char *, char *, char *, char *, char *, char *, int, int, Cmatcher, char *, char **));
/**/
char *(*comp_strptr) _((int*, int*, int));
@@ -61,7 +61,7 @@
int (*getcpatptr) _((char *, int, char *, int));
/**/
-void (*makecomplistcallptr) _((Compctl));
+int (*makecomplistcallptr) _((Compctl));
/**/
int (*makecomplistctlptr) _((int));
diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c Wed Mar 3 17:22:41 1999
+++ Src/Zle/compctl.c Thu Mar 4 10:10:48 1999
@@ -1663,7 +1663,7 @@
zerrnam(name, "command names illegal", NULL, 0);
ret = 1;
} else
- makecomplistcallptr(cc);
+ ret = makecomplistcallptr(cc);
freecompctl(cc);
return ret;
@@ -1802,11 +1802,11 @@
return 1;
match = cpcmatcher(match);
- addmatchesptr(ipre, ppre, psuf, prpre, pre, suf, group,
- rs, rf, ign, f, a, match, expl, argv);
+ a = addmatchesptr(ipre, ppre, psuf, prpre, pre, suf, group,
+ rs, rf, ign, f, a, match, expl, argv);
freecmatcher(match);
- return 0;
+ return a;
}
/**/
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c Thu Mar 4 08:47:27 1999
+++ Src/Zle/zle_tricky.c Thu Mar 4 10:17:05 1999
@@ -3981,14 +3981,14 @@
* the matches. */
/**/
-void
+int
addmatches(char *ipre, char *ppre, char *psuf, char *prpre, char *pre,
char *suf, char *group, char *rems, char *remf, char *ign,
int flags, int aflags, Cmatcher match, char *exp, char **argv)
{
char *s, *t, *e, *me, *ms, *lipre = NULL, *lpre = NULL, *lsuf = NULL;
char **aign = NULL;
- int lpl, lsl, i, pl, sl, test, bpl, bsl, llpl = 0, llsl = 0;
+ int lpl, lsl, i, pl, sl, test, bpl, bsl, llpl = 0, llsl = 0, nm = mnum;
Aminfo ai = NULL;
Cline lc = NULL;
LinkList l = NULL;
@@ -4346,6 +4346,8 @@
/* We switched back to the current heap, now restore the stack of
* matchers. */
mstack = oms;
+
+ return (mnum == nm);
}
/* This adds a match to the list of matches. The string to add is given *
@@ -5451,9 +5453,11 @@
}
/**/
-void
+int
makecomplistcall(Compctl cc)
{
+ int nm = mnum;
+
SWITCHHEAPS(compheap) {
HEAPALLOC {
int ooffs = offs, lip, lp;
@@ -5467,6 +5471,8 @@
compnmatches = mnum;
} LASTALLOC;
} SWITCHBACKHEAPS;
+
+ return (mnum == nm);
}
/* A simple counter to avoid endless recursion between old and new style *
diff -u od/Zsh/compwid.yo Doc/Zsh/compwid.yo
--- od/Zsh/compwid.yo Wed Mar 3 10:55:46 1999
+++ Doc/Zsh/compwid.yo Thu Mar 4 10:15:14 1999
@@ -228,6 +228,9 @@
specifications given with the tt(-M) flag to tt(compgen) and the
global matching specifications given to the tt(compctl) builtin
command.
+
+The return value can be used to test if matches were added. It is zero
+if at least one match was added and non-zero otherwise.
)
xitem(tt(compadd) [ tt(-qQfnUam) ] [ tt(-F) var(array) ])
xitem([ tt(-P) var(prefix) ] [ tt(-S) var(suffix) ])
@@ -239,10 +242,17 @@
This builtin command can be used to add matches and directly control
all the information the completion code stores with each possible
-match.
+match. The return value is zero if at least one match was added and
+non-zero if no matches were added.
The completion code breaks the string to complete into six fields in
-the order: var(<ipre><apre><hpre><word><hsuf><asuf>). The first field
+the order:
+
+indent(
+var(<ipre><apre><hpre><word><hsuf><asuf>)
+)
+
+The first field
is an ignored prefix taken from the line, the contents of the
tt(IPREFIX) parameter plus the string given with the tt(-i)
option. With the tt(-U) option given, only the string from the tt(-i)
@@ -499,10 +509,10 @@
like tt(-between) but using pattern matching
)
item(tt(-nmatches) var(number))(
-true if the the value of tt(NMATCHES) is equal to var(number)
+true if the the value of tt(compstate[nmatches]) is equal to var(number)
)
item(tt(-matcher) var(number))(
-true if the value of tt(MATCHER) is equal to var(number)
+true if the value of tt(compstate[matcher]) is equal to var(number)
)
enditem()
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~1999-03-04 9:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-04 9:21 Sven Wischnowsky [this message]
1999-03-04 9:33 Sven Wischnowsky
1999-03-05 7:59 Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199903040921.KAA02212@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).