OpenCoverage

complete.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/complete.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is complete.def, from which is created complete.c.-
2It implements the builtins "complete", "compgen", and "compopt" in Bash.-
3-
4Copyright (C) 1999-2015 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES complete.c-
22-
23$BUILTIN complete-
24$DEPENDS_ON PROGRAMMABLE_COMPLETION-
25$FUNCTION complete_builtin-
26$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]-
27Specify how arguments are to be completed by Readline.-
28-
29For each NAME, specify how arguments are to be completed. If no options-
30are supplied, existing completion specifications are printed in a way that-
31allows them to be reused as input.-
32-
33Options:-
34 -p print existing completion specifications in a reusable format-
35 -r remove a completion specification for each NAME, or, if no-
36 NAMEs are supplied, all completion specifications-
37 -D apply the completions and actions as the default for commands-
38 without any specific completion defined-
39 -E apply the completions and actions to "empty" commands ---
40 completion attempted on a blank line-
41-
42When completion is attempted, the actions are applied in the order the-
43uppercase-letter options are listed above. The -D option takes-
44precedence over -E.-
45-
46Exit Status:-
47Returns success unless an invalid option is supplied or an error occurs.-
48$END-
49-
50#include <config.h>-
51-
52#include <stdio.h>-
53-
54#include "../bashtypes.h"-
55-
56#if defined (HAVE_UNISTD_H)-
57# include <unistd.h>-
58#endif-
59-
60#include "../bashansi.h"-
61#include "../bashintl.h"-
62-
63#include "../shell.h"-
64#include "../builtins.h"-
65#include "../pcomplete.h"-
66#include "../bashline.h"-
67-
68#include "common.h"-
69#include "bashgetopt.h"-
70-
71#include <readline/readline.h>-
72-
73#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)-
74-
75/* Structure containing all the non-action (binary) options; filled in by-
76 build_actions(). */-
77struct _optflags {-
78 int pflag;-
79 int rflag;-
80 int Dflag;-
81 int Eflag;-
82};-
83-
84static int find_compact __P((char *));-
85static int find_compopt __P((char *));-
86-
87static int build_actions __P((WORD_LIST *, struct _optflags *, unsigned long *, unsigned long *));-
88-
89static int remove_cmd_completions __P((WORD_LIST *));-
90-
91static int print_one_completion __P((char *, COMPSPEC *));-
92static int print_compitem __P((BUCKET_CONTENTS *));-
93static void print_compopts __P((const char *, COMPSPEC *, int));-
94static void print_all_completions __P((void));-
95static int print_cmd_completions __P((WORD_LIST *));-
96-
97static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg;-
98-
99static const struct _compacts {-
100 const char * const actname;-
101 int actflag;-
102 int actopt;-
103} compacts[] = {-
104 { "alias", CA_ALIAS, 'a' },-
105 { "arrayvar", CA_ARRAYVAR, 0 },-
106 { "binding", CA_BINDING, 0 },-
107 { "builtin", CA_BUILTIN, 'b' },-
108 { "command", CA_COMMAND, 'c' },-
109 { "directory", CA_DIRECTORY, 'd' },-
110 { "disabled", CA_DISABLED, 0 },-
111 { "enabled", CA_ENABLED, 0 },-
112 { "export", CA_EXPORT, 'e' },-
113 { "file", CA_FILE, 'f' },-
114 { "function", CA_FUNCTION, 0 },-
115 { "helptopic", CA_HELPTOPIC, 0 },-
116 { "hostname", CA_HOSTNAME, 0 },-
117 { "group", CA_GROUP, 'g' },-
118 { "job", CA_JOB, 'j' },-
119 { "keyword", CA_KEYWORD, 'k' },-
120 { "running", CA_RUNNING, 0 },-
121 { "service", CA_SERVICE, 's' },-
122 { "setopt", CA_SETOPT, 0 },-
123 { "shopt", CA_SHOPT, 0 },-
124 { "signal", CA_SIGNAL, 0 },-
125 { "stopped", CA_STOPPED, 0 },-
126 { "user", CA_USER, 'u' },-
127 { "variable", CA_VARIABLE, 'v' },-
128 { (char *)NULL, 0, 0 },-
129};-
130-
131/* This should be a STRING_INT_ALIST */-
132static const struct _compopt {-
133 const char * const optname;-
134 int optflag;-
135} compopts[] = {-
136 { "bashdefault", COPT_BASHDEFAULT },-
137 { "default", COPT_DEFAULT },-
138 { "dirnames", COPT_DIRNAMES },-
139 { "filenames",COPT_FILENAMES},-
140 { "noquote", COPT_NOQUOTE },-
141 { "nosort", COPT_NOSORT },-
142 { "nospace", COPT_NOSPACE },-
143 { "plusdirs", COPT_PLUSDIRS },-
144 { (char *)NULL, 0 },-
145};-
146-
147static int-
148find_compact (name)-
149 char *name;-
150{-
151 register int i;-
152-
153 for (i = 0; compacts[i].actname; i++)
compacts[i].actnameDescription
TRUEevaluated 152 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-152
154 if (STREQ (name, compacts[i].actname))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( compacts[i].actname ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(name)[0] == (...i].actname)[0]Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-128
155 return i;
executed 10 times by 1 test: return i;
Executed by:
  • Self test
10
156 return -1;
never executed: return -1;
0
157}-
158-
159static int-
160find_compopt (name)-
161 char *name;-
162{-
163 register int i;-
164-
165 for (i = 0; compopts[i].optname; i++)
compopts[i].optnameDescription
TRUEevaluated 76 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-76
166 if (STREQ (name, compopts[i].optname))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( compopts[i].optname ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(name)[0] == (...i].optname)[0]Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 52 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-52
167 return i;
executed 16 times by 1 test: return i;
Executed by:
  • Self test
16
168 return -1;
never executed: return -1;
0
169}-
170-
171/* Build the actions and compspec options from the options specified in LIST.-
172 ACTP is a pointer to an unsigned long in which to place the bitmap of-
173 actions. OPTP is a pointer to an unsigned long in which to place the-
174 bitmap of compspec options (arguments to `-o'). PP, if non-null, gets 1-
175 if -p is supplied; RP, if non-null, gets 1 if -r is supplied.-
176 If either is null, the corresponding option generates an error.-
177 This also sets variables corresponding to options that take arguments as-
178 a side effect; the caller should ensure that those variables are set to-
179 NULL before calling build_actions. Return value:-
180 EX_USAGE = bad option-
181 EXECUTION_SUCCESS = some options supplied-
182 EXECUTION_FAILURE = no options supplied-
183*/-
184-
185static int-
186build_actions (list, flagp, actp, optp)-
187 WORD_LIST *list;-
188 struct _optflags *flagp;-
189 unsigned long *actp, *optp;-
190{-
191 int opt, ind, opt_given;-
192 unsigned long acts, copts;-
193-
194 acts = copts = (unsigned long)0L;-
195 opt_given = 0;-
196-
197 reset_internal_getopt ();-
198 while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:DE")) != -1)
(opt = interna...:C:DE")) != -1Description
TRUEevaluated 235 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
209-235
199 {-
200 opt_given = 1;-
201 switch (opt)-
202 {-
203 case 'r':
never executed: case 'r':
0
204 if (flagp)
flagpDescription
TRUEnever evaluated
FALSEnever evaluated
0
205 {-
206 flagp->rflag = 1;-
207 break;
never executed: break;
0
208 }-
209 else-
210 {-
211 sh_invalidopt ("-r");-
212 builtin_usage ();-
213 return (EX_USAGE);
never executed: return (258);
0
214 }-
215-
216 case 'p':
never executed: case 'p':
0
217 if (flagp)
flagpDescription
TRUEnever evaluated
FALSEnever evaluated
0
218 {-
219 flagp->pflag = 1;-
220 break;
never executed: break;
0
221 }-
222 else-
223 {-
224 sh_invalidopt ("-p");-
225 builtin_usage ();-
226 return (EX_USAGE);
never executed: return (258);
0
227 }-
228-
229 case 'a':
executed 2 times by 1 test: case 'a':
Executed by:
  • Self test
2
230 acts |= CA_ALIAS;-
231 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
232 case 'b':
executed 2 times by 1 test: case 'b':
Executed by:
  • Self test
2
233 acts |= CA_BUILTIN;-
234 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
235 case 'c':
executed 2 times by 1 test: case 'c':
Executed by:
  • Self test
2
236 acts |= CA_COMMAND;-
237 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
238 case 'd':
executed 2 times by 1 test: case 'd':
Executed by:
  • Self test
2
239 acts |= CA_DIRECTORY;-
240 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
241 case 'e':
never executed: case 'e':
0
242 acts |= CA_EXPORT;-
243 break;
never executed: break;
0
244 case 'f':
never executed: case 'f':
0
245 acts |= CA_FILE;-
246 break;
never executed: break;
0
247 case 'g':
never executed: case 'g':
0
248 acts |= CA_GROUP;-
249 break;
never executed: break;
0
250 case 'j':
executed 2 times by 1 test: case 'j':
Executed by:
  • Self test
2
251 acts |= CA_JOB;-
252 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
253 case 'k':
never executed: case 'k':
0
254 acts |= CA_KEYWORD;-
255 break;
never executed: break;
0
256 case 's':
never executed: case 's':
0
257 acts |= CA_SERVICE;-
258 break;
never executed: break;
0
259 case 'u':
executed 2 times by 1 test: case 'u':
Executed by:
  • Self test
2
260 acts |= CA_USER;-
261 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
262 case 'v':
executed 2 times by 1 test: case 'v':
Executed by:
  • Self test
2
263 acts |= CA_VARIABLE;-
264 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
265 case 'o':
executed 16 times by 1 test: case 'o':
Executed by:
  • Self test
16
266 ind = find_compopt (list_optarg);-
267 if (ind < 0)
ind < 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-16
268 {-
269 sh_invalidoptname (list_optarg);-
270 return (EX_USAGE);
never executed: return (258);
0
271 }-
272 copts |= compopts[ind].optflag;-
273 break;
executed 16 times by 1 test: break;
Executed by:
  • Self test
16
274 case 'A':
executed 10 times by 1 test: case 'A':
Executed by:
  • Self test
10
275 ind = find_compact (list_optarg);-
276 if (ind < 0)
ind < 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-10
277 {-
278 builtin_error (_("%s: invalid action name"), list_optarg);-
279 return (EX_USAGE);
never executed: return (258);
0
280 }-
281 acts |= compacts[ind].actflag;-
282 break;
executed 10 times by 1 test: break;
Executed by:
  • Self test
10
283 case 'C':
never executed: case 'C':
0
284 Carg = list_optarg;-
285 break;
never executed: break;
0
286 case 'D':
executed 2 times by 1 test: case 'D':
Executed by:
  • Self test
2
287 if (flagp)
flagpDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
288 {-
289 flagp->Dflag = 1;-
290 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
291 }-
292 else-
293 {-
294 sh_invalidopt ("-D");-
295 builtin_usage ();-
296 return (EX_USAGE);
never executed: return (258);
0
297 }-
298 case 'E':
never executed: case 'E':
0
299 if (flagp)
flagpDescription
TRUEnever evaluated
FALSEnever evaluated
0
300 {-
301 flagp->Eflag = 1;-
302 break;
never executed: break;
0
303 }-
304 else-
305 {-
306 sh_invalidopt ("-E");-
307 builtin_usage ();-
308 return (EX_USAGE);
never executed: return (258);
0
309 }-
310 case 'F':
executed 185 times by 1 test: case 'F':
Executed by:
  • Self test
185
311 Farg = list_optarg;-
312 break;
executed 185 times by 1 test: break;
Executed by:
  • Self test
185
313 case 'G':
never executed: case 'G':
0
314 Garg = list_optarg;-
315 break;
never executed: break;
0
316 case 'P':
executed 4 times by 1 test: case 'P':
Executed by:
  • Self test
4
317 Parg = list_optarg;-
318 break;
executed 4 times by 1 test: break;
Executed by:
  • Self test
4
319 case 'S':
executed 4 times by 1 test: case 'S':
Executed by:
  • Self test
4
320 Sarg = list_optarg;-
321 break;
executed 4 times by 1 test: break;
Executed by:
  • Self test
4
322 case 'W':
never executed: case 'W':
0
323 Warg = list_optarg;-
324 break;
never executed: break;
0
325 case 'X':
never executed: case 'X':
0
326 Xarg = list_optarg;-
327 break;
never executed: break;
0
328 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
329 default:
never executed: default:
0
330 builtin_usage ();-
331 return (EX_USAGE);
never executed: return (258);
0
332 }-
333 }-
334-
335 *actp = acts;-
336 *optp = copts;-
337-
338 return (opt_given ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
executed 209 times by 1 test: return (opt_given ? 0 : 1);
Executed by:
  • Self test
209
339}-
340-
341/* Add, remove, and display completion specifiers. */-
342int-
343complete_builtin (list)-
344 WORD_LIST *list;-
345{-
346 int opt_given, rval;-
347 unsigned long acts, copts;-
348 COMPSPEC *cs;-
349 struct _optflags oflags;-
350 WORD_LIST *l, *wl;-
351-
352 if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
353 {-
354 print_all_completions ();-
355 return (EXECUTION_SUCCESS);
never executed: return (0);
0
356 }-
357-
358 opt_given = oflags.pflag = oflags.rflag = oflags.Dflag = oflags.Eflag = 0;-
359-
360 acts = copts = (unsigned long)0L;-
361 Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL;-
362 cs = (COMPSPEC *)NULL;-
363-
364 /* Build the actions from the arguments. Also sets the [A-Z]arg variables-
365 as a side effect if they are supplied as options. */-
366 rval = build_actions (list, &oflags, &acts, &copts);-
367 if (rval == EX_USAGE)
rval == 258Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
368 return (rval);
never executed: return (rval);
0
369 opt_given = rval != EXECUTION_FAILURE;-
370-
371 list = loptend;-
372-
373 wl = oflags.Dflag ? make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL)
oflags.DflagDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
2-207
374 : (oflags.Eflag ? make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL) : 0);
oflags.EflagDescription
TRUEnever evaluated
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
0-207
375-
376 /* -p overrides everything else */-
377 if (oflags.pflag || (list == 0 && opt_given == 0))
oflags.pflagDescription
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
list == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
opt_given == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-209
378 {-
379 if (wl)
wlDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 {-
381 rval = print_cmd_completions (wl);-
382 dispose_words (wl);-
383 return rval;
never executed: return rval;
0
384 }-
385 else if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
386 {-
387 print_all_completions ();-
388 return (EXECUTION_SUCCESS);
never executed: return (0);
0
389 }-
390 return (print_cmd_completions (list));
never executed: return (print_cmd_completions (list));
0
391 }-
392-
393 /* next, -r overrides everything else. */-
394 if (oflags.rflag)
oflags.rflagDescription
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
395 {-
396 if (wl)
wlDescription
TRUEnever evaluated
FALSEnever evaluated
0
397 {-
398 rval = remove_cmd_completions (wl);-
399 dispose_words (wl);-
400 return rval;
never executed: return rval;
0
401 }-
402 else if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
403 {-
404 progcomp_flush ();-
405 return (EXECUTION_SUCCESS);
never executed: return (0);
0
406 }-
407 return (remove_cmd_completions (list));
never executed: return (remove_cmd_completions (list));
0
408 }-
409-
410 if (wl == 0 && list == 0 && opt_given)
wl == 0Description
TRUEevaluated 207 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
list == 0Description
TRUEnever evaluated
FALSEevaluated 207 times by 1 test
Evaluated by:
  • Self test
opt_givenDescription
TRUEnever evaluated
FALSEnever evaluated
0-207
411 {-
412 builtin_usage ();-
413 return (EX_USAGE);
never executed: return (258);
0
414 }-
415-
416 /* If we get here, we need to build a compspec and add it for each-
417 remaining argument. */-
418 cs = compspec_create ();-
419 cs->actions = acts;-
420 cs->options = copts;-
421-
422 cs->globpat = STRDUP (Garg);
(Garg)Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
423 cs->words = STRDUP (Warg);
(Warg)Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
424 cs->prefix = STRDUP (Parg);
(Parg)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 205 times by 1 test
Evaluated by:
  • Self test
4-205
425 cs->suffix = STRDUP (Sarg);
(Sarg)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 205 times by 1 test
Evaluated by:
  • Self test
4-205
426 cs->funcname = STRDUP (Farg);
(Farg)Description
TRUEevaluated 185 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24-185
427 cs->command = STRDUP (Carg);
(Carg)Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
428 cs->filterpat = STRDUP (Xarg);
(Xarg)Description
TRUEnever evaluated
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
0-209
429-
430 for (rval = EXECUTION_SUCCESS, l = wl ? wl : list ; l; l = l->next)
lDescription
TRUEevaluated 601 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 209 times by 1 test
Evaluated by:
  • Self test
209-601
431 {-
432 /* Add CS as the compspec for the specified commands. */-
433 if (progcomp_insert (l->word->word, cs) == 0)
progcomp_inser...word, cs) == 0Description
TRUEnever evaluated
FALSEevaluated 601 times by 1 test
Evaluated by:
  • Self test
0-601
434 rval = EXECUTION_FAILURE;
never executed: rval = 1;
0
435 }
executed 601 times by 1 test: end of block
Executed by:
  • Self test
