OpenCoverage

pcomplib.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/pcomplib.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* pcomplib.c - library functions for programmable completion. */-
2-
3/* Copyright (C) 1999-2009 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 "bashansi.h"-
26#include <stdio.h>-
27-
28#if defined (HAVE_UNISTD_H)-
29# ifdef _MINIX-
30# include <sys/types.h>-
31# endif-
32# include <unistd.h>-
33#endif-
34-
35#include "bashintl.h"-
36-
37#include "shell.h"-
38#include "pcomplete.h"-
39-
40#define COMPLETE_HASH_BUCKETS 256 /* must be power of two */-
41-
42#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)-
43-
44HASH_TABLE *prog_completes = (HASH_TABLE *)NULL;-
45-
46static void free_progcomp __P((PTR_T));-
47-
48COMPSPEC *-
49compspec_create ()-
50{-
51 COMPSPEC *ret;-
52-
53 ret = (COMPSPEC *)xmalloc (sizeof (COMPSPEC));-
54 ret->refcount = 0;-
55-
56 ret->actions = (unsigned long)0;-
57 ret->options = (unsigned long)0;-
58-
59 ret->globpat = (char *)NULL;-
60 ret->words = (char *)NULL;-
61 ret->prefix = (char *)NULL;-
62 ret->suffix = (char *)NULL;-
63 ret->funcname = (char *)NULL;-
64 ret->command = (char *)NULL;-
65 ret->lcommand = (char *)NULL;-
66 ret->filterpat = (char *)NULL;-
67-
68 return ret;
executed 209 times by 1 test: return ret;
Executed by:
  • Self test
209
69}-
70-
71void-
72compspec_dispose (cs)-
73 COMPSPEC *cs;-
74{-
75 cs->refcount--;-
76 if (cs->refcount == 0)
cs->refcount == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
77 {-
78 FREE (cs->globpat);
never executed: sh_xfree((cs->globpat), "pcomplib.c", 78);
cs->globpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
79 FREE (cs->words);
never executed: sh_xfree((cs->words), "pcomplib.c", 79);
cs->wordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
80 FREE (cs->prefix);
never executed: sh_xfree((cs->prefix), "pcomplib.c", 80);
cs->prefixDescription
TRUEnever evaluated
FALSEnever evaluated
0
81 FREE (cs->suffix);
never executed: sh_xfree((cs->suffix), "pcomplib.c", 81);
cs->suffixDescription
TRUEnever evaluated
FALSEnever evaluated
0
82 FREE (cs->funcname);
never executed: sh_xfree((cs->funcname), "pcomplib.c", 82);
cs->funcnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
83 FREE (cs->command);
never executed: sh_xfree((cs->command), "pcomplib.c", 83);
cs->commandDescription
TRUEnever evaluated
FALSEnever evaluated
0
84 FREE (cs->lcommand);
never executed: sh_xfree((cs->lcommand), "pcomplib.c", 84);
cs->lcommandDescription
TRUEnever evaluated
FALSEnever evaluated
0
85 FREE (cs->filterpat);
never executed: sh_xfree((cs->filterpat), "pcomplib.c", 85);
cs->filterpatDescription
TRUEnever evaluated
FALSEnever evaluated
0
86-
87 free (cs);-
88 }
never executed: end of block
0
89}
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
90-
91COMPSPEC *-
92compspec_copy (cs)-
93 COMPSPEC *cs;-
94{-
95 COMPSPEC *new;-
96-
97 new = (COMPSPEC *)xmalloc (sizeof (COMPSPEC));-
98-
99 new->refcount = 1; /* was cs->refcount, but this is a fresh copy */-
100 new->actions = cs->actions;-
101 new->options = cs->options;-
102-
103 new->globpat = STRDUP (cs->globpat);
(cs->globpat)Description
TRUEnever evaluated
FALSEnever evaluated
0
104 new->words = STRDUP (cs->words);
(cs->words)Description
TRUEnever evaluated
FALSEnever evaluated
0
105 new->prefix = STRDUP (cs->prefix);
(cs->prefix)Description
TRUEnever evaluated
FALSEnever evaluated
0
106 new->suffix = STRDUP (cs->suffix);
(cs->suffix)Description
TRUEnever evaluated
FALSEnever evaluated
0
107 new->funcname = STRDUP (cs->funcname);
(cs->funcname)Description
TRUEnever evaluated
FALSEnever evaluated
0
108 new->command = STRDUP (cs->command);
(cs->command)Description
TRUEnever evaluated
FALSEnever evaluated
0
109 new->lcommand = STRDUP (cs->lcommand);
(cs->lcommand)Description
TRUEnever evaluated
FALSEnever evaluated
0
110 new->filterpat = STRDUP (cs->filterpat);
(cs->filterpat)Description
TRUEnever evaluated
FALSEnever evaluated
0
111-
112 return new;
never executed: return new;
0
113}-
114-
115void-
116progcomp_create ()-
117{-
118 if (prog_completes == 0)
prog_completes == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
119 prog_completes = hash_create (COMPLETE_HASH_BUCKETS);
executed 2 times by 1 test: prog_completes = hash_create (256);
Executed by:
  • Self test
2
120}
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
121-
122int-
123progcomp_size ()-
124{-
125 return (HASH_ENTRIES (prog_completes));
never executed: return (((prog_completes) ? (prog_completes)->nentries : 0));
0
126}-
127-
128static void-
129free_progcomp (data)-
130 PTR_T data;-
131{-
132 COMPSPEC *cs;-
133-
134 cs = (COMPSPEC *)data;-
135 compspec_dispose (cs);-
136}
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
137 -
138void-
139progcomp_flush ()-
140{-
141 if (prog_completes)
prog_completesDescription
TRUEnever evaluated
FALSEnever evaluated
0
142 hash_flush (prog_completes, free_progcomp);
never executed: hash_flush (prog_completes, free_progcomp);
0
143}
never executed: end of block
0
144-
145void-
146progcomp_dispose ()-
147{-
148 if (prog_completes)
prog_completesDescription
TRUEnever evaluated
FALSEnever evaluated
0
149 hash_dispose (prog_completes);
never executed: hash_dispose (prog_completes);
0
150 prog_completes = (HASH_TABLE *)NULL;-
151}
never executed: end of block
0
152-
153int-
154progcomp_remove (cmd)-
155 char *cmd;-
156{-
157 register BUCKET_CONTENTS *item;-
158-
159 if (prog_completes == 0)
prog_completes == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
160 return 1;
never executed: return 1;
0
161-
162 item = hash_remove (cmd, prog_completes, 0);-
163 if (item)
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
164 {-
165 if (item->data)
item->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 free_progcomp (item->data);
never executed: free_progcomp (item->data);
0
167 free (item->key);-
168 free (item);-
169 return (1);
never executed: return (1);
0
170 }-
171 return (0);
never executed: return (0);
0
172}-
173-
174int-
175progcomp_insert (cmd, cs)-
176 char *cmd;-
177 COMPSPEC *cs;-
178{-
179 register BUCKET_CONTENTS *item;-
180-
181 if (cs == NULL)
cs == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 601 times by 1 test
Evaluated by:
  • Self test
0-601
182 programming_error (_("progcomp_insert: %s: NULL COMPSPEC"), cmd);
never executed: programming_error ( dcgettext (((void *)0), "progcomp_insert: %s: NULL COMPSPEC" , 5) , cmd);
0
183-
184 if (prog_completes == 0)
prog_completes == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 599 times by 1 test
Evaluated by:
  • Self test
2-599
185 progcomp_create ();
executed 2 times by 1 test: progcomp_create ();
Executed by:
  • Self test
2
186-
187 cs->refcount++;-
188 item = hash_insert (cmd, prog_completes, 0);-
189 if (item->data)
item->dataDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 599 times by 1 test
Evaluated by:
  • Self test
2-599
190 free_progcomp (item->data);
executed 2 times by 1 test: free_progcomp (item->data);
Executed by:
  • Self test
2
191 else-
192 item->key = savestring (cmd);
executed 599 times by 1 test: item->key = (char *)strcpy (sh_xmalloc((1 + strlen (cmd)), "pcomplib.c", 192), (cmd));
Executed by:
  • Self test
599
193 item->data = cs;-
194-
195 return 1;
executed 601 times by 1 test: return 1;
Executed by:
  • Self test
601
196}-
197-
198COMPSPEC *-
199progcomp_search (cmd)-
200 const char *cmd;-
201{-
202 register BUCKET_CONTENTS *item;-
203 COMPSPEC *cs;-
204-
205 if (prog_completes == 0)
prog_completes == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
206 return ((COMPSPEC *)NULL);
never executed: return ((COMPSPEC *) ((void *)0) );
0
207-
208 item = hash_search (cmd, prog_completes, 0);-
209-
210 if (item == NULL)
item == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
211 return ((COMPSPEC *)NULL);
never executed: return ((COMPSPEC *) ((void *)0) );
0
212-
213 cs = (COMPSPEC *)item->data;-
214-
215 return (cs);
never executed: return (cs);
0
216}-
217-
218void-
219progcomp_walk (pfunc)-
220 hash_wfunc *pfunc;-
221{-
222 if (prog_completes == 0 || pfunc == 0 || HASH_ENTRIES (prog_completes) == 0)
(prog_completes)Description
TRUEnever evaluated
FALSEnever evaluated
prog_completes == 0Description
TRUEnever evaluated
FALSEnever evaluated
pfunc == 0Description
TRUEnever evaluated
FALSEnever evaluated
((prog_complet...ries : 0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
223 return;
never executed: return;
0
224-
225 hash_walk (prog_completes, pfunc);-
226}
never executed: end of block
0
227-
228#endif /* PROGRAMMABLE_COMPLETION */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2