OpenCoverage

pathexp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/pathexp.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* pathexp.c -- The shell interface to the globbing library. */-
2-
3/* Copyright (C) 1995-2014 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#include "bashtypes.h"-
24#include <stdio.h>-
25-
26#if defined (HAVE_UNISTD_H)-
27# include <unistd.h>-
28#endif-
29-
30#include "bashansi.h"-
31-
32#include "shell.h"-
33#include "pathexp.h"-
34#include "flags.h"-
35-
36#include "shmbutil.h"-
37#include "bashintl.h"-
38-
39#include <glob/strmatch.h>-
40-
41static int glob_name_is_acceptable __P((const char *));-
42static void ignore_globbed_names __P((char **, sh_ignore_func_t *));-
43static char *split_ignorespec __P((char *, int *));-
44 -
45#if defined (USE_POSIX_GLOB_LIBRARY)-
46# include <glob.h>-
47typedef int posix_glob_errfunc_t __P((const char *, int));-
48#else-
49# include <glob/glob.h>-
50#endif-
51-
52/* Control whether * matches .files in globbing. */-
53int glob_dot_filenames;-
54-
55/* Control whether the extended globbing features are enabled. */-
56int extended_glob = EXTGLOB_DEFAULT;-
57-
58/* Control enabling special handling of `**' */-
59int glob_star = 0;-
60-
61/* Return nonzero if STRING has any unquoted special globbing chars in it. */-
62int-
63unquoted_glob_pattern_p (string)-
64 register char *string;-
65{-
66 register int c;-
67 char *send;-
68 int open;-
69-
70 DECLARE_MBSTATE;-
71-
72 open = 0;-
73 send = string + strlen (string);-
74-
75 while (c = *string++)
c = *string++Description
TRUEevaluated 196256284 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 62402102 times by 1 test
Evaluated by:
  • Self test
62402102-196256284
76 {-
77 switch (c)-
78 {-
79 case '?':
executed 13 times by 1 test: case '?':
Executed by:
  • Self test
13
80 case '*':
executed 152 times by 1 test: case '*':
Executed by:
  • Self test
152
81 return (1);
executed 165 times by 1 test: return (1);
Executed by:
  • Self test
165
82-
83 case '[':
executed 4455 times by 1 test: case '[':
Executed by:
  • Self test
4455
84 open++;-
85 continue;
executed 4455 times by 1 test: continue;
Executed by:
  • Self test
4455
86-
87 case ']':
executed 4428 times by 1 test: case ']':
Executed by:
  • Self test
4428
88 if (open)
openDescription
TRUEevaluated 603 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3825 times by 1 test
Evaluated by:
  • Self test
603-3825
89 return (1);
executed 603 times by 1 test: return (1);
Executed by:
  • Self test
603
90 continue;
executed 3825 times by 1 test: continue;
Executed by:
  • Self test
3825
91-
92 case '+':
executed 3381 times by 1 test: case '+':
Executed by:
  • Self test
3381
93 case '@':
executed 72 times by 1 test: case '@':
Executed by:
  • Self test
72
94 case '!':
executed 1557 times by 1 test: case '!':
Executed by:
  • Self test
1557
95 if (*string == '(') /*)*/
*string == '('Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4973 times by 1 test
Evaluated by:
  • Self test
37-4973
96 return (1);
executed 37 times by 1 test: return (1);
Executed by:
  • Self test
37
97 continue;
executed 4973 times by 1 test: continue;
Executed by:
  • Self test
4973
98-
99 case CTLESC:
executed 49577663 times by 1 test: case '\001':
Executed by:
  • Self test
49577663
100 case '\\':
executed 180 times by 1 test: case '\\':
Executed by:
  • Self test
180
101 if (*string++ == '\0')
*string++ == '\0'Description
TRUEevaluated 82 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49577761 times by 1 test
Evaluated by:
  • Self test
82-49577761
102 return (0);
executed 82 times by 1 test: return (0);
Executed by:
  • Self test
82
103 }
executed 49577761 times by 1 test: end of block
Executed by:
  • Self test
49577761
104-
105 /* Advance one fewer byte than an entire multibyte character to-
106 account for the auto-increment in the loop above. */-
107#ifdef HANDLE_MULTIBYTE-
108 string--;-
109 ADVANCE_CHAR_P (string, send - string);
executed 190590052 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 4103536 times by 1 test: end of block
Executed by:
  • Self test
executed 426 times by 1 test: end of block
Executed by:
  • Self test
executed 194693162 times by 1 test: (string) += (mblength < 1) ? 0 : (mblength - 1);
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 194693588 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1548556 times by 1 test
Evaluated by:
  • Self test
_fDescription
TRUEevaluated 190590052 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4103536 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-2Description
TRUEevaluated 183 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 194693405 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEevaluated 243 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 194693162 times by 1 test
Evaluated by:
  • Self test
183-194693588
110 string++;-
111#else-
112 ADVANCE_CHAR_P (string, send - string);-
113#endif-
114 }
executed 196242144 times by 1 test: end of block
Executed by:
  • Self test
196242144
115 return (0);
executed 62402102 times by 1 test: return (0);
Executed by:
  • Self test
62402102
116}-
117-
118/* Return 1 if C is a character that is `special' in a POSIX ERE and needs to-
119 be quoted to match itself. */-
120static inline int-
121ere_char (c)-
122 int c;-
123{-
124 switch (c)-
125 {-
126 case '.':
executed 10 times by 1 test: case '.':
Executed by:
  • Self test
10
127 case '[':
executed 18 times by 1 test: case '[':
Executed by:
  • Self test
18
128 case '\\':
executed 23 times by 1 test: case '\\':
Executed by:
  • Self test
23
129 case '(':
executed 7 times by 1 test: case '(':
Executed by:
  • Self test
7
130 case ')':
executed 7 times by 1 test: case ')':
Executed by:
  • Self test
7
131 case '*':
executed 3 times by 1 test: case '*':
Executed by:
  • Self test
3
132 case '+':
never executed: case '+':
0
133 case '?':
never executed: case '?':
0
134 case '{':
never executed: case '{':
0
135 case '|':
never executed: case '|':
0
136 case '^':
never executed: case '^':
0
137 case '$':
executed 1 time by 1 test: case '$':
Executed by:
  • Self test
1
138 return 1;
executed 69 times by 1 test: return 1;
Executed by:
  • Self test
69
139 default:
executed 125 times by 1 test: default:
Executed by:
  • Self test
125
140 return 0;
executed 125 times by 1 test: return 0;
Executed by:
  • Self test
125
141 }-
142 return (0);
dead code: return (0);
-
143}-
144-
145int-
146glob_char_p (s)-
147 const char *s;-
148{-
149 switch (*s)-
150 {-
151 case '*':
never executed: case '*':
0
152 case '[':
executed 1 time by 1 test: case '[':
Executed by:
  • Self test
1
153 case ']':
executed 1 time by 1 test: case ']':
Executed by:
  • Self test
1
154 case '?':
never executed: case '?':
0
155 case '\\':
executed 7 times by 1 test: case '\\':
Executed by:
  • Self test
7
156 return 1;
executed 9 times by 1 test: return 1;
Executed by:
  • Self test
9
157 case '+':
executed 2 times by 1 test: case '+':
Executed by:
  • Self test
2
158 case '@':
never executed: case '@':
0
159 case '!':
executed 9 times by 1 test: case '!':
Executed by:
  • Self test
9
160 if (s[1] == '(') /*(*/
s[1] == '('Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
0-11
161 return 1;
never executed: return 1;
0
162 break;
executed 11 times by 1 test: break;
Executed by:
  • Self test
11
163 }-
164 return 0;
executed 102 times by 1 test: return 0;
Executed by:
  • Self test
102
165}-
166-
167/* PATHNAME can contain characters prefixed by CTLESC; this indicates-
168 that the character is to be quoted. We quote it here in the style-
169 that the glob library recognizes. If flags includes QGLOB_CVTNULL,-
170 we change quoted null strings (pathname[0] == CTLNUL) into empty-
171 strings (pathname[0] == 0). If this is called after quote removal-
172 is performed, (flags & QGLOB_CVTNULL) should be 0; if called when quote-
173 removal has not been done (for example, before attempting to match a-
174 pattern while executing a case statement), flags should include-
175 QGLOB_CVTNULL. If flags includes QGLOB_FILENAME, appropriate quoting-
176 to match a filename should be performed. QGLOB_REGEXP means we're-
177 quoting for a Posix ERE (for [[ string =~ pat ]]) and that requires-
178 some special handling. */-
179char *-
180quote_string_for_globbing (pathname, qflags)-
181 const char *pathname;-
182 int qflags;-
183{-
184 char *temp;-
185 register int i, j;-
186 int cclass, collsym, equiv, c, last_was_backslash;-
187 int savei, savej;-
188-
189 temp = (char *)xmalloc (2 * strlen (pathname) + 1);-
190-
191 if ((qflags & QGLOB_CVTNULL) && QUOTED_NULL (pathname))
(qflags & 0x01)Description
TRUEevaluated 49171180 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 805 times by 1 test
Evaluated by:
  • Self test
(pathname)[0] == '\177'Description
TRUEevaluated 8219675 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40951505 times by 1 test
Evaluated by:
  • Self test
(pathname)[1] == '\0'Description
TRUEevaluated 8219675 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-49171180
192 {-
193 temp[0] = '\0';-
194 return temp;
executed 8219675 times by 1 test: return temp;
Executed by:
  • Self test
8219675
195 }-
196-
197 cclass = collsym = equiv = last_was_backslash = 0;-
198 for (i = j = 0; pathname[i]; i++)
pathname[i]Description
TRUEevaluated 115655548 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 40952302 times by 1 test
Evaluated by:
  • Self test
40952302-115655548
199 {-
200 /* Fix for CTLESC at the end of the string? */-
201 if (pathname[i] == CTLESC && pathname[i+1] == '\0')
pathname[i] == '\001'Description
TRUEevaluated 87526480 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28129068 times by 1 test
Evaluated by:
  • Self test
pathname[i+1] == '\0'Description
TRUEnever evaluated
FALSEevaluated 87526480 times by 1 test
Evaluated by:
  • Self test
0-87526480
202 {-
203 temp[j++] = pathname[i++];-
204 break;
never executed: break;
0
205 }-
206 /* If we are parsing regexp, turn CTLESC CTLESC into CTLESC. It's not an-
207 ERE special character, so we should just be able to pass it through. */-
208 else if ((qflags & (QGLOB_REGEXP|QGLOB_CTLESC)) && pathname[i] == CTLESC && pathname[i+1] == CTLESC)
(qflags & (0x04|0x08))Description
TRUEevaluated 28117882 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87537666 times by 1 test
Evaluated by:
  • Self test
pathname[i] == '\001'Description
TRUEevaluated 259 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28117623 times by 1 test
Evaluated by:
  • Self test
pathname[i+1] == '\001'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 235 times by 1 test
Evaluated by:
  • Self test
24-87537666
209 {-
210 i++;-
211 temp[j++] = pathname[i];-
212 continue;
executed 24 times by 1 test: continue;
Executed by:
  • Self test
24
213 }-
214 else if (pathname[i] == CTLESC)
pathname[i] == '\001'Description
TRUEevaluated 87526456 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28129068 times by 1 test
Evaluated by:
  • Self test
28129068-87526456
215 {-
216 if ((qflags & QGLOB_FILENAME) && pathname[i+1] == '/')
(qflags & 0x02)Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87526424 times by 1 test
Evaluated by:
  • Self test
pathname[i+1] == '/'Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
0-87526424
217 continue;
never executed: continue;
0
218 /* What to do if preceding char is backslash? */-
219 if (pathname[i+1] != CTLESC && (qflags & QGLOB_REGEXP) && ere_char (pathname[i+1]) == 0)
pathname[i+1] != '\001'Description
TRUEevaluated 87526392 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64 times by 1 test
Evaluated by:
  • Self test
(qflags & 0x04)Description
TRUEevaluated 194 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87526198 times by 1 test
Evaluated by:
  • Self test
ere_char (pathname[i+1]) == 0Description
TRUEevaluated 125 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
64-87526392
220 continue;
executed 125 times by 1 test: continue;
Executed by:
  • Self test
125
221 temp[j++] = '\\';-
222 i++;-
223 if (pathname[i] == '\0')
pathname[i] == '\0'Description
TRUEnever evaluated
FALSEevaluated 87526331 times by 1 test
Evaluated by:
  • Self test
0-87526331
224 break;
never executed: break;
0
225 }
executed 87526331 times by 1 test: end of block
Executed by:
  • Self test
87526331
226 else if ((qflags & QGLOB_REGEXP) && (i == 0 || pathname[i-1] != CTLESC) && pathname[i] == '[') /*]*/
(qflags & 0x04)Description
TRUEevaluated 339 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28128729 times by 1 test
Evaluated by:
  • Self test
i == 0Description
TRUEevaluated 41 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 298 times by 1 test
Evaluated by:
  • Self test
pathname[i-1] != '\001'Description
TRUEevaluated 170 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
pathname[i] == '['Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 172 times by 1 test
Evaluated by:
  • Self test
39-28128729
227 {-
228 temp[j++] = pathname[i++]; /* open bracket */-
229 savej = j;-
230 savei = i;-
231 c = pathname[i++]; /* c == char after open bracket */-
232 if (c == '^') /* ignore pattern negation */
c == '^'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
7-32
233 {-
234 temp[j++] = c;-
235 c = pathname[i++];-
236 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
237 if (c == ']') /* ignore right bracket if first char */
c == ']'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
1-38
238 {-
239 temp[j++] = c;-
240 c = pathname[i++];-
241 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
242 do-
243 {-
244 if (c == 0)
c == 0Description
TRUEnever evaluated
FALSEevaluated 146 times by 1 test
Evaluated by:
  • Self test
0-146
245 goto endpat;
never executed: goto endpat;
0
246 else if (c == CTLESC)
c == '\001'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
16-130
247 {-
248 /* skip c, check for EOS, let assignment at end of loop */-
249 /* pathname[i] == backslash-escaped character */-
250 if (pathname[i] == 0)
pathname[i] == 0Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-16
251 goto endpat;
never executed: goto endpat;
0
252 temp[j++] = pathname[i++];-
253 }
executed 16 times by 1 test: end of block
Executed by:
  • Self test
16
254 else if (c == '[' && pathname[i] == ':')
c == '['Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
pathname[i] == ':'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
9-107
255 {-
256 temp[j++] = c;-
257 temp[j++] = pathname[i++];-
258 cclass = 1;-
259 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
260 else if (cclass && c == ':' && pathname[i] == ']')
cclassDescription
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 67 times by 1 test
Evaluated by:
  • Self test
c == ':'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
pathname[i] == ']'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-67
261 {-
262 temp[j++] = c;-
263 temp[j++] = pathname[i++];-
264 cclass = 0;-
265 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
266 else if (c == '[' && pathname[i] == '=')
c == '['Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 98 times by 1 test
Evaluated by:
  • Self test
pathname[i] == '='Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
6-98
267 {-
268 temp[j++] = c;-
269 temp[j++] = pathname[i++];-
270 if (pathname[i] == ']')
pathname[i] == ']'Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
271 temp[j++] = pathname[i++]; /* right brack can be in equiv */
never executed: temp[j++] = pathname[i++];
0
272 equiv = 1;-
273 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
274 else if (equiv && c == '=' && pathname[i] == ']')
equivDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 94 times by 1 test
Evaluated by:
  • Self test
c == '='Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
pathname[i] == ']'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-94
275 {-
276 temp[j++] = c;-
277 temp[j++] = pathname[i++];-
278 equiv = 0;-
279 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
280 else if (c == '[' && pathname[i] == '.')
c == '['Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 92 times by 1 test
Evaluated by:
  • Self test
pathname[i] == '.'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-92
281 {-
282 temp[j++] = c;-
283 temp[j++] = pathname[i++];-
284 if (pathname[i] == ']')
pathname[i] == ']'Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-8
285 temp[j++] = pathname[i++]; /* right brack can be in collsym */
never executed: temp[j++] = pathname[i++];
0
286 collsym = 1;-
287 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
288 else if (collsym && c == '.' && pathname[i] == ']')
collsymDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 76 times by 1 test
Evaluated by:
  • Self test
c == '.'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
pathname[i] == ']'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-76
289 {-
290 temp[j++] = c;-
291 temp[j++] = pathname[i++];-
292 collsym = 0;-
293 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
294 else-
295 temp[j++] = c;
executed 84 times by 1 test: temp[j++] = c;
Executed by:
  • Self test
84
296 }-
297 while (((c = pathname[i++]) != ']') && c != 0);
((c = pathname[i++]) != ']')Description
TRUEevaluated 108 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
c != 0Description
TRUEevaluated 107 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-108
298-
299 /* If we don't find the closing bracket before we hit the end of-
300 the string, rescan string without treating it as a bracket-
301 expression (has implications for backslash and special ERE-
302 chars) */-
303 if (c == 0)
c == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
1-38
304 {-
305 i = savei - 1; /* -1 for autoincrement above */-
306 j = savej;-
307 continue;
executed 1 time by 1 test: continue;
Executed by:
  • Self test
1
308 }-
309-
310 temp[j++] = c; /* closing right bracket */-
311 i--; /* increment will happen above in loop */-
312 continue; /* skip double assignment below */
executed 38 times by 1 test: continue;
Executed by:
  • Self test
38
313 }-
314 else if (pathname[i] == '\\' && (qflags & QGLOB_REGEXP) == 0)
pathname[i] == '\\'Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28128919 times by 1 test
Evaluated by:
  • Self test
(qflags & 0x04) == 0Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
9-28128919
315 {-
316 /* XXX - if not quoting regexp, use backslash as quote char. Should-
317 we just pass it through without treating it as special? That is-
318 what ksh93 seems to do. */-
319-
320 /* If we want to pass through backslash unaltered, comment out these-
321 lines. */-
322 temp[j++] = '\\';-
323-
324 i++;-
325 if (pathname[i] == '\0')
pathname[i] == '\0'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
8-93
326 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
327 /* If we are turning CTLESC CTLESC into CTLESC, we need to do that-
328 even when the first CTLESC is preceded by a backslash. */-
329 if ((qflags & QGLOB_CTLESC) && pathname[i] == CTLESC && pathname[i+1] == CTLESC)
(qflags & 0x08)Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
pathname[i] == '\001'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 51 times by 1 test
Evaluated by:
  • Self test
pathname[i+1] == '\001'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-55
330 i++; /* skip over one of the CTLESCs */
executed 4 times by 1 test: i++;
Executed by:
  • Self test
4
331 }
executed 93 times by 1 test: end of block
Executed by:
  • Self test
93
332 else if (pathname[i] == '\\' && (qflags & QGLOB_REGEXP))
pathname[i] == '\\'Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28128919 times by 1 test
Evaluated by:
  • Self test
(qflags & 0x04)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-28128919
333 last_was_backslash = 1;
executed 9 times by 1 test: last_was_backslash = 1;
Executed by:
  • Self test
9
334 temp[j++] = pathname[i];-
335 }
executed 115655352 times by 1 test: end of block
Executed by:
  • Self test
115655352
336endpat:
code before this statement executed 40952310 times by 1 test: endpat:
Executed by:
  • Self test
40952310
337 temp[j] = '\0';-
338-
339 return (temp);
executed 40952310 times by 1 test: return (temp);
Executed by:
  • Self test
40952310
340}-
341-
342char *-
343quote_globbing_chars (string)-
344 const char *string;-
345{-
346 size_t slen;-
347 char *temp, *t;-
348 const char *s, *send;-
349 DECLARE_MBSTATE;-
350-
351 slen = strlen (string);-
352 send = string + slen;-
353-
354 temp = (char *)xmalloc (slen * 2 + 1);-
355 for (t = temp, s = string; *s; )
*sDescription
TRUEevaluated 109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-109
356 {-
357 if (glob_char_p (s))
glob_char_p (s)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 100 times by 1 test
Evaluated by:
  • Self test
9-100
358 *t++ = '\\';
executed 9 times by 1 test: *t++ = '\\';
Executed by:
  • Self test
9
359-
360 /* Copy a single (possibly multibyte) character from s to t,-
361 incrementing both. */-
362 COPY_CHAR_P (t, s, send);
executed 42 times by 1 test: mblength = 1;
Executed by:
  • Self test
executed 1 time by 1 test: mblength = 1;
Executed by:
  • Self test
never executed: end of block
never executed: end of block
executed 43 times by 1 test: mblength = (mblength < 1) ? 1 : mblength;
Executed by:
  • Self test
executed 43 times by 1 test: *(t)++ = *(s)++;
Executed by:
  • Self test
executed 43 times by 1 test: end of block
Executed by:
  • Self test
executed 66 times by 1 test: *(t)++ = *(s)++;
Executed by:
  • Self test
locale_mb_cur_max > 1Description
TRUEevaluated 43 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
_kDescription
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
_k < mblengthDescription
TRUEevaluated 43 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
(mblength < 1)Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
locale_utf8localeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((*(s) & 0x80) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
0-66
363 }
executed 109 times by 1 test: end of block
Executed by:
  • Self test
109
364 *t = '\0';-
365 return temp;
executed 5 times by 1 test: return temp;
Executed by:
  • Self test
5
366}-
367-
368/* Call the glob library to do globbing on PATHNAME. */-
369char **-
370shell_glob_filename (pathname)-
371 const char *pathname;-
372{-
373#if defined (USE_POSIX_GLOB_LIBRARY)-
374 register int i;-
375 char *temp, **results;-
376 glob_t filenames;-
377 int glob_flags;-
378-
379 temp = quote_string_for_globbing (pathname, QGLOB_FILENAME);-
380-
381 filenames.gl_offs = 0;-
382-
383# if defined (GLOB_PERIOD)-
384 glob_flags = glob_dot_filenames ? GLOB_PERIOD : 0;-
385# else-
386 glob_flags = 0;-
387# endif /* !GLOB_PERIOD */-
388-
389 glob_flags |= (GLOB_ERR | GLOB_DOOFFS);-
390-
391 i = glob (temp, glob_flags, (posix_glob_errfunc_t *)NULL, &filenames);-
392-
393 free (temp);-
394-
395 if (i == GLOB_NOSPACE || i == GLOB_ABORTED)-
396 return ((char **)NULL);-
397 else if (i == GLOB_NOMATCH)-
398 filenames.gl_pathv = (char **)NULL;-
399 else if (i != 0) /* other error codes not in POSIX.2 */-
400 filenames.gl_pathv = (char **)NULL;-
401-
402 results = filenames.gl_pathv;-
403-
404 if (results && ((GLOB_FAILED (results)) == 0))-
405 {-
406 if (should_ignore_glob_matches ())-
407 ignore_glob_matches (results);-
408 if (results && results[0])-
409 strvec_sort (results);-
410 else-
411 {-
412 FREE (results);-
413 results = (char **)NULL;-
414 }-
415 }-
416-
417 return (results);-
418-
419#else /* !USE_POSIX_GLOB_LIBRARY */-
420-
421 char *temp, **results;-
422 int gflags;-
423-
424 noglob_dot_filenames = glob_dot_filenames == 0;-
425-
426 temp = quote_string_for_globbing (pathname, QGLOB_FILENAME);-
427 gflags = glob_star ? GX_GLOBSTAR : 0;
glob_starDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 780 times by 1 test
Evaluated by:
  • Self test
25-780
428 results = glob_filename (temp, gflags);-
429 free (temp);-
430-
431 if (results && ((GLOB_FAILED (results)) == 0))
resultsDescription
TRUEevaluated 805 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((results) ==..._return) == 0)Description
TRUEevaluated 748 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
0-805
432 {-
433 if (should_ignore_glob_matches ())
should_ignore_glob_matches ()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 744 times by 1 test
Evaluated by:
  • Self test
4-744
434 ignore_glob_matches (results);
executed 4 times by 1 test: ignore_glob_matches (results);
Executed by:
  • Self test
4
435 if (results && results[0])
resultsDescription
TRUEevaluated 748 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
results[0]Description
TRUEevaluated 110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 638 times by 1 test
Evaluated by:
  • Self test
0-748
436 strvec_sort (results);
executed 110 times by 1 test: strvec_sort (results);
Executed by:
  • Self test
110
437 else-
438 {-
439 FREE (results);
executed 638 times by 1 test: sh_xfree((results), "pathexp.c", 439);
Executed by:
  • Self test
resultsDescription
TRUEevaluated 638 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-638
440 results = (char **)&glob_error_return;-
441 }
executed 638 times by 1 test: end of block
Executed by:
  • Self test
638
442 }-
443-
444 return (results);
executed 805 times by 1 test: return (results);
Executed by:
  • Self test
805
445#endif /* !USE_POSIX_GLOB_LIBRARY */-
446}-
447-
448/* Stuff for GLOBIGNORE. */-
449-
450static struct ignorevar globignore =-
451{-
452 "GLOBIGNORE",-
453 (struct ign *)0,-
454 0,-
455 (char *)0,-
456 (sh_iv_item_func_t *)0,-
457};-
458-
459/* Set up to ignore some glob matches because the value of GLOBIGNORE-
460 has changed. If GLOBIGNORE is being unset, we also need to disable-
461 the globbing of filenames beginning with a `.'. */-
462void-
463setup_glob_ignore (name)-
464 char *name;-
465{-
466 char *v;-
467-
468 v = get_string_value (name);-
469 setup_ignore_patterns (&globignore);-
470-
471 if (globignore.num_ignores)
globignore.num_ignoresDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
4-18
472 glob_dot_filenames = 1;
executed 4 times by 1 test: glob_dot_filenames = 1;
Executed by:
  • Self test
4
473 else if (v == 0)
v == 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-17
474 glob_dot_filenames = 0;
executed 17 times by 1 test: glob_dot_filenames = 0;
Executed by:
  • Self test
17
475}
executed 22 times by 1 test: end of block
Executed by:
  • Self test
22
476-
477int-
478should_ignore_glob_matches ()-
479{-
480 return globignore.num_ignores;
executed 748 times by 1 test: return globignore.num_ignores;
Executed by:
  • Self test
748
481}-
482-
483/* Return 0 if NAME matches a pattern in the globignore.ignores list. */-
484static int-
485glob_name_is_acceptable (name)-
486 const char *name;-
487{-
488 struct ign *p;-
489 int flags;-
490-
491 /* . and .. are never matched */-
492 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
name[0] == '.'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 62 times by 1 test
Evaluated by:
  • Self test
name[1] == '\0'Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
name[1] == '.'Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
name[2] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-62
493 return (0);
never executed: return (0);
0
494-
495 flags = FNM_PATHNAME | FNMATCH_EXTFLAG | FNMATCH_NOCASEGLOB;-
496 for (p = globignore.ignores; p->val; p++)
p->valDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
19-184
497 {-
498 if (strmatch (p->val, (char *)name, flags) != FNM_NOMATCH)
strmatch (p->v...e, flags) != 1Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 135 times by 1 test
Evaluated by:
  • Self test
49-135
499 return (0);
executed 49 times by 1 test: return (0);
Executed by:
  • Self test
49
500 }
executed 135 times by 1 test: end of block
Executed by:
  • Self test
135
501 return (1);
executed 19 times by 1 test: return (1);
Executed by:
  • Self test
19
502}-
503-
504/* Internal function to test whether filenames in NAMES should be-
505 ignored. NAME_FUNC is a pointer to a function to call with each-
506 name. It returns non-zero if the name is acceptable to the particular-
507 ignore function which called _ignore_names; zero if the name should-
508 be removed from NAMES. */-
509-
510static void-
511ignore_globbed_names (names, name_func)-
512 char **names;-
513 sh_ignore_func_t *name_func;-
514{-
515 char **newnames;-
516 int n, i;-
517-
518 for (i = 0; names[i]; i++)
names[i]Description
TRUEevaluated 68 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-68
519 ;
executed 68 times by 1 test: ;
Executed by:
  • Self test
68
520 newnames = strvec_create (i + 1);-
521-
522 for (n = i = 0; names[i]; i++)
names[i]Description
TRUEevaluated 68 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-68
523 {-
524 if ((*name_func) (names[i]))
(*name_func) (names[i])Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test
19-49
525 newnames[n++] = names[i];
executed 19 times by 1 test: newnames[n++] = names[i];
Executed by:
  • Self test
19
526 else-
527 free (names[i]);
executed 49 times by 1 test: sh_xfree((names[i]), "pathexp.c", 527);
Executed by:
  • Self test
49
528 }-
529-
530 newnames[n] = (char *)NULL;-
531-
532 if (n == 0)
n == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2
533 {-
534 names[0] = (char *)NULL;-
535 free (newnames);-
536 return;
executed 2 times by 1 test: return;
Executed by:
  • Self test
2
537 }-
538-
539 /* Copy the acceptable names from NEWNAMES back to NAMES and set the-
540 new array end. */-
541 for (n = 0; newnames[n]; n++)
newnames[n]Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-19
542 names[n] = newnames[n];
executed 19 times by 1 test: names[n] = newnames[n];
Executed by:
  • Self test
19
543 names[n] = (char *)NULL;-
544 free (newnames);-
545}
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
546-
547void-
548ignore_glob_matches (names)-
549 char **names;-
550{-
551 if (globignore.num_ignores == 0)
globignore.num_ignores == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
552 return;
never executed: return;
0
553-
554 ignore_globbed_names (names, glob_name_is_acceptable);-
555}
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
556-
557static char *-
558split_ignorespec (s, ip)-
559 char *s;-
560 int *ip;-
561{-
562 char *t;-
563 int n, i;-
564-
565 if (s == 0)
s == 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
566 return 0;
never executed: return 0;
0
567-
568 i = *ip;-
569 if (s[i] == 0)
s[i] == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
6-20
570 return 0;
executed 6 times by 1 test: return 0;
Executed by:
  • Self test
6
571-
572 n = skip_to_delim (s, i, ":", SD_NOJMP|SD_EXTGLOB|SD_GLOB);-
573 t = substring (s, i, n);-
574-
575 if (s[n] == ':')
s[n] == ':'Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-14
576 n++;
executed 14 times by 1 test: n++;
Executed by:
  • Self test
14
577 *ip = n; -
578 return t;
executed 20 times by 1 test: return t;
Executed by:
  • Self test
20
579}-
580 -
581void-
582setup_ignore_patterns (ivp)-
583 struct ignorevar *ivp;-
584{-
585 int numitems, maxitems, ptr;-
586 char *colon_bit, *this_ignoreval;-
587 struct ign *p;-
588-
589 this_ignoreval = get_string_value (ivp->varname);-
590-
591 /* If nothing has changed then just exit now. */-
592 if ((this_ignoreval && ivp->last_ignoreval && STREQ (this_ignoreval, ivp->last_ignoreval)) ||
never executed: __result = (((const unsigned char *) (const char *) ( this_ignoreval ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( ivp->last_ignoreval ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
this_ignorevalDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test
ivp->last_ignorevalDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
(this_ignoreva..._ignoreval)[0]Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-50
593 (!this_ignoreval && !ivp->last_ignoreval))
!this_ignorevalDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
!ivp->last_ignorevalDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-50
594 return;
executed 52 times by 1 test: return;
Executed by:
  • Self test
52
595-
596 /* Oops. The ignore variable has changed. Re-parse it. */-
597 ivp->num_ignores = 0;-
598-
599 if (ivp->ignores)
ivp->ignoresDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
3-5
600 {-
601 for (p = ivp->ignores; p->val; p++)
p->valDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-10
602 free(p->val);
executed 10 times by 1 test: sh_xfree((p->val), "pathexp.c", 602);
Executed by:
  • Self test
10
603 free (ivp->ignores);-
604 ivp->ignores = (struct ign *)NULL;-
605 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
606-
607 if (ivp->last_ignoreval)
ivp->last_ignorevalDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
3-5
608 {-
609 free (ivp->last_ignoreval);-
610 ivp->last_ignoreval = (char *)NULL;-
611 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
612-
613 if (this_ignoreval == 0 || *this_ignoreval == '\0')
this_ignoreval == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
*this_ignoreval == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
1-7
614 return;
executed 2 times by 1 test: return;
Executed by:
  • Self test
2
615-
616 ivp->last_ignoreval = savestring (this_ignoreval);-
617-
618 numitems = maxitems = ptr = 0;-
619-
620#if 0-
621 while (colon_bit = extract_colon_unit (this_ignoreval, &ptr))-
622#else-
623 while (colon_bit = split_ignorespec (this_ignoreval, &ptr))
colon_bit = sp...noreval, &ptr)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-20
624#endif-
625 {-
626 if (numitems + 1 >= maxitems)
numitems + 1 >= maxitemsDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
6-14
627 {-
628 maxitems += 10;-
629 ivp->ignores = (struct ign *)xrealloc (ivp->ignores, maxitems * sizeof (struct ign));-
630 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
631 ivp->ignores[numitems].val = colon_bit;-
632 ivp->ignores[numitems].len = strlen (colon_bit);-
633 ivp->ignores[numitems].flags = 0;-
634 if (ivp->item_func)
ivp->item_funcDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
7-13
635 (*ivp->item_func) (&ivp->ignores[numitems]);
executed 7 times by 1 test: (*ivp->item_func) (&ivp->ignores[numitems]);
Executed by:
  • Self test
7
636 numitems++;-
637 }
executed 20 times by 1 test: end of block
Executed by:
  • Self test
20
638 ivp->ignores[numitems].val = (char *)NULL;-
639 ivp->num_ignores = numitems;-
640}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2