Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/array.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
2 | * array.c - functions to create, destroy, access, and manipulate arrays | - | ||||||||||||||||||||||||||||||||||||||||||||||||
3 | * of strings. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
4 | * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
5 | * Arrays are sparse doubly-linked lists. An element's index is stored | - | ||||||||||||||||||||||||||||||||||||||||||||||||
6 | * with it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
7 | * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
8 | * Chet Ramey | - | ||||||||||||||||||||||||||||||||||||||||||||||||
9 | * chet@ins.cwru.edu | - | ||||||||||||||||||||||||||||||||||||||||||||||||
10 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
11 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
12 | /* Copyright (C) 1997-2016 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
14 | This file is part of GNU Bash, the Bourne Again SHell. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
16 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||||||||
17 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||||||||
18 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
19 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
21 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
24 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
26 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||||||||
27 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
28 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
30 | #include "config.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
32 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
34 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
35 | # ifdef _MINIX | - | ||||||||||||||||||||||||||||||||||||||||||||||||
36 | # include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
37 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
38 | # include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
39 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
41 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
42 | #include "bashansi.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
44 | #include "shell.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
45 | #include "array.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
46 | #include "builtins/common.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
48 | #define ADD_BEFORE(ae, new) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
49 | do { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
50 | ae->prev->next = new; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
51 | new->prev = ae->prev; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
52 | ae->prev = new; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
53 | new->next = ae; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
54 | } while(0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
56 | #define ADD_AFTER(ae, new) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
57 | do { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
58 | ae->next->prev = new; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
59 | new->next = ae->next; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
60 | new->prev = ae; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
61 | ae->next = new; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
62 | } while (0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
64 | static char *array_to_string_internal __P((ARRAY_ELEMENT *, ARRAY_ELEMENT *, char *, int)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
66 | static char *spacesep = " "; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
68 | #define IS_LASTREF(a) (a->lastref) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
70 | #define LASTREF_START(a, i) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
71 | (IS_LASTREF(a) && i >= element_index(a->lastref)) ? a->lastref \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
72 | : element_forw(a->head) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
74 | #define LASTREF(a) (a->lastref ? a->lastref : element_forw(a->head)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
76 | #define INVALIDATE_LASTREF(a) a->lastref = 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
77 | #define SET_LASTREF(a, e) a->lastref = (e) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
78 | #define UNSET_LASTREF(a) a->lastref = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
80 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
81 | array_create() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
82 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
83 | ARRAY *r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
84 | ARRAY_ELEMENT *head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
86 | r = (ARRAY *)xmalloc(sizeof(ARRAY)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
87 | r->type = array_indexed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
88 | r->max_index = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
89 | r->num_elements = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
90 | r->lastref = (ARRAY_ELEMENT *)0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
91 | head = array_create_element(-1, (char *)NULL); /* dummy head */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
92 | head->prev = head->next = head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
93 | r->head = head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
94 | return(r); executed 760887 times by 1 test: return(r); Executed by:
| 760887 | ||||||||||||||||||||||||||||||||||||||||||||||||
95 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
97 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
98 | array_flush (a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
99 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
100 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
101 | register ARRAY_ELEMENT *r, *r1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
103 | if (a == 0)
| 0-722402 | ||||||||||||||||||||||||||||||||||||||||||||||||
104 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
105 | for (r = element_forw(a->head); r != a->head; ) {
| 722402-734452 | ||||||||||||||||||||||||||||||||||||||||||||||||
106 | r1 = element_forw(r); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
107 | array_dispose_element(r); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
108 | r = r1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
109 | } executed 734452 times by 1 test: end of block Executed by:
| 734452 | ||||||||||||||||||||||||||||||||||||||||||||||||
110 | a->head->next = a->head->prev = a->head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
111 | a->max_index = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
112 | a->num_elements = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
113 | INVALIDATE_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
114 | } executed 722402 times by 1 test: end of block Executed by:
| 722402 | ||||||||||||||||||||||||||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
116 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
117 | array_dispose(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
118 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
120 | if (a == 0)
| 0-711728 | ||||||||||||||||||||||||||||||||||||||||||||||||
121 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
122 | array_flush (a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
123 | array_dispose_element(a->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
124 | free(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
125 | } executed 711728 times by 1 test: end of block Executed by:
| 711728 | ||||||||||||||||||||||||||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
127 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
128 | array_copy(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
129 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
130 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
131 | ARRAY *a1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
132 | ARRAY_ELEMENT *ae, *new; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
134 | if (a == 0)
| 0-711168 | ||||||||||||||||||||||||||||||||||||||||||||||||
135 | return((ARRAY *) NULL); never executed: return((ARRAY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
136 | a1 = array_create(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
137 | a1->type = a->type; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
138 | a1->max_index = a->max_index; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
139 | a1->num_elements = a->num_elements; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
140 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
| 711168-712634 | ||||||||||||||||||||||||||||||||||||||||||||||||
141 | new = array_create_element(element_index(ae), element_value(ae)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
142 | ADD_BEFORE(a1->head, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
143 | if (ae == LASTREF(a))
| 0-712634 | ||||||||||||||||||||||||||||||||||||||||||||||||
144 | SET_LASTREF(a1, new); executed 711168 times by 1 test: a1->lastref = (new); Executed by:
| 711168 | ||||||||||||||||||||||||||||||||||||||||||||||||
145 | } executed 712634 times by 1 test: end of block Executed by:
| 712634 | ||||||||||||||||||||||||||||||||||||||||||||||||
146 | return(a1); executed 711168 times by 1 test: return(a1); Executed by:
| 711168 | ||||||||||||||||||||||||||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
149 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
150 | * Make and return a new array composed of the elements in array A from | - | ||||||||||||||||||||||||||||||||||||||||||||||||
151 | * S to E, inclusive. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
152 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
153 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
154 | array_slice(array, s, e) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
155 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
156 | ARRAY_ELEMENT *s, *e; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
157 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
158 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
159 | ARRAY_ELEMENT *p, *n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
160 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
161 | arrayind_t mi; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
163 | a = array_create (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
164 | a->type = array->type; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
166 | for (mi = 0, p = s, i = 0; p != e; p = element_forw(p), i++) {
| 75-170 | ||||||||||||||||||||||||||||||||||||||||||||||||
167 | n = array_create_element (element_index(p), element_value(p)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
168 | ADD_BEFORE(a->head, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
169 | mi = element_index(n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
170 | } executed 170 times by 1 test: end of block Executed by:
| 170 | ||||||||||||||||||||||||||||||||||||||||||||||||
171 | a->num_elements = i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
172 | a->max_index = mi; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
173 | return a; executed 75 times by 1 test: return a; Executed by:
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||
174 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
176 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
177 | * Walk the array, calling FUNC once for each element, with the array | - | ||||||||||||||||||||||||||||||||||||||||||||||||
178 | * element as the argument. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
179 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
180 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
181 | array_walk(a, func, udata) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
182 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
183 | sh_ae_map_func_t *func; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
184 | void *udata; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
185 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
186 | register ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
188 | if (a == 0 || array_empty(a))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
189 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
190 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
191 | if ((*func)(ae, udata) < 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
192 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
195 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
196 | * Shift the array A N elements to the left. Delete the first N elements | - | ||||||||||||||||||||||||||||||||||||||||||||||||
197 | * and subtract N from the indices of the remaining elements. If FLAGS | - | ||||||||||||||||||||||||||||||||||||||||||||||||
198 | * does not include AS_DISPOSE, this returns a singly-linked null-terminated | - | ||||||||||||||||||||||||||||||||||||||||||||||||
199 | * list of elements so the caller can dispose of the chain. If FLAGS | - | ||||||||||||||||||||||||||||||||||||||||||||||||
200 | * includes AS_DISPOSE, this function disposes of the shifted-out elements | - | ||||||||||||||||||||||||||||||||||||||||||||||||
201 | * and returns NULL. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
202 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
203 | ARRAY_ELEMENT * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
204 | array_shift(a, n, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
205 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
206 | int n, flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
207 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
208 | register ARRAY_ELEMENT *ae, *ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
209 | register int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
211 | if (a == 0 || array_empty(a) || n <= 0)
| 0-4917167 | ||||||||||||||||||||||||||||||||||||||||||||||||
212 | return ((ARRAY_ELEMENT *)NULL); executed 15 times by 1 test: return ((ARRAY_ELEMENT *) ((void *)0) ); Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
214 | INVALIDATE_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
215 | for (i = 0, ret = ae = element_forw(a->head); ae != a->head && i < n; ae = element_forw(ae), i++)
| 1200-9833104 | ||||||||||||||||||||||||||||||||||||||||||||||||
216 | ; executed 4917152 times by 1 test: ; Executed by:
| 4917152 | ||||||||||||||||||||||||||||||||||||||||||||||||
217 | if (ae == a->head) {
| 1200-4915952 | ||||||||||||||||||||||||||||||||||||||||||||||||
218 | /* Easy case; shifting out all of the elements */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
219 | if (flags & AS_DISPOSE) {
| 0-1200 | ||||||||||||||||||||||||||||||||||||||||||||||||
220 | array_flush (a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
221 | return ((ARRAY_ELEMENT *)NULL); never executed: return ((ARRAY_ELEMENT *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
222 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
223 | for (ae = ret; element_forw(ae) != a->head; ae = element_forw(ae))
| 0-1200 | ||||||||||||||||||||||||||||||||||||||||||||||||
224 | ; never executed: ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
225 | element_forw(ae) = (ARRAY_ELEMENT *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
226 | a->head->next = a->head->prev = a->head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
227 | a->max_index = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
228 | a->num_elements = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
229 | return ret; executed 1200 times by 1 test: return ret; Executed by:
| 1200 | ||||||||||||||||||||||||||||||||||||||||||||||||
230 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
231 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
232 | * ae now points to the list of elements we want to retain. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
233 | * ret points to the list we want to either destroy or return. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
234 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
235 | ae->prev->next = (ARRAY_ELEMENT *)NULL; /* null-terminate RET */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
237 | a->head->next = ae; /* slice RET out of the array */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
238 | ae->prev = a->head; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
240 | for ( ; ae != a->head; ae = element_forw(ae))
| 4915952-5334252 | ||||||||||||||||||||||||||||||||||||||||||||||||
241 | element_index(ae) -= n; /* renumber retained indices */ executed 5334252 times by 1 test: ((ae)->ind) -= n; Executed by:
| 5334252 | ||||||||||||||||||||||||||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
243 | a->num_elements -= n; /* modify bookkeeping information */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
244 | a->max_index = element_index(a->head->prev); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
246 | if (flags & AS_DISPOSE) {
| 0-4915952 | ||||||||||||||||||||||||||||||||||||||||||||||||
247 | for (ae = ret; ae; ) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
248 | ret = element_forw(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
249 | array_dispose_element(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
250 | ae = ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
251 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
252 | return ((ARRAY_ELEMENT *)NULL); never executed: return ((ARRAY_ELEMENT *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
253 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
255 | return ret; executed 4915952 times by 1 test: return ret; Executed by:
| 4915952 | ||||||||||||||||||||||||||||||||||||||||||||||||
256 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
258 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
259 | * Shift array A right N indices. If S is non-null, it becomes the value of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
260 | * the new element 0. Returns the number of elements in the array after the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
261 | * shift. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
262 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
263 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
264 | array_rshift (a, n, s) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
265 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
266 | int n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
267 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
269 | register ARRAY_ELEMENT *ae, *new; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
271 | if (a == 0 || (array_empty(a) && s == 0))
| 0-4945747 | ||||||||||||||||||||||||||||||||||||||||||||||||
272 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
273 | else if (n <= 0)
| 0-4945747 | ||||||||||||||||||||||||||||||||||||||||||||||||
274 | return (a->num_elements); never executed: return (a->num_elements); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
276 | ae = element_forw(a->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
277 | if (s) {
| 0-4945747 | ||||||||||||||||||||||||||||||||||||||||||||||||
278 | new = array_create_element(0, s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
279 | ADD_BEFORE(ae, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
280 | a->num_elements++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
281 | if (array_num_elements(a) == 1) { /* array was empty */
| 17028-4928719 | ||||||||||||||||||||||||||||||||||||||||||||||||
282 | a->max_index = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
283 | return 1; executed 17028 times by 1 test: return 1; Executed by:
| 17028 | ||||||||||||||||||||||||||||||||||||||||||||||||
284 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
285 | } executed 4928719 times by 1 test: end of block Executed by:
| 4928719 | ||||||||||||||||||||||||||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
287 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
288 | * Renumber all elements in the array except the one we just added. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
289 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
290 | for ( ; ae != a->head; ae = element_forw(ae))
| 4928719-5419831 | ||||||||||||||||||||||||||||||||||||||||||||||||
291 | element_index(ae) += n; executed 5419831 times by 1 test: ((ae)->ind) += n; Executed by:
| 5419831 | ||||||||||||||||||||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
293 | a->max_index = element_index(a->head->prev); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
295 | INVALIDATE_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
296 | return (a->num_elements); executed 4928719 times by 1 test: return (a->num_elements); Executed by:
| 4928719 | ||||||||||||||||||||||||||||||||||||||||||||||||
297 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
299 | ARRAY_ELEMENT * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
300 | array_unshift_element(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
301 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
302 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
303 | return (array_shift (a, 1, 0)); never executed: return (array_shift (a, 1, 0)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
304 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
305 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
306 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
307 | array_shift_element(a, v) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
308 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
309 | char *v; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
310 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
311 | return (array_rshift (a, 1, v)); never executed: return (array_rshift (a, 1, v)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
312 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
314 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
315 | array_quote(array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
316 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
318 | ARRAY_ELEMENT *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
319 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
321 | if (array == 0 || array_head(array) == 0 || array_empty(array))
| 0-78 | ||||||||||||||||||||||||||||||||||||||||||||||||
322 | return (ARRAY *)NULL; never executed: return (ARRAY *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
323 | for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
| 78-237 | ||||||||||||||||||||||||||||||||||||||||||||||||
324 | t = quote_string (a->value); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
325 | FREE(a->value); executed 237 times by 1 test: sh_xfree((a->value), "array.c", 325); Executed by:
| 0-237 | ||||||||||||||||||||||||||||||||||||||||||||||||
326 | a->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
327 | } executed 237 times by 1 test: end of block Executed by:
| 237 | ||||||||||||||||||||||||||||||||||||||||||||||||
328 | return array; executed 78 times by 1 test: return array; Executed by:
| 78 | ||||||||||||||||||||||||||||||||||||||||||||||||
329 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
331 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
332 | array_quote_escapes(array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
333 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
334 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
335 | ARRAY_ELEMENT *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
336 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
338 | if (array == 0 || array_head(array) == 0 || array_empty(array))
| 0-146 | ||||||||||||||||||||||||||||||||||||||||||||||||
339 | return (ARRAY *)NULL; never executed: return (ARRAY *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
340 | for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
| 146-732 | ||||||||||||||||||||||||||||||||||||||||||||||||
341 | t = quote_escapes (a->value); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
342 | FREE(a->value); executed 732 times by 1 test: sh_xfree((a->value), "array.c", 342); Executed by:
| 0-732 | ||||||||||||||||||||||||||||||||||||||||||||||||
343 | a->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
344 | } executed 732 times by 1 test: end of block Executed by:
| 732 | ||||||||||||||||||||||||||||||||||||||||||||||||
345 | return array; executed 146 times by 1 test: return array; Executed by:
| 146 | ||||||||||||||||||||||||||||||||||||||||||||||||
346 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
348 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
349 | array_dequote(array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
350 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
351 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
352 | ARRAY_ELEMENT *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
353 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
355 | if (array == 0 || array_head(array) == 0 || array_empty(array))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
356 | return (ARRAY *)NULL; never executed: return (ARRAY *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
357 | for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
358 | t = dequote_string (a->value); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
359 | FREE(a->value); never executed: sh_xfree((a->value), "array.c", 359);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
360 | a->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
361 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
362 | return array; never executed: return array; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
364 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
365 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
366 | array_dequote_escapes(array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
367 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
368 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
369 | ARRAY_ELEMENT *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
370 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
372 | if (array == 0 || array_head(array) == 0 || array_empty(array))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
373 | return (ARRAY *)NULL; never executed: return (ARRAY *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
374 | for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
375 | t = dequote_escapes (a->value); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
376 | FREE(a->value); never executed: sh_xfree((a->value), "array.c", 376);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
377 | a->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
378 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
379 | return array; never executed: return array; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
382 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
383 | array_remove_quoted_nulls(array) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
384 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
385 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
386 | ARRAY_ELEMENT *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
388 | if (array == 0 || array_head(array) == 0 || array_empty(array))
| 0-29 | ||||||||||||||||||||||||||||||||||||||||||||||||
389 | return (ARRAY *)NULL; never executed: return (ARRAY *) ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
390 | for (a = element_forw(array->head); a != array->head; a = element_forw(a))
| 29-200 | ||||||||||||||||||||||||||||||||||||||||||||||||
391 | a->value = remove_quoted_nulls (a->value); executed 200 times by 1 test: a->value = remove_quoted_nulls (a->value); Executed by:
| 200 | ||||||||||||||||||||||||||||||||||||||||||||||||
392 | return array; executed 29 times by 1 test: return array; Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||
393 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
395 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
396 | * Return a string whose elements are the members of array A beginning at | - | ||||||||||||||||||||||||||||||||||||||||||||||||
397 | * index START and spanning NELEM members. Null elements are counted. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
398 | * Since arrays are sparse, unset array elements are not counted. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
399 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
400 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
401 | array_subrange (a, start, nelem, starsub, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
402 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
403 | arrayind_t start, nelem; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
404 | int starsub, quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
405 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
406 | ARRAY *a2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
407 | ARRAY_ELEMENT *h, *p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
408 | arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
409 | char *ifs, *sifs, *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
410 | int slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
412 | p = a ? array_head (a) : 0;
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
413 | if (p == 0 || array_empty (a) || start > array_max_index(a))
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
414 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
416 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
417 | * Find element with index START. If START corresponds to an unset | - | ||||||||||||||||||||||||||||||||||||||||||||||||
418 | * element (arrays can be sparse), use the first element whose index | - | ||||||||||||||||||||||||||||||||||||||||||||||||
419 | * is >= START. If START is < 0, we count START indices back from | - | ||||||||||||||||||||||||||||||||||||||||||||||||
420 | * the end of A (not elements, even with sparse arrays -- START is an | - | ||||||||||||||||||||||||||||||||||||||||||||||||
421 | * index). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
422 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
423 | for (p = element_forw(p); p != array_head(a) && start > element_index(p); p = element_forw(p))
| 0-194 | ||||||||||||||||||||||||||||||||||||||||||||||||
424 | ; executed 119 times by 1 test: ; Executed by:
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
426 | if (p == a->head)
| 0-75 | ||||||||||||||||||||||||||||||||||||||||||||||||
427 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
429 | /* Starting at P, take NELEM elements, inclusive. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
430 | for (i = 0, h = p; p != a->head && i < nelem; i++, p = element_forw(p))
| 17-187 | ||||||||||||||||||||||||||||||||||||||||||||||||
431 | ; executed 170 times by 1 test: ; Executed by:
| 170 | ||||||||||||||||||||||||||||||||||||||||||||||||
432 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
433 | a2 = array_slice(a, h, p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
435 | if (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))
| 27-48 | ||||||||||||||||||||||||||||||||||||||||||||||||
436 | array_quote(a2); executed 27 times by 1 test: array_quote(a2); Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||||||||
437 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
438 | array_quote_escapes(a2); executed 48 times by 1 test: array_quote_escapes(a2); Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
440 | if (starsub && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT))) {
| 2-70 | ||||||||||||||||||||||||||||||||||||||||||||||||
441 | /* ${array[*]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
442 | array_remove_quoted_nulls (a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
443 | sifs = ifs_firstchar ((int *)NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
444 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
445 | free (sifs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
446 | } else if (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) { executed 3 times by 1 test: end of block Executed by:
| 3-48 | ||||||||||||||||||||||||||||||||||||||||||||||||
447 | /* ${array[@]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
448 | sifs = ifs_firstchar (&slen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
449 | ifs = getifs (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
450 | if (ifs == 0 || *ifs == 0) {
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||
451 | if (slen < 2)
| 0-4 | ||||||||||||||||||||||||||||||||||||||||||||||||
452 | sifs = xrealloc(sifs, 2); executed 4 times by 1 test: sifs = sh_xrealloc((sifs), (2), "array.c", 452); Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
453 | sifs[0] = ' '; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
454 | sifs[1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
455 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
456 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
457 | free (sifs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
458 | } else executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||
459 | t = array_to_string (a2, " ", 0); executed 48 times by 1 test: t = array_to_string (a2, " ", 0); Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||
460 | array_dispose(a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
462 | return t; executed 75 times by 1 test: return t; Executed by:
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||
463 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
465 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
466 | array_patsub (a, pat, rep, mflags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
467 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
468 | char *pat, *rep; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
469 | int mflags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
470 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
471 | ARRAY *a2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
472 | ARRAY_ELEMENT *e; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
473 | char *t, *sifs, *ifs; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
474 | int slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
475 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
476 | if (a == 0 || array_head(a) == 0 || array_empty(a))
| 0-138 | ||||||||||||||||||||||||||||||||||||||||||||||||
477 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
479 | a2 = array_copy(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
480 | for (e = element_forw(a2->head); e != a2->head; e = element_forw(e)) {
| 138-770 | ||||||||||||||||||||||||||||||||||||||||||||||||
481 | t = pat_subst(element_value(e), pat, rep, mflags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
482 | FREE(element_value(e)); executed 770 times by 1 test: sh_xfree((((e)->value)), "array.c", 482); Executed by:
| 0-770 | ||||||||||||||||||||||||||||||||||||||||||||||||
483 | e->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
484 | } executed 770 times by 1 test: end of block Executed by:
| 770 | ||||||||||||||||||||||||||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
486 | if (mflags & MATCH_QUOTED)
| 46-92 | ||||||||||||||||||||||||||||||||||||||||||||||||
487 | array_quote(a2); executed 46 times by 1 test: array_quote(a2); Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||
488 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
489 | array_quote_escapes(a2); executed 92 times by 1 test: array_quote_escapes(a2); Executed by:
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
491 | if (mflags & MATCH_STARSUB) {
| 24-114 | ||||||||||||||||||||||||||||||||||||||||||||||||
492 | array_remove_quoted_nulls (a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
493 | if ((mflags & MATCH_QUOTED) == 0 && ifs_is_null)
| 0-21 | ||||||||||||||||||||||||||||||||||||||||||||||||
494 | sifs = spacesep; never executed: sifs = spacesep; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
495 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
496 | sifs = ifs_firstchar((int *)NULL); executed 24 times by 1 test: sifs = ifs_firstchar((int *) ((void *)0) ); Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||
497 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
498 | if (sifs != spacesep)
| 0-24 | ||||||||||||||||||||||||||||||||||||||||||||||||
499 | free(sifs); executed 24 times by 1 test: sh_xfree((sifs), "array.c", 499); Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||
500 | } else if (mflags & MATCH_QUOTED) { executed 24 times by 1 test: end of block Executed by:
| 24-71 | ||||||||||||||||||||||||||||||||||||||||||||||||
501 | /* ${array[@]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
502 | sifs = ifs_firstchar (&slen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
503 | ifs = getifs (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
504 | if (ifs == 0 || *ifs == 0) {
| 0-43 | ||||||||||||||||||||||||||||||||||||||||||||||||
505 | if (slen < 2)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
506 | sifs = xrealloc (sifs, 2); never executed: sifs = sh_xrealloc((sifs), (2), "array.c", 506); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
507 | sifs[0] = ' '; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
508 | sifs[1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
509 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
510 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
511 | free(sifs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
512 | } else executed 43 times by 1 test: end of block Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||||||||||||||
513 | t = array_to_string (a2, " ", 0); executed 71 times by 1 test: t = array_to_string (a2, " ", 0); Executed by:
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||
514 | array_dispose (a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
516 | return t; executed 138 times by 1 test: return t; Executed by:
| 138 | ||||||||||||||||||||||||||||||||||||||||||||||||
517 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
519 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
520 | array_modcase (a, pat, modop, mflags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
521 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
522 | char *pat; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
523 | int modop; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
524 | int mflags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
525 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
526 | ARRAY *a2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
527 | ARRAY_ELEMENT *e; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
528 | char *t, *sifs, *ifs; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
529 | int slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
530 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
531 | if (a == 0 || array_head(a) == 0 || array_empty(a))
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
532 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
534 | a2 = array_copy(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
535 | for (e = element_forw(a2->head); e != a2->head; e = element_forw(e)) {
| 11-29 | ||||||||||||||||||||||||||||||||||||||||||||||||
536 | t = sh_modcase(element_value(e), pat, modop); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
537 | FREE(element_value(e)); executed 29 times by 1 test: sh_xfree((((e)->value)), "array.c", 537); Executed by:
| 0-29 | ||||||||||||||||||||||||||||||||||||||||||||||||
538 | e->value = t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
539 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||
540 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
541 | if (mflags & MATCH_QUOTED)
| 5-6 | ||||||||||||||||||||||||||||||||||||||||||||||||
542 | array_quote(a2); executed 5 times by 1 test: array_quote(a2); Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
543 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
544 | array_quote_escapes(a2); executed 6 times by 1 test: array_quote_escapes(a2); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
546 | if (mflags & MATCH_STARSUB) {
| 2-9 | ||||||||||||||||||||||||||||||||||||||||||||||||
547 | array_remove_quoted_nulls (a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
548 | if ((mflags & MATCH_QUOTED) == 0 && ifs_is_null)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
549 | sifs = spacesep; never executed: sifs = spacesep; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
550 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
551 | sifs = ifs_firstchar((int *)NULL); executed 2 times by 1 test: sifs = ifs_firstchar((int *) ((void *)0) ); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
552 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
553 | if (sifs != spacesep)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||
554 | free(sifs); executed 2 times by 1 test: sh_xfree((sifs), "array.c", 554); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
555 | } else if (mflags & MATCH_QUOTED) { executed 2 times by 1 test: end of block Executed by:
| 2-6 | ||||||||||||||||||||||||||||||||||||||||||||||||
556 | /* ${array[@]} */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
557 | sifs = ifs_firstchar (&slen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
558 | ifs = getifs (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
559 | if (ifs == 0 || *ifs == 0) {
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||||||||
560 | if (slen < 2)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
561 | sifs = xrealloc (sifs, 2); never executed: sifs = sh_xrealloc((sifs), (2), "array.c", 561); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
562 | sifs[0] = ' '; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
563 | sifs[1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
565 | t = array_to_string (a2, sifs, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
566 | free(sifs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
567 | } else executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
568 | t = array_to_string (a2, " ", 0); executed 6 times by 1 test: t = array_to_string (a2, " ", 0); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||
569 | array_dispose (a2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
570 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
571 | return t; executed 11 times by 1 test: return t; Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||
572 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
573 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
574 | * Allocate and return a new array element with index INDEX and value | - | ||||||||||||||||||||||||||||||||||||||||||||||||
575 | * VALUE. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
576 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
577 | ARRAY_ELEMENT * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
578 | array_create_element(indx, value) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
579 | arrayind_t indx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
580 | char *value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
581 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
582 | ARRAY_ELEMENT *r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
584 | r = (ARRAY_ELEMENT *)xmalloc(sizeof(ARRAY_ELEMENT)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
585 | r->ind = indx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
586 | r->value = value ? savestring(value) : (char *)NULL;
| 760887-5732043 | ||||||||||||||||||||||||||||||||||||||||||||||||
587 | r->next = r->prev = (ARRAY_ELEMENT *) NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
588 | return(r); executed 6492930 times by 1 test: return(r); Executed by:
| 6492930 | ||||||||||||||||||||||||||||||||||||||||||||||||
589 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
590 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
591 | #ifdef INCLUDE_UNUSED | - | ||||||||||||||||||||||||||||||||||||||||||||||||
592 | ARRAY_ELEMENT * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
593 | array_copy_element(ae) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
594 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
595 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
596 | return(ae ? array_create_element(element_index(ae), element_value(ae)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
597 | : (ARRAY_ELEMENT *) NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
598 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
599 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
601 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
602 | array_dispose_element(ae) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
603 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
604 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
605 | if (ae) {
| 15-6373478 | ||||||||||||||||||||||||||||||||||||||||||||||||
606 | FREE(ae->value); executed 5651639 times by 1 test: sh_xfree((ae->value), "array.c", 606); Executed by:
| 721839-5651639 | ||||||||||||||||||||||||||||||||||||||||||||||||
607 | free(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
608 | } executed 6373478 times by 1 test: end of block Executed by:
| 6373478 | ||||||||||||||||||||||||||||||||||||||||||||||||
609 | } executed 6373493 times by 1 test: end of block Executed by:
| 6373493 | ||||||||||||||||||||||||||||||||||||||||||||||||
610 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
611 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
612 | * Add a new element with index I and value V to array A (a[i] = v). | - | ||||||||||||||||||||||||||||||||||||||||||||||||
613 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
614 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
615 | array_insert(a, i, v) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
616 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
617 | arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
618 | char *v; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
619 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
620 | register ARRAY_ELEMENT *new, *ae, *start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
621 | arrayind_t startind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
622 | int direction; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
623 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
624 | if (a == 0)
| 0-73492 | ||||||||||||||||||||||||||||||||||||||||||||||||
625 | return(-1); never executed: return(-1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
626 | new = array_create_element(i, v); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
627 | if (i > array_max_index(a)) {
| 10147-63345 | ||||||||||||||||||||||||||||||||||||||||||||||||
628 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
629 | * Hook onto the end. This also works for an empty array. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
630 | * Fast path for the common case of allocating arrays | - | ||||||||||||||||||||||||||||||||||||||||||||||||
631 | * sequentially. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
632 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
633 | ADD_BEFORE(a->head, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
634 | a->max_index = i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
635 | a->num_elements++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
636 | SET_LASTREF(a, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
637 | return(0); executed 63345 times by 1 test: return(0); Executed by:
| 63345 | ||||||||||||||||||||||||||||||||||||||||||||||||
638 | } else if (i < array_first_index(a)) {
| 8-10139 | ||||||||||||||||||||||||||||||||||||||||||||||||
639 | /* Hook at the beginning */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
640 | ADD_AFTER(a->head, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
641 | a->num_elements++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
642 | SET_LASTREF(a, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
643 | return(0); executed 8 times by 1 test: return(0); Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
644 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
645 | #if OPTIMIZE_SEQUENTIAL_ARRAY_ASSIGNMENT | - | ||||||||||||||||||||||||||||||||||||||||||||||||
646 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
647 | * Otherwise we search for the spot to insert it. The lastref | - | ||||||||||||||||||||||||||||||||||||||||||||||||
648 | * handle optimizes the case of sequential or almost-sequential | - | ||||||||||||||||||||||||||||||||||||||||||||||||
649 | * assignments that are not at the end of the array. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
650 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
651 | start = LASTREF(a);
| 0-10139 | ||||||||||||||||||||||||||||||||||||||||||||||||
652 | /* Use same strategy as array_reference to avoid paying large penalty | - | ||||||||||||||||||||||||||||||||||||||||||||||||
653 | for semi-random assignment pattern. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
654 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
655 | if (i < startind/2) {
| 18-10121 | ||||||||||||||||||||||||||||||||||||||||||||||||
656 | start = element_forw(a->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
657 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
658 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
659 | } else if (i >= startind) { executed 18 times by 1 test: end of block Executed by:
| 18-10089 | ||||||||||||||||||||||||||||||||||||||||||||||||
660 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
661 | } else { executed 10089 times by 1 test: end of block Executed by:
| 10089 | ||||||||||||||||||||||||||||||||||||||||||||||||
662 | direction = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
663 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||||||||||||||||||||||||||||||||
664 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
665 | start = element_forw(ae->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
666 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
667 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
668 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
669 | for (ae = start; ae != a->head; ) {
| 0-10256 | ||||||||||||||||||||||||||||||||||||||||||||||||
670 | if (element_index(ae) == i) {
| 145-10111 | ||||||||||||||||||||||||||||||||||||||||||||||||
671 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
672 | * Replacing an existing element. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
673 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
674 | free(element_value(ae)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
675 | /* Just swap in the new value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
676 | ae->value = new->value; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
677 | new->value = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
678 | array_dispose_element(new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
679 | SET_LASTREF(a, ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
680 | return(0); executed 10111 times by 1 test: return(0); Executed by:
| 10111 | ||||||||||||||||||||||||||||||||||||||||||||||||
681 | } else if (direction == 1 && element_index(ae) > i) {
| 6-88 | ||||||||||||||||||||||||||||||||||||||||||||||||
682 | ADD_BEFORE(ae, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
683 | a->num_elements++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
684 | SET_LASTREF(a, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
685 | return(0); executed 6 times by 1 test: return(0); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||
686 | } else if (direction == -1 && element_index(ae) < i) {
| 22-82 | ||||||||||||||||||||||||||||||||||||||||||||||||
687 | ADD_AFTER(ae, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
688 | a->num_elements++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
689 | SET_LASTREF(a, new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
690 | return(0); executed 22 times by 1 test: return(0); Executed by:
| 22 | ||||||||||||||||||||||||||||||||||||||||||||||||
691 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
692 | ae = direction == 1 ? element_forw(ae) : element_back(ae);
| 35-82 | ||||||||||||||||||||||||||||||||||||||||||||||||
693 | } executed 117 times by 1 test: end of block Executed by:
| 117 | ||||||||||||||||||||||||||||||||||||||||||||||||
694 | array_dispose_element(new); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
695 | INVALIDATE_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
696 | return (-1); /* problem */ never executed: return (-1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
697 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
698 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
699 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
700 | * Delete the element with index I from array A and return it so the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
701 | * caller can dispose of it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
702 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
703 | ARRAY_ELEMENT * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
704 | array_remove(a, i) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
705 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
706 | arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
707 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
708 | register ARRAY_ELEMENT *ae, *start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
709 | arrayind_t startind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
710 | int direction; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
711 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
712 | if (a == 0 || array_empty(a))
| 0-73 | ||||||||||||||||||||||||||||||||||||||||||||||||
713 | return((ARRAY_ELEMENT *) NULL); never executed: return((ARRAY_ELEMENT *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
714 | if (i > array_max_index(a) || i < array_first_index(a))
| 0-38 | ||||||||||||||||||||||||||||||||||||||||||||||||
715 | return((ARRAY_ELEMENT *)NULL); /* Keep roving pointer into array to optimize sequential access */ executed 38 times by 1 test: return((ARRAY_ELEMENT *) ((void *)0) ); Executed by:
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||
716 | start = LASTREF(a);
| 0-35 | ||||||||||||||||||||||||||||||||||||||||||||||||
717 | /* Use same strategy as array_reference to avoid paying large penalty | - | ||||||||||||||||||||||||||||||||||||||||||||||||
718 | for semi-random assignment pattern. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
719 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
720 | if (i < startind/2) {
| 1-34 | ||||||||||||||||||||||||||||||||||||||||||||||||
721 | start = element_forw(a->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
722 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
723 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
724 | } else if (i >= startind) { executed 1 time by 1 test: end of block Executed by:
| 1-31 | ||||||||||||||||||||||||||||||||||||||||||||||||
725 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
726 | } else { executed 31 times by 1 test: end of block Executed by:
| 31 | ||||||||||||||||||||||||||||||||||||||||||||||||
727 | direction = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
728 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
729 | for (ae = start; ae != a->head; ) {
| 0-50 | ||||||||||||||||||||||||||||||||||||||||||||||||
730 | if (element_index(ae) == i) {
| 15-35 | ||||||||||||||||||||||||||||||||||||||||||||||||
731 | ae->next->prev = ae->prev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
732 | ae->prev->next = ae->next; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
733 | a->num_elements--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
734 | if (i == array_max_index(a))
| 17-18 | ||||||||||||||||||||||||||||||||||||||||||||||||
735 | a->max_index = element_index(ae->prev); executed 17 times by 1 test: a->max_index = ((ae->prev)->ind); Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||
736 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
737 | INVALIDATE_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
738 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
739 | if (ae->next != a->head)
| 17-18 | ||||||||||||||||||||||||||||||||||||||||||||||||
740 | SET_LASTREF(a, ae->next); executed 18 times by 1 test: a->lastref = (ae->next); Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||
741 | else if (ae->prev != a->head)
| 5-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
742 | SET_LASTREF(a, ae->prev); executed 5 times by 1 test: a->lastref = (ae->prev); Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
743 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
744 | INVALIDATE_LASTREF(a); executed 12 times by 1 test: a->lastref = 0; Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||
745 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
746 | return(ae); executed 35 times by 1 test: return(ae); Executed by:
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||
747 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
748 | ae = (direction == 1) ? element_forw(ae) : element_back(ae);
| 3-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
749 | if (direction == 1 && element_index(ae) > i)
| 0-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
750 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
751 | else if (direction == -1 && element_index(ae) < i)
| 0-12 | ||||||||||||||||||||||||||||||||||||||||||||||||
752 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
753 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||
754 | return((ARRAY_ELEMENT *) NULL); never executed: return((ARRAY_ELEMENT *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
755 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
757 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
758 | * Return the value of a[i]. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
759 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
760 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
761 | array_reference(a, i) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
762 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
763 | arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
764 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
765 | register ARRAY_ELEMENT *ae, *start; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
766 | arrayind_t startind; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
767 | int direction; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
768 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
769 | if (a == 0 || array_empty(a))
| 0-28632 | ||||||||||||||||||||||||||||||||||||||||||||||||
770 | return((char *) NULL); executed 77 times by 1 test: return((char *) ((void *)0) ); Executed by:
| 77 | ||||||||||||||||||||||||||||||||||||||||||||||||
771 | if (i > array_max_index(a) || i < array_first_index(a))
| 34-28521 | ||||||||||||||||||||||||||||||||||||||||||||||||
772 | return((char *)NULL); /* Keep roving pointer into array to optimize sequential access */ executed 68 times by 1 test: return((char *) ((void *)0) ); Executed by:
| 68 | ||||||||||||||||||||||||||||||||||||||||||||||||
773 | start = LASTREF(a); /* lastref pointer */
| 12401-16086 | ||||||||||||||||||||||||||||||||||||||||||||||||
774 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
775 | if (i < startind/2) { /* XXX - guess */
| 1092-27395 | ||||||||||||||||||||||||||||||||||||||||||||||||
776 | start = element_forw(a->head); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
777 | startind = element_index(start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
778 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
779 | } else if (i >= startind) { executed 1092 times by 1 test: end of block Executed by:
| 1092-23509 | ||||||||||||||||||||||||||||||||||||||||||||||||
780 | direction = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
781 | } else { executed 23509 times by 1 test: end of block Executed by:
| 23509 | ||||||||||||||||||||||||||||||||||||||||||||||||
782 | direction = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
783 | } executed 3886 times by 1 test: end of block Executed by:
| 3886 | ||||||||||||||||||||||||||||||||||||||||||||||||
784 | for (ae = start; ae != a->head; ) {
| 0-381002 | ||||||||||||||||||||||||||||||||||||||||||||||||
785 | if (element_index(ae) == i) {
| 28097-352905 | ||||||||||||||||||||||||||||||||||||||||||||||||
786 | SET_LASTREF(a, ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
787 | return(element_value(ae)); executed 28097 times by 1 test: return(((ae)->value)); Executed by:
| 28097 | ||||||||||||||||||||||||||||||||||||||||||||||||
788 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
789 | ae = (direction == 1) ? element_forw(ae) : element_back(ae);
| 9817-343088 | ||||||||||||||||||||||||||||||||||||||||||||||||
790 | /* Take advantage of index ordering to short-circuit */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
791 | /* If we don't find it, set the lastref pointer to the element | - | ||||||||||||||||||||||||||||||||||||||||||||||||
792 | that's `closest', assuming that the unsuccessful reference | - | ||||||||||||||||||||||||||||||||||||||||||||||||
793 | will quickly be followed by an assignment. No worse than | - | ||||||||||||||||||||||||||||||||||||||||||||||||
794 | not changing it from the previous value or resetting it. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
795 | if (direction == 1 && element_index(ae) > i) {
| 386-343088 | ||||||||||||||||||||||||||||||||||||||||||||||||
796 | start = ae; /* use for SET_LASTREF below */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
797 | break; executed 386 times by 1 test: break; Executed by:
| 386 | ||||||||||||||||||||||||||||||||||||||||||||||||
798 | } else if (direction == -1 && element_index(ae) < i) {
| 4-342702 | ||||||||||||||||||||||||||||||||||||||||||||||||
799 | start = ae; /* use for SET_LASTREF below */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
800 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
801 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
802 | } executed 352515 times by 1 test: end of block Executed by:
| 352515 | ||||||||||||||||||||||||||||||||||||||||||||||||
803 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
804 | UNSET_LASTREF(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
805 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
806 | SET_LASTREF(a, start); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
807 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
808 | return((char *) NULL); executed 390 times by 1 test: return((char *) ((void *)0) ); Executed by:
| 390 | ||||||||||||||||||||||||||||||||||||||||||||||||
809 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
810 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
811 | /* Convenience routines for the shell to translate to and from the form used | - | ||||||||||||||||||||||||||||||||||||||||||||||||
812 | by the rest of the code. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
814 | WORD_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
815 | array_to_word_list(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
816 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
817 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
818 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
819 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
820 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
821 | if (a == 0 || array_empty(a))
| 0-793 | ||||||||||||||||||||||||||||||||||||||||||||||||
822 | return((WORD_LIST *)NULL); executed 26 times by 1 test: return((WORD_LIST *) ((void *)0) ); Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||
823 | list = (WORD_LIST *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
824 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
| 767-3328 | ||||||||||||||||||||||||||||||||||||||||||||||||
825 | list = make_word_list (make_bare_word(element_value(ae)), list); executed 3328 times by 1 test: list = make_word_list (make_bare_word(((ae)->value)), list); Executed by:
| 3328 | ||||||||||||||||||||||||||||||||||||||||||||||||
826 | return (REVERSE_LIST(list, WORD_LIST *)); executed 767 times by 1 test: return (((list && list->next) ? (WORD_LIST *)list_reverse ((GENERIC_LIST *)list) : (WORD_LIST *)(list))); Executed by:
| 767 | ||||||||||||||||||||||||||||||||||||||||||||||||
827 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
828 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
829 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
830 | array_from_word_list (list) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
831 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
832 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
833 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
835 | if (list == 0)
| 0-27 | ||||||||||||||||||||||||||||||||||||||||||||||||
836 | return((ARRAY *)NULL); never executed: return((ARRAY *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
837 | a = array_create(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
838 | return (array_assign_list (a, list)); executed 27 times by 1 test: return (array_assign_list (a, list)); Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||||||||
839 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
840 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
841 | WORD_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
842 | array_keys_to_word_list(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
843 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
844 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
845 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
846 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
847 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
848 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
849 | if (a == 0 || array_empty(a))
| 0-8 | ||||||||||||||||||||||||||||||||||||||||||||||||
850 | return((WORD_LIST *)NULL); never executed: return((WORD_LIST *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
851 | list = (WORD_LIST *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
852 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
| 8-34 | ||||||||||||||||||||||||||||||||||||||||||||||||
853 | t = itos(element_index(ae)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
854 | list = make_word_list (make_bare_word(t), list); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
855 | free(t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
856 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||
857 | return (REVERSE_LIST(list, WORD_LIST *)); executed 8 times by 1 test: return (((list && list->next) ? (WORD_LIST *)list_reverse ((GENERIC_LIST *)list) : (WORD_LIST *)(list))); Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||
858 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
859 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
860 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
861 | array_assign_list (array, list) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
862 | ARRAY *array; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
863 | WORD_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
864 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
865 | register WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
866 | register arrayind_t i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
867 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
868 | for (l = list, i = 0; l; l = l->next, i++)
| 27-87 | ||||||||||||||||||||||||||||||||||||||||||||||||
869 | array_insert(array, i, l->word->word); executed 87 times by 1 test: array_insert(array, i, l->word->word); Executed by:
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||
870 | return array; executed 27 times by 1 test: return array; Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||||||||
871 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
872 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
873 | char ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||
874 | array_to_argv (a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
875 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
876 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
877 | char **ret, *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
878 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
879 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
881 | if (a == 0 || array_empty(a))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
882 | return ((char **)NULL); never executed: return ((char **) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
883 | ret = strvec_create (array_num_elements (a) + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
884 | i = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
885 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
886 | t = element_value (ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
887 | ret[i++] = t ? savestring (t) : (char *)NULL;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
888 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
889 | ret[i] = (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
890 | return (ret); never executed: return (ret); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
891 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
892 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
893 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
894 | * Return a string that is the concatenation of the elements in A from START | - | ||||||||||||||||||||||||||||||||||||||||||||||||
895 | * to END, separated by SEP. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
896 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
897 | static char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
898 | array_to_string_internal (start, end, sep, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
899 | ARRAY_ELEMENT *start, *end; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
900 | char *sep; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
901 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
902 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
903 | char *result, *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
904 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
905 | int slen, rsize, rlen, reg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
907 | if (start == end) /* XXX - should not happen */
| 0-224 | ||||||||||||||||||||||||||||||||||||||||||||||||
908 | return ((char *)NULL); never executed: return ((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
910 | slen = strlen(sep); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
911 | result = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
912 | for (rsize = rlen = 0, ae = start; ae != end; ae = element_forw(ae)) {
| 224-969 | ||||||||||||||||||||||||||||||||||||||||||||||||
913 | if (rsize == 0)
| 224-745 | ||||||||||||||||||||||||||||||||||||||||||||||||
914 | result = (char *)xmalloc (rsize = 64); executed 224 times by 1 test: result = (char *)sh_xmalloc((rsize = 64), "array.c", 914); Executed by:
| 224 | ||||||||||||||||||||||||||||||||||||||||||||||||
915 | if (element_value(ae)) {
| 0-969 | ||||||||||||||||||||||||||||||||||||||||||||||||
916 | t = quoted ? quote_string(element_value(ae)) : element_value(ae);
| 0-969 | ||||||||||||||||||||||||||||||||||||||||||||||||
917 | reg = strlen(t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
918 | RESIZE_MALLOCED_BUFFER (result, rlen, (reg + slen + 2), executed 9 times by 1 test: rsize += (rsize); Executed by:
executed 9 times by 1 test: end of block Executed by:
| 9-960 | ||||||||||||||||||||||||||||||||||||||||||||||||
919 | rsize, rsize); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
920 | strcpy(result + rlen, t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
921 | rlen += reg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
922 | if (quoted)
| 0-969 | ||||||||||||||||||||||||||||||||||||||||||||||||
923 | free(t); never executed: sh_xfree((t), "array.c", 923); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
924 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
925 | * Add a separator only after non-null elements. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
926 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
927 | if (element_forw(ae) != end) {
| 224-745 | ||||||||||||||||||||||||||||||||||||||||||||||||
928 | strcpy(result + rlen, sep); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
929 | rlen += slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
930 | } executed 745 times by 1 test: end of block Executed by:
| 745 | ||||||||||||||||||||||||||||||||||||||||||||||||
931 | } executed 969 times by 1 test: end of block Executed by:
| 969 | ||||||||||||||||||||||||||||||||||||||||||||||||
932 | } executed 969 times by 1 test: end of block Executed by:
| 969 | ||||||||||||||||||||||||||||||||||||||||||||||||
933 | if (result)
| 0-224 | ||||||||||||||||||||||||||||||||||||||||||||||||
934 | result[rlen] = '\0'; /* XXX */ executed 224 times by 1 test: result[rlen] = '\0'; Executed by:
| 224 | ||||||||||||||||||||||||||||||||||||||||||||||||
935 | return(result); executed 224 times by 1 test: return(result); Executed by:
| 224 | ||||||||||||||||||||||||||||||||||||||||||||||||
936 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
937 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
938 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
939 | array_to_assign (a, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
940 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
941 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
942 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
943 | char *result, *valstr, *is; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
944 | char indstr[INT_STRLEN_BOUND(intmax_t) + 1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
945 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
946 | int rsize, rlen, elen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
948 | if (a == 0 || array_empty (a))
| 0-277 | ||||||||||||||||||||||||||||||||||||||||||||||||
949 | return((char *)NULL); executed 51 times by 1 test: return((char *) ((void *)0) ); Executed by:
| 51 | ||||||||||||||||||||||||||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
951 | result = (char *)xmalloc (rsize = 128); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
952 | result[0] = '('; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
953 | rlen = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
955 | for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae)) {
| 226-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
956 | is = inttostr (element_index(ae), indstr, sizeof(indstr)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
957 | valstr = element_value (ae) ?
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
958 | (ansic_shouldquote (element_value (ae)) ?
| 3-520 | ||||||||||||||||||||||||||||||||||||||||||||||||
959 | ansic_quote (element_value(ae), 0, (int *)0) : | - | ||||||||||||||||||||||||||||||||||||||||||||||||
960 | sh_double_quote (element_value (ae))) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
961 | : (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
962 | elen = STRLEN (is) + 8 + STRLEN (valstr);
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
963 | RESIZE_MALLOCED_BUFFER (result, rlen, (elen + 1), rsize, rsize); never executed: rsize += (rsize); never executed: end of block
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
964 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
965 | result[rlen++] = '['; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
966 | strcpy (result + rlen, is); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
967 | rlen += STRLEN (is);
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
968 | result[rlen++] = ']'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
969 | result[rlen++] = '='; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
970 | if (valstr) {
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
971 | strcpy (result + rlen, valstr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
972 | rlen += STRLEN (valstr);
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
973 | } executed 523 times by 1 test: end of block Executed by:
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||
974 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
975 | if (element_forw(ae) != a->head)
| 226-297 | ||||||||||||||||||||||||||||||||||||||||||||||||
976 | result[rlen++] = ' '; executed 297 times by 1 test: result[rlen++] = ' '; Executed by:
| 297 | ||||||||||||||||||||||||||||||||||||||||||||||||
977 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
978 | FREE (valstr); executed 523 times by 1 test: sh_xfree((valstr), "array.c", 978); Executed by:
| 0-523 | ||||||||||||||||||||||||||||||||||||||||||||||||
979 | } executed 523 times by 1 test: end of block Executed by:
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||
980 | RESIZE_MALLOCED_BUFFER (result, rlen, 1, rsize, 8); never executed: rsize += (8); never executed: end of block
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||||||||
981 | result[rlen++] = ')'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
982 | result[rlen] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
983 | if (quoted) {
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||||||||
984 | /* This is not as efficient as it could be... */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
985 | valstr = sh_single_quote (result); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
986 | free (result); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
987 | result = valstr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
988 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
989 | return(result); executed 226 times by 1 test: return(result); Executed by:
| 226 | ||||||||||||||||||||||||||||||||||||||||||||||||
990 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
991 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
992 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
993 | array_to_string (a, sep, quoted) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
994 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
995 | char *sep; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
996 | int quoted; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
997 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
998 | if (a == 0)
| 0-224 | ||||||||||||||||||||||||||||||||||||||||||||||||
999 | return((char *)NULL); never executed: return((char *) ((void *)0) ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1000 | if (array_empty(a))
| 0-224 | ||||||||||||||||||||||||||||||||||||||||||||||||
1001 | return(savestring("")); never executed: return((char *)strcpy (sh_xmalloc((1 + strlen ("")), "array.c", 1001), (""))); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
1002 | return (array_to_string_internal (element_forw(a->head), a->head, sep, quoted)); executed 224 times by 1 test: return (array_to_string_internal (((a->head)->next), a->head, sep, quoted)); Executed by:
| 224 | ||||||||||||||||||||||||||||||||||||||||||||||||
1003 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1004 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1005 | #if defined (INCLUDE_UNUSED) || defined (TEST_ARRAY) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1006 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1007 | * Return an array consisting of elements in S, separated by SEP | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1008 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1009 | ARRAY * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1010 | array_from_string(s, sep) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1011 | char *s, *sep; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1012 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1013 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1014 | WORD_LIST *w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1015 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1016 | if (s == 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1017 | return((ARRAY *)NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1018 | w = list_string (s, sep, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1019 | if (w == 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1020 | return((ARRAY *)NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1021 | a = array_from_word_list (w); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1022 | return (a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1023 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1024 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1026 | #if defined (TEST_ARRAY) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1027 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1028 | * To make a running version, compile -DTEST_ARRAY and link with: | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1029 | * xmalloc.o syntax.o lib/malloc/libmalloc.a lib/sh/libsh.a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1030 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1031 | int interrupt_immediately = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1032 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1033 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1034 | signal_is_trapped(s) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1035 | int s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1036 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1037 | return 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1038 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1039 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1040 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1041 | fatal_error(const char *s, ...) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1042 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1043 | fprintf(stderr, "array_test: fatal memory error\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1044 | abort(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1045 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1047 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1048 | programming_error(const char *s, ...) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1049 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1050 | fprintf(stderr, "array_test: fatal programming error\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1051 | abort(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1052 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1053 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1054 | WORD_DESC * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1055 | make_bare_word (s) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1056 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1057 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1058 | WORD_DESC *w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1060 | w = (WORD_DESC *)xmalloc(sizeof(WORD_DESC)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1061 | w->word = s ? savestring(s) : savestring (""); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1062 | w->flags = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1063 | return w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1064 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1066 | WORD_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1067 | make_word_list(x, l) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1068 | WORD_DESC *x; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1069 | WORD_LIST *l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1070 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1071 | WORD_LIST *w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1073 | w = (WORD_LIST *)xmalloc(sizeof(WORD_LIST)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1074 | w->word = x; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1075 | w->next = l; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1076 | return w; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1077 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1078 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1079 | WORD_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1080 | list_string(s, t, i) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1081 | char *s, *t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1082 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1083 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1084 | char *r, *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1085 | WORD_LIST *wl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1087 | if (s == 0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1088 | return (WORD_LIST *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1089 | r = savestring(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1090 | wl = (WORD_LIST *)NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1091 | a = strtok(r, t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1092 | while (a) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1093 | wl = make_word_list (make_bare_word(a), wl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1094 | a = strtok((char *)NULL, t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1095 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1096 | return (REVERSE_LIST (wl, WORD_LIST *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1097 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1099 | GENERIC_LIST * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1100 | list_reverse (list) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1101 | GENERIC_LIST *list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1102 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1103 | register GENERIC_LIST *next, *prev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1105 | for (prev = 0; list; ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1106 | next = list->next; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1107 | list->next = prev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1108 | prev = list; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1109 | list = next; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1110 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1111 | return prev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1112 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1113 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1114 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1115 | pat_subst(s, t, u, i) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1116 | char *s, *t, *u; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1117 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1118 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1119 | return ((char *)NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1120 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1121 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1122 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1123 | quote_string(s) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1124 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1125 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1126 | return savestring(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1127 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1128 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1129 | print_element(ae) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1130 | ARRAY_ELEMENT *ae; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1131 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1132 | char lbuf[INT_STRLEN_BOUND (intmax_t) + 1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1133 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1134 | printf("array[%s] = %s\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1135 | inttostr (element_index(ae), lbuf, sizeof (lbuf)), | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1136 | element_value(ae)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1137 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1139 | print_array(a) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1140 | ARRAY *a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1141 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1142 | printf("\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1143 | array_walk(a, print_element, (void *)NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1144 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1145 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1146 | main() | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1147 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1148 | ARRAY *a, *new_a, *copy_of_a; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1149 | ARRAY_ELEMENT *ae, *aew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1150 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1151 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1152 | a = array_create(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1153 | array_insert(a, 1, "one"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1154 | array_insert(a, 7, "seven"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1155 | array_insert(a, 4, "four"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1156 | array_insert(a, 1029, "one thousand twenty-nine"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1157 | array_insert(a, 12, "twelve"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1158 | array_insert(a, 42, "forty-two"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1159 | print_array(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1160 | s = array_to_string (a, " ", 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1161 | printf("s = %s\n", s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1162 | copy_of_a = array_from_string(s, " "); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1163 | printf("copy_of_a:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1164 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1165 | array_dispose(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1166 | printf("\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1167 | free(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1168 | ae = array_remove(a, 4); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1169 | array_dispose_element(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1170 | ae = array_remove(a, 1029); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1171 | array_dispose_element(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1172 | array_insert(a, 16, "sixteen"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1173 | print_array(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1174 | s = array_to_string (a, " ", 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1175 | printf("s = %s\n", s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1176 | copy_of_a = array_from_string(s, " "); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1177 | printf("copy_of_a:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1178 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1179 | array_dispose(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1180 | printf("\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1181 | free(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1182 | array_insert(a, 2, "two"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1183 | array_insert(a, 1029, "new one thousand twenty-nine"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1184 | array_insert(a, 0, "zero"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1185 | array_insert(a, 134, ""); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1186 | print_array(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1187 | s = array_to_string (a, ":", 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1188 | printf("s = %s\n", s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1189 | copy_of_a = array_from_string(s, ":"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1190 | printf("copy_of_a:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1191 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1192 | array_dispose(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1193 | printf("\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1194 | free(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1195 | new_a = array_copy(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1196 | print_array(new_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1197 | s = array_to_string (new_a, ":", 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1198 | printf("s = %s\n", s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1199 | copy_of_a = array_from_string(s, ":"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1200 | free(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1201 | printf("copy_of_a:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1202 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1203 | array_shift(copy_of_a, 2, AS_DISPOSE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1204 | printf("copy_of_a shifted by two:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1205 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1206 | ae = array_shift(copy_of_a, 2, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1207 | printf("copy_of_a shifted by two:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1208 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1209 | for ( ; ae; ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1210 | aew = element_forw(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1211 | array_dispose_element(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1212 | ae = aew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1213 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1214 | array_rshift(copy_of_a, 1, (char *)0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1215 | printf("copy_of_a rshift by 1:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1216 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1217 | array_rshift(copy_of_a, 2, "new element zero"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1218 | printf("copy_of_a rshift again by 2 with new element zero:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1219 | print_array(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1220 | s = array_to_assign(copy_of_a, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1221 | printf("copy_of_a=%s\n", s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1222 | free(s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1223 | ae = array_shift(copy_of_a, array_num_elements(copy_of_a), 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1224 | for ( ; ae; ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1225 | aew = element_forw(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1226 | array_dispose_element(ae); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1227 | ae = aew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1228 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1229 | array_dispose(copy_of_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1230 | printf("\n"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1231 | array_dispose(a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1232 | array_dispose(new_a); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1233 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1234 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
1235 | #endif /* TEST_ARRAY */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
1236 | #endif /* ARRAY_VARS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |