OpenCoverage

pcomplete.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/pcomplete.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* pcomplete.c - functions to generate lists of matches for programmable completion. */-
2-
3/* Copyright (C) 1999-2018 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include <config.h>-
22-
23#if defined (PROGRAMMABLE_COMPLETION)-
24-
25#include "bashtypes.h"-
26#include "posixstat.h"-
27-
28#if defined (HAVE_UNISTD_H)-
29# include <unistd.h>-
30#endif-
31-
32#include <signal.h>-
33-
34#if defined (PREFER_STDARG)-
35# include <stdarg.h>-
36#else-
37# include <varargs.h>-
38#endif-
39-
40#include <sys/time.h>-
41-
42#include <stdio.h>-
43#include "bashansi.h"-
44#include "bashintl.h"-
45-
46#include "shell.h"-
47#include "pcomplete.h"-
48#include "alias.h"-
49#include "bashline.h"-
50#include "execute_cmd.h"-
51#include "pathexp.h"-
52-
53#if defined (JOB_CONTROL)-
54# include "jobs.h"-
55#endif-
56-
57#if !defined (NSIG)-
58# include "trap.h"-
59#endif-
60-
61#include "shmbutil.h"-
62-
63#include "builtins.h"-
64#include "builtins/common.h"-
65#include "builtins/builtext.h"-
66-
67#include <glob/glob.h>-
68#include <glob/strmatch.h>-
69-
70#include <readline/rlconf.h>-
71#include <readline/readline.h>-
72#include <readline/history.h>-
73-
74#ifdef STRDUP-
75# undef STRDUP-
76#endif-
77#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)-
78-
79typedef SHELL_VAR **SVFUNC ();-
80-
81#ifndef HAVE_STRPBRK-
82extern char *strpbrk __P((char *, char *));-
83#endif-
84-
85extern STRING_INT_ALIST word_token_alist[];-
86extern char *signal_names[];-
87-
88#if defined (DEBUG)-
89#if defined (PREFER_STDARG)-
90static void debug_printf (const char *, ...) __attribute__((__format__ (printf, 1, 2)));-
91#endif-
92#endif /* DEBUG */-
93-
94static int it_init_joblist __P((ITEMLIST *, int));-
95-
96static int it_init_aliases __P((ITEMLIST *));-
97static int it_init_arrayvars __P((ITEMLIST *));-
98static int it_init_bindings __P((ITEMLIST *));-
99static int it_init_builtins __P((ITEMLIST *));-
100static int it_init_disabled __P((ITEMLIST *));-
101static int it_init_enabled __P((ITEMLIST *));-
102static int it_init_exported __P((ITEMLIST *));-
103static int it_init_functions __P((ITEMLIST *));-
104static int it_init_helptopics __P((ITEMLIST *));-
105static int it_init_hostnames __P((ITEMLIST *));-
106static int it_init_jobs __P((ITEMLIST *));-
107static int it_init_running __P((ITEMLIST *));-
108static int it_init_stopped __P((ITEMLIST *));-
109static int it_init_keywords __P((ITEMLIST *));-
110static int it_init_signals __P((ITEMLIST *));-
111static int it_init_variables __P((ITEMLIST *));-
112static int it_init_setopts __P((ITEMLIST *));-
113static int it_init_shopts __P((ITEMLIST *));-
114-
115static int shouldexp_filterpat __P((char *));-
116static char *preproc_filterpat __P((char *, const char *));-
117-
118static void init_itemlist_from_varlist __P((ITEMLIST *, SVFUNC *));-
119-
120static STRINGLIST *gen_matches_from_itemlist __P((ITEMLIST *, const char *));-
121static STRINGLIST *gen_action_completions __P((COMPSPEC *, const char *));-
122static STRINGLIST *gen_globpat_matches __P((COMPSPEC *, const char *));-
123static STRINGLIST *gen_wordlist_matches __P((COMPSPEC *, const char *));-
124static STRINGLIST *gen_shell_function_matches __P((COMPSPEC *, const char *,-
125 const char *,-
126 char *, int, WORD_LIST *,-
127 int, int, int *));-
128static STRINGLIST *gen_command_matches __P((COMPSPEC *, const char *,-
129 const char *,-
130 char *, int, WORD_LIST *,-
131 int, int));-
132-
133static STRINGLIST *gen_progcomp_completions __P((const char *, const char *,-
134 const char *,-
135 int, int, int *, int *,-
136 COMPSPEC **));-
137-
138static char *pcomp_filename_completion_function __P((const char *, int));-
139-
140#if defined (ARRAY_VARS)-
141static SHELL_VAR *bind_comp_words __P((WORD_LIST *));-
142#endif-
143static void bind_compfunc_variables __P((char *, int, WORD_LIST *, int, int));-
144static void unbind_compfunc_variables __P((int));-
145static WORD_LIST *build_arg_list __P((char *, const char *, const char *, WORD_LIST *, int));-
146static WORD_LIST *command_line_to_word_list __P((char *, int, int, int *, int *));-
147-
148#ifdef DEBUG-
149static int progcomp_debug = 0;-
150#endif-
151-
152int prog_completion_enabled = 1;-
153-
154#ifdef ALIAS-
155int progcomp_alias = 0; /* unavailable to user code for now */-
156#endif-
157-
158/* These are used to manage the arrays of strings for possible completions. */-
159ITEMLIST it_aliases = { 0, it_init_aliases, (STRINGLIST *)0 };-
160ITEMLIST it_arrayvars = { LIST_DYNAMIC, it_init_arrayvars, (STRINGLIST *)0 };-
161ITEMLIST it_bindings = { 0, it_init_bindings, (STRINGLIST *)0 };-
162ITEMLIST it_builtins = { 0, it_init_builtins, (STRINGLIST *)0 };-
163ITEMLIST it_commands = { LIST_DYNAMIC }; /* unused */-
164ITEMLIST it_directories = { LIST_DYNAMIC }; /* unused */-
165ITEMLIST it_disabled = { 0, it_init_disabled, (STRINGLIST *)0 };-
166ITEMLIST it_enabled = { 0, it_init_enabled, (STRINGLIST *)0 };-
167ITEMLIST it_exports = { LIST_DYNAMIC, it_init_exported, (STRINGLIST *)0 };-
168ITEMLIST it_files = { LIST_DYNAMIC }; /* unused */-
169ITEMLIST it_functions = { 0, it_init_functions, (STRINGLIST *)0 };-
170ITEMLIST it_helptopics = { 0, it_init_helptopics, (STRINGLIST *)0 };-
171ITEMLIST it_hostnames = { LIST_DYNAMIC, it_init_hostnames, (STRINGLIST *)0 };-
172ITEMLIST it_groups = { LIST_DYNAMIC }; /* unused */-
173ITEMLIST it_jobs = { LIST_DYNAMIC, it_init_jobs, (STRINGLIST *)0 };-
174ITEMLIST it_keywords = { 0, it_init_keywords, (STRINGLIST *)0 };-
175ITEMLIST it_running = { LIST_DYNAMIC, it_init_running, (STRINGLIST *)0 };-
176ITEMLIST it_services = { LIST_DYNAMIC }; /* unused */-
177ITEMLIST it_setopts = { 0, it_init_setopts, (STRINGLIST *)0 };-
178ITEMLIST it_shopts = { 0, it_init_shopts, (STRINGLIST *)0 };-
179ITEMLIST it_signals = { 0, it_init_signals, (STRINGLIST *)0 };-
180ITEMLIST it_stopped = { LIST_DYNAMIC, it_init_stopped, (STRINGLIST *)0 };-
181ITEMLIST it_users = { LIST_DYNAMIC }; /* unused */-
182ITEMLIST it_variables = { LIST_DYNAMIC, it_init_variables, (STRINGLIST *)0 };-
183-
184COMPSPEC *pcomp_curcs;-
185const char *pcomp_curcmd;-
186const char *pcomp_curtxt;-
187-
188char *pcomp_line;-
189int pcomp_ind;-
190-
191#ifdef DEBUG-
192/* Debugging code */-
193static void-
194#if defined (PREFER_STDARG)-
195debug_printf (const char *format, ...)-
196#else-
197debug_printf (format, va_alist)-
198 const char *format;-
199 va_dcl-
200#endif-
201{-
202 va_list args;-
203-
204 if (progcomp_debug == 0)
progcomp_debug == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
205 return;
never executed: return;
0
206-
207 SH_VA_START (args, format);-
208-
209 fprintf (stdout, "DEBUG: ");-
210 vfprintf (stdout, format, args);-
211 fprintf (stdout, "\n");-
212-
213 rl_on_new_line ();-
214-
215 va_end (args);-
216}
never executed: end of block
0
217#endif-
218-
219/* Functions to manage the item lists */-
220-
221void-
222set_itemlist_dirty (it)-
223 ITEMLIST *it;-
224{-
225 it->flags |= LIST_DIRTY;-
226}
executed 15966 times by 1 test: end of block
Executed by:
  • Self test