601
436-
437 dispose_words (wl);-
438 return (rval);
executed 209 times by 1 test: return (rval);
Executed by:
  • Self test
209
439}-
440-
441static int-
442remove_cmd_completions (list)-
443 WORD_LIST *list;-
444{-
445 WORD_LIST *l;-
446 int ret;-
447-
448 for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next)
lDescription
TRUEnever evaluated
FALSEnever evaluated
0
449 {-
450 if (progcomp_remove (l->word->word) == 0)
progcomp_remov...rd->word) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
451 {-
452 builtin_error (_("%s: no completion specification"), l->word->word);-
453 ret = EXECUTION_FAILURE;-
454 }
never executed: end of block
0
455 }
never executed: end of block
0
456 return ret;
never executed: return ret;
0
457}-
458-
459#define SQPRINTARG(a, f) \-
460 do { \-
461 if (a) \-
462 { \-
463 x = sh_single_quote (a); \-
464 printf ("%s %s ", f, x); \-
465 free (x); \-
466 } \-
467 } while (0)-
468-
469#define PRINTARG(a, f) \-
470 do { \-
471 if (a) \-
472 printf ("%s %s ", f, a); \-
473 } while (0)-
474-
475#define PRINTOPT(a, f) \-
476 do { \-
477 if (acts & a) \-
478 printf ("%s ", f); \-
479 } while (0)-
480-
481#define PRINTACT(a, f) \-
482 do { \-
483 if (acts & a) \-
484 printf ("-A %s ", f); \-
485 } while (0)-
486-
487#define PRINTCOMPOPT(a, f) \-
488 do { \-
489 if (copts & a) \-
490 printf ("-o %s ", f); \-
491 } while (0)-
492-
493#define XPRINTCOMPOPT(a, f) \-
494 do { \-
495 if (copts & a) \-
496 printf ("-o %s ", f); \-
497 else \-
498 printf ("+o %s ", f); \-
499 } while (0)-
500-
501static int-
502print_one_completion (cmd, cs)-
503 char *cmd;-
504 COMPSPEC *cs;-
505{-
506 unsigned long acts, copts;-
507 char *x;-
508-
509 printf ("complete ");-
510-
511 copts = cs->options;-
512-
513 /* First, print the -o options. */-
514 PRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
never executed: printf ("-o %s ", "bashdefault");
copts & (1<<6)Description
TRUEnever evaluated
FALSEnever evaluated
0
515 PRINTCOMPOPT (COPT_DEFAULT, "default");
never executed: printf ("-o %s ", "default");
copts & (1<<1)Description
TRUEnever evaluated
FALSEnever evaluated
0
516 PRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
never executed: printf ("-o %s ", "dirnames");
copts & (1<<3)Description
TRUEnever evaluated
FALSEnever evaluated
0
517 PRINTCOMPOPT (COPT_FILENAMES, "filenames");
never executed: printf ("-o %s ", "filenames");
copts & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
0
518 PRINTCOMPOPT (COPT_NOQUOTE, "noquote");
never executed: printf ("-o %s ", "noquote");
copts & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
519 PRINTCOMPOPT (COPT_NOSORT, "nosort");
never executed: printf ("-o %s ", "nosort");
copts & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
0
520 PRINTCOMPOPT (COPT_NOSPACE, "nospace");
never executed: printf ("-o %s ", "nospace");
copts & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
521 PRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
never executed: printf ("-o %s ", "plusdirs");
copts & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
0
522-
523 acts = cs->actions;-
524-
525 /* simple flags next */-
526 PRINTOPT (CA_ALIAS, "-a");
never executed: printf ("%s ", "-a");
acts & (1<<0)Description
TRUEnever evaluated
FALSEnever evaluated
0
527 PRINTOPT (CA_BUILTIN, "-b");
never executed: printf ("%s ", "-b");
acts & (1<<3)Description
TRUEnever evaluated
FALSEnever evaluated
0
528 PRINTOPT (CA_COMMAND, "-c");
never executed: printf ("%s ", "-c");
acts & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
529 PRINTOPT (CA_DIRECTORY, "-d");
never executed: printf ("%s ", "-d");
acts & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
530 PRINTOPT (CA_EXPORT, "-e");
never executed: printf ("%s ", "-e");
acts & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
0
531 PRINTOPT (CA_FILE, "-f");
never executed: printf ("%s ", "-f");
acts & (1<<9)Description
TRUEnever evaluated
FALSEnever evaluated
0
532 PRINTOPT (CA_GROUP, "-g");
never executed: printf ("%s ", "-g");
acts & (1<<11)Description
TRUEnever evaluated
FALSEnever evaluated
0
533 PRINTOPT (CA_JOB, "-j");
never executed: printf ("%s ", "-j");
acts & (1<<14)Description
TRUEnever evaluated
FALSEnever evaluated
0
534 PRINTOPT (CA_KEYWORD, "-k");
never executed: printf ("%s ", "-k");
acts & (1<<15)Description
TRUEnever evaluated
FALSEnever evaluated
0
535 PRINTOPT (CA_SERVICE, "-s");
never executed: printf ("%s ", "-s");
acts & (1<<17)Description
TRUEnever evaluated
FALSEnever evaluated
0
536 PRINTOPT (CA_USER, "-u");
never executed: printf ("%s ", "-u");
acts & (1<<22)Description
TRUEnever evaluated
FALSEnever evaluated
0
537 PRINTOPT (CA_VARIABLE, "-v");
never executed: printf ("%s ", "-v");
acts & (1<<23)Description
TRUEnever evaluated
FALSEnever evaluated
0
538-
539 /* now the rest of the actions */-
540 PRINTACT (CA_ARRAYVAR, "arrayvar");
never executed: printf ("-A %s ", "arrayvar");
acts & (1<<1)Description
TRUEnever evaluated
FALSEnever evaluated
0
541 PRINTACT (CA_BINDING, "binding");
never executed: printf ("-A %s ", "binding");
acts & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
0
542 PRINTACT (CA_DISABLED, "disabled");
never executed: printf ("-A %s ", "disabled");
acts & (1<<6)Description
TRUEnever evaluated
FALSEnever evaluated
0
543 PRINTACT (CA_ENABLED, "enabled");
never executed: printf ("-A %s ", "enabled");
acts & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
0
544 PRINTACT (CA_FUNCTION, "function");
never executed: printf ("-A %s ", "function");
acts & (1<<10)Description
TRUEnever evaluated
FALSEnever evaluated
0
545 PRINTACT (CA_HELPTOPIC, "helptopic");
never executed: printf ("-A %s ", "helptopic");
acts & (1<<12)Description
TRUEnever evaluated
FALSEnever evaluated
0
546 PRINTACT (CA_HOSTNAME, "hostname");
never executed: printf ("-A %s ", "hostname");
acts & (1<<13)Description
TRUEnever evaluated
FALSEnever evaluated
0
547 PRINTACT (CA_RUNNING, "running");
never executed: printf ("-A %s ", "running");
acts & (1<<16)Description
TRUEnever evaluated
FALSEnever evaluated
0
548 PRINTACT (CA_SETOPT, "setopt");
never executed: printf ("-A %s ", "setopt");
acts & (1<<18)Description
TRUEnever evaluated
FALSEnever evaluated
0
549 PRINTACT (CA_SHOPT, "shopt");
never executed: printf ("-A %s ", "shopt");
acts & (1<<19)Description
TRUEnever evaluated
FALSEnever evaluated
0
550 PRINTACT (CA_SIGNAL, "signal");
never executed: printf ("-A %s ", "signal");
acts & (1<<20)Description
TRUEnever evaluated
FALSEnever evaluated
0
551 PRINTACT (CA_STOPPED, "stopped");
never executed: printf ("-A %s ", "stopped");
acts & (1<<21)Description
TRUEnever evaluated
FALSEnever evaluated
0
552-
553 /* now the rest of the arguments */-
554-
555 /* arguments that require quoting */-
556 SQPRINTARG (cs->globpat, "-G");
never executed: end of block
cs->globpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
557 SQPRINTARG (cs->words, "-W");
never executed: end of block
cs->wordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
558 SQPRINTARG (cs->prefix, "-P");
never executed: end of block
cs->prefixDescription
TRUEnever evaluated
FALSEnever evaluated
0
559 SQPRINTARG (cs->suffix, "-S");
never executed: end of block
cs->suffixDescription
TRUEnever evaluated
FALSEnever evaluated
0
560 SQPRINTARG (cs->filterpat, "-X");
never executed: end of block
cs->filterpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
561-
562 SQPRINTARG (cs->command, "-C");
never executed: end of block
cs->commandDescription
TRUEnever evaluated
FALSEnever evaluated
0
563-
564 /* simple arguments that don't require quoting */-
565 PRINTARG (cs->funcname, "-F");
never executed: printf ("%s %s ", "-F", cs->funcname);
cs->funcnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
566-
567 if (STREQ (cmd, EMPTYCMD))
never executed: __result = (((const unsigned char *) (const char *) ( cmd ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "_EmptycmD_" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cmd)[0] == ("_EmptycmD_")[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
568 printf ("-E\n");
never executed: printf ("-E\n");
0
569 else if (STREQ (cmd, DEFAULTCMD))
never executed: __result = (((const unsigned char *) (const char *) ( cmd ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "_DefaultCmD_" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cmd)[0] == ("...faultCmD_")[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
570 printf ("-D\n");
never executed: printf ("-D\n");
0
571 else-
572 printf ("%s\n", cmd);
never executed: printf ("%s\n", cmd);
0
573-
574 return (0);
never executed: return (0);
0
575}-
576-
577static void-
578print_compopts (cmd, cs, full)-
579 const char *cmd;-
580 COMPSPEC *cs;-
581 int full;-
582{-
583 int copts;-
584-
585 printf ("compopt ");-
586 copts = cs->options;-
587-
588 if (full)
fullDescription
TRUEnever evaluated
FALSEnever evaluated
0
589 {-
590 XPRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
never executed: printf ("-o %s ", "bashdefault");
never executed: printf ("+o %s ", "bashdefault");
copts & (1<<6)Description
TRUEnever evaluated
FALSEnever evaluated
0
591 XPRINTCOMPOPT (COPT_DEFAULT, "default");
never executed: printf ("-o %s ", "default");
never executed: printf ("+o %s ", "default");
copts & (1<<1)Description
TRUEnever evaluated
FALSEnever evaluated
0
592 XPRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
never executed: printf ("-o %s ", "dirnames");
never executed: printf ("+o %s ", "dirnames");
copts & (1<<3)Description
TRUEnever evaluated
FALSEnever evaluated
0
593 XPRINTCOMPOPT (COPT_FILENAMES, "filenames");
never executed: printf ("-o %s ", "filenames");
never executed: printf ("+o %s ", "filenames");
copts & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
0
594 XPRINTCOMPOPT (COPT_NOQUOTE, "noquote");
never executed: printf ("-o %s ", "noquote");
never executed: printf ("+o %s ", "noquote");
copts & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
595 XPRINTCOMPOPT (COPT_NOSORT, "nosort");
never executed: printf ("-o %s ", "nosort");
never executed: printf ("+o %s ", "nosort");
copts & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
0
596 XPRINTCOMPOPT (COPT_NOSPACE, "nospace");
never executed: printf ("-o %s ", "nospace");
never executed: printf ("+o %s ", "nospace");
copts & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
597 XPRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
never executed: printf ("-o %s ", "plusdirs");
never executed: printf ("+o %s ", "plusdirs");
copts & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
0
598 }
never executed: end of block
0
599 else-
600 {-
601 PRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
never executed: printf ("-o %s ", "bashdefault");
copts & (1<<6)Description
TRUEnever evaluated
FALSEnever evaluated
0
602 PRINTCOMPOPT (COPT_DEFAULT, "default");
never executed: printf ("-o %s ", "default");
copts & (1<<1)Description
TRUEnever evaluated
FALSEnever evaluated
0
603 PRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
never executed: printf ("-o %s ", "dirnames");
copts & (1<<3)Description
TRUEnever evaluated
FALSEnever evaluated
0
604 PRINTCOMPOPT (COPT_FILENAMES, "filenames");
never executed: printf ("-o %s ", "filenames");
copts & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
0
605 PRINTCOMPOPT (COPT_NOQUOTE, "noquote");
never executed: printf ("-o %s ", "noquote");
copts & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
606 PRINTCOMPOPT (COPT_NOSORT, "nosort");
never executed: printf ("-o %s ", "nosort");
copts & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
0
607 PRINTCOMPOPT (COPT_NOSPACE, "nospace");
never executed: printf ("-o %s ", "nospace");
copts & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
608 PRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
never executed: printf ("-o %s ", "plusdirs");
copts & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
0
609 }
never executed: end of block
0
610-
611 if (STREQ (cmd, EMPTYCMD))
never executed: __result = (((const unsigned char *) (const char *) ( cmd ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "_EmptycmD_" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cmd)[0] == ("_EmptycmD_")[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
612 printf ("-E\n");
never executed: printf ("-E\n");
0
613 else if (STREQ (cmd, DEFAULTCMD))
never executed: __result = (((const unsigned char *) (const char *) ( cmd ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "_DefaultCmD_" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cmd)[0] == ("...faultCmD_")[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
614 printf ("-D\n");
never executed: printf ("-D\n");
0
615 else-
616 printf ("%s\n", cmd);
never executed: printf ("%s\n", cmd);
0
617}-
618-
619static int-
620print_compitem (item)-
621 BUCKET_CONTENTS *item;-
622{-
623 COMPSPEC *cs;-
624 char *cmd;-
625-
626 cmd = item->key;-
627 cs = (COMPSPEC *)item->data;-
628-
629 return (print_one_completion (cmd, cs));
never executed: return (print_one_completion (cmd, cs));
0
630}-
631-
632static void-
633print_all_completions ()-
634{-
635 progcomp_walk (print_compitem);-
636}
never executed: end of block
0
637-
638static int-
639print_cmd_completions (list)-
640 WORD_LIST *list;-
641{-
642 WORD_LIST *l;-
643 COMPSPEC *cs;-
644 int ret;-
645-
646 for (ret = EXECUTION_SUCCESS, l = list; l; l = l->next)
lDescription
TRUEnever evaluated
FALSEnever evaluated
0
647 {-
648 cs = progcomp_search (l->word->word);-
649 if (cs)
csDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 print_one_completion (l->word->word, cs);
never executed: print_one_completion (l->word->word, cs);
0
651 else-
652 {-
653 builtin_error (_("%s: no completion specification"), l->word->word);-
654 ret = EXECUTION_FAILURE;-
655 }
never executed: end of block
0
656 }-
657-
658 return (sh_chkwrite (ret));
never executed: return (sh_chkwrite (ret));
0
659}-
660-
661$BUILTIN compgen-
662$DEPENDS_ON PROGRAMMABLE_COMPLETION-
663$FUNCTION compgen_builtin-
664$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]-
665Display possible completions depending on the options.-
666-
667Intended to be used from within a shell function generating possible-
668completions. If the optional WORD argument is supplied, matches against-
669WORD are generated.-
670-
671Exit Status:-
672Returns success unless an invalid option is supplied or an error occurs.-
673$END-
674-
675int-
676compgen_builtin (list)-
677 WORD_LIST *list;-
678{-
679 int rval;-
680 unsigned long acts, copts;-
681 COMPSPEC *cs;-
682 STRINGLIST *sl;-
683 char *word, **matches;-
684 char *old_line;-
685 int old_ind;-
686-
687 if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
688 return (EXECUTION_SUCCESS);
never executed: return (0);
0
689-
690 acts = copts = (unsigned long)0L;-
691 Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL;-
692 cs = (COMPSPEC *)NULL;-
693-
694 /* Build the actions from the arguments. Also sets the [A-Z]arg variables-
695 as a side effect if they are supplied as options. */-
696 rval = build_actions (list, (struct _optflags *)NULL, &acts, &copts);-
697 if (rval == EX_USAGE)
rval == 258Description
TRUEnever evaluated
FALSEnever evaluated
0
698 return (rval);
never executed: return (rval);
0
699 if (rval == EXECUTION_FAILURE)
rval == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
700 return (EXECUTION_SUCCESS);
never executed: return (0);
0
701-
702 list = loptend;-
703-
704 word = (list && list->word) ? list->word->word : "";
listDescription
TRUEnever evaluated
FALSEnever evaluated
list->wordDescription
TRUEnever evaluated
FALSEnever evaluated
0
705-
706 if (Farg)
FargDescription
TRUEnever evaluated
FALSEnever evaluated
0
707 builtin_error (_("warning: -F option may not work as you expect"));
never executed: builtin_error ( dcgettext (((void *)0), "warning: -F option may not work as you expect" , 5) );
0
708 if (Carg)
CargDescription
TRUEnever evaluated
FALSEnever evaluated
0
709 builtin_error (_("warning: -C option may not work as you expect"));
never executed: builtin_error ( dcgettext (((void *)0), "warning: -C option may not work as you expect" , 5) );
0
710-
711 /* If we get here, we need to build a compspec and evaluate it. */-
712 cs = compspec_create ();-
713 cs->actions = acts;-
714 cs->options = copts;-
715 cs->refcount = 1;-
716-
717 cs->globpat = STRDUP (Garg);
(Garg)Description
TRUEnever evaluated
FALSEnever evaluated
0
718 cs->words = STRDUP (Warg);
(Warg)Description
TRUEnever evaluated
FALSEnever evaluated
0
719 cs->prefix = STRDUP (Parg);
(Parg)Description
TRUEnever evaluated
FALSEnever evaluated
0
720 cs->suffix = STRDUP (Sarg);
(Sarg)Description
TRUEnever evaluated
FALSEnever evaluated
0
721 cs->funcname = STRDUP (Farg);
(Farg)Description
TRUEnever evaluated
FALSEnever evaluated
0
722 cs->command = STRDUP (Carg);
(Carg)Description
TRUEnever evaluated
FALSEnever evaluated
0
723 cs->filterpat = STRDUP (Xarg);
(Xarg)Description
TRUEnever evaluated
FALSEnever evaluated
0
724-
725 rval = EXECUTION_FAILURE;-
726-
727 /* probably don't have to save these, just being safe */-
728 old_line = pcomp_line;-
729 old_ind = pcomp_ind;-
730 pcomp_line = (char *)NULL;-
731 pcomp_ind = 0;-
732 sl = gen_compspec_completions (cs, "compgen", word, 0, 0, 0);-
733 pcomp_line = old_line;-
734 pcomp_ind = old_ind;-
735-
736 /* If the compspec wants the bash default completions, temporarily-
737 turn off programmable completion and call the bash completion code. */-
738 if ((sl == 0 || sl->list_len == 0) && (copts & COPT_BASHDEFAULT))
sl == 0Description
TRUEnever evaluated
FALSEnever evaluated
sl->list_len == 0Description
TRUEnever evaluated
FALSEnever evaluated
(copts & (1<<6))Description
TRUEnever evaluated
FALSEnever evaluated
0
739 {-
740 matches = bash_default_completion (word, 0, 0, 0, 0);-
741 sl = completions_to_stringlist (matches);-
742 strvec_dispose (matches);-
743 }
never executed: end of block
0
744-
745 /* This isn't perfect, but it's the best we can do, given what readline-
746 exports from its set of completion utility functions. */-
747 if ((sl == 0 || sl->list_len == 0) && (copts & COPT_DEFAULT))
sl == 0Description
TRUEnever evaluated
FALSEnever evaluated
sl->list_len == 0Description
TRUEnever evaluated
FALSEnever evaluated
(copts & (1<<1))Description
TRUEnever evaluated
FALSEnever evaluated
0
748 {-
749 matches = rl_completion_matches (word, rl_filename_completion_function);-
750 strlist_dispose (sl);-
751 sl = completions_to_stringlist (matches);-
752 strvec_dispose (matches);-
753 }
never executed: end of block
0
754-
755 if (sl)
slDescription
TRUEnever evaluated
FALSEnever evaluated
0
756 {-
757 if (sl->list && sl->list_len)
sl->listDescription
TRUEnever evaluated
FALSEnever evaluated
sl->list_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
758 {-
759 rval = EXECUTION_SUCCESS;-
760 strlist_print (sl, (char *)NULL);-
761 }
never executed: end of block
0
762 strlist_dispose (sl);-
763 }
never executed: end of block
0
764-
765 compspec_dispose (cs);-
766 return (rval);
never executed: return (rval);
0
767}-
768-
769$BUILTIN compopt-
770$DEPENDS_ON PROGRAMMABLE_COMPLETION-
771$FUNCTION compopt_builtin-
772$SHORT_DOC compopt [-o|+o option] [-DE] [name ...]-
773Modify or display completion options.-
774-
775Modify the completion options for each NAME, or, if no NAMEs are supplied,-
776the completion currently being executed. If no OPTIONs are given, print-
777the completion options for each NAME or the current completion specification.-
778-
779Options:-
780 -o option Set completion option OPTION for each NAME-
781 -D Change options for the "default" command completion-
782 -E Change options for the "empty" command completion-
783-
784Using `+o' instead of `-o' turns off the specified option.-
785-
786Arguments:-
787-
788Each NAME refers to a command for which a completion specification must-
789have previously been defined using the `complete' builtin. If no NAMEs-
790are supplied, compopt must be called by a function currently generating-
791completions, and the options for that currently-executing completion-
792generator are modified.-
793-
794Exit Status:-
795Returns success unless an invalid option is supplied or NAME does not-
796have a completion specification defined.-
797$END-
798-
799int-
800compopt_builtin (list)-
801 WORD_LIST *list;-
802{-
803 int opts_on, opts_off, *opts, opt, oind, ret, Dflag, Eflag;-
804 WORD_LIST *l, *wl;-
805 COMPSPEC *cs;-
806-
807 opts_on = opts_off = Eflag = Dflag = 0;-
808 ret = EXECUTION_SUCCESS;-
809-
810 reset_internal_getopt ();-
811 while ((opt = internal_getopt (list, "+o:DE")) != -1)
(opt = interna...+o:DE")) != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
812 {-
813 opts = (list_opttype == '-') ? &opts_on : &opts_off;
(list_opttype == '-')Description
TRUEnever evaluated
FALSEnever evaluated
0
814-
815 switch (opt)-
816 {-
817 case 'o':
never executed: case 'o':
0
818 oind = find_compopt (list_optarg);-
819 if (oind < 0)
oind < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
820 {-
821 sh_invalidoptname (list_optarg);-
822 return (EX_USAGE);
never executed: return (258);
0
823 }-
824 *opts |= compopts[oind].optflag;-
825 break;
never executed: break;
0
826 case 'D':
never executed: case 'D':
0
827 Dflag = 1;-
828 break;
never executed: break;
0
829 case 'E:
never executed: case 'E':
0
830 Eflag = 1;-
831 break;
never executed: break;
0
832 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
833 default:
never executed: default:
0
834 builtin_usage ();-
835 return (EX_USAGE);
never executed: return (258);
0
836 }-
837 }-
838 list = loptend;-
839-
840 wl = Dflag ? make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL)
DflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
841 : (Eflag ? make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL) : 0);
EflagDescription
TRUEnever evaluated
FALSEnever evaluated
0
842-
843 if (list == 0 && wl == 0)
list == 0Description
TRUEnever evaluated
FALSEnever evaluated
wl == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
844 {-
845 if (RL_ISSTATE (RL_STATE_COMPLETING) == 0 || pcomp_curcs == 0)
(rl_readline_s...0004000)) == 0Description
TRUEnever evaluated
FALSEnever evaluated
pcomp_curcs == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
846 {-
847 builtin_error (_("not currently executing completion function"));-
848 return (EXECUTION_FAILURE);
never executed: return (1);
0
849 }-
850 cs = pcomp_curcs;-
851-
852 if (opts_on == 0 && opts_off == 0)
opts_on == 0Description
TRUEnever evaluated
FALSEnever evaluated
opts_off == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
853 {-
854 print_compopts (pcomp_curcmd, cs, 1);-
855 return (sh_chkwrite (ret));
never executed: return (sh_chkwrite (ret));
0
856 }-
857-
858 /* Set the compspec options */-
859 pcomp_set_compspec_options (cs, opts_on, 1);-
860 pcomp_set_compspec_options (cs, opts_off, 0);-
861-
862 /* And change the readline variables the options control */-
863 pcomp_set_readline_variables (opts_on, 1);-
864 pcomp_set_readline_variables (opts_off, 0);-
865-
866 return (ret);
never executed: return (ret);
0
867 }-
868-
869 for (l = wl ? wl : list; l; l = l->next)
lDescription
TRUEnever evaluated
FALSEnever evaluated
0
870 {-
871 cs = progcomp_search (l->word->word);-
872 if (cs == 0)
cs == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
873 {-
874 builtin_error (_("%s: no completion specification"), l->word->word);-
875 ret = EXECUTION_FAILURE;-
876 continue;
never executed: continue;
0
877 }-
878 if (opts_on == 0 && opts_off == 0)
opts_on == 0Description
TRUEnever evaluated
FALSEnever evaluated
opts_off == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
879 {-
880 print_compopts (l->word->word, cs, 1);-
881 continue; /* XXX -- fill in later */
never executed: continue;
0
882 }-
883-
884 /* Set the compspec options */-
885 pcomp_set_compspec_options (cs, opts_on, 1);-
886 pcomp_set_compspec_options (cs, opts_off, 0);-
887 }
never executed: end of block
0
888-
889 if (wl)
wlDescription
TRUEnever evaluated
FALSEnever evaluated
0
890 dispose_words (wl);
never executed: dispose_words (wl);
0
891-
892 return (ret);
never executed: return (ret);
0
893}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2