From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7940 invoked from network); 20 Oct 1999 20:42:05 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 20 Oct 1999 20:42:05 -0000 Received: (qmail 4723 invoked by alias); 20 Oct 1999 20:32:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8340 Received: (qmail 16884 invoked from network); 20 Oct 1999 13:27:17 -0000 Date: Wed, 20 Oct 1999 15:27:07 +0200 (MET DST) Message-Id: <199910201327.PAA01571@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: "Andrej Borsenkow"'s message of Fri, 15 Oct 1999 19:06:35 +0400 Subject: PATCH: completion funcs (was: Re: Problems with _arguments) Andrej Borsenkow wrote: > #compdef sudo > > _arguments \ > ... \ > '*::complete command and/or arguments:_normal' I had this still in a test file and happened to see it again yesterday... I think for such sub-command completion we probably should use something like: _arguments \ ... \ ':command: _command_names -e' \ '*::arguments: _normal' This will ensure that only external commands will be completed in command position. Anyway, I found a little problem with my last change to `_path_files': completion on an empty string was broken. And I found a small bug in `computil' where it got confused about the range of words to restrict `compwords' to. The indexes stored in the C-code are now zero-based, hopefully making things easier to understand. Then there were two allocation bugs (well, one was a free() bug: the array for the argument information for options wasn't freed). The other one was a missing ztrdup(). Ahem. Bye Sven diff -u oldsrc/Zle/computil.c Src/Zle/computil.c --- oldsrc/Zle/computil.c Tue Oct 19 15:51:04 1999 +++ Src/Zle/computil.c Wed Oct 20 15:24:12 1999 @@ -926,6 +926,8 @@ while (i--) if (*p++) freelinklist(p[-1], freestr); + + zfree(ca_laststate.oargs, ca_laststate.d->nopts * sizeof(LinkList)); } for (ptr = d->opts; ptr; ptr = ptr->next) ptr->active = 1; @@ -1051,7 +1053,10 @@ (state.def->type == CAA_RREST || state.def->type == CAA_RARGS)) { state.inrest = 0; - state.argbeg = cur; + state.opt = 0; + state.optbeg = state.nargbeg; + state.argbeg = cur - 1; + for (; line; line = compwords[cur++]) { PERMALLOC { addlinknode(state.args, ztrdup(line)); @@ -1082,11 +1087,10 @@ else { LinkList l = state.oargs[state.curopt->num]; - for (; line; line = compwords[cur++]) { - PERMALLOC { - addlinknode(l, line); - } LASTALLOC; - } + PERMALLOC { + for (; line; line = compwords[cur++]) + addlinknode(l, ztrdup(line)); + } LASTALLOC; memcpy(&ca_laststate, &state, sizeof(state)); ca_laststate.ddef = NULL; ca_laststate.doff = 0; @@ -1103,8 +1107,8 @@ else { ca_laststate.def = adef; ca_laststate.ddef = NULL; - ca_laststate.argbeg = state.nargbeg; - ca_laststate.optbeg = state.restbeg; + ca_laststate.optbeg = state.nargbeg; + ca_laststate.argbeg = state.restbeg; ca_laststate.singles = state.singles; } } @@ -1116,21 +1120,26 @@ { if (l) { LinkNode n; - int len = 1; + int len = 0; char *p, *ret, *q; - for (n = firstnode(l); n; incnode(n)) + for (n = firstnode(l); n; incnode(n)) { + len++; for (p = (char *) getdata(n); *p; p++) len += (*p == ':' ? 2 : 1); - + } ret = q = (char *) zalloc(len); - for (n = firstnode(l); n; incnode(n)) + for (n = firstnode(l); n;) { for (p = (char *) getdata(n); *p; p++) { if (*p == ':') *q++ = '\\'; *q++ = *p; } + incnode(n); + if (n) + *q++ = ':'; + } *q = '\0'; return ret; @@ -1206,10 +1215,10 @@ if (ca_laststate.doff > 0) ignore_prefix(ca_laststate.doff); if (arg->type == CAA_RARGS) - restrict_range(ca_laststate.argbeg - 1, + restrict_range(ca_laststate.optbeg, arrlen(compwords) - 1); else if (arg->type == CAA_RREST) - restrict_range(ca_laststate.optbeg - 1, + restrict_range(ca_laststate.argbeg, arrlen(compwords) - 1); return 0; } diff -u -r oldcompletion/Core/_path_files Completion/Core/_path_files --- oldcompletion/Core/_path_files Mon Oct 18 13:20:37 1999 +++ Completion/Core/_path_files Wed Oct 20 08:46:29 1999 @@ -277,7 +277,7 @@ # otherwise this would keep `_files' from completing all filenames # if none of the patterns match. - if [[ -z "$tpre$tsuf" ]]; then + if [[ -z "$tpre$tsuf" && -n "$pre$suf" ]]; then tmp1=( "$tmp2[@]" ) addsfx=(-S '') remsfx=() -- Sven Wischnowsky wischnow@informatik.hu-berlin.de