Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/hash.def |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | - | |||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | extern int dot_found_in_search; | - | ||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||
13 | static int add_hashed_command (char *, int); | - | ||||||||||||||||||||||||
14 | static int print_hash_info (BUCKET_CONTENTS *); | - | ||||||||||||||||||||||||
15 | static int print_portable_hash_info (BUCKET_CONTENTS *); | - | ||||||||||||||||||||||||
16 | static int print_hashed_commands (int); | - | ||||||||||||||||||||||||
17 | static int list_hashed_filename_targets (WORD_LIST *, int); | - | ||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||
22 | int | - | ||||||||||||||||||||||||
23 | hash_builtin (list) | - | ||||||||||||||||||||||||
24 | WORD_LIST *list; | - | ||||||||||||||||||||||||
25 | { | - | ||||||||||||||||||||||||
26 | int expunge_hash_table, list_targets, list_portably, delete, opt; | - | ||||||||||||||||||||||||
27 | char *w, *pathname; | - | ||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | if (hashing_enabled == 0
| 5-46 | ||||||||||||||||||||||||
30 | { | - | ||||||||||||||||||||||||
31 | builtin_error ( | - | ||||||||||||||||||||||||
32 | dcgettext (((void *)0), | - | ||||||||||||||||||||||||
33 | "hashing disabled" | - | ||||||||||||||||||||||||
34 | , 5) | - | ||||||||||||||||||||||||
35 | ); | - | ||||||||||||||||||||||||
36 | return executed 5 times by 1 test: (1);return (1); Executed by:
executed 5 times by 1 test: return (1); Executed by:
| 5 | ||||||||||||||||||||||||
37 | } | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | expunge_hash_table = list_targets = list_portably = delete = 0; | - | ||||||||||||||||||||||||
40 | pathname = (char *) | - | ||||||||||||||||||||||||
41 | ((void *)0) | - | ||||||||||||||||||||||||
42 | ; | - | ||||||||||||||||||||||||
43 | reset_internal_getopt (); | - | ||||||||||||||||||||||||
44 | while ((
| 23-41 | ||||||||||||||||||||||||
45 | { | - | ||||||||||||||||||||||||
46 | switch (opt) | - | ||||||||||||||||||||||||
47 | { | - | ||||||||||||||||||||||||
48 | case never executed: 'd':case 'd': never executed: case 'd': | 0 | ||||||||||||||||||||||||
49 | delete = 1; | - | ||||||||||||||||||||||||
50 | break; never executed: break; | 0 | ||||||||||||||||||||||||
51 | case never executed: 'l':case 'l': never executed: case 'l': | 0 | ||||||||||||||||||||||||
52 | list_portably = 1; | - | ||||||||||||||||||||||||
53 | break; never executed: break; | 0 | ||||||||||||||||||||||||
54 | case executed 6 times by 1 test: 'p':case 'p': Executed by:
executed 6 times by 1 test: case 'p': Executed by:
| 6 | ||||||||||||||||||||||||
55 | pathname = list_optarg; | - | ||||||||||||||||||||||||
56 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||||||||||||||
57 | case executed 12 times by 1 test: 'r':case 'r': Executed by:
executed 12 times by 1 test: case 'r': Executed by:
| 12 | ||||||||||||||||||||||||
58 | expunge_hash_table = 1; | - | ||||||||||||||||||||||||
59 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||||||||
60 | case never executed: 't':case 't': never executed: case 't': | 0 | ||||||||||||||||||||||||
61 | list_targets = 1; | - | ||||||||||||||||||||||||
62 | break; never executed: break; | 0 | ||||||||||||||||||||||||
63 | case never executed: -99:case -99: never executed: builtin_help (); returncase -99: never executed: (258);return (258); never executed: return (258); | 0 | ||||||||||||||||||||||||
64 | default executed 5 times by 1 test: :default: Executed by:
executed 5 times by 1 test: default: Executed by:
| 5 | ||||||||||||||||||||||||
65 | builtin_usage (); | - | ||||||||||||||||||||||||
66 | return executed 5 times by 1 test: (258);return (258); Executed by:
executed 5 times by 1 test: return (258); Executed by:
| 5 | ||||||||||||||||||||||||
67 | } | - | ||||||||||||||||||||||||
68 | } | - | ||||||||||||||||||||||||
69 | list = loptend; | - | ||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | if (list == 0
| 0-22 | ||||||||||||||||||||||||
73 | { | - | ||||||||||||||||||||||||
74 | sh_needarg ("-t"); | - | ||||||||||||||||||||||||
75 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
76 | } | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | if (list == 0
| 10-22 | ||||||||||||||||||||||||
81 | { | - | ||||||||||||||||||||||||
82 | opt = print_hashed_commands (list_portably); | - | ||||||||||||||||||||||||
83 | if (opt == 0
| 0-7 | ||||||||||||||||||||||||
84 | printf ( executed 7 times by 1 test: printf ( dcgettext (((void *)0), "%s: hash table empty\n" , 5) , this_command_name); Executed by:
| 7 | ||||||||||||||||||||||||
85 | dcgettext (((void *)0), executed 7 times by 1 test: printf ( dcgettext (((void *)0), "%s: hash table empty\n" , 5) , this_command_name); Executed by:
| 7 | ||||||||||||||||||||||||
86 | "%s: hash table empty\n" executed 7 times by 1 test: printf ( dcgettext (((void *)0), "%s: hash table empty\n" , 5) , this_command_name); Executed by:
| 7 | ||||||||||||||||||||||||
87 | , 5) executed 7 times by 1 test: printf ( dcgettext (((void *)0), "%s: hash table empty\n" , 5) , this_command_name); Executed by:
| 7 | ||||||||||||||||||||||||
88 | , this_command_name); executed 7 times by 1 test: printf ( dcgettext (((void *)0), "%s: hash table empty\n" , 5) , this_command_name); Executed by:
| 7 | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | return executed 10 times by 1 test: (0);return (0); Executed by:
executed 10 times by 1 test: return (0); Executed by:
| 10 | ||||||||||||||||||||||||
91 | } | - | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | if (expunge_hash_table
| 12-19 | ||||||||||||||||||||||||
94 | phash_flush (); executed 12 times by 1 test: phash_flush (); Executed by:
| 12 | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | if (list_targets
| 0-31 | ||||||||||||||||||||||||
98 | return never executed: (list_hashed_filename_targets (list, list_portably));return (list_hashed_filename_targets (list, list_portably)); never executed: return (list_hashed_filename_targets (list, list_portably)); | 0 | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||
101 | if (restricted
| 0-31 | ||||||||||||||||||||||||
102 | { | - | ||||||||||||||||||||||||
103 | if ( | - | ||||||||||||||||||||||||
104 | (
| 0 | ||||||||||||||||||||||||
105 | '/'
| 0 | ||||||||||||||||||||||||
106 | )
| 0 | ||||||||||||||||||||||||
107 | pathname
| 0 | ||||||||||||||||||||||||
108 | )
| 0 | ||||||||||||||||||||||||
109 | '/'
| 0 | ||||||||||||||||||||||||
110 | ) == '\0'
| 0 | ||||||||||||||||||||||||
111 | pathname
| 0 | ||||||||||||||||||||||||
112 | ,
| 0 | ||||||||||||||||||||||||
113 | '/'
| 0 | ||||||||||||||||||||||||
114 | ) : __builtin_strchr (
| 0 | ||||||||||||||||||||||||
115 | pathname
| 0 | ||||||||||||||||||||||||
116 | ,
| 0 | ||||||||||||||||||||||||
117 | '/'
| 0 | ||||||||||||||||||||||||
118 | )))
| 0 | ||||||||||||||||||||||||
119 | ) | - | ||||||||||||||||||||||||
120 | { | - | ||||||||||||||||||||||||
121 | sh_restricted (pathname); | - | ||||||||||||||||||||||||
122 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
123 | } | - | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | w = find_user_command (pathname); | - | ||||||||||||||||||||||||
127 | if (w == 0
| 0 | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | sh_notfound (pathname); | - | ||||||||||||||||||||||||
130 | sh_xfree((w), "./hash.def", 164); | - | ||||||||||||||||||||||||
131 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||||||||||||||
132 | } | - | ||||||||||||||||||||||||
133 | sh_xfree((w), "./hash.def", 167); | - | ||||||||||||||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | for (opt = 0; list
| 19-31 | ||||||||||||||||||||||||
138 | { | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | w = list->word->word; | - | ||||||||||||||||||||||||
141 | if (absolute_program (w)
| 0-19 | ||||||||||||||||||||||||
142 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
143 | else if (pathname
| 6-13 | ||||||||||||||||||||||||
144 | { | - | ||||||||||||||||||||||||
145 | if (is_directory (pathname)
| 0-6 | ||||||||||||||||||||||||
146 | { | - | ||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | builtin_error ("%s: %s", pathname, strerror ( | - | ||||||||||||||||||||||||
149 | 21 | - | ||||||||||||||||||||||||
150 | )); | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | opt = 1; | - | ||||||||||||||||||||||||
155 | } never executed: end of block | 0 | ||||||||||||||||||||||||
156 | else | - | ||||||||||||||||||||||||
157 | phash_insert (w, pathname, 0, 0); executed 6 times by 1 test: phash_insert (w, pathname, 0, 0); Executed by:
| 6 | ||||||||||||||||||||||||
158 | } | - | ||||||||||||||||||||||||
159 | else if (delete
| 0-13 | ||||||||||||||||||||||||
160 | { | - | ||||||||||||||||||||||||
161 | if (phash_remove (w)
| 0 | ||||||||||||||||||||||||
162 | { | - | ||||||||||||||||||||||||
163 | sh_notfound (w); | - | ||||||||||||||||||||||||
164 | opt = 1; | - | ||||||||||||||||||||||||
165 | } never executed: end of block | 0 | ||||||||||||||||||||||||
166 | } never executed: end of block | 0 | ||||||||||||||||||||||||
167 | else if (add_hashed_command (w, 0)
| 5-8 | ||||||||||||||||||||||||
168 | opt = 1; executed 5 times by 1 test: opt = 1; Executed by:
| 5 | ||||||||||||||||||||||||
169 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | fflush ( | - | ||||||||||||||||||||||||
172 | stdout | - | ||||||||||||||||||||||||
173 | ); | - | ||||||||||||||||||||||||
174 | return executed 31 times by 1 test: (opt);return (opt); Executed by:
executed 31 times by 1 test: return (opt); Executed by:
| 31 | ||||||||||||||||||||||||
175 | } | - | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | static int | - | ||||||||||||||||||||||||
178 | add_hashed_command (w, quiet) | - | ||||||||||||||||||||||||
179 | char *w; | - | ||||||||||||||||||||||||
180 | int quiet; | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | int rv; | - | ||||||||||||||||||||||||
183 | char *full_path; | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | rv = 0; | - | ||||||||||||||||||||||||
186 | if (find_function (w) == 0
| 0-13 | ||||||||||||||||||||||||
187 | { | - | ||||||||||||||||||||||||
188 | phash_remove (w); | - | ||||||||||||||||||||||||
189 | full_path = find_user_command (w); | - | ||||||||||||||||||||||||
190 | if (full_path
| 0-8 | ||||||||||||||||||||||||
191 | phash_insert (w, full_path, dot_found_in_search, 0); executed 8 times by 1 test: phash_insert (w, full_path, dot_found_in_search, 0); Executed by:
| 8 | ||||||||||||||||||||||||
192 | else | - | ||||||||||||||||||||||||
193 | { | - | ||||||||||||||||||||||||
194 | if (quiet == 0
| 0-5 | ||||||||||||||||||||||||
195 | sh_notfound (w); executed 5 times by 1 test: sh_notfound (w); Executed by:
| 5 | ||||||||||||||||||||||||
196 | rv++; | - | ||||||||||||||||||||||||
197 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||
198 | do { if (full_path
executed 8 times by 1 test: } while (0);sh_xfree((full_path), "./hash.def", 228); Executed by:
| 5-8 | ||||||||||||||||||||||||
199 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||
200 | return executed 13 times by 1 test: (rv);return (rv); Executed by:
executed 13 times by 1 test: return (rv); Executed by:
| 13 | ||||||||||||||||||||||||
201 | } | - | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | static int | - | ||||||||||||||||||||||||
205 | print_hash_info (item) | - | ||||||||||||||||||||||||
206 | BUCKET_CONTENTS *item; | - | ||||||||||||||||||||||||
207 | { | - | ||||||||||||||||||||||||
208 | printf ("%4d\t%s\n", item->times_found, ((PATH_DATA *)(item)->data)->path); | - | ||||||||||||||||||||||||
209 | return executed 8 times by 1 test: 0;return 0; Executed by:
executed 8 times by 1 test: return 0; Executed by:
| 8 | ||||||||||||||||||||||||
210 | } | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | static int | - | ||||||||||||||||||||||||
213 | print_portable_hash_info (item) | - | ||||||||||||||||||||||||
214 | BUCKET_CONTENTS *item; | - | ||||||||||||||||||||||||
215 | { | - | ||||||||||||||||||||||||
216 | char *fp, *fn; | - | ||||||||||||||||||||||||
217 | - | |||||||||||||||||||||||||
218 | fp = printable_filename (((PATH_DATA *)(item)->data)->path, 1); | - | ||||||||||||||||||||||||
219 | fn = printable_filename (item->key, 1); | - | ||||||||||||||||||||||||
220 | printf ("builtin hash -p %s %s\n", fp, fn); | - | ||||||||||||||||||||||||
221 | if (fp != ((PATH_DATA *)(item)->data)->path
| 0 | ||||||||||||||||||||||||
222 | sh_xfree((fp), "./hash.def", 252); never executed: sh_xfree((fp), "./hash.def", 252); | 0 | ||||||||||||||||||||||||
223 | if (fn != item->key
| 0 | ||||||||||||||||||||||||
224 | sh_xfree((fn), "./hash.def", 254); never executed: sh_xfree((fn), "./hash.def", 254); | 0 | ||||||||||||||||||||||||
225 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
226 | } | - | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | static int | - | ||||||||||||||||||||||||
229 | print_hashed_commands (fmt) | - | ||||||||||||||||||||||||
230 | int fmt; | - | ||||||||||||||||||||||||
231 | { | - | ||||||||||||||||||||||||
232 | if (hashed_filenames == 0
| 0-7 | ||||||||||||||||||||||||
233 | return executed 7 times by 1 test: (0);return (0); Executed by:
executed 7 times by 1 test: return (0); Executed by:
| 7 | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | if (fmt == 0
| 0-3 | ||||||||||||||||||||||||
236 | printf ( executed 3 times by 1 test: printf ( dcgettext (((void *)0), "hits\tcommand\n" , 5) ); Executed by:
| 3 | ||||||||||||||||||||||||
237 | dcgettext (((void *)0), executed 3 times by 1 test: printf ( dcgettext (((void *)0), "hits\tcommand\n" , 5) ); Executed by:
| 3 | ||||||||||||||||||||||||
238 | "hits\tcommand\n" executed 3 times by 1 test: printf ( dcgettext (((void *)0), "hits\tcommand\n" , 5) ); Executed by:
| 3 | ||||||||||||||||||||||||
239 | , 5) executed 3 times by 1 test: printf ( dcgettext (((void *)0), "hits\tcommand\n" , 5) ); Executed by:
| 3 | ||||||||||||||||||||||||
240 | ); executed 3 times by 1 test: printf ( dcgettext (((void *)0), "hits\tcommand\n" , 5) ); Executed by:
| 3 | ||||||||||||||||||||||||
241 | hash_walk (hashed_filenames, fmt ? print_portable_hash_info : print_hash_info); | - | ||||||||||||||||||||||||
242 | return executed 3 times by 1 test: (1);return (1); Executed by:
executed 3 times by 1 test: return (1); Executed by:
| 3 | ||||||||||||||||||||||||
243 | } | - | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | static int | - | ||||||||||||||||||||||||
246 | list_hashed_filename_targets (list, fmt) | - | ||||||||||||||||||||||||
247 | WORD_LIST *list; | - | ||||||||||||||||||||||||
248 | int fmt; | - | ||||||||||||||||||||||||
249 | { | - | ||||||||||||||||||||||||
250 | int all_found, multiple; | - | ||||||||||||||||||||||||
251 | char *target; | - | ||||||||||||||||||||||||
252 | WORD_LIST *l; | - | ||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||
254 | all_found = 1; | - | ||||||||||||||||||||||||
255 | multiple = list->next != 0; | - | ||||||||||||||||||||||||
256 | - | |||||||||||||||||||||||||
257 | for (l = list; l
| 0 | ||||||||||||||||||||||||
258 | { | - | ||||||||||||||||||||||||
259 | target = phash_search (l->word->word); | - | ||||||||||||||||||||||||
260 | if (target == 0
| 0 | ||||||||||||||||||||||||
261 | { | - | ||||||||||||||||||||||||
262 | all_found = 0; | - | ||||||||||||||||||||||||
263 | sh_notfound (l->word->word); | - | ||||||||||||||||||||||||
264 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
265 | } | - | ||||||||||||||||||||||||
266 | if (fmt
| 0 | ||||||||||||||||||||||||
267 | printf ("builtin hash -p %s %s\n", target, l->word->word); never executed: printf ("builtin hash -p %s %s\n", target, l->word->word); | 0 | ||||||||||||||||||||||||
268 | else | - | ||||||||||||||||||||||||
269 | { | - | ||||||||||||||||||||||||
270 | if (multiple
| 0 | ||||||||||||||||||||||||
271 | printf ("%s\t", l->word->word); never executed: printf ("%s\t", l->word->word); | 0 | ||||||||||||||||||||||||
272 | printf ("%s\n", target); | - | ||||||||||||||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||||||||||||||
274 | sh_xfree((target), "./hash.def", 300); | - | ||||||||||||||||||||||||
275 | } never executed: end of block | 0 | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | return never executed: (all_found ? 0 : 1);return (all_found ? 0 : 1); never executed: return (all_found ? 0 : 1); | 0 | ||||||||||||||||||||||||
278 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |