OpenCoverage

assoc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/assoc.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * assoc.c - functions to manipulate associative arrays-
3 *-
4 * Associative arrays are standard shell hash tables.-
5 *-
6 * Chet Ramey-
7 * chet@ins.cwru.edu-
8 */-
9-
10/* Copyright (C) 2008,2009,2011 Free Software Foundation, Inc.-
11-
12 This file is part of GNU Bash, the Bourne Again SHell.-
13-
14 Bash is free software: you can redistribute it and/or modify-
15 it under the terms of the GNU General Public License as published by-
16 the Free Software Foundation, either version 3 of the License, or-
17 (at your option) any later version.-
18-
19 Bash is distributed in the hope that it will be useful,-
20 but WITHOUT ANY WARRANTY; without even the implied warranty of-
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
22 GNU General Public License for more details.-
23-
24 You should have received a copy of the GNU General Public License-
25 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
26*/-
27-
28#include "config.h"-
29-
30#if defined (ARRAY_VARS)-
31-
32#if defined (HAVE_UNISTD_H)-
33# ifdef _MINIX-
34# include <sys/types.h>-
35# endif-
36# include <unistd.h>-
37#endif-
38-
39#include <stdio.h>-
40#include "bashansi.h"-
41-
42#include "shell.h"-
43#include "array.h"-
44#include "assoc.h"-
45#include "builtins/common.h"-
46-
47static WORD_LIST *assoc_to_word_list_internal __P((HASH_TABLE *, int));-
48-
49/* assoc_create == hash_create */-
50-
51void-
52assoc_dispose (hash)-
53 HASH_TABLE *hash;-
54{-
55 if (hash)
hashDescription
TRUEevaluated 111 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-111
56 {-
57 hash_flush (hash, 0);-
58 hash_dispose (hash);-
59 }
executed 111 times by 1 test: end of block
Executed by:
  • Self test
111
60}
executed 111 times by 1 test: end of block
Executed by:
  • Self test
111
61-
62void-
63assoc_flush (hash)-
64 HASH_TABLE *hash;-
65{-
66 hash_flush (hash, 0);-
67}
executed 70 times by 1 test: end of block
Executed by:
  • Self test
70
68-
69int-
70assoc_insert (hash, key, value)-
71 HASH_TABLE *hash;-
72 char *key;-
73 char *value;-
74{-
75 BUCKET_CONTENTS *b;-
76-
77 b = hash_search (key, hash, HASH_CREATE);-
78 if (b == 0)
b == 0Description
TRUEnever evaluated
FALSEevaluated 590 times by 1 test
Evaluated by:
  • Self test
0-590
79 return -1;
never executed: return -1;
0
80 /* If we are overwriting an existing element's value, we're not going to-
81 use the key. Nothing in the array assignment code path frees the key-
82 string, so we can free it here to avoid a memory leak. */-
83 if (b->key != key)
b->key != keyDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 562 times by 1 test
Evaluated by:
  • Self test
28-562
84 free (key);
executed 28 times by 1 test: sh_xfree((key), "assoc.c", 84);
Executed by:
  • Self test
28
85 FREE (b->data);
executed 28 times by 1 test: sh_xfree((b->data), "assoc.c", 85);
Executed by:
  • Self test
b->dataDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 562 times by 1 test
Evaluated by:
  • Self test
28-562
86 b->data = value ? savestring (value) : (char *)0;
valueDescription
TRUEevaluated 590 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-590
87 return (0);
executed 590 times by 1 test: return (0);
Executed by:
  • Self test
590
88}-
89-
90/* Like assoc_insert, but returns b->data instead of freeing it */-
91PTR_T-
92assoc_replace (hash, key, value)-
93 HASH_TABLE *hash;-
94 char *key;-
95 char *value;-
96{-
97 BUCKET_CONTENTS *b;-
98 PTR_T t;-
99-
100 b = hash_search (key, hash, HASH_CREATE);-
101 if (b == 0)
b == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
102 return (PTR_T)0;
never executed: return (void *)0;
0
103 /* If we are overwriting an existing element's value, we're not going to-
104 use the key. Nothing in the array assignment code path frees the key-
105 string, so we can free it here to avoid a memory leak. */-
106 if (b->key != key)
b->key != keyDescription
TRUEnever evaluated
FALSEnever evaluated
0
107 free (key);
never executed: sh_xfree((key), "assoc.c", 107);
0
108 t = b->data;-
109 b->data = value ? savestring (value) : (char *)0;
valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
110 return t;
never executed: return t;
0
111}-
112-
113void-
114assoc_remove (hash, string)-
115 HASH_TABLE *hash;-
116 char *string;-
117{-
118 BUCKET_CONTENTS *b;-
119-
120 b = hash_remove (string, hash, 0);-
121 if (b)
bDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
122 {-
123 free ((char *)b->data);-
124 free (b->key);-
125 free (b);-
126 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
127}
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
128-
129char *-
130assoc_reference (hash, string)-
131 HASH_TABLE *hash;-
132 char *string;-
133{-
134 BUCKET_CONTENTS *b;-
135-
136 if (hash == 0)
hash == 0Description
TRUEnever evaluated
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
0-88
137 return (char *)0;
never executed: return (char *)0;
0
138-
139 b = hash_search (string, hash, 0);-
140 return (b ? (char *)b->data : 0);
executed 88 times by 1 test: return (b ? (char *)b->data : 0);
Executed by:
  • Self test
88
141}-
142-
143/* Quote the data associated with each element of the hash table ASSOC,-
144 using quote_string */-
145HASH_TABLE *-
146assoc_quote (h)-
147 HASH_TABLE *h;-
148{-
149 int i;-
150 BUCKET_CONTENTS *tlist;-
151 char *t;-
152-
153 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-10
154 return ((HASH_TABLE *)NULL);
never executed: return ((HASH_TABLE *) ((void *)0) );
0
155 -
156 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-1280
157 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1280 times by 1 test
Evaluated by:
  • Self test
56-1280
158 {-
159 t = quote_string ((char *)tlist->data);-
160 FREE (tlist->data);
executed 56 times by 1 test: sh_xfree((tlist->data), "assoc.c", 160);
Executed by:
  • Self test
tlist->dataDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-56
161 tlist->data = t;-
162 }
executed 56 times by 1 test: end of block
Executed by:
  • Self test
56
163-
164 return h;
executed 10 times by 1 test: return h;
Executed by:
  • Self test
10
165}-
166-
167/* Quote escape characters in the data associated with each element-
168 of the hash table ASSOC, using quote_escapes */-
169HASH_TABLE *-
170assoc_quote_escapes (h)-
171 HASH_TABLE *h;-
172{-
173 int i;-
174 BUCKET_CONTENTS *tlist;-
175 char *t;-
176-
177 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-10
178 return ((HASH_TABLE *)NULL);
never executed: return ((HASH_TABLE *) ((void *)0) );
0
179 -
180 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEevaluated 1280 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-1280
181 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1280 times by 1 test
Evaluated by:
  • Self test
32-1280
182 {-
183 t = quote_escapes ((char *)tlist->data);-
184 FREE (tlist->data);
executed 32 times by 1 test: sh_xfree((tlist->data), "assoc.c", 184);
Executed by:
  • Self test
tlist->dataDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32
185 tlist->data = t;-
186 }
executed 32 times by 1 test: end of block
Executed by:
  • Self test
32
187-
188 return h;
executed 10 times by 1 test: return h;
Executed by:
  • Self test
10
189}-
190-
191HASH_TABLE *-
192assoc_dequote (h)-
193 HASH_TABLE *h;-
194{-
195 int i;-
196 BUCKET_CONTENTS *tlist;-
197 char *t;-
198-
199 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEnever evaluated
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
200 return ((HASH_TABLE *)NULL);
never executed: return ((HASH_TABLE *) ((void *)0) );
0
201 -
202 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEnever evaluated
FALSEnever evaluated
0
203 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEnever evaluated
FALSEnever evaluated
0
204 {-
205 t = dequote_string ((char *)tlist->data);-
206 FREE (tlist->data);
never executed: sh_xfree((tlist->data), "assoc.c", 206);
tlist->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
207 tlist->data = t;-
208 }
never executed: end of block
0
209-
210 return h;
never executed: return h;
0
211}-
212-
213HASH_TABLE *-
214assoc_dequote_escapes (h)-
215 HASH_TABLE *h;-
216{-
217 int i;-
218 BUCKET_CONTENTS *tlist;-
219 char *t;-
220-
221 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEnever evaluated
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
222 return ((HASH_TABLE *)NULL);
never executed: return ((HASH_TABLE *) ((void *)0) );
0
223 -
224 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEnever evaluated
FALSEnever evaluated
0
225 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEnever evaluated
FALSEnever evaluated
0
226 {-
227 t = dequote_escapes ((char *)tlist->data);-
228 FREE (tlist->data);
never executed: sh_xfree((tlist->data), "assoc.c", 228);
tlist->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
229 tlist->data = t;-
230 }
never executed: end of block
0
231-
232 return h;
never executed: return h;
0
233}-
234-
235HASH_TABLE *-
236assoc_remove_quoted_nulls (h)-
237 HASH_TABLE *h;-
238{-
239 int i;-
240 BUCKET_CONTENTS *tlist;-
241 char *t;-
242-
243 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
244 return ((HASH_TABLE *)NULL);
never executed: return ((HASH_TABLE *) ((void *)0) );
0
245 -
246 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEevaluated 384 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-384
247 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 384 times by 1 test
Evaluated by:
  • Self test
12-384
248 {-
249 t = remove_quoted_nulls ((char *)tlist->data);-
250 tlist->data = t;-
251 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
252-
253 return h;
executed 3 times by 1 test: return h;
Executed by:
  • Self test
3
254}-
255-
256/*-
257 * Return a string whose elements are the members of array H beginning at-
258 * the STARTth element and spanning NELEM members. Null elements are counted.-
259 */-
260char *-
261assoc_subrange (hash, start, nelem, starsub, quoted)-
262HASH_TABLE *hash;-
263arrayind_t start, nelem;-
264int starsub, quoted;-
265{-
266 WORD_LIST *l, *save, *h, *t;-
267 int i, j;-
268 char *ret;-
269-
270 if (assoc_empty (hash))
((hash)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
271 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
272-
273 save = l = assoc_to_word_list (hash);-
274 if (save == 0)
save == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
275 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
276-
277 for (i = 1; l && i < start; i++)
lDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i < startDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
278 l = l->next;
never executed: l = l->next;
0
279 if (l == 0)
l == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
280 {-
281 dispose_words (save);-
282 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
283 }-
284 for (j = 0,h = t = l; l && j < nelem; j++)
lDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
j < nelemDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
285 {-
286 t = l;-
287 l = l->next;-
288 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
289-
290 t->next = (WORD_LIST *)NULL;-
291-
292 ret = string_list_pos_params (starsub ? '*' : '@', h, quoted);-
293-
294 if (t != l)
t != lDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
295 t->next = l;
executed 2 times by 1 test: t->next = l;
Executed by:
  • Self test
2
296-
297 dispose_words (save);-
298 return (ret);
executed 2 times by 1 test: return (ret);
Executed by:
  • Self test
2
299-
300}-
301-
302char *-
303assoc_patsub (h, pat, rep, mflags)-
304 HASH_TABLE *h;-
305 char *pat, *rep;-
306 int mflags;-
307{-
308 BUCKET_CONTENTS *tlist;-
309 int i, slen;-
310 HASH_TABLE *h2;-
311 char *t, *sifs, *ifs;-
312-
313 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-8
314 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
315-
316 h2 = assoc_copy (h);-
317 for (i = 0; i < h2->nbuckets; i++)
i < h2->nbucketsDescription
TRUEevaluated 1024 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-1024
318 for (tlist = hash_items (i, h2); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1024 times by 1 test
Evaluated by:
  • Self test
56-1024
319 {-
320 t = pat_subst ((char *)tlist->data, pat, rep, mflags);-
321 FREE (tlist->data);
executed 56 times by 1 test: sh_xfree((tlist->data), "assoc.c", 321);
Executed by:
  • Self test
tlist->dataDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-56
322 tlist->data = t;-
323 }
executed 56 times by 1 test: end of block
Executed by:
  • Self test
56
324-
325 if (mflags & MATCH_QUOTED)
mflags & 0x020Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-6
326 assoc_quote (h2);
executed 6 times by 1 test: assoc_quote (h2);
Executed by:
  • Self test
6
327 else-
328 assoc_quote_escapes (h2);
executed 2 times by 1 test: assoc_quote_escapes (h2);
Executed by:
  • Self test
2
329-
330 if (mflags & MATCH_STARSUB)
mflags & 0x080Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
1-7
331 {-
332 assoc_remove_quoted_nulls (h2);-
333 sifs = ifs_firstchar ((int *)NULL);-
334 t = assoc_to_string (h2, sifs, 0);-
335 free (sifs);-
336 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
337 else if (mflags & MATCH_QUOTED)
mflags & 0x020Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-5
338 {-
339 /* ${array[@]} */-
340 sifs = ifs_firstchar (&slen);-
341 ifs = getifs ();-
342 if (ifs == 0 || *ifs == 0)
ifs == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
*ifs == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
343 {-
344 if (slen < 2)
slen < 2Description
TRUEnever evaluated
FALSEnever evaluated
0
345 sifs = xrealloc (sifs, 2);
never executed: sifs = sh_xrealloc((sifs), (2), "assoc.c", 345);
0
346 sifs[0] = ' ';-
347 sifs[1] = '\0';-
348 }
never executed: end of block
0
349 t = assoc_to_string (h2, sifs, 0);-
350 free(sifs);-
351 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
352 else-
353 t = assoc_to_string (h2, " ", 0);
executed 2 times by 1 test: t = assoc_to_string (h2, " ", 0);
Executed by:
  • Self test
2
354-
355 assoc_dispose (h2);-
356-
357 return t;
executed 8 times by 1 test: return t;
Executed by:
  • Self test
8
358}-
359-
360char *-
361assoc_modcase (h, pat, modop, mflags)-
362 HASH_TABLE *h;-
363 char *pat;-
364 int modop;-
365 int mflags;-
366{-
367 BUCKET_CONTENTS *tlist;-
368 int i, slen;-
369 HASH_TABLE *h2;-
370 char *t, *sifs, *ifs;-
371-
372 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-12
373 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
374-
375 h2 = assoc_copy (h);-
376 for (i = 0; i < h2->nbuckets; i++)
i < h2->nbucketsDescription
TRUEevaluated 1536 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
12-1536
377 for (tlist = hash_items (i, h2); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1536 times by 1 test
Evaluated by:
  • Self test
32-1536
378 {-
379 t = sh_modcase ((char *)tlist->data, pat, modop);-
380 FREE (tlist->data);
executed 32 times by 1 test: sh_xfree((tlist->data), "assoc.c", 380);
Executed by:
  • Self test
tlist->dataDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32
381 tlist->data = t;-
382 }
executed 32 times by 1 test: end of block
Executed by:
  • Self test
32
383-
384 if (mflags & MATCH_QUOTED)
mflags & 0x020Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
4-8
385 assoc_quote (h2);
executed 4 times by 1 test: assoc_quote (h2);
Executed by:
  • Self test
4
386 else-
387 assoc_quote_escapes (h2);
executed 8 times by 1 test: assoc_quote_escapes (h2);
Executed by:
  • Self test
8
388-
389 if (mflags & MATCH_STARSUB)
mflags & 0x080Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
2-10
390 {-
391 assoc_remove_quoted_nulls (h2);-
392 sifs = ifs_firstchar ((int *)NULL);-
393 t = assoc_to_string (h2, sifs, 0);-
394 free (sifs);-
395 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
396 else if (mflags & MATCH_QUOTED)
mflags & 0x020Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
2-8
397 {-
398 /* ${array[@]} */-
399 sifs = ifs_firstchar (&slen);-
400 ifs = getifs ();-
401 if (ifs == 0 || *ifs == 0)
ifs == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
*ifs == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
402 {-
403 if (slen < 2)
slen < 2Description
TRUEnever evaluated
FALSEnever evaluated
0
404 sifs = xrealloc (sifs, 2);
never executed: sifs = sh_xrealloc((sifs), (2), "assoc.c", 404);
0
405 sifs[0] = ' ';-
406 sifs[1] = '\0';-
407 }
never executed: end of block
0
408 t = assoc_to_string (h2, sifs, 0);-
409 free(sifs);-
410 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
411 else-
412 t = assoc_to_string (h2, " ", 0);
executed 8 times by 1 test: t = assoc_to_string (h2, " ", 0);
Executed by:
  • Self test
8
413-
414 assoc_dispose (h2);-
415-
416 return t;
executed 12 times by 1 test: return t;
Executed by:
  • Self test
12
417}-
418-
419char *-
420assoc_to_assign (hash, quoted)-
421 HASH_TABLE *hash;-
422 int quoted;-
423{-
424 char *ret;-
425 char *istr, *vstr;-
426 int i, rsize, rlen, elen;-
427 BUCKET_CONTENTS *tlist;-
428-
429 if (hash == 0 || assoc_empty (hash))
hash == 0Description
TRUEnever evaluated
FALSEevaluated 121 times by 1 test
Evaluated by:
  • Self test
((hash)->nentries == 0)Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
0-121
430 return (char *)0;
executed 34 times by 1 test: return (char *)0;
Executed by:
  • Self test
34
431-
432 ret = xmalloc (rsize = 128);-
433 ret[0] = '(';-
434 rlen = 1;-
435-
436 for (i = 0; i < hash->nbuckets; i++)
i < hash->nbucketsDescription
TRUEevaluated 11136 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
87-11136
437 for (tlist = hash_items (i, hash); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11136 times by 1 test
Evaluated by:
  • Self test
194-11136
438 {-
439 if (ansic_shouldquote (tlist->key))
ansic_shouldquote (tlist->key)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 193 times by 1 test
Evaluated by:
  • Self test
1-193
440 istr = ansic_quote (tlist->key, 0, (int *)0);
executed 1 time by 1 test: istr = ansic_quote (tlist->key, 0, (int *)0);
Executed by:
  • Self test
1
441 else if (sh_contains_shell_metas (tlist->key))
sh_contains_sh...s (tlist->key)Description
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 123 times by 1 test
Evaluated by:
  • Self test
70-123
442 istr = sh_double_quote (tlist->key);
executed 70 times by 1 test: istr = sh_double_quote (tlist->key);
Executed by:
  • Self test
70
443 else if (ALL_ELEMENT_SUB (tlist->key[0]) && tlist->key[1] == '\0')
(tlist->key[0]) == '@'Description
TRUEnever evaluated
FALSEevaluated 123 times by 1 test
Evaluated by:
  • Self test
(tlist->key[0]) == '*'Description
TRUEnever evaluated
FALSEevaluated 123 times by 1 test
Evaluated by:
  • Self test
tlist->key[1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-123
444 istr = sh_double_quote (tlist->key);
never executed: istr = sh_double_quote (tlist->key);
0
445 else-
446 istr = tlist->key;
executed 123 times by 1 test: istr = tlist->key;
Executed by:
  • Self test
123
447-
448 vstr = tlist->data ? (ansic_shouldquote ((char *)tlist->data) ?
tlist->dataDescription
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
ansic_shouldqu...*)tlist->data)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 193 times by 1 test
Evaluated by:
  • Self test
0-194
449 ansic_quote ((char *)tlist->data, 0, (int *)0) :-
450 sh_double_quote ((char *)tlist->data))-
451 : (char *)0;-
452-
453 elen = STRLEN (istr) + 8 + STRLEN (vstr);
(istr)[1]Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
(istr)[2]Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)[1]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)[2]Description
TRUEevaluated 186 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(istr)Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(istr)[0]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)[0]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-194
454 RESIZE_MALLOCED_BUFFER (ret, rlen, (elen+1), rsize, rsize);
never executed: rsize += (rsize);
never executed: end of block
(rlen) + ((elen+1)) >= rsizeDescription
TRUEnever evaluated
FALSEevaluated 194 times by 1 test
Evaluated by:
  • Self test
(rlen) + ((elen+1)) >= rsizeDescription
TRUEnever evaluated
FALSEnever evaluated
0-194
455-
456 ret[rlen++] = '[';-
457 strcpy (ret+rlen, istr);-
458 rlen += STRLEN (istr);
(istr)[1]Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
(istr)[2]Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(istr)Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(istr)[0]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-194
459 ret[rlen++] = ']';-
460 ret[rlen++] = '=';-
461 if (vstr)
vstrDescription
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-194
462 {-
463 strcpy (ret + rlen, vstr);-
464 rlen += STRLEN (vstr);
(vstr)[1]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)[2]Description
TRUEevaluated 186 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(vstr)Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(vstr)[0]Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-194
465 }
executed 194 times by 1 test: end of block
Executed by:
  • Self test
194
466 ret[rlen++] = ' ';-
467-
468-
469 if (istr != tlist->key)
istr != tlist->keyDescription
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 123 times by 1 test
Evaluated by:
  • Self test
71-123
470 FREE (istr);
executed 71 times by 1 test: sh_xfree((istr), "assoc.c", 470);
Executed by:
  • Self test
executed 71 times by 1 test: end of block
Executed by:
  • Self test
istrDescription
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-71
471-
472 FREE (vstr);
executed 194 times by 1 test: sh_xfree((vstr), "assoc.c", 472);
Executed by:
  • Self test
vstrDescription
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-194
473 }
executed 194 times by 1 test: end of block
Executed by:
  • Self test
194
474-
475 RESIZE_MALLOCED_BUFFER (ret, rlen, 1, rsize, 8);
never executed: rsize += (8);
never executed: end of block
(rlen) + (1) >= rsizeDescription
TRUEnever evaluated
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
(rlen) + (1) >= rsizeDescription
TRUEnever evaluated
FALSEnever evaluated
0-87
476 ret[rlen++] = ')';-
477 ret[rlen] = '\0';-
478-
479 if (quoted)
quotedDescription
TRUEnever evaluated
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
0-87
480 {-
481 vstr = sh_single_quote (ret);-
482 free (ret);-
483 ret = vstr;-
484 }
never executed: end of block
0
485-
486 return ret;
executed 87 times by 1 test: return ret;
Executed by:
  • Self test
87
487}-
488-
489static WORD_LIST *-
490assoc_to_word_list_internal (h, t)-
491 HASH_TABLE *h;-
492 int t;-
493{-
494 WORD_LIST *list;-
495 int i;-
496 BUCKET_CONTENTS *tlist;-
497 char *w;-
498-
499 if (h == 0 || assoc_empty (h))
h == 0Description
TRUEnever evaluated
FALSEevaluated 129 times by 1 test
Evaluated by:
  • Self test
((h)->nentries == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
0-129
500 return((WORD_LIST *)NULL);
executed 1 time by 1 test: return((WORD_LIST *) ((void *)0) );
Executed by:
  • Self test
1
501 list = (WORD_LIST *)NULL;-
502 -
503 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEevaluated 15872 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
128-15872
504 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 424 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15872 times by 1 test
Evaluated by:
  • Self test
424-15872
505 {-
506 w = (t == 0) ? (char *)tlist->data : (char *)tlist->key;
(t == 0)Description
TRUEevaluated 367 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
57-367
507 list = make_word_list (make_bare_word(w), list);-
508 }
executed 424 times by 1 test: end of block
Executed by:
  • Self test
424
509 return (REVERSE_LIST(list, WORD_LIST *));
executed 128 times by 1 test: return (((list && list->next) ? (WORD_LIST *)list_reverse ((GENERIC_LIST *)list) : (WORD_LIST *)(list)));
Executed by:
  • Self test
128
510}-
511-
512WORD_LIST *-
513assoc_to_word_list (h)-
514 HASH_TABLE *h;-
515{-
516 return (assoc_to_word_list_internal (h, 0));
executed 97 times by 1 test: return (assoc_to_word_list_internal (h, 0));
Executed by:
  • Self test
97
517}-
518-
519WORD_LIST *-
520assoc_keys_to_word_list (h)-
521 HASH_TABLE *h;-
522{-
523 return (assoc_to_word_list_internal (h, 1));
executed 32 times by 1 test: return (assoc_to_word_list_internal (h, 1));
Executed by:
  • Self test
32
524}-
525-
526char *-
527assoc_to_string (h, sep, quoted)-
528 HASH_TABLE *h;-
529 char *sep;-
530 int quoted;-
531{-
532 BUCKET_CONTENTS *tlist;-
533 int i;-
534 char *result, *t, *w;-
535 WORD_LIST *list, *l;-
536-
537 if (h == 0)
h == 0Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
0-20
538 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
539 if (assoc_empty (h))
((h)->nentries == 0)Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
0-20
540 return (savestring (""));
never executed: return ((char *)strcpy (sh_xmalloc((1 + strlen ("")), "assoc.c", 540), ("")));
0
541-
542 result = NULL;-
543 l = list = NULL;-
544 /* This might be better implemented directly, but it's simple to implement-
545 by converting to a word list first, possibly quoting the data, then-
546 using list_string */-
547 for (i = 0; i < h->nbuckets; i++)
i < h->nbucketsDescription
TRUEevaluated 2560 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
20-2560
548 for (tlist = hash_items (i, h); tlist; tlist = tlist->next)
tlistDescription
TRUEevaluated 88 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2560 times by 1 test
Evaluated by:
  • Self test
88-2560
549 {-
550 w = (char *)tlist->data;-
551 if (w == 0)
w == 0Description
TRUEnever evaluated
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
0-88
552 continue;
never executed: continue;
0
553 t = quoted ? quote_string (w) : savestring (w);
quotedDescription
TRUEnever evaluated
FALSEevaluated 88 times by 1 test
Evaluated by:
  • Self test
0-88
554 list = make_word_list (make_bare_word(t), list);-
555 FREE (t);
executed 88 times by 1 test: sh_xfree((t), "assoc.c", 555);
Executed by:
  • Self test
tDescription
TRUEevaluated 88 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-88
556 }
executed 88 times by 1 test: end of block
Executed by:
  • Self test
88
557-
558 l = REVERSE_LIST(list, WORD_LIST *);
listDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
list->nextDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-20
559-
560 result = l ? string_list_internal (l, sep) : savestring ("");
lDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-20
561 dispose_words (l); -
562-
563 return result;
executed 20 times by 1 test: return result;
Executed by:
  • Self test
20
564}-
565-
566#endif /* ARRAY_VARS */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2