zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: return value for comp{add,gen}
@ 1999-03-04  9:21 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-04  9:21 UTC (permalink / raw)
  To: zsh-workers


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: return value for comp{add,gen}
@ 1999-03-05  7:59 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-05  7:59 UTC (permalink / raw)
  To: zsh-workers


[ I sent this yesterday, but it didn't make it through, it seems. ]

About 5634...

Bart just told me that there is a hunk in compwid.yo that failed. This
is the patch from 5621, sent again. You may savely ignore the failed
hunk. I apologise (seems I forgot to copy the file after that first
patch).


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: return value for comp{add,gen}
@ 1999-03-04  9:33 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-03-04  9:33 UTC (permalink / raw)
  To: zsh-workers


( I just accidentally typed C-c C-c too early... )

I wrote:

> 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.

I have not changed the return value since I think the `compctl was
found' is the most important think to know about when using it. And
since this will be called in a rather top-levellish way in most cases, 
the simple test `(( compstate[nmatches] ))' should be enough.

Also, I'm not too sure about the `compstate[last_nmatches]' Andrej
suggested. The exact number is seldom of interest and if it is, the
shell code is simple enough, I think.

As for the convention of using `matches were added' as the condition
to set the return values of the example functions: yes, I like
this. After a somwhat cursory glance at some of the function I even
think that this wouldn't required too many changes (since most
functions call `comp{add,gen}' or helper functions like `_files' at
the end).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-03-05  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-04  9:21 PATCH: return value for comp{add,gen} Sven Wischnowsky
1999-03-04  9:33 Sven Wischnowsky
1999-03-05  7:59 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).