OpenCoverage

dircolors.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/dircolors.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* dircolors - output commands to set the LS_COLOR environment variable-
2 Copyright (C) 1996-2018 Free Software Foundation, Inc.-
3 Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000 H. Peter Anvin-
4-
5 This program is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation, either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 This program is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
17-
18#include <config.h>-
19-
20#include <sys/types.h>-
21#include <fnmatch.h>-
22#include <getopt.h>-
23-
24#include "system.h"-
25#include "dircolors.h"-
26#include "c-strcase.h"-
27#include "die.h"-
28#include "error.h"-
29#include "obstack.h"-
30#include "quote.h"-
31#include "stdio--.h"-
32#include "xstrndup.h"-
33-
34/* The official name of this program (e.g., no 'g' prefix). */-
35#define PROGRAM_NAME "dircolors"-
36-
37#define AUTHORS proper_name ("H. Peter Anvin")-
38-
39#define obstack_chunk_alloc malloc-
40#define obstack_chunk_free free-
41-
42enum Shell_syntax-
43{-
44 SHELL_SYNTAX_BOURNE,-
45 SHELL_SYNTAX_C,-
46 SHELL_SYNTAX_UNKNOWN-
47};-
48-
49#define APPEND_CHAR(C) obstack_1grow (&lsc_obstack, C)-
50#define APPEND_TWO_CHAR_STRING(S) \-
51 do \-
52 { \-
53 APPEND_CHAR (S[0]); \-
54 APPEND_CHAR (S[1]); \-
55 } \-
56 while (0)-
57-
58/* Accumulate in this obstack the value for the LS_COLORS environment-
59 variable. */-
60static struct obstack lsc_obstack;-
61-
62static const char *const slack_codes[] =-
63{-
64 "NORMAL", "NORM", "FILE", "RESET", "DIR", "LNK", "LINK",-
65 "SYMLINK", "ORPHAN", "MISSING", "FIFO", "PIPE", "SOCK", "BLK", "BLOCK",-
66 "CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",-
67 "END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",-
68 "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",-
69 "MULTIHARDLINK", "CLRTOEOL", NULL-
70};-
71-
72static const char *const ls_codes[] =-
73{-
74 "no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi",-
75 "so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",-
76 "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "mh", "cl", NULL-
77};-
78verify (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes));-
79-
80static struct option const long_options[] =-
81 {-
82 {"bourne-shell", no_argument, NULL, 'b'},-
83 {"sh", no_argument, NULL, 'b'},-
84 {"csh", no_argument, NULL, 'c'},-
85 {"c-shell", no_argument, NULL, 'c'},-
86 {"print-database", no_argument, NULL, 'p'},-
87 {GETOPT_HELP_OPTION_DECL},-
88 {GETOPT_VERSION_OPTION_DECL},-
89 {NULL, 0, NULL, 0}-
90 };-
91-
92void-
93usage (int status)-
94{-
95 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 11 times by 1 test
Evaluated by:
  • dircolors
3-11
96 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • dircolors
3
97 else-
98 {-
99 printf (_("Usage: %s [OPTION]... [FILE]\n"), program_name);-
100 fputs (_("\-
101Output commands to set the LS_COLORS environment variable.\n\-
102\n\-
103Determine format of output:\n\-
104 -b, --sh, --bourne-shell output Bourne shell code to set LS_COLORS\n\-
105 -c, --csh, --c-shell output C shell code to set LS_COLORS\n\-
106 -p, --print-database output defaults\n\-
107"), stdout);-
108 fputs (HELP_OPTION_DESCRIPTION, stdout);-
109 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
110 fputs (_("\-
111\n\-
112If FILE is specified, read it to determine which colors to use for which\n\-
113file types and extensions. Otherwise, a precompiled database is used.\n\-
114For details on the format of these files, run 'dircolors --print-database'.\n\-
115"), stdout);-
116 emit_ancillary_info (PROGRAM_NAME);-
117 }
executed 11 times by 1 test: end of block
Executed by:
  • dircolors
11
118-
119 exit (status);
executed 14 times by 1 test: exit (status);
Executed by:
  • dircolors
14
120}-
121-
122/* If the SHELL environment variable is set to 'csh' or 'tcsh,'-
123 assume C shell. Else Bourne shell. */-
124-
125static enum Shell_syntax-
126guess_shell_syntax (void)-
127{-
128 char *shell;-
129-
130 shell = getenv ("SHELL");-
131 if (shell == NULL || *shell == '\0')
shell == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
*shell == '\0'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
0-1
132 return SHELL_SYNTAX_UNKNOWN;
never executed: return SHELL_SYNTAX_UNKNOWN;
0
133-
134 shell = last_component (shell);-
135-
136 if (STREQ (shell, "csh") || STREQ (shell, "tcsh"))
never executed: __result = (((const unsigned char *) (const char *) ( shell ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "csh" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( shell ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "tcsh" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
__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
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
__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
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
__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-1
137 return SHELL_SYNTAX_C;
never executed: return SHELL_SYNTAX_C;
0
138-
139 return SHELL_SYNTAX_BOURNE;
executed 1 time by 1 test: return SHELL_SYNTAX_BOURNE;
Executed by:
  • dircolors
1
140}-
141-
142static void-
143parse_line (char const *line, char **keyword, char **arg)-
144{-
145 char const *p;-
146 char const *keyword_start;-
147 char const *arg_start;-
148-
149 *keyword = NULL;-
150 *arg = NULL;-
151-
152 for (p = line; isspace (to_uchar (*p)); ++p)
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 414 times by 1 test
Evaluated by:
  • dircolors
4-414
153 continue;
executed 4 times by 1 test: continue;
Executed by:
  • dircolors
4
154-
155 /* Ignore blank lines and shell-style comments. */-
156 if (*p == '\0' || *p == '#')
*p == '\0'Description
TRUEnever evaluated
FALSEevaluated 414 times by 1 test
Evaluated by:
  • dircolors
*p == '#'Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 336 times by 1 test
Evaluated by:
  • dircolors
0-414
157 return;
executed 78 times by 1 test: return;
Executed by:
  • dircolors
78
158-
159 keyword_start = p;-
160-
161 while (!isspace (to_uchar (*p)) && *p != '\0')
! ((*__ctype_b...int) _ISspace)Description
TRUEevaluated 1489 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 336 times by 1 test
Evaluated by:
  • dircolors
*p != '\0'Description
TRUEevaluated 1489 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-1489
162 {-
163 ++p;-
164 }
executed 1489 times by 1 test: end of block
Executed by:
  • dircolors
1489
165-
166 *keyword = xstrndup (keyword_start, p - keyword_start);-
167 if (*p == '\0')
*p == '\0'Description
TRUEnever evaluated
FALSEevaluated 336 times by 1 test
Evaluated by:
  • dircolors
0-336
168 return;
never executed: return;
0
169-
170 do-
171 {-
172 ++p;-
173 }
executed 336 times by 1 test: end of block
Executed by:
  • dircolors
336
174 while (isspace (to_uchar (*p)));
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEevaluated 336 times by 1 test
Evaluated by:
  • dircolors
0-336
175-
176 if (*p == '\0' || *p == '#')
*p == '\0'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 335 times by 1 test
Evaluated by:
  • dircolors
*p == '#'Description
TRUEnever evaluated
FALSEevaluated 335 times by 1 test
Evaluated by:
  • dircolors
0-335
177 return;
executed 1 time by 1 test: return;
Executed by:
  • dircolors
1
178-
179 arg_start = p;-
180-
181 while (*p != '\0' && *p != '#')
*p != '\0'Description
TRUEevaluated 1810 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 301 times by 1 test
Evaluated by:
  • dircolors
*p != '#'Description
TRUEevaluated 1776 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 34 times by 1 test
Evaluated by:
  • dircolors
34-1810
182 ++p;
executed 1776 times by 1 test: ++p;
Executed by:
  • dircolors
1776
183-
184 for (--p; isspace (to_uchar (*p)); --p)
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 61 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 335 times by 1 test
Evaluated by:
  • dircolors
61-335
185 continue;
executed 61 times by 1 test: continue;
Executed by:
  • dircolors
61
186 ++p;-
187-
188 *arg = xstrndup (arg_start, p - arg_start);-
189}
executed 335 times by 1 test: end of block
Executed by:
  • dircolors
335
190-
191/* FIXME: Write a string to standard out, while watching for "dangerous"-
192 sequences like unescaped : and = characters. */-
193-
194static void-
195append_quoted (const char *str)-
196{-
197 bool need_backslash = true;-
198-
199 while (*str != '\0')
*str != '\0'Description
TRUEevaluated 89 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
21-89
200 {-
201 switch (*str)-
202 {-
203 case '\'':
executed 2 times by 1 test: case '\'':
Executed by:
  • dircolors
2
204 APPEND_CHAR ('\'');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
0-2
205 APPEND_CHAR ('\\');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
0-2
206 APPEND_CHAR ('\'');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
0-2
207 need_backslash = true;-
208 break;
executed 2 times by 1 test: break;
Executed by:
  • dircolors
2
209-
210 case '\\':
never executed: case '\\':
0
211 case '^':
never executed: case '^':
0
212 need_backslash = !need_backslash;-
213 break;
never executed: break;
0
214-
215 case ':':
executed 1 time by 1 test: case ':':
Executed by:
  • dircolors
1
216 case '=':
never executed: case '=':
0
217 if (need_backslash)
need_backslashDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-1
218 APPEND_CHAR ('\\');
executed 1 time by 1 test: __extension__ ({ struct obstack *__o = (&lsc_obstack); if (__extension__ ({ struct obstack const *__o1 = (__o); (size_t) (__o1->chunk_limit - __o1->next_free); }) < 1) _obstack_newchunk (__o, 1); ((void) (*((__o)->next_free)++ = ('\\'))); });
Executed by:
  • dircolors
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
0-1
219 FALLTHROUGH;-
220-
221 default:
code before this statement executed 1 time by 1 test: default:
Executed by:
  • dircolors
executed 86 times by 1 test: default:
Executed by:
  • dircolors
1-86
222 need_backslash = true;-
223 break;
executed 87 times by 1 test: break;
Executed by:
  • dircolors
87
224 }-
225-
226 APPEND_CHAR (*str);
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 89 times by 1 test
Evaluated by:
  • dircolors
0-89
227 ++str;-
228 }
executed 89 times by 1 test: end of block
Executed by:
  • dircolors
89
229}
executed 21 times by 1 test: end of block
Executed by:
  • dircolors
21
230-
231/* Read the file open on FP (with name FILENAME). First, look for a-
232 'TERM name' directive where name matches the current terminal type.-
233 Once found, translate and accumulate the associated directives onto-
234 the global obstack LSC_OBSTACK. Give a diagnostic-
235 upon failure (unrecognized keyword is the only way to fail here).-
236 Return true if successful. */-
237-
238static bool-
239dc_parse_stream (FILE *fp, const char *filename)-
240{-
241 size_t line_number = 0;-
242 char const *next_G_line = G_line;-
243 char *input_line = NULL;-
244 size_t input_line_size = 0;-
245 char const *line;-
246 char const *term;-
247 bool ok = true;-
248-
249 /* State for the parser. */-
250 enum { ST_TERMNO, ST_TERMYES, ST_TERMSURE, ST_GLOBAL } state = ST_GLOBAL;-
251-
252 /* Get terminal type */-
253 term = getenv ("TERM");-
254 if (term == NULL || *term == '\0')
term == ((void *)0)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
*term == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-10
255 term = "none";
executed 10 times by 1 test: term = "none";
Executed by:
  • dircolors
10
256-
257 while (1)-
258 {-
259 char *keywd, *arg;-
260 bool unrecognized;-
261-
262 ++line_number;-
263-
264 if (fp)
fpDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 388 times by 1 test
Evaluated by:
  • dircolors
36-388
265 {-
266 if (getline (&input_line, &input_line_size, fp) <= 0)
getline (&inpu...size, fp) <= 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 28 times by 1 test
Evaluated by:
  • dircolors
8-28
267 {-
268 free (input_line);-
269 break;
executed 8 times by 1 test: break;
Executed by:
  • dircolors
8
270 }-
271 line = input_line;-
272 }
executed 28 times by 1 test: end of block
Executed by:
  • dircolors
28
273 else-
274 {-
275 if (next_G_line == G_line + sizeof G_line)
next_G_line ==... sizeof G_lineDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 386 times by 1 test
Evaluated by:
  • dircolors
2-386
276 break;
executed 2 times by 1 test: break;
Executed by:
  • dircolors
2
277 line = next_G_line;-
278 next_G_line += strlen (next_G_line) + 1;-
279 }
executed 386 times by 1 test: end of block
Executed by:
  • dircolors
386
280-
281 parse_line (line, &keywd, &arg);-
282-
283 if (keywd == NULL)
keywd == ((void *)0)Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 336 times by 1 test
Evaluated by:
  • dircolors
78-336
284 continue;
executed 78 times by 1 test: continue;
Executed by:
  • dircolors
78
285-
286 if (arg == NULL)
arg == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 335 times by 1 test
Evaluated by:
  • dircolors
1-335
287 {-
288 error (0, 0, _("%s:%lu: invalid line; missing second token"),-
289 quotef (filename), (unsigned long int) line_number);-
290 ok = false;-
291 free (keywd);-
292 continue;
executed 1 time by 1 test: continue;
Executed by:
  • dircolors
1
293 }-
294-
295 unrecognized = false;-
296 if (c_strcasecmp (keywd, "TERM") == 0)
c_strcasecmp (..., "TERM") == 0Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 283 times by 1 test
Evaluated by:
  • dircolors
52-283
297 {-
298 if (fnmatch (arg, term, 0) == 0)
fnmatch (arg, term, 0) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 50 times by 1 test
Evaluated by:
  • dircolors
2-50
299 state = ST_TERMSURE;
executed 2 times by 1 test: state = ST_TERMSURE;
Executed by:
  • dircolors
2
300 else if (state != ST_TERMSURE)
state != ST_TERMSUREDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-50
301 state = ST_TERMNO;
executed 50 times by 1 test: state = ST_TERMNO;
Executed by:
  • dircolors
50
302 }
executed 52 times by 1 test: end of block
Executed by:
  • dircolors
52
303 else-
304 {-
305 if (state == ST_TERMSURE)
state == ST_TERMSUREDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 281 times by 1 test
Evaluated by:
  • dircolors
2-281
306 state = ST_TERMYES; /* Another TERM can cancel */
executed 2 times by 1 test: state = ST_TERMYES;
Executed by:
  • dircolors
2
307-
308 if (state != ST_TERMNO)
state != ST_TERMNODescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 262 times by 1 test
Evaluated by:
  • dircolors
21-262
309 {-
310 if (keywd[0] == '.')
keywd[0] == '.'Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
311 {-
312 APPEND_CHAR ('*');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
313 append_quoted (keywd);-
314 APPEND_CHAR ('=');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
315 append_quoted (arg);-
316 APPEND_CHAR (':');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
317 }
never executed: end of block
0
318 else if (keywd[0] == '*')
keywd[0] == '*'Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
319 {-
320 append_quoted (keywd);-
321 APPEND_CHAR ('=');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
322 append_quoted (arg);-
323 APPEND_CHAR (':');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEnever evaluated
0
324 }
never executed: end of block
0
325 else if (c_strcasecmp (keywd, "OPTIONS") == 0
c_strcasecmp (...OPTIONS") == 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
326 || c_strcasecmp (keywd, "COLOR") == 0
c_strcasecmp (... "COLOR") == 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
327 || c_strcasecmp (keywd, "EIGHTBIT") == 0)
c_strcasecmp (...IGHTBIT") == 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
328 {-
329 /* Ignore. */-
330 }
never executed: end of block
0
331 else-
332 {-
333 int i;-
334-
335 for (i = 0; slack_codes[i] != NULL; ++i)
slack_codes[i] != ((void *)0)Description
TRUEevaluated 458 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-458
336 if (c_strcasecmp (keywd, slack_codes[i]) == 0)
c_strcasecmp (...codes[i]) == 0Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 437 times by 1 test
Evaluated by:
  • dircolors
21-437
337 break;
executed 21 times by 1 test: break;
Executed by:
  • dircolors
21
338-
339 if (slack_codes[i] != NULL)
slack_codes[i] != ((void *)0)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-21
340 {-
341 APPEND_TWO_CHAR_STRING (ls_codes[i]);
never executed: _obstack_newchunk (__o, 1);
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
342 APPEND_CHAR ('=');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
343 append_quoted (arg);-
344 APPEND_CHAR (':');
never executed: _obstack_newchunk (__o, 1);
__extension__ ..._free); }) < 1Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dircolors
0-21
345 }
executed 21 times by 1 test: end of block
Executed by:
  • dircolors
21
346 else-
347 {-
348 unrecognized = true;-
349 }
never executed: end of block
0
350 }-
351 }-
352 else-
353 {-
354 unrecognized = true;-
355 }
executed 262 times by 1 test: end of block
Executed by:
  • dircolors
262
356 }-
357-
358 if (unrecognized && (state == ST_TERMSURE || state == ST_TERMYES))
unrecognizedDescription
TRUEevaluated 262 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 73 times by 1 test
Evaluated by:
  • dircolors
state == ST_TERMSUREDescription
TRUEnever evaluated
FALSEevaluated 262 times by 1 test
Evaluated by:
  • dircolors
state == ST_TERMYESDescription
TRUEnever evaluated
FALSEevaluated 262 times by 1 test
Evaluated by:
  • dircolors
0-262
359 {-
360 error (0, 0, _("%s:%lu: unrecognized keyword %s"),-
361 (filename ? quotef (filename) : _("<internal>")),-
362 (unsigned long int) line_number, keywd);-
363 ok = false;-
364 }
never executed: end of block
0
365-
366 free (keywd);-
367 free (arg);-
368 }
executed 335 times by 1 test: end of block
Executed by:
  • dircolors
335
369-
370 return ok;
executed 10 times by 1 test: return ok;
Executed by:
  • dircolors
10
371}-
372-
373static bool-
374dc_parse_file (const char *filename)-
375{-
376 bool ok;-
377-
378 if (! STREQ (filename, "-") && freopen (filename, "r", stdin) == NULL)
never executed: __result = (((const unsigned char *) (const char *) ( filename ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
! ( __extensio...)))); }) == 0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
__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
TRUEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
__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
freopen_safer ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
0-8
379 {-
380 error (0, errno, "%s", quotef (filename));-
381 return false;
never executed: return 0 ;
0
382 }-
383-
384 ok = dc_parse_stream (stdin, filename);-
385-
386 if (fclose (stdin) != 0)
rpl_fclose ( stdin ) != 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
0-8
387 {-
388 error (0, errno, "%s", quotef (filename));-
389 return false;
never executed: return 0 ;
0
390 }-
391-
392 return ok;
executed 8 times by 1 test: return ok;
Executed by:
  • dircolors
8
393}-
394-
395int-
396main (int argc, char **argv)-
397{-
398 bool ok = true;-
399 int optc;-
400 enum Shell_syntax syntax = SHELL_SYNTAX_UNKNOWN;-
401 bool print_database = false;-
402-
403 initialize_main (&argc, &argv);-
404 set_program_name (argv[0]);-
405 setlocale (LC_ALL, "");-
406 bindtextdomain (PACKAGE, LOCALEDIR);-
407 textdomain (PACKAGE);-
408-
409 atexit (close_stdout);-
410-
411 while ((optc = getopt_long (argc, argv, "bcp", long_options, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dircolors
10-35
412 switch (optc)-
413 {-
414 case 'b': /* Bourne shell syntax. */
executed 12 times by 1 test: case 'b':
Executed by:
  • dircolors
12
415 syntax = SHELL_SYNTAX_BOURNE;-
416 break;
executed 12 times by 1 test: break;
Executed by:
  • dircolors
12
417-
418 case 'c': /* C shell syntax. */
executed 3 times by 1 test: case 'c':
Executed by:
  • dircolors
3
419 syntax = SHELL_SYNTAX_C;-
420 break;
executed 3 times by 1 test: break;
Executed by:
  • dircolors
3
421-
422 case 'p':
executed 2 times by 1 test: case 'p':
Executed by:
  • dircolors
2
423 print_database = true;-
424 break;
executed 2 times by 1 test: break;
Executed by:
  • dircolors
2
425-
426 case_GETOPT_HELP_CHAR;
never executed: break;
executed 11 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • dircolors
0-11
427-
428 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • dircolors
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • dircolors
0-4
429-
430 default:
executed 3 times by 1 test: default:
Executed by:
  • dircolors
3
431 usage (EXIT_FAILURE);-
432 }
never executed: end of block
0
433-
434 argc -= optind;-
435 argv += optind;-
436-
437 /* It doesn't make sense to use --print with either of-
438 --bourne or --c-shell. */-
439 if (print_database && syntax != SHELL_SYNTAX_UNKNOWN)
print_databaseDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dircolors
syntax != SHELL_SYNTAX_UNKNOWNDescription
TRUEnever evaluated
FALSEnever evaluated
0-10
440 {-
441 error (0, 0,-
442 _("the options to output dircolors' internal database and\n"-
443 "to select a shell syntax are mutually exclusive"));-
444 usage (EXIT_FAILURE);-
445 }
never executed: end of block
0
446-
447 if ((!print_database) < argc)
(!print_database) < argcDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dircolors
0-10
448 {-
449 error (0, 0, _("extra operand %s"), quote (argv[!print_database]));-
450 if (print_database)
print_databaseDescription
TRUEnever evaluated
FALSEnever evaluated
0
451 fprintf (stderr, "%s\n",
never executed: fprintf ( stderr , "%s\n", dcgettext (((void *)0), "file operands cannot be combined with " "--print-database (-p)" , 5) );
0
452 _("file operands cannot be combined with "
never executed: fprintf ( stderr , "%s\n", dcgettext (((void *)0), "file operands cannot be combined with " "--print-database (-p)" , 5) );
0
453 "--print-database (-p)"));
never executed: fprintf ( stderr , "%s\n", dcgettext (((void *)0), "file operands cannot be combined with " "--print-database (-p)" , 5) );
0
454 usage (EXIT_FAILURE);-
455 }
never executed: end of block
0
456-
457 if (print_database)
print_databaseDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dircolors
0-10
458 {-
459 char const *p = G_line;-
460 while (p - G_line < sizeof G_line)
p - G_line < sizeof G_lineDescription
TRUEnever evaluated
FALSEnever evaluated
0
461 {-
462 puts (p);-
463 p += strlen (p) + 1;-
464 }
never executed: end of block
0
465 }
never executed: end of block
0
466 else-
467 {-
468 /* If shell syntax was not explicitly specified, try to guess it. */-
469 if (syntax == SHELL_SYNTAX_UNKNOWN)
syntax == SHELL_SYNTAX_UNKNOWNDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
1-9
470 {-
471 syntax = guess_shell_syntax ();-
472 if (syntax == SHELL_SYNTAX_UNKNOWN)
syntax == SHELL_SYNTAX_UNKNOWNDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
0-1
473 {-
474 die (EXIT_FAILURE, 0,-
475 _("no SHELL environment variable, and no shell type option given"));-
476 }
never executed: end of block
0
477 }
executed 1 time by 1 test: end of block
Executed by:
  • dircolors
1
478-
479 obstack_init (&lsc_obstack);-
480 if (argc == 0)
argc == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dircolors
2-8
481 ok = dc_parse_stream (NULL, NULL);
executed 2 times by 1 test: ok = dc_parse_stream ( ((void *)0) , ((void *)0) );
Executed by:
  • dircolors
2
482 else-
483 ok = dc_parse_file (argv[0]);
executed 8 times by 1 test: ok = dc_parse_file (argv[0]);
Executed by:
  • dircolors
8
484-
485 if (ok)
okDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dircolors
1-9
486 {-
487 size_t len = obstack_object_size (&lsc_obstack);-
488 char *s = obstack_finish (&lsc_obstack);
executed 4 times by 1 test: __o1->maybe_empty_object = 1;
Executed by:
  • dircolors
never executed: __o1->next_free = __o1->chunk_limit;
__o1->next_free == __valueDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dircolors
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dircolors
(size_t) (__o1...) __o1->chunk)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
sizeof (ptrdif...izeof (void *)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
sizeof (ptrdif...izeof (void *)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
0-9
489 const char *prefix;-
490 const char *suffix;-
491-
492 if (syntax == SHELL_SYNTAX_BOURNE)
syntax == SHELL_SYNTAX_BOURNEDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • dircolors
FALSEnever evaluated
0-9
493 {-
494 prefix = "LS_COLORS='";-
495 suffix = "';\nexport LS_COLORS\n";-
496 }
executed 9 times by 1 test: end of block
Executed by:
  • dircolors
9
497 else-
498 {-
499 prefix = "setenv LS_COLORS '";-
500 suffix = "'\n";-
501 }
never executed: end of block
0
502 fputs (prefix, stdout);-
503 fwrite (s, 1, len, stdout);
never executed: break;
(__builtin_exp...r++))) == (-1)Description
TRUEnever evaluated
FALSEnever evaluated
__cnt > 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_expe...write_end), 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
504 fputs (suffix, stdout);-
505 }
executed 9 times by 1 test: end of block
Executed by:
  • dircolors
9
506 }
executed 10 times by 1 test: end of block
Executed by:
  • dircolors
10
507-
508 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 10 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • dircolors
10
509}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2