15966
227-
228void-
229initialize_itemlist (itp)-
230 ITEMLIST *itp;-
231{-
232 (*itp->list_getter) (itp);-
233 itp->flags |= LIST_INITIALIZED;-
234 itp->flags &= ~LIST_DIRTY;-
235}
never executed: end of block
0
236-
237void-
238clean_itemlist (itp)-
239 ITEMLIST *itp;-
240{-
241 STRINGLIST *sl;-
242-
243 sl = itp->slist;-
244 if (sl)
slDescription
TRUEnever evaluated
FALSEnever evaluated
0
245 {-
246 if ((itp->flags & (LIST_DONTFREEMEMBERS|LIST_DONTFREE)) == 0)
(itp->flags & ...0|0x010)) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
247 strvec_flush (sl->list);
never executed: strvec_flush (sl->list);
0
248 if ((itp->flags & LIST_DONTFREE) == 0)
(itp->flags & 0x010) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
249 free (sl->list);
never executed: sh_xfree((sl->list), "pcomplete.c", 249);
0
250 free (sl);-
251 }
never executed: end of block
0
252 itp->slist = (STRINGLIST *)NULL;-
253 itp->flags &= ~(LIST_DONTFREE|LIST_DONTFREEMEMBERS|LIST_INITIALIZED|LIST_DIRTY);-
254}
never executed: end of block
0
255-
256-
257static int-
258shouldexp_filterpat (s)-
259 char *s;-
260{-
261 register char *p;-
262-
263 for (p = s; p && *p; p++)
pDescription
TRUEnever evaluated
FALSEnever evaluated
*pDescription
TRUEnever evaluated
FALSEnever evaluated
0
264 {-
265 if (*p == '\\')
*p == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
0
266 p++;
never executed: p++;
0
267 else if (*p == '&')
*p == '&'Description
TRUEnever evaluated
FALSEnever evaluated
0
268 return 1;
never executed: return 1;
0
269 }
never executed: end of block
0
270 return 0;
never executed: return 0;
0
271}-
272-
273/* Replace any instance of `&' in PAT with TEXT. Backslash may be used to-
274 quote a `&' and inhibit substitution. Returns a new string. This just-
275 calls stringlib.c:strcreplace(). */-
276static char *-
277preproc_filterpat (pat, text)-
278 char *pat;-
279 const char *text;-
280{-
281 char *ret;-
282-
283 ret = strcreplace (pat, '&', text, 1);-
284 return ret;
never executed: return ret;
0
285}-
286 -
287/* Remove any match of FILTERPAT from SL. A `&' in FILTERPAT is replaced by-
288 TEXT. A leading `!' in FILTERPAT negates the pattern; in this case-
289 any member of SL->list that does *not* match will be removed. This returns-
290 a new STRINGLIST with the matching members of SL *copied*. Any-
291 non-matching members of SL->list are *freed*. */ -
292STRINGLIST *-
293filter_stringlist (sl, filterpat, text)-
294 STRINGLIST *sl;-
295 char *filterpat;-
296 const char *text;-
297{-
298 int i, m, not;-
299 STRINGLIST *ret;-
300 char *npat, *t;-
301-
302 if (sl == 0 || sl->list == 0 || sl->list_len == 0)
sl == 0Description
TRUEnever evaluated
FALSEnever evaluated
sl->list == 0Description
TRUEnever evaluated
FALSEnever evaluated
sl->list_len == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
303 return sl;
never executed: return sl;
0
304-
305 npat = shouldexp_filterpat (filterpat) ? preproc_filterpat (filterpat, text) : filterpat;
shouldexp_filt...at (filterpat)Description
TRUEnever evaluated
FALSEnever evaluated
0
306-
307#if defined (EXTENDED_GLOB)-
308 not = (npat[0] == '!' && (extended_glob == 0 || npat[1] != '(')); /*)*/
npat[0] == '!'Description
TRUEnever evaluated
FALSEnever evaluated
extended_glob == 0Description
TRUEnever evaluated
FALSEnever evaluated
npat[1] != '('Description
TRUEnever evaluated
FALSEnever evaluated
0
309#else-
310 not = (npat[0] == '!');-
311#endif-
312 t = not ? npat + 1 : npat;
notDescription
TRUEnever evaluated
FALSEnever evaluated
0
313-
314 ret = strlist_create (sl->list_size);-
315 for (i = 0; i < sl->list_len; i++)
i < sl->list_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
316 {-
317 m = strmatch (t, sl->list[i], FNMATCH_EXTFLAG | FNMATCH_IGNCASE);-
318 if ((not && m == FNM_NOMATCH) || (not == 0 && m != FNM_NOMATCH))
notDescription
TRUEnever evaluated
FALSEnever evaluated
m == 1Description
TRUEnever evaluated
FALSEnever evaluated
not == 0Description
TRUEnever evaluated
FALSEnever evaluated
m != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
319 free (sl->list[i]);
never executed: sh_xfree((sl->list[i]), "pcomplete.c", 319);
0
320 else-
321 ret->list[ret->list_len++] = sl->list[i];
never executed: ret->list[ret->list_len++] = sl->list[i];
0
322 }-
323-
324 ret->list[ret->list_len] = (char *)NULL;-
325 if (npat != filterpat)
npat != filterpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
326 free (npat);
never executed: sh_xfree((npat), "pcomplete.c", 326);
0
327-
328 return ret;
never executed: return ret;
0
329}-
330-
331/* Turn an array of strings returned by rl_completion_matches into a STRINGLIST.-
332 This understands how rl_completion_matches sets matches[0] (the lcd of the-
333 strings in the list, unless it's the only match). */-
334STRINGLIST *-
335completions_to_stringlist (matches)-
336 char **matches;-
337{-
338 STRINGLIST *sl;-
339 int mlen, i, n;-
340-
341 mlen = (matches == 0) ? 0 : strvec_len (matches);
(matches == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
342 sl = strlist_create (mlen + 1);-
343-
344 if (matches == 0 || matches[0] == 0)
matches == 0Description
TRUEnever evaluated
FALSEnever evaluated
matches[0] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
345 return sl;
never executed: return sl;
0
346-
347 if (matches[1] == 0)
matches[1] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
348 {-
349 sl->list[0] = STRDUP (matches[0]);
(matches[0])Description
TRUEnever evaluated
FALSEnever evaluated
0
350 sl->list[sl->list_len = 1] = (char *)NULL;-
351 return sl;
never executed: return sl;
0
352 }-
353-
354 for (i = 1, n = 0; i < mlen; i++, n++)
i < mlenDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 sl->list[n] = STRDUP (matches[i]);
never executed: sl->list[n] = ((matches[i]) ? (char *)strcpy (sh_xmalloc((1 + strlen (matches[i])), "pcomplete.c", 355), (matches[i])) : (char *) ((void *)0) );
(matches[i])Description
TRUEnever evaluated
FALSEnever evaluated
0
356 sl->list_len = n;-
357 sl->list[n] = (char *)NULL;-
358-
359 return sl;
never executed: return sl;
0
360}-
361-
362/* Functions to manage the various ITEMLISTs that we populate internally.-
363 The caller is responsible for setting ITP->flags correctly. */-
364-
365static int-
366it_init_aliases (itp)-
367 ITEMLIST *itp;-
368{-
369#ifdef ALIAS-
370 alias_t **alias_list;-
371 register int i, n;-
372 STRINGLIST *sl;-
373-
374 alias_list = all_aliases ();-
375 if (alias_list == 0)
alias_list == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
376 {-
377 itp->slist = (STRINGLIST *)NULL;-
378 return 0;
never executed: return 0;
0
379 }-
380 for (n = 0; alias_list[n]; n++)
alias_list[n]Description
TRUEnever evaluated
FALSEnever evaluated
0
381 ;
never executed: ;
0
382 sl = strlist_create (n+1);-
383 for (i = 0; i < n; i++)
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
384 sl->list[i] = STRDUP (alias_list[i]->name);
never executed: sl->list[i] = ((alias_list[i]->name) ? (char *)strcpy (sh_xmalloc((1 + strlen (alias_list[i]->name)), "pcomplete.c", 384), (alias_list[i]->name)) : (char *) ((void *)0) );
(alias_list[i]->name)Description
TRUEnever evaluated
FALSEnever evaluated
0
385 sl->list[n] = (char *)NULL;-
386 sl->list_size = sl->list_len = n;-
387 itp->slist = sl;-
388#else-
389 itp->slist = (STRINGLIST *)NULL;-
390#endif-
391 free (alias_list);-
392 return 1;
never executed: return 1;
0
393}-
394-
395static void-
396init_itemlist_from_varlist (itp, svfunc)-
397 ITEMLIST *itp;-
398 SVFUNC *svfunc;-
399{-
400 SHELL_VAR **vlist;-
401 STRINGLIST *sl;-
402 register int i, n;-
403-
404 vlist = (*svfunc) ();-
405 if (vlist == 0)
vlist == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
406 {-
407 itp->slist = (STRINGLIST *)NULL;-
408 return;
never executed: return;
0
409 } -
410 for (n = 0; vlist[n]; n++)
vlist[n]Description
TRUEnever evaluated
FALSEnever evaluated
0
411 ;
never executed: ;
0
412 sl = strlist_create (n+1);-
413 for (i = 0; i < n; i++)
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
414 sl->list[i] = savestring (vlist[i]->name);
never executed: sl->list[i] = (char *)strcpy (sh_xmalloc((1 + strlen (vlist[i]->name)), "pcomplete.c", 414), (vlist[i]->name));
0
415 sl->list[sl->list_len = n] = (char *)NULL;-
416 itp->slist = sl;-
417}
never executed: end of block
0
418-
419static int-
420it_init_arrayvars (itp)-
421 ITEMLIST *itp;-
422{-
423#if defined (ARRAY_VARS)-
424 init_itemlist_from_varlist (itp, all_array_variables);-
425 return 1;
never executed: return 1;
0
426#else-
427 return 0;-
428#endif-
429}-
430-
431static int-
432it_init_bindings (itp)-
433 ITEMLIST *itp;-
434{-
435 char **blist;-
436 STRINGLIST *sl;-
437-
438 /* rl_funmap_names allocates blist, but not its members */-
439 blist = (char **)rl_funmap_names (); /* XXX fix const later */-
440 sl = strlist_create (0);-
441 sl->list = blist;-
442 sl->list_size = 0;-
443 sl->list_len = strvec_len (sl->list);-
444 itp->flags |= LIST_DONTFREEMEMBERS;-
445 itp->slist = sl;-
446-
447 return 0;
never executed: return 0;
0
448}-
449-
450static int-
451it_init_builtins (itp)-
452 ITEMLIST *itp;-
453{-
454 STRINGLIST *sl;-
455 register int i, n;-
456-
457 sl = strlist_create (num_shell_builtins);-
458 for (i = n = 0; i < num_shell_builtins; i++)
i < num_shell_builtinsDescription
TRUEnever evaluated
FALSEnever evaluated
0
459 if (shell_builtins[i].function)
shell_builtins[i].functionDescription
TRUEnever evaluated
FALSEnever evaluated
0
460 sl->list[n++] = shell_builtins[i].name;
never executed: sl->list[n++] = shell_builtins[i].name;
0
461 sl->list[sl->list_len = n] = (char *)NULL;-
462 itp->flags |= LIST_DONTFREEMEMBERS;-
463 itp->slist = sl;-
464 return 0;
never executed: return 0;
0
465}-
466-
467static int-
468it_init_enabled (itp)-
469 ITEMLIST *itp;-
470{-
471 STRINGLIST *sl;-
472 register int i, n;-
473-
474 sl = strlist_create (num_shell_builtins);-
475 for (i = n = 0; i < num_shell_builtins; i++)
i < num_shell_builtinsDescription
TRUEnever evaluated
FALSEnever evaluated
0
476 {-
477 if (shell_builtins[i].function && (shell_builtins[i].flags & BUILTIN_ENABLED))
shell_builtins[i].functionDescription
TRUEnever evaluated
FALSEnever evaluated
(shell_builtin....flags & 0x01)Description
TRUEnever evaluated
FALSEnever evaluated
0
478 sl->list[n++] = shell_builtins[i].name;
never executed: sl->list[n++] = shell_builtins[i].name;
0
479 }
never executed: end of block
0
480 sl->list[sl->list_len = n] = (char *)NULL;-
481 itp->flags |= LIST_DONTFREEMEMBERS;-
482 itp->slist = sl;-
483 return 0;
never executed: return 0;
0
484}-
485-
486static int-
487it_init_disabled (itp)-
488 ITEMLIST *itp;-
489{-
490 STRINGLIST *sl;-
491 register int i, n;-
492-
493 sl = strlist_create (num_shell_builtins);-
494 for (i = n = 0; i < num_shell_builtins; i++)
i < num_shell_builtinsDescription
TRUEnever evaluated
FALSEnever evaluated
0
495 {-
496 if (shell_builtins[i].function && ((shell_builtins[i].flags & BUILTIN_ENABLED) == 0))
shell_builtins[i].functionDescription
TRUEnever evaluated
FALSEnever evaluated
((shell_builti... & 0x01) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
497 sl->list[n++] = shell_builtins[i].name;
never executed: sl->list[n++] = shell_builtins[i].name;
0
498 }
never executed: end of block
0
499 sl->list[sl->list_len = n] = (char *)NULL;-
500 itp->flags |= LIST_DONTFREEMEMBERS;-
501 itp->slist = sl;-
502 return 0;
never executed: return 0;
0
503}-
504-
505static int-
506it_init_exported (itp)-
507 ITEMLIST *itp;-
508{-
509 init_itemlist_from_varlist (itp, all_exported_variables);-
510 return 0;
never executed: return 0;
0
511}-
512-
513static int-
514it_init_functions (itp)-
515 ITEMLIST *itp;-
516{-
517 init_itemlist_from_varlist (itp, all_visible_functions);-
518 return 0;
never executed: return 0;
0
519}-
520-
521/* Like it_init_builtins, but includes everything the help builtin looks at,-
522 not just builtins with an active implementing function. */-
523static int-
524it_init_helptopics (itp)-
525 ITEMLIST *itp;-
526{-
527 STRINGLIST *sl;-
528 register int i, n;-
529-
530 sl = strlist_create (num_shell_builtins);-
531 for (i = n = 0; i < num_shell_builtins; i++)
i < num_shell_builtinsDescription
TRUEnever evaluated
FALSEnever evaluated
0
532 sl->list[n++] = shell_builtins[i].name;
never executed: sl->list[n++] = shell_builtins[i].name;
0
533 sl->list[sl->list_len = n] = (char *)NULL;-
534 itp->flags |= LIST_DONTFREEMEMBERS;-
535 itp->slist = sl;-
536 return 0;
never executed: return 0;
0
537}-
538-
539static int-
540it_init_hostnames (itp)-
541 ITEMLIST *itp;-
542{-
543 STRINGLIST *sl;-
544-
545 sl = strlist_create (0);-
546 sl->list = get_hostname_list ();-
547 sl->list_len = sl->list ? strvec_len (sl->list) : 0;
sl->listDescription
TRUEnever evaluated
FALSEnever evaluated
0
548 sl->list_size = sl->list_len;-
549 itp->slist = sl;-
550 itp->flags |= LIST_DONTFREEMEMBERS|LIST_DONTFREE;-
551 return 0;
never executed: return 0;
0
552}-
553-
554static int-
555it_init_joblist (itp, jstate)-
556 ITEMLIST *itp;-
557 int jstate;-
558{-
559#if defined (JOB_CONTROL)-
560 STRINGLIST *sl;-
561 register int i;-
562 register PROCESS *p;-
563 char *s, *t;-
564 JOB *j;-
565 JOB_STATE ws; /* wanted state */-
566-
567 ws = JNONE;-
568 if (jstate == 0)
jstate == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
569 ws = JRUNNING;
never executed: ws = JRUNNING;
0
570 else if (jstate == 1)
jstate == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
571 ws = JSTOPPED;
never executed: ws = JSTOPPED;
0
572-
573 sl = strlist_create (js.j_jobslots);-
574 for (i = js.j_jobslots - 1; i >= 0; i--)
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
575 {-
576 j = get_job_by_jid (i);-
577 if (j == 0)
j == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
578 continue;
never executed: continue;
0
579 p = j->pipe;-
580 if (jstate == -1 || JOBSTATE(i) == ws)
jstate == -1Description
TRUEnever evaluated
FALSEnever evaluated
(jobs[(i)]->state) == wsDescription
TRUEnever evaluated
FALSEnever evaluated
0
581 {-
582 s = savestring (p->command);-
583 t = strpbrk (s, " \t\n");-
584 if (t)
tDescription
TRUEnever evaluated
FALSEnever evaluated
0
585 *t = '\0';
never executed: *t = '\0';
0
586 sl->list[sl->list_len++] = s;-
587 }
never executed: end of block
0
588 }
never executed: end of block
0
589 itp->slist = sl;-
590#else-
591 itp->slist = (STRINGLIST *)NULL;-
592#endif-
593 return 0;
never executed: return 0;
0
594}-
595-
596static int-
597it_init_jobs (itp)-
598 ITEMLIST *itp;-
599{-
600 return (it_init_joblist (itp, -1));
never executed: return (it_init_joblist (itp, -1));
0
601}-
602-
603static int-
604it_init_running (itp)-
605 ITEMLIST *itp;-
606{-
607 return (it_init_joblist (itp, 0));
never executed: return (it_init_joblist (itp, 0));
0
608}-
609-
610static int-
611it_init_stopped (itp)-
612 ITEMLIST *itp;-
613{-
614 return (it_init_joblist (itp, 1));
never executed: return (it_init_joblist (itp, 1));
0
615}-
616-
617static int-
618it_init_keywords (itp)-
619 ITEMLIST *itp;-
620{-
621 STRINGLIST *sl;-
622 register int i, n;-
623-
624 for (n = 0; word_token_alist[n].word; n++)
word_token_alist[n].wordDescription
TRUEnever evaluated
FALSEnever evaluated
0
625 ;
never executed: ;
0
626 sl = strlist_create (n);-
627 for (i = 0; i < n; i++)
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
628 sl->list[i] = word_token_alist[i].word;
never executed: sl->list[i] = word_token_alist[i].word;
0
629 sl->list[sl->list_len = i] = (char *)NULL;-
630 itp->flags |= LIST_DONTFREEMEMBERS;-
631 itp->slist = sl;-
632 return 0;
never executed: return 0;
0
633}-
634-
635static int-
636it_init_signals (itp)-
637 ITEMLIST *itp;-
638{-
639 STRINGLIST *sl;-
640-
641 sl = strlist_create (0);-
642 sl->list = signal_names;-
643 sl->list_len = strvec_len (sl->list);-
644 itp->flags |= LIST_DONTFREE;-
645 itp->slist = sl;-
646 return 0;
never executed: return 0;
0
647}-
648-
649static int-
650it_init_variables (itp)-
651 ITEMLIST *itp;-
652{-
653 init_itemlist_from_varlist (itp, all_visible_variables);-
654 return 0;
never executed: return 0;
0
655}-
656-
657static int-
658it_init_setopts (itp)-
659 ITEMLIST *itp;-
660{-
661 STRINGLIST *sl;-
662-
663 sl = strlist_create (0);-
664 sl->list = get_minus_o_opts ();-
665 sl->list_len = strvec_len (sl->list);-
666 itp->slist = sl;-
667 itp->flags |= LIST_DONTFREEMEMBERS;-
668 return 0;
never executed: return 0;
0
669}-
670-
671static int-
672it_init_shopts (itp)-
673 ITEMLIST *itp;-
674{-
675 STRINGLIST *sl;-
676-
677 sl = strlist_create (0);-
678 sl->list = get_shopt_options ();-
679 sl->list_len = strvec_len (sl->list);-
680 itp->slist = sl;-
681 itp->flags |= LIST_DONTFREEMEMBERS;-
682 return 0;
never executed: return 0;
0
683}-
684-
685/* Generate a list of all matches for TEXT using the STRINGLIST in itp->slist-
686 as the list of possibilities. If the itemlist has been marked dirty or-
687 it should be regenerated every time, destroy the old STRINGLIST and make a-
688 new one before trying the match. TEXT is dequoted before attempting a-
689 match. */-
690static STRINGLIST *-
691gen_matches_from_itemlist (itp, text)-
692 ITEMLIST *itp;-
693 const char *text;-
694{-
695 STRINGLIST *ret, *sl;-
696 int tlen, i, n;-
697 char *ntxt;-
698-
699 if ((itp->flags & (LIST_DIRTY|LIST_DYNAMIC)) ||
(itp->flags & (0x002|0x001))Description
TRUEnever evaluated
FALSEnever evaluated
0
700 (itp->flags & LIST_INITIALIZED) == 0)
(itp->flags & 0x004) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
701 {-
702 if (itp->flags & (LIST_DIRTY|LIST_DYNAMIC))
itp->flags & (0x002|0x001)Description
TRUEnever evaluated
FALSEnever evaluated
0
703 clean_itemlist (itp);
never executed: clean_itemlist (itp);
0
704 if ((itp->flags & LIST_INITIALIZED) == 0)
(itp->flags & 0x004) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
705 initialize_itemlist (itp);
never executed: initialize_itemlist (itp);
0
706 }
never executed: end of block
0
707 if (itp->slist == 0)
itp->slist == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
708 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
709 ret = strlist_create (itp->slist->list_len+1);-
710 sl = itp->slist;-
711-
712 ntxt = bash_dequote_text (text);-
713 tlen = STRLEN (ntxt);
(ntxt)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)[0]Description
TRUEnever evaluated
FALSEnever evaluated
0
714-
715 for (i = n = 0; i < sl->list_len; i++)
i < sl->list_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
716 {-
717 if (tlen == 0 || STREQN (sl->list[i], ntxt, tlen))
never executed: __result = (((const unsigned char *) (const char *) ( sl->list[i] ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ntxt ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(tlen == 0)Description
TRUEnever evaluated
FALSEnever evaluated
tlen == 0Description
TRUEnever evaluated
FALSEnever evaluated
((tlen == 0) ?...len ))) == 0))Description
TRUEnever evaluated
FALSEnever evaluated
(sl->list[i])[0] == (ntxt)[0]Description
TRUEnever evaluated
FALSEnever evaluated
(__extension__... tlen ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( tlen )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... sl->list[i] )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( sl->l...e_t) ( tlen ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( ntxt )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( ntxt ...e_t) ( tlen ))Description
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
718 ret->list[n++] = STRDUP (sl->list[i]);
never executed: ret->list[n++] = ((sl->list[i]) ? (char *)strcpy (sh_xmalloc((1 + strlen (sl->list[i])), "pcomplete.c", 718), (sl->list[i])) : (char *) ((void *)0) );
(sl->list[i])Description
TRUEnever evaluated
FALSEnever evaluated
0
719 }
never executed: end of block
0
720 ret->list[ret->list_len = n] = (char *)NULL;-
721-
722 FREE (ntxt);
never executed: sh_xfree((ntxt), "pcomplete.c", 722);
ntxtDescription
TRUEnever evaluated
FALSEnever evaluated
0
723 return ret;
never executed: return ret;
0
724}-
725-
726/* A wrapper for rl_filename_completion_function that dequotes the filename-
727 before attempting completions. */-
728static char *-
729pcomp_filename_completion_function (text, state)-
730 const char *text;-
731 int state;-
732{-
733 static char *dfn; /* dequoted filename */-
734 int iscompgen, iscompleting;-
735-
736 if (state == 0)
state == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
737 {-
738 FREE (dfn);
never executed: sh_xfree((dfn), "pcomplete.c", 738);
dfnDescription
TRUEnever evaluated
FALSEnever evaluated
0
739 /* remove backslashes quoting special characters in filenames. */-
740 /* There are roughly three paths we can follow to get here:-
741 1. complete -f-
742 2. compgen -f "$word" from a completion function-
743 3. compgen -f "$word" from the command line-
744 They all need to be handled.-
745-
746 In the first two cases, readline will run the filename dequoting-
747 function in rl_filename_completion_function if it found a filename-
748 quoting character in the word to be completed-
749 (rl_completion_found_quote). We run the dequoting function here-
750 if we're running compgen, we're not completing, and the-
751 rl_filename_completion_function won't dequote the filename-
752 (rl_completion_found_quote == 0). */-
753 iscompgen = this_shell_builtin == compgen_builtin;-
754 iscompleting = RL_ISSTATE (RL_STATE_COMPLETING);-
755 if (iscompgen && iscompleting == 0 && rl_completion_found_quote == 0
iscompgenDescription
TRUEnever evaluated
FALSEnever evaluated
iscompleting == 0Description
TRUEnever evaluated
FALSEnever evaluated
rl_completion_found_quote == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
756 && rl_filename_dequoting_function)
rl_filename_dequoting_functionDescription
TRUEnever evaluated
FALSEnever evaluated
0
757 {-
758 /* Use rl_completion_quote_character because any single or-
759 double quotes have been removed by the time TEXT makes it-
760 here, and we don't want to remove backslashes inside-
761 quoted strings. */-
762 dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);-
763 }
never executed: end of block
0
764 /* Intended to solve a mismatched assumption by bash-completion. If-
765 the text to be completed is empty, but bash-completion turns it into-
766 a quoted string ('') assuming that this code will dequote it before-
767 calling readline, do the dequoting. */-
768 else if (iscompgen && iscompleting &&
iscompgenDescription
TRUEnever evaluated
FALSEnever evaluated
iscompletingDescription
TRUEnever evaluated
FALSEnever evaluated
0
769 pcomp_curtxt && *pcomp_curtxt == 0 &&
pcomp_curtxtDescription
TRUEnever evaluated
FALSEnever evaluated
*pcomp_curtxt == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
770 text && (*text == '\'' || *text == '"') && text[1] == text[0] && text[2] == 0 &&
textDescription
TRUEnever evaluated
FALSEnever evaluated
*text == '\''Description
TRUEnever evaluated
FALSEnever evaluated
*text == '"'Description
TRUEnever evaluated
FALSEnever evaluated
text[1] == text[0]Description
TRUEnever evaluated
FALSEnever evaluated
text[2] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
771 rl_filename_dequoting_function)
rl_filename_dequoting_functionDescription
TRUEnever evaluated
FALSEnever evaluated
0
772 dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
never executed: dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
0
773 /* Another mismatched assumption by bash-completion. If compgen is being-
774 run as part of bash-completion, and the argument to compgen is not-
775 the same as the word originally passed to the programmable completion-
776 code, dequote the argument if it has quote characters. It's an-
777 attempt to detect when bash-completion is quoting its filename-
778 argument before calling compgen. */-
779 /* We could check whether gen_shell_function_matches is in the call-
780 stack by checking whether the gen-shell-function-matches tag is in-
781 the unwind-protect stack, but there's no function to do that yet.-
782 We could simply check whether we're executing in a function by-
783 checking variable_context, and may end up doing that. */-
784 else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
iscompgenDescription
TRUEnever evaluated
FALSEnever evaluated
iscompletingDescription
TRUEnever evaluated
FALSEnever evaluated
rl_filename_dequoting_functionDescription
TRUEnever evaluated
FALSEnever evaluated
0
785 pcomp_curtxt && text &&
pcomp_curtxtDescription
TRUEnever evaluated
FALSEnever evaluated
textDescription
TRUEnever evaluated
FALSEnever evaluated
0
786 STREQ (pcomp_curtxt, text) == 0 &&
never executed: __result = (((const unsigned char *) (const char *) ( pcomp_curtxt ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( text ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
((pcomp_curtxt... }) == 0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
(pcomp_curtxt)[0] == (text)[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
787 variable_context &&
variable_contextDescription
TRUEnever evaluated
FALSEnever evaluated
0
788 sh_contains_quotes (text)) /* guess */
sh_contains_quotes (text)Description
TRUEnever evaluated
FALSEnever evaluated
0
789 dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
never executed: dfn = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
0
790 else-
791 dfn = savestring (text);
never executed: dfn = (char *)strcpy (sh_xmalloc((1 + strlen (text)), "pcomplete.c", 791), (text));
0
792 }-
793-
794 return (rl_filename_completion_function (dfn, state));
never executed: return (rl_filename_completion_function (dfn, state));
0
795}-
796-
797#define GEN_COMPS(bmap, flag, it, text, glist, tlist) \-
798 do { \-
799 if (bmap & flag) \-
800 { \-
801 tlist = gen_matches_from_itemlist (it, text); \-
802 if (tlist) \-
803 { \-
804 glist = strlist_append (glist, tlist); \-
805 strlist_dispose (tlist); \-
806 } \-
807 } \-
808 } while (0)-
809-
810#define GEN_XCOMPS(bmap, flag, text, func, cmatches, glist, tlist) \-
811 do { \-
812 if (bmap & flag) \-
813 { \-
814 cmatches = rl_completion_matches (text, func); \-
815 tlist = completions_to_stringlist (cmatches); \-
816 glist = strlist_append (glist, tlist); \-
817 strvec_dispose (cmatches); \-
818 strlist_dispose (tlist); \-
819 } \-
820 } while (0)-
821-
822/* Functions to generate lists of matches from the actions member of CS. */-
823-
824static STRINGLIST *-
825gen_action_completions (cs, text)-
826 COMPSPEC *cs;-
827 const char *text;-
828{-
829 STRINGLIST *ret, *tmatches;-
830 char **cmatches; /* from rl_completion_matches ... */-
831 unsigned long flags;-
832 int t;-
833-
834 ret = tmatches = (STRINGLIST *)NULL;-
835 flags = cs->actions;-
836-
837 GEN_COMPS (flags, CA_ALIAS, &it_aliases, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<0)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
838 GEN_COMPS (flags, CA_ARRAYVAR, &it_arrayvars, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<1)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
839 GEN_COMPS (flags, CA_BINDING, &it_bindings, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
840 GEN_COMPS (flags, CA_BUILTIN, &it_builtins, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<3)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
841 GEN_COMPS (flags, CA_DISABLED, &it_disabled, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<6)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
842 GEN_COMPS (flags, CA_ENABLED, &it_enabled, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
843 GEN_COMPS (flags, CA_EXPORT, &it_exports, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
844 GEN_COMPS (flags, CA_FUNCTION, &it_functions, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<10)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
845 GEN_COMPS (flags, CA_HELPTOPIC, &it_helptopics, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<12)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
846 GEN_COMPS (flags, CA_HOSTNAME, &it_hostnames, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<13)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
847 GEN_COMPS (flags, CA_JOB, &it_jobs, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<14)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
848 GEN_COMPS (flags, CA_KEYWORD, &it_keywords, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<15)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
849 GEN_COMPS (flags, CA_RUNNING, &it_running, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<16)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
850 GEN_COMPS (flags, CA_SETOPT, &it_setopts, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<18)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
851 GEN_COMPS (flags, CA_SHOPT, &it_shopts, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<19)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
852 GEN_COMPS (flags, CA_SIGNAL, &it_signals, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<20)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
853 GEN_COMPS (flags, CA_STOPPED, &it_stopped, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<21)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
854 GEN_COMPS (flags, CA_VARIABLE, &it_variables, text, ret, tmatches);
never executed: end of block
never executed: end of block
flags & (1<<23)Description
TRUEnever evaluated
FALSEnever evaluated
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
855-
856 GEN_XCOMPS(flags, CA_COMMAND, text, command_word_completion_function, cmatches, ret, tmatches);
never executed: end of block
flags & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
857 GEN_XCOMPS(flags, CA_FILE, text, pcomp_filename_completion_function, cmatches, ret, tmatches);
never executed: end of block
flags & (1<<9)Description
TRUEnever evaluated
FALSEnever evaluated
0
858 GEN_XCOMPS(flags, CA_USER, text, rl_username_completion_function, cmatches, ret, tmatches);
never executed: end of block
flags & (1<<22)Description
TRUEnever evaluated
FALSEnever evaluated
0
859 GEN_XCOMPS(flags, CA_GROUP, text, bash_groupname_completion_function, cmatches, ret, tmatches);
never executed: end of block
flags & (1<<11)Description
TRUEnever evaluated
FALSEnever evaluated
0
860 GEN_XCOMPS(flags, CA_SERVICE, text, bash_servicename_completion_function, cmatches, ret, tmatches);
never executed: end of block
flags & (1<<17)Description
TRUEnever evaluated
FALSEnever evaluated
0
861-
862 /* And lastly, the special case for directories */-
863 if (flags & CA_DIRECTORY)
flags & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
864 {-
865 t = rl_filename_completion_desired;-
866 rl_completion_mark_symlink_dirs = 1; /* override user preference */-
867 cmatches = bash_directory_completion_matches (text);-
868 /* If we did not want filename completion before this, and there are-
869 no matches, turn off rl_filename_completion_desired so whatever-
870 matches we get are not treated as filenames (it gets turned on by-
871 rl_filename_completion_function unconditionally). */-
872 if (t == 0 && cmatches == 0 && rl_filename_completion_desired == 1)
t == 0Description
TRUEnever evaluated
FALSEnever evaluated
cmatches == 0Description
TRUEnever evaluated
FALSEnever evaluated
rl_filename_co...n_desired == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
873 rl_filename_completion_desired = 0;
never executed: rl_filename_completion_desired = 0;
0
874 tmatches = completions_to_stringlist (cmatches);-
875 ret = strlist_append (ret, tmatches);-
876 strvec_dispose (cmatches);-
877 strlist_dispose (tmatches);-
878 }
never executed: end of block
0
879-
880 return ret;
never executed: return ret;
0
881}-
882-
883/* Generate a list of matches for CS->globpat. Unresolved: should this use-
884 TEXT as a match prefix, or just go without? Currently, the code does not-
885 use TEXT, just globs CS->globpat and returns the results. If we do decide-
886 to use TEXT, we should call quote_string_for_globbing before the call to-
887 glob_filename. */-
888static STRINGLIST *-
889gen_globpat_matches (cs, text)-
890 COMPSPEC *cs;-
891 const char *text;-
892{-
893 STRINGLIST *sl;-
894-
895 sl = strlist_create (0);-
896 sl->list = glob_filename (cs->globpat, 0);-
897 if (GLOB_FAILED (sl->list))
(sl->list) == ...b_error_returnDescription
TRUEnever evaluated
FALSEnever evaluated
0
898 sl->list = (char **)NULL;
never executed: sl->list = (char **) ((void *)0) ;
0
899 if (sl->list)
sl->listDescription
TRUEnever evaluated
FALSEnever evaluated
0
900 sl->list_len = sl->list_size = strvec_len (sl->list);
never executed: sl->list_len = sl->list_size = strvec_len (sl->list);
0
901 return sl;
never executed: return sl;
0
902}-
903-
904/* Perform the shell word expansions on CS->words and return the results.-
905 Again, this ignores TEXT. */-
906static STRINGLIST *-
907gen_wordlist_matches (cs, text)-
908 COMPSPEC *cs;-
909 const char *text;-
910{-
911 WORD_LIST *l, *l2;-
912 STRINGLIST *sl;-
913 int nw, tlen;-
914 char *ntxt; /* dequoted TEXT to use in comparisons */-
915-
916 if (cs->words == 0 || cs->words[0] == '\0')
cs->words == 0Description
TRUEnever evaluated
FALSEnever evaluated
cs->words[0] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
917 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
918-
919 /* This used to be a simple expand_string(cs->words, 0), but that won't-
920 do -- there's no way to split a simple list into individual words-
921 that way, since the shell semantics say that word splitting is done-
922 only on the results of expansion. split_at_delims also handles embedded-
923 quoted strings and preserves the quotes for the expand_words_shellexp-
924 function call that follows. */-
925 /* XXX - this is where this function spends most of its time */-
926 l = split_at_delims (cs->words, strlen (cs->words), (char *)NULL, -1, 0, (int *)NULL, (int *)NULL);-
927 if (l == 0)
l == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
928 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
929 /* This will jump back to the top level if the expansion fails... */-
930 l2 = expand_words_shellexp (l);-
931 dispose_words (l);-
932-
933 nw = list_length (l2);-
934 sl = strlist_create (nw + 1);-
935-
936 ntxt = bash_dequote_text (text);-
937 tlen = STRLEN (ntxt);
(ntxt)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)Description
TRUEnever evaluated
FALSEnever evaluated
(ntxt)[0]Description
TRUEnever evaluated
FALSEnever evaluated
0
938-
939 for (nw = 0, l = l2; l; l = l->next)
lDescription
TRUEnever evaluated
FALSEnever evaluated
0
940 {-
941 if (tlen == 0 || STREQN (l->word->word, ntxt, tlen))
never executed: __result = (((const unsigned char *) (const char *) ( l->word->word ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ntxt ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(tlen == 0)Description
TRUEnever evaluated
FALSEnever evaluated
tlen == 0Description
TRUEnever evaluated
FALSEnever evaluated
((tlen == 0) ?...len ))) == 0))Description
TRUEnever evaluated
FALSEnever evaluated
(l->word->word...] == (ntxt)[0]Description
TRUEnever evaluated
FALSEnever evaluated
(__extension__... tlen ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( tlen )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...->word->word )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( l->wo...e_t) ( tlen ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( ntxt )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( ntxt ...e_t) ( tlen ))Description
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
942 sl->list[nw++] = STRDUP (l->word->word);
never executed: sl->list[nw++] = ((l->word->word) ? (char *)strcpy (sh_xmalloc((1 + strlen (l->word->word)), "pcomplete.c", 942), (l->word->word)) : (char *) ((void *)0) );
(l->word->word)Description
TRUEnever evaluated
FALSEnever evaluated
0
943 }
never executed: end of block
0
944 sl->list[sl->list_len = nw] = (char *)NULL;-
945-
946 dispose_words (l2);-
947 FREE (ntxt);
never executed: sh_xfree((ntxt), "pcomplete.c", 947);
ntxtDescription
TRUEnever evaluated
FALSEnever evaluated
0
948 return sl;
never executed: return sl;
0
949}-
950-
951#ifdef ARRAY_VARS-
952-
953static SHELL_VAR *-
954bind_comp_words (lwords)-
955 WORD_LIST *lwords;-
956{-
957 SHELL_VAR *v;-
958-
959 v = find_variable_noref ("COMP_WORDS");-
960 if (v == 0)
v == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
961 v = make_new_array_variable ("COMP_WORDS");
never executed: v = make_new_array_variable ("COMP_WORDS");
0
962 if (nameref_p (v))
((((v)->attrib... (0x0000800)))Description
TRUEnever evaluated
FALSEnever evaluated
0
963 VUNSETATTR (v, att_nameref);
never executed: ((v)->attributes &= ~(0x0000800));
0
964#if 0-
965 if (readonly_p (v))-
966 VUNSETATTR (v, att_readonly);-
967#endif-
968 if (array_p (v) == 0)
((((v)->attrib...000004))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
969 v = convert_var_to_array (v);
never executed: v = convert_var_to_array (v);
0
970 v = assign_array_var_from_word_list (v, lwords, 0);-
971-
972 VUNSETATTR (v, att_invisible);-
973 return v;
never executed: return v;
0
974}-
975#endif /* ARRAY_VARS */-
976-
977static void-
978bind_compfunc_variables (line, ind, lwords, cw, exported)-
979 char *line;-
980 int ind;-
981 WORD_LIST *lwords;-
982 int cw, exported;-
983{-
984 char ibuf[INT_STRLEN_BOUND(int) + 1];-
985 char *value;-
986 SHELL_VAR *v;-
987 size_t llen;-
988 int c;-
989-
990 /* Set the variables that the function expects while it executes. Maybe-
991 these should be in the function environment (temporary_env). */-
992 v = bind_variable ("COMP_LINE", line, 0);-
993 if (v && exported)
vDescription
TRUEnever evaluated
FALSEnever evaluated
exportedDescription
TRUEnever evaluated
FALSEnever evaluated
0
994 VSETATTR(v, att_exported);
never executed: ((v)->attributes |= (0x0000001));
0
995-
996 /* Post bash-4.2: COMP_POINT is characters instead of bytes. */-
997 c = line[ind];-
998 line[ind] = '\0';-
999 llen = MB_STRLEN (line);
( (__ctype_get...r_max ()) > 1)Description
TRUEnever evaluated
FALSEnever evaluated
(line)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(line)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(line)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(line)Description
TRUEnever evaluated
FALSEnever evaluated
(line)[0]Description
TRUEnever evaluated
FALSEnever evaluated
(line)Description
TRUEnever evaluated
FALSEnever evaluated
(line)[0]Description
TRUEnever evaluated
FALSEnever evaluated
0
1000 line[ind] = c;-
1001 value = inttostr (llen, ibuf, sizeof(ibuf));-
1002 v = bind_int_variable ("COMP_POINT", value, 0);-
1003 if (v && exported)
vDescription
TRUEnever evaluated
FALSEnever evaluated
exportedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1004 VSETATTR(v, att_exported);
never executed: ((v)->attributes |= (0x0000001));
0
1005-
1006 value = inttostr (rl_completion_type, ibuf, sizeof (ibuf));-
1007 v = bind_int_variable ("COMP_TYPE", value, 0);-
1008 if (v && exported)
vDescription
TRUEnever evaluated
FALSEnever evaluated
exportedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1009 VSETATTR(v, att_exported);
never executed: ((v)->attributes |= (0x0000001));
0
1010-
1011 value = inttostr (rl_completion_invoking_key, ibuf, sizeof (ibuf));-
1012 v = bind_int_variable ("COMP_KEY", value, 0);-
1013 if (v && exported)
vDescription
TRUEnever evaluated
FALSEnever evaluated
exportedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1014 VSETATTR(v, att_exported);
never executed: ((v)->attributes |= (0x0000001));
0
1015-
1016 /* Since array variables can't be exported, we don't bother making the-
1017 array of words. */-
1018 if (exported == 0)
exported == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1019 {-
1020#ifdef ARRAY_VARS-
1021 v = bind_comp_words (lwords);-
1022 value = inttostr (cw, ibuf, sizeof(ibuf));-
1023 bind_int_variable ("COMP_CWORD", value, 0);-
1024#endif-
1025 }
never executed: end of block
0
1026 else-
1027 array_needs_making = 1;
never executed: array_needs_making = 1;
0
1028}-
1029-
1030static void-
1031unbind_compfunc_variables (exported)-
1032 int exported;-
1033{-
1034 unbind_variable_noref ("COMP_LINE");-
1035 unbind_variable_noref ("COMP_POINT");-
1036 unbind_variable_noref ("COMP_TYPE");-
1037 unbind_variable_noref ("COMP_KEY");-
1038#ifdef ARRAY_VARS-
1039 unbind_variable_noref ("COMP_WORDS");-
1040 unbind_variable_noref ("COMP_CWORD");-
1041#endif-
1042 if (exported)
exportedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1043 array_needs_making = 1;
never executed: array_needs_making = 1;
0
1044}
never executed: end of block
0
1045-
1046/* Build the list of words to pass to a function or external command-
1047 as arguments. When the function or command is invoked,-
1048-
1049 $0 == function or command being invoked-
1050 $1 == command name-
1051 $2 == word to be completed (possibly null)-
1052 $3 == previous word-
1053-
1054 Functions can access all of the words in the current command line-
1055 with the COMP_WORDS array. External commands cannot; they have to-
1056 make do with the COMP_LINE and COMP_POINT variables. */-
1057-
1058static WORD_LIST *-
1059build_arg_list (cmd, cname, text, lwords, ind)-
1060 char *cmd;-
1061 const char *cname;-
1062 const char *text;-
1063 WORD_LIST *lwords;-
1064 int ind;-
1065{-
1066 WORD_LIST *ret, *cl, *l;-
1067 WORD_DESC *w;-
1068 int i;-
1069-
1070 ret = (WORD_LIST *)NULL;-
1071 w = make_word (cmd);-
1072 ret = make_word_list (w, (WORD_LIST *)NULL); /* $0 */-
1073-
1074 w = make_word (cname); /* $1 */-
1075 cl = ret->next = make_word_list (w, (WORD_LIST *)NULL);-
1076-
1077 w = make_word (text);-
1078 cl->next = make_word_list (w, (WORD_LIST *)NULL); /* $2 */-
1079 cl = cl->next;-
1080-
1081 /* Search lwords for current word */-
1082 for (l = lwords, i = 1; l && i < ind-1; l = l->next, i++)
lDescription
TRUEnever evaluated
FALSEnever evaluated
i < ind-1Description
TRUEnever evaluated
FALSEnever evaluated
0
1083 ;
never executed: ;
0
1084 w = (l && l->word) ? copy_word (l->word) : make_word ("");
lDescription
TRUEnever evaluated
FALSEnever evaluated
l->wordDescription
TRUEnever evaluated
FALSEnever evaluated
0
1085 cl->next = make_word_list (w, (WORD_LIST *)NULL);-
1086-
1087 return ret;
never executed: return ret;
0
1088}-
1089-
1090/* Build a command string with-
1091 $0 == cs->funcname (function to execute for completion list)-
1092 $1 == command name (command being completed)-
1093 $2 = word to be completed (possibly null)-
1094 $3 = previous word-
1095 and run in the current shell. The function should put its completion-
1096 list into the array variable COMPREPLY. We build a STRINGLIST-
1097 from the results and return it.-
1098-
1099 Since the shell function should return its list of matches in an array-
1100 variable, this does nothing if arrays are not compiled into the shell. */-
1101-
1102static STRINGLIST *-
1103gen_shell_function_matches (cs, cmd, text, line, ind, lwords, nw, cw, foundp)-
1104 COMPSPEC *cs;-
1105 const char *cmd;-
1106 const char *text;-
1107 char *line;-
1108 int ind;-
1109 WORD_LIST *lwords;-
1110 int nw, cw;-
1111 int *foundp;-
1112{-
1113 char *funcname;-
1114 STRINGLIST *sl;-
1115 SHELL_VAR *f, *v;-
1116 WORD_LIST *cmdlist;-
1117 int fval, found;-
1118 sh_parser_state_t ps;-
1119 sh_parser_state_t * restrict pps;-
1120#if defined (ARRAY_VARS)-
1121 ARRAY *a;-
1122#endif-
1123-
1124 found = 0;-
1125 if (foundp)
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1126 *foundp = found;
never executed: *foundp = found;
0
1127-
1128 funcname = cs->funcname;-
1129 f = find_function (funcname);-
1130 if (f == 0)
f == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1131 {-
1132 internal_error (_("completion: function `%s' not found"), funcname);-
1133 rl_ding ();-
1134 rl_on_new_line ();-
1135 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
1136 }-
1137-
1138#if !defined (ARRAY_VARS)-
1139 return ((STRINGLIST *)NULL);-
1140#else-
1141-
1142 /* We pass cw - 1 because command_line_to_word_list returns indices that are-
1143 1-based, while bash arrays are 0-based. */-
1144 bind_compfunc_variables (line, ind, lwords, cw - 1, 0);-
1145-
1146 cmdlist = build_arg_list (funcname, cmd, text, lwords, cw);-
1147-
1148 pps = &ps;-
1149 save_parser_state (pps);-
1150 begin_unwind_frame ("gen-shell-function-matches");-
1151 add_unwind_protect (restore_parser_state, (char *)pps);-
1152 add_unwind_protect (dispose_words, (char *)cmdlist);-
1153 add_unwind_protect (unbind_compfunc_variables, (char *)0);-
1154-
1155 fval = execute_shell_function (f, cmdlist); -
1156-
1157 discard_unwind_frame ("gen-shell-function-matches");-
1158 restore_parser_state (pps);-
1159-
1160 found = fval != EX_NOTFOUND;-
1161 if (fval == EX_RETRYFAIL)
fval == 124Description
TRUEnever evaluated
FALSEnever evaluated
0
1162 found |= PCOMP_RETRYFAIL;
never executed: found |= ((1<<8) << 1);
0
1163 if (foundp)
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1164 *foundp = found;
never executed: *foundp = found;
0
1165-
1166 /* Now clean up and destroy everything. */-
1167 dispose_words (cmdlist);-
1168 unbind_compfunc_variables (0);-
1169-
1170 /* The list of completions is returned in the array variable COMPREPLY. */-
1171 v = find_variable ("COMPREPLY");-
1172 if (v == 0)
v == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1173 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
1174 if (array_p (v) == 0 && assoc_p (v) == 0)
((((v)->attrib...000004))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
((((v)->attrib...000040))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1175 v = convert_var_to_array (v);
never executed: v = convert_var_to_array (v);
0
1176-
1177 VUNSETATTR (v, att_invisible);-
1178-
1179 a = array_cell (v);-
1180 if (found == 0 || (found & PCOMP_RETRYFAIL) || a == 0 || array_p (v) == 0 || array_empty (a))
found == 0Description
TRUEnever evaluated
FALSEnever evaluated
(found & ((1<<8) << 1))Description
TRUEnever evaluated
FALSEnever evaluated
a == 0Description
TRUEnever evaluated
FALSEnever evaluated
((((v)->attrib...000004))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
((a)->num_elements == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1181 sl = (STRINGLIST *)NULL;
never executed: sl = (STRINGLIST *) ((void *)0) ;
0
1182 else-
1183 {-
1184 /* XXX - should we filter the list of completions so only those matching-
1185 TEXT are returned? Right now, we do not. */-
1186 sl = strlist_create (0);-
1187 sl->list = array_to_argv (a);-
1188 sl->list_len = sl->list_size = array_num_elements (a);-
1189 }
never executed: end of block
0
1190-
1191 /* XXX - should we unbind COMPREPLY here? */-
1192 unbind_variable_noref ("COMPREPLY");-
1193-
1194 return (sl);
never executed: return (sl);
0
1195#endif-
1196}-
1197-
1198/* Build a command string with-
1199 $0 == cs->command (command to execute for completion list)-
1200 $1 == command name (command being completed)-
1201 $2 == word to be completed (possibly null)-
1202 $3 == previous word-
1203 and run it with command substitution. Parse the results, one word-
1204 per line, with backslashes allowed to escape newlines. Build a-
1205 STRINGLIST from the results and return it. */-
1206-
1207static STRINGLIST *-
1208gen_command_matches (cs, cmd, text, line, ind, lwords, nw, cw)-
1209 COMPSPEC *cs;-
1210 const char *cmd;-
1211 const char *text;-
1212 char *line;-
1213 int ind;-
1214 WORD_LIST *lwords;-
1215 int nw, cw;-
1216{-
1217 char *csbuf, *cscmd, *t;-
1218 int cmdlen, cmdsize, n, ws, we;-
1219 WORD_LIST *cmdlist, *cl;-
1220 WORD_DESC *tw;-
1221 STRINGLIST *sl;-
1222-
1223 bind_compfunc_variables (line, ind, lwords, cw, 1);-
1224 cmdlist = build_arg_list (cs->command, cmd, text, lwords, cw);-
1225-
1226 /* Estimate the size needed for the buffer. */-
1227 n = strlen (cs->command);-
1228 cmdsize = n + 1;-
1229 for (cl = cmdlist->next; cl; cl = cl->next)
clDescription
TRUEnever evaluated
FALSEnever evaluated
0
1230 cmdsize += STRLEN (cl->word->word) + 3;
never executed: cmdsize += (((cl->word->word) && (cl->word->word)[0]) ? ((cl->word->word)[1] ? ((cl->word->word)[2] ? strlen(cl->word->word) : 2) : 1) : 0) + 3;
(cl->word->word)[1]Description
TRUEnever evaluated
FALSEnever evaluated
(cl->word->word)[2]Description
TRUEnever evaluated
FALSEnever evaluated
(cl->word->word)Description
TRUEnever evaluated
FALSEnever evaluated
(cl->word->word)[0]Description
TRUEnever evaluated
FALSEnever evaluated
0
1231 cmdsize += 2;-
1232-
1233 /* allocate the string for the command and fill it in. */-
1234 cscmd = (char *)xmalloc (cmdsize + 1);-
1235-
1236 strcpy (cscmd, cs->command); /* $0 */-
1237 cmdlen = n;-
1238 cscmd[cmdlen++] = ' ';-
1239 for (cl = cmdlist->next; cl; cl = cl->next) /* $1, $2, $3, ... */
clDescription
TRUEnever evaluated
FALSEnever evaluated
0
1240 {-
1241 t = sh_single_quote (cl->word->word ? cl->word->word : "");-
1242 n = strlen (t);-
1243 RESIZE_MALLOCED_BUFFER (cscmd, cmdlen, n + 2, cmdsize, 64);
never executed: cmdsize += (64);
never executed: end of block
(cmdlen) + (n + 2) >= cmdsizeDescription
TRUEnever evaluated
FALSEnever evaluated
(cmdlen) + (n + 2) >= cmdsizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1244 strcpy (cscmd + cmdlen, t);-
1245 cmdlen += n;-
1246 if (cl->next)
cl->nextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1247 cscmd[cmdlen++] = ' ';
never executed: cscmd[cmdlen++] = ' ';
0
1248 free (t);-
1249 }
never executed: end of block
0
1250 cscmd[cmdlen] = '\0';-
1251-
1252 tw = command_substitute (cscmd, 0, 0);-
1253 csbuf = tw ? tw->word : (char *)NULL;
twDescription
TRUEnever evaluated
FALSEnever evaluated
0
1254 if (tw)
twDescription
TRUEnever evaluated
FALSEnever evaluated
0
1255 dispose_word_desc (tw);
never executed: dispose_word_desc (tw);
0
1256-
1257 /* Now clean up and destroy everything. */-
1258 dispose_words (cmdlist);-
1259 free (cscmd);-
1260 unbind_compfunc_variables (1);-
1261-
1262 if (csbuf == 0 || *csbuf == '\0')
csbuf == 0Description
TRUEnever evaluated
FALSEnever evaluated
*csbuf == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
1263 {-
1264 FREE (csbuf);
never executed: sh_xfree((csbuf), "pcomplete.c", 1264);
csbufDescription
TRUEnever evaluated
FALSEnever evaluated
0
1265 return ((STRINGLIST *)NULL);
never executed: return ((STRINGLIST *) ((void *)0) );
0
1266 }-
1267-
1268 /* Now break CSBUF up at newlines, with backslash allowed to escape a-
1269 newline, and put the individual words into a STRINGLIST. */-
1270 sl = strlist_create (16);-
1271 for (ws = 0; csbuf[ws]; )
csbuf[ws]Description
TRUEnever evaluated
FALSEnever evaluated
0
1272 {-
1273 we = ws;-
1274 while (csbuf[we] && csbuf[we] != '\n')
csbuf[we]Description
TRUEnever evaluated
FALSEnever evaluated
csbuf[we] != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1275 {-
1276 if (csbuf[we] == '\\' && csbuf[we+1] == '\n')
csbuf[we] == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
csbuf[we+1] == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1277 we++;
never executed: we++;
0
1278 we++;-
1279 }
never executed: end of block
0
1280 t = substring (csbuf, ws, we);-
1281 if (sl->list_len >= sl->list_size - 1)
sl->list_len >...>list_size - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1282 strlist_resize (sl, sl->list_size + 16);
never executed: strlist_resize (sl, sl->list_size + 16);
0
1283 sl->list[sl->list_len++] = t;-
1284 while (csbuf[we] == '\n') we++;
never executed: we++;
csbuf[we] == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
1285 ws = we;-
1286 }
never executed: end of block
0
1287 sl->list[sl->list_len] = (char *)NULL;-
1288-
1289 free (csbuf);-
1290 return (sl);
never executed: return (sl);
0
1291}-
1292-
1293static WORD_LIST *-
1294command_line_to_word_list (line, llen, sentinel, nwp, cwp)-
1295 char *line;-
1296 int llen, sentinel, *nwp, *cwp;-
1297{-
1298 WORD_LIST *ret;-
1299 char *delims;-
1300-
1301#if 0-
1302 delims = "()<>;&| \t\n"; /* shell metacharacters break words */-
1303#else-
1304 delims = rl_completer_word_break_characters;-
1305#endif-
1306 ret = split_at_delims (line, llen, delims, sentinel, SD_NOQUOTEDELIM|SD_COMPLETE, nwp, cwp);-
1307 return (ret);
never executed: return (ret);
0
1308}-
1309-
1310/* Evaluate COMPSPEC *cs and return all matches for WORD. */-
1311-
1312STRINGLIST *-
1313gen_compspec_completions (cs, cmd, word, start, end, foundp)-
1314 COMPSPEC *cs;-
1315 const char *cmd;-
1316 const char *word;-
1317 int start, end;-
1318 int *foundp;-
1319{-
1320 STRINGLIST *ret, *tmatches;-
1321 char *line;-
1322 int llen, nw, cw, found, foundf;-
1323 WORD_LIST *lwords;-
1324 WORD_DESC *lw;-
1325 COMPSPEC *tcs;-
1326-
1327 found = 1;-
1328-
1329#ifdef DEBUG-
1330 debug_printf ("gen_compspec_completions (%s, %s, %d, %d)", cmd, word, start, end);-
1331 debug_printf ("gen_compspec_completions: %s -> %p", cmd, cs);-
1332#endif-
1333 ret = gen_action_completions (cs, word);-
1334#ifdef DEBUG-
1335 if (ret && progcomp_debug)
retDescription
TRUEnever evaluated
FALSEnever evaluated
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1336 {-
1337 debug_printf ("gen_action_completions (%p, %s) -->", cs, word);-
1338 strlist_print (ret, "\t");-
1339 rl_on_new_line ();-
1340 }
never executed: end of block
0
1341#endif-
1342-
1343 /* Now we start generating completions based on the other members of CS. */-
1344 if (cs->globpat)
cs->globpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1345 {-
1346 tmatches = gen_globpat_matches (cs, word);-
1347 if (tmatches)
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1348 {-
1349#ifdef DEBUG-
1350 if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1351 {-
1352 debug_printf ("gen_globpat_matches (%p, %s) -->", cs, word);-
1353 strlist_print (tmatches, "\t");-
1354 rl_on_new_line ();-
1355 }
never executed: end of block
0
1356#endif-
1357 ret = strlist_append (ret, tmatches);-
1358 strlist_dispose (tmatches);-
1359 rl_filename_completion_desired = 1;-
1360 }
never executed: end of block
0
1361 }
never executed: end of block
0
1362-
1363 if (cs->words)
cs->wordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1364 {-
1365 tmatches = gen_wordlist_matches (cs, word);-
1366 if (tmatches)
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1367 {-
1368#ifdef DEBUG-
1369 if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1370 {-
1371 debug_printf ("gen_wordlist_matches (%p, %s) -->", cs, word);-
1372 strlist_print (tmatches, "\t");-
1373 rl_on_new_line ();-
1374 }
never executed: end of block
0
1375#endif-
1376 ret = strlist_append (ret, tmatches);-
1377 strlist_dispose (tmatches);-
1378 }
never executed: end of block
0
1379 }
never executed: end of block
0
1380-
1381 lwords = (WORD_LIST *)NULL;-
1382 line = (char *)NULL;-
1383 if (cs->command || cs->funcname)
cs->commandDescription
TRUEnever evaluated
FALSEnever evaluated
cs->funcnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1384 {-
1385 /* If we have a command or function to execute, we need to first break-
1386 the command line into individual words, find the number of words,-
1387 and find the word in the list containing the word to be completed. */-
1388 line = substring (pcomp_line, start, end);-
1389 llen = end - start;-
1390-
1391#ifdef DEBUG-
1392 debug_printf ("command_line_to_word_list (%s, %d, %d, %p, %p)",-
1393 line, llen, pcomp_ind - start, &nw, &cw);-
1394#endif-
1395 lwords = command_line_to_word_list (line, llen, pcomp_ind - start, &nw, &cw);-
1396 /* If we skipped a NULL word at the beginning of the line, add it back */-
1397 if (lwords && lwords->word && cmd[0] == 0 && lwords->word->word[0] != 0)
lwordsDescription
TRUEnever evaluated
FALSEnever evaluated
lwords->wordDescription
TRUEnever evaluated
FALSEnever evaluated
cmd[0] == 0Description
TRUEnever evaluated
FALSEnever evaluated
lwords->word->word[0] != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1398 {-
1399 lw = make_bare_word (cmd);-
1400 lwords = make_word_list (lw, lwords);-
1401 nw++;-
1402 cw++;-
1403 }
never executed: end of block
0
1404#ifdef DEBUG-
1405 if (lwords == 0 && llen > 0)
lwords == 0Description
TRUEnever evaluated
FALSEnever evaluated
llen > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1406 debug_printf ("ERROR: command_line_to_word_list returns NULL");
never executed: debug_printf ("ERROR: command_line_to_word_list returns NULL");
0
1407 else if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1408 {-
1409 debug_printf ("command_line_to_word_list -->");-
1410 printf ("\t");-
1411 print_word_list (lwords, "!");-
1412 printf ("\n");-
1413 fflush(stdout);-
1414 rl_on_new_line ();-
1415 }
never executed: end of block
0
1416#endif-
1417 }
never executed: end of block
0
1418-
1419 if (cs->funcname)
cs->funcnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1420 {-
1421 foundf = 0;-
1422 tmatches = gen_shell_function_matches (cs, cmd, word, line, pcomp_ind - start, lwords, nw, cw, &foundf);-
1423 if (foundf != 0)
foundf != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1424 found = foundf;
never executed: found = foundf;
0
1425 if (tmatches)
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1426 {-
1427#ifdef DEBUG-
1428 if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1429 {-
1430 debug_printf ("gen_shell_function_matches (%p, %s, %s, %p, %d, %d) -->", cs, cmd, word, lwords, nw, cw);-
1431 strlist_print (tmatches, "\t");-
1432 rl_on_new_line ();-
1433 }
never executed: end of block
0
1434#endif-
1435 ret = strlist_append (ret, tmatches);-
1436 strlist_dispose (tmatches);-
1437 }
never executed: end of block
0
1438 }
never executed: end of block
0
1439-
1440 if (cs->command)
cs->commandDescription
TRUEnever evaluated
FALSEnever evaluated
0
1441 {-
1442 tmatches = gen_command_matches (cs, cmd, word, line, pcomp_ind - start, lwords, nw, cw);-
1443 if (tmatches)
tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1444 {-
1445#ifdef DEBUG-
1446 if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1447 {-
1448 debug_printf ("gen_command_matches (%p, %s, %s, %p, %d, %d) -->", cs, cmd, word, lwords, nw, cw);-
1449 strlist_print (tmatches, "\t");-
1450 rl_on_new_line ();-
1451 }
never executed: end of block
0
1452#endif-
1453 ret = strlist_append (ret, tmatches);-
1454 strlist_dispose (tmatches);-
1455 }
never executed: end of block
0
1456 }
never executed: end of block
0
1457-
1458 if (cs->command || cs->funcname)
cs->commandDescription
TRUEnever evaluated
FALSEnever evaluated
cs->funcnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1459 {-
1460 if (lwords)
lwordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1461 dispose_words (lwords);
never executed: dispose_words (lwords);
0
1462 FREE (line);
never executed: sh_xfree((line), "pcomplete.c", 1462);
lineDescription
TRUEnever evaluated
FALSEnever evaluated
0
1463 }
never executed: end of block
0
1464-
1465 if (foundp)
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1466 *foundp = found;
never executed: *foundp = found;
0
1467-
1468 if (found == 0 || (found & PCOMP_RETRYFAIL))
found == 0Description
TRUEnever evaluated
FALSEnever evaluated
(found & ((1<<8) << 1))Description
TRUEnever evaluated
FALSEnever evaluated
0
1469 {-
1470 strlist_dispose (ret);-
1471 return NULL;
never executed: return ((void *)0) ;
0
1472 }-
1473-
1474 if (cs->filterpat)
cs->filterpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1475 {-
1476 tmatches = filter_stringlist (ret, cs->filterpat, word);-
1477#ifdef DEBUG-
1478 if (progcomp_debug)
progcomp_debugDescription
TRUEnever evaluated
FALSEnever evaluated
0
1479 {-
1480 debug_printf ("filter_stringlist (%p, %s, %s) -->", ret, cs->filterpat, word);-
1481 strlist_print (tmatches, "\t");-
1482 rl_on_new_line ();-
1483 }
never executed: end of block
0
1484#endif-
1485 if (ret && ret != tmatches)
retDescription
TRUEnever evaluated
FALSEnever evaluated
ret != tmatchesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1486 {-
1487 FREE (ret->list);
never executed: sh_xfree((ret->list), "pcomplete.c", 1487);
ret->listDescription
TRUEnever evaluated
FALSEnever evaluated
0
1488 free (ret);-
1489 }
never executed: end of block
0
1490 ret = tmatches;-
1491 }
never executed: end of block
0
1492-
1493 if (cs->prefix || cs->suffix)
cs->prefixDescription
TRUEnever evaluated
FALSEnever evaluated
cs->suffixDescription
TRUEnever evaluated
FALSEnever evaluated
0
1494 ret = strlist_prefix_suffix (ret, cs->prefix, cs->suffix);
never executed: ret = strlist_prefix_suffix (ret, cs->prefix, cs->suffix);
0
1495-
1496 /* If no matches have been generated and the user has specified that-
1497 directory completion should be done as a default, call-
1498 gen_action_completions again to generate a list of matching directory-
1499 names. */-
1500 if ((ret == 0 || ret->list_len == 0) && (cs->options & COPT_DIRNAMES))
ret == 0Description
TRUEnever evaluated
FALSEnever evaluated
ret->list_len == 0Description
TRUEnever evaluated
FALSEnever evaluated
(cs->options & (1<<3))Description
TRUEnever evaluated
FALSEnever evaluated
0
1501 {-
1502 tcs = compspec_create ();-
1503 tcs->actions = CA_DIRECTORY;-
1504 FREE (ret);
never executed: sh_xfree((ret), "pcomplete.c", 1504);
retDescription
TRUEnever evaluated
FALSEnever evaluated
0
1505 ret = gen_action_completions (tcs, word);-
1506 compspec_dispose (tcs);-
1507 }
never executed: end of block
0
1508 else if (cs->options & COPT_PLUSDIRS)
cs->options & (1<<7)Description
TRUEnever evaluated
FALSEnever evaluated
0
1509 {-
1510 tcs = compspec_create ();-
1511 tcs->actions = CA_DIRECTORY;-
1512 tmatches = gen_action_completions (tcs, word);-
1513 ret = strlist_append (ret, tmatches);-
1514 strlist_dispose (tmatches);-
1515 compspec_dispose (tcs);-
1516 }
never executed: end of block
0
1517-
1518 return (ret);
never executed: return (ret);
0
1519}-
1520-
1521void-
1522pcomp_set_readline_variables (flags, nval)-
1523 int flags, nval;-
1524{-
1525 /* If the user specified that the compspec returns filenames, make-
1526 sure that readline knows it. */-
1527 if (flags & COPT_FILENAMES)
flags & (1<<2)Description
TRUEnever evaluated
FALSEnever evaluated
0
1528 rl_filename_completion_desired = nval;
never executed: rl_filename_completion_desired = nval;
0
1529 /* If the user doesn't want a space appended, tell readline. */-
1530 if (flags & COPT_NOSPACE)
flags & (1<<5)Description
TRUEnever evaluated
FALSEnever evaluated
0
1531 rl_completion_suppress_append = nval;
never executed: rl_completion_suppress_append = nval;
0
1532 /* The value here is inverted, since the default is on and the `noquote'-
1533 option is supposed to turn it off */-
1534 if (flags & COPT_NOQUOTE)
flags & (1<<4)Description
TRUEnever evaluated
FALSEnever evaluated
0
1535 rl_filename_quoting_desired = 1 - nval;
never executed: rl_filename_quoting_desired = 1 - nval;
0
1536 if (flags & COPT_NOSORT)
flags & (1<<8)Description
TRUEnever evaluated
FALSEnever evaluated
0
1537 rl_sort_completion_matches = 1 - nval;
never executed: rl_sort_completion_matches = 1 - nval;
0
1538}
never executed: end of block
0
1539-
1540/* Set or unset FLAGS in the options word of the current compspec.-
1541 SET_OR_UNSET is 1 for setting, 0 for unsetting. */-
1542void-
1543pcomp_set_compspec_options (cs, flags, set_or_unset)-
1544 COMPSPEC *cs;-
1545 int flags, set_or_unset;-
1546{-
1547 if (cs == 0 && ((cs = pcomp_curcs) == 0))
cs == 0Description
TRUEnever evaluated
FALSEnever evaluated
((cs = pcomp_curcs) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1548 return;
never executed: return;
0
1549 if (set_or_unset)
set_or_unsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1550 cs->options |= flags;
never executed: cs->options |= flags;
0
1551 else-
1552 cs->options &= ~flags;
never executed: cs->options &= ~flags;
0
1553}-
1554-
1555static STRINGLIST *-
1556gen_progcomp_completions (ocmd, cmd, word, start, end, foundp, retryp, lastcs)-
1557 const char *ocmd;-
1558 const char *cmd;-
1559 const char *word;-
1560 int start, end;-
1561 int *foundp, *retryp;-
1562 COMPSPEC **lastcs;-
1563{-
1564 COMPSPEC *cs, *oldcs;-
1565 const char *oldcmd, *oldtxt;-
1566 STRINGLIST *ret;-
1567-
1568 cs = progcomp_search (ocmd);-
1569-
1570 if (cs == 0 || cs == *lastcs)
cs == 0Description
TRUEnever evaluated
FALSEnever evaluated
cs == *lastcsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1571 {-
1572#if 0-
1573 if (foundp)-
1574 *foundp = 0;-
1575#endif-
1576 return (NULL);
never executed: return ( ((void *)0) );
0
1577 }-
1578-
1579 if (*lastcs)
*lastcsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1580 compspec_dispose (*lastcs);
never executed: compspec_dispose (*lastcs);
0
1581 cs->refcount++; /* XXX */-
1582 *lastcs = cs;-
1583-
1584 cs = compspec_copy (cs);-
1585-
1586 oldcs = pcomp_curcs;-
1587 oldcmd = pcomp_curcmd;-
1588 oldtxt = pcomp_curtxt;-
1589-
1590 pcomp_curcs = cs;-
1591 pcomp_curcmd = cmd;-
1592 pcomp_curtxt = word;-
1593-
1594 ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);-
1595-
1596 pcomp_curcs = oldcs;-
1597 pcomp_curcmd = oldcmd;-
1598 pcomp_curtxt = oldtxt;-
1599-
1600 /* We need to conditionally handle setting *retryp here */-
1601 if (retryp)
retrypDescription
TRUEnever evaluated
FALSEnever evaluated
0
1602 *retryp = foundp && (*foundp & PCOMP_RETRYFAIL);
never executed: *retryp = foundp && (*foundp & ((1<<8) << 1));
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
(*foundp & ((1<<8) << 1))Description
TRUEnever evaluated
FALSEnever evaluated
0
1603-
1604 if (foundp)
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1605 {-
1606 *foundp &= ~PCOMP_RETRYFAIL;-
1607 *foundp |= cs->options;-
1608 }
never executed: end of block
0
1609-
1610 compspec_dispose (cs);-
1611 return ret;
never executed: return ret;
0
1612}-
1613-
1614/* The driver function for the programmable completion code. Returns a list-
1615 of matches for WORD, which is an argument to command CMD. START and END-
1616 bound the command currently being completed in pcomp_line (usually-
1617 rl_line_buffer). */-
1618char **-
1619programmable_completions (cmd, word, start, end, foundp)-
1620 const char *cmd;-
1621 const char *word;-
1622 int start, end, *foundp;-
1623{-
1624 COMPSPEC *lastcs;-
1625 STRINGLIST *ret;-
1626 char **rmatches, *t;-
1627 int found, retry, count;-
1628 char *ocmd;-
1629 int oend;-
1630#if defined (ALIAS)-
1631 alias_t *al;-
1632#endif-
1633-
1634 lastcs = 0;-
1635 found = count = 0;-
1636-
1637 pcomp_line = rl_line_buffer;-
1638 pcomp_ind = rl_point;-
1639-
1640 ocmd = (char *)cmd;-
1641 oend = end;-
1642-
1643 do-
1644 {-
1645 retry = 0;-
1646-
1647 /* We look at the basename of CMD if the full command does not have-
1648 an associated COMPSPEC. */-
1649 ret = gen_progcomp_completions (ocmd, ocmd, word, start, oend, &found, &retry, &lastcs);-
1650 if (found == 0)
found == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1651 {-
1652 t = strrchr (ocmd, '/');-
1653 if (t && *(++t))
tDescription
TRUEnever evaluated
FALSEnever evaluated
*(++t)Description
TRUEnever evaluated
FALSEnever evaluated
0
1654 ret = gen_progcomp_completions (t, ocmd, word, start, oend, &found, &retry, &lastcs);
never executed: ret = gen_progcomp_completions (t, ocmd, word, start, oend, &found, &retry, &lastcs);
0
1655 }
never executed: end of block
0
1656-
1657 if (found == 0)
found == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1658 ret = gen_progcomp_completions (DEFAULTCMD, ocmd, word, start, oend, &found, &retry, &lastcs);
never executed: ret = gen_progcomp_completions ("_DefaultCmD_", ocmd, word, start, oend, &found, &retry, &lastcs);
0
1659-
1660#if defined (ALIAS)-
1661 /* Look up any alias for CMD, try to gen completions for it */-
1662 /* Look up the alias, find the value, build a new line replacing CMD-
1663 with that value, offsetting PCOMP_IND and END appropriately, reset-
1664 PCOMP_LINE to the new line and OCMD with the new command name, then-
1665 call gen_progcomp_completions again. We could use alias_expand for-
1666 this, but it does more (and less) than we need right now. */-
1667 if (found == 0 && retry == 0 && progcomp_alias && (al = find_alias (ocmd)))
found == 0Description
TRUEnever evaluated
FALSEnever evaluated
retry == 0Description
TRUEnever evaluated
FALSEnever evaluated
progcomp_aliasDescription
TRUEnever evaluated
FALSEnever evaluated
(al = find_alias (ocmd))Description
TRUEnever evaluated
FALSEnever evaluated
0
1668 {-
1669 char *ncmd, *nline, *ntxt;-
1670 int ind, lendiff;-
1671 size_t nlen, olen, llen;-
1672-
1673 /* We found an alias for OCMD. Take the value and build a new line */-
1674 ntxt = al->value;-
1675 nlen = strlen (ntxt);-
1676 if (nlen == 0)
nlen == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1677 break;
never executed: break;
0
1678 olen = strlen (ocmd);-
1679 lendiff = nlen - olen; /* can be negative */-
1680 llen = strlen (pcomp_line);-
1681-
1682 nline = (char *)xmalloc (llen + lendiff + 1);-
1683 if (start > 0)
start > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1684 strncpy (nline, pcomp_line, start);
never executed: __builtin_strncpy ( nline , pcomp_line , start ) ;
0
1685 strncpy (nline + start, ntxt, nlen);-
1686 strcpy (nline + start + nlen, pcomp_line + start + olen);-
1687-
1688 /* Find the first word of the alias value and use that as OCMD. We-
1689 don't check the alias value to see whether it begins with a valid-
1690 command name, so this can be fooled. */-
1691 ind = skip_to_delim (ntxt, 0, "()<>;&| \t\n", SD_NOJMP|SD_COMPLETE); /*)*/-
1692 if (ind > 0)
ind > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1693 ncmd = substring (ntxt, 0, ind);
never executed: ncmd = substring (ntxt, 0, ind);
0
1694 else-
1695 {-
1696 free (nline);-
1697 break; /* will free pcomp_line and ocmd later */
never executed: break;
0
1698 }-
1699-
1700 /* Adjust PCOMP_IND and OEND appropriately */-
1701 pcomp_ind += lendiff;-
1702 oend += lendiff;-
1703-
1704 /* Set up values with new line. WORD stays the same. */-
1705 if (ocmd != cmd)
ocmd != cmdDescription
TRUEnever evaluated
FALSEnever evaluated
0
1706 free (ocmd);
never executed: sh_xfree((ocmd), "pcomplete.c", 1706);
0
1707 if (pcomp_line != rl_line_buffer)
pcomp_line != rl_line_bufferDescription
TRUEnever evaluated
FALSEnever evaluated
0
1708 free (pcomp_line);
never executed: sh_xfree((pcomp_line), "pcomplete.c", 1708);
0
1709-
1710 ocmd = ncmd;-
1711 pcomp_line = nline;-
1712-
1713 /* And go back and start over. */-
1714 retry = 1;-
1715 }
never executed: end of block
0
1716#endif /* ALIAS */-
1717-
1718 count++;-
1719-
1720 if (count > 32)
count > 32Description
TRUEnever evaluated
FALSEnever evaluated
0
1721 {-
1722 internal_warning (_("programmable_completion: %s: possible retry loop"), cmd);-
1723 break;
never executed: break;
0
1724 }-
1725 }
never executed: end of block
0
1726 while (retry);
retryDescription
TRUEnever evaluated
FALSEnever evaluated
0
1727-
1728 if (pcomp_line != rl_line_buffer)
pcomp_line != rl_line_bufferDescription
TRUEnever evaluated
FALSEnever evaluated
0
1729 free (pcomp_line);
never executed: sh_xfree((pcomp_line), "pcomplete.c", 1729);
0
1730 if (ocmd != cmd)
ocmd != cmdDescription
TRUEnever evaluated
FALSEnever evaluated
0
1731 free (ocmd);
never executed: sh_xfree((ocmd), "pcomplete.c", 1731);
0
1732-
1733 if (ret)
retDescription
TRUEnever evaluated
FALSEnever evaluated
0
1734 {-
1735 rmatches = ret->list;-
1736 free (ret);-
1737 }
never executed: end of block
0
1738 else-
1739 rmatches = (char **)NULL;
never executed: rmatches = (char **) ((void *)0) ;
0
1740-
1741 if (foundp)
foundpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1742 *foundp = found;
never executed: *foundp = found;
0
1743-
1744 if (lastcs) /* XXX - should be while? */
lastcsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1745 compspec_dispose (lastcs);
never executed: compspec_dispose (lastcs);
0
1746-
1747 /* XXX restore pcomp_line and pcomp_ind? */-
1748 pcomp_line = rl_line_buffer;-
1749 pcomp_ind = rl_point;-
1750-
1751 return (rmatches);
never executed: return (rmatches);
0
1752}-
1753-
1754#endif /* PROGRAMMABLE_COMPLETION */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2