OpenCoverage

expand.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/expand.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* expand - convert tabs to spaces-
2 Copyright (C) 1989-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* By default, convert all tabs to spaces.-
18 Preserves backspace characters in the output; they decrement the-
19 column count for tab calculations.-
20 The default action is equivalent to -8.-
21-
22 Options:-
23 --tabs=tab1[,tab2[,...]]-
24 -t tab1[,tab2[,...]]-
25 -tab1[,tab2[,...]] If only one tab stop is given, set the tabs tab1-
26 columns apart instead of the default 8. Otherwise,-
27 set the tabs at columns tab1, tab2, etc. (numbered from-
28 0); replace any tabs beyond the tab stops given with-
29 single spaces.-
30 --initial-
31 -i Only convert initial tabs on each line to spaces.-
32-
33 David MacKenzie <djm@gnu.ai.mit.edu> */-
34-
35#include <config.h>-
36-
37#include <stdio.h>-
38#include <getopt.h>-
39#include <sys/types.h>-
40#include "system.h"-
41#include "die.h"-
42#include "xstrndup.h"-
43-
44#include "expand-common.h"-
45-
46/* The official name of this program (e.g., no 'g' prefix). */-
47#define PROGRAM_NAME "expand"-
48-
49#define AUTHORS proper_name ("David MacKenzie")-
50-
51static char const shortopts[] = "it:0::1::2::3::4::5::6::7::8::9::";-
52-
53static struct option const longopts[] =-
54{-
55 {"tabs", required_argument, NULL, 't'},-
56 {"initial", no_argument, NULL, 'i'},-
57 {GETOPT_HELP_OPTION_DECL},-
58 {GETOPT_VERSION_OPTION_DECL},-
59 {NULL, 0, NULL, 0}-
60};-
61-
62void-
63usage (int status)-
64{-
65 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 5 times by 1 test
Evaluated by:
  • expand
3-5
66 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • expand
3
67 else-
68 {-
69 printf (_("\-
70Usage: %s [OPTION]... [FILE]...\n\-
71"),-
72 program_name);-
73 fputs (_("\-
74Convert tabs in each FILE to spaces, writing to standard output.\n\-
75"), stdout);-
76-
77 emit_stdin_note ();-
78 emit_mandatory_arg_note ();-
79-
80 fputs (_("\-
81 -i, --initial do not convert tabs after non blanks\n\-
82 -t, --tabs=N have tabs N characters apart, not 8\n\-
83"), stdout);-
84 emit_tab_list_info ();-
85 fputs (HELP_OPTION_DESCRIPTION, stdout);-
86 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
87 emit_ancillary_info (PROGRAM_NAME);-
88 }
executed 5 times by 1 test: end of block
Executed by:
  • expand
5
89 exit (status);
executed 8 times by 1 test: exit (status);
Executed by:
  • expand
8
90}-
91-
92-
93/* Change tabs to spaces, writing to stdout.-
94 Read each file in 'file_list', in order. */-
95-
96static void-
97expand (void)-
98{-
99 /* Input stream. */-
100 FILE *fp = next_file (NULL);-
101-
102 if (!fp)
!fpDescription
TRUEnever evaluated
FALSEevaluated 49 times by 1 test
Evaluated by:
  • expand
0-49
103 return;
never executed: return;
0
104-
105 while (true)-
106 {-
107 /* Input character, or EOF. */-
108 int c;-
109-
110 /* If true, perform translations. */-
111 bool convert = true;-
112-
113-
114 /* The following variables have valid values only when CONVERT-
115 is true: */-
116-
117 /* Column of next input character. */-
118 uintmax_t column = 0;-
119-
120 /* Index in TAB_LIST of next tab stop to examine. */-
121 size_t tab_index = 0;-
122-
123-
124 /* Convert a line of text. */-
125-
126 do-
127 {-
128 while ((c = getc (fp)) < 0 && (fp = next_file (fp)))
(c = getc_unlocked (fp)) < 0Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 338 times by 1 test
Evaluated by:
  • expand
(fp = next_file (fp))Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 49 times by 1 test
Evaluated by:
  • expand
3-338
129 continue;
executed 3 times by 1 test: continue;
Executed by:
  • expand
3
130-
131 if (convert)
convertDescription
TRUEevaluated 381 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 6 times by 1 test
Evaluated by:
  • expand
6-381
132 {-
133 if (c == '\t')
c == '\t'Description
TRUEevaluated 120 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 261 times by 1 test
Evaluated by:
  • expand
120-261
134 {-
135 /* Column the next input tab stop is on. */-
136 uintmax_t next_tab_column;-
137 bool last_tab IF_LINT (=0);-
138-
139 next_tab_column = get_next_tab_column (column, &tab_index,-
140 &last_tab);-
141-
142 if (last_tab)
last_tabDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 115 times by 1 test
Evaluated by:
  • expand
5-115
143 next_tab_column = column + 1;
executed 5 times by 1 test: next_tab_column = column + 1;
Executed by:
  • expand
5
144-
145 if (next_tab_column < column)
next_tab_column < columnDescription
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • expand
0-120
146 die (EXIT_FAILURE, 0, _("input line is too long"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"input line is too long\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "input line is too long" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "input line is too long" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
147-
148 while (++column < next_tab_column)
++column < next_tab_columnDescription
TRUEevaluated 279 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 120 times by 1 test
Evaluated by:
  • expand
120-279
149 if (putchar (' ') < 0)
putchar_unlocked (' ') < 0Description
TRUEnever evaluated
FALSEevaluated 279 times by 1 test
Evaluated by:
  • expand
0-279
150 die (EXIT_FAILURE, errno, _("write error"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"write error\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "write error" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "write error" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
151-
152 c = ' ';-
153 }
executed 120 times by 1 test: end of block
Executed by:
  • expand
120
154 else if (c == '\b')
c == '\b'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 249 times by 1 test
Evaluated by:
  • expand
12-249
155 {-
156 /* Go back one column, and force recalculation of the-
157 next tab stop. */-
158 column -= !!column;-
159 tab_index -= !!tab_index;-
160 }
executed 12 times by 1 test: end of block
Executed by:
  • expand
12
161 else-
162 {-
163 column++;-
164 if (!column)
!columnDescription
TRUEnever evaluated
FALSEevaluated 249 times by 1 test
Evaluated by:
  • expand
0-249
165 die (EXIT_FAILURE, 0, _("input line is too long"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"input line is too long\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "input line is too long" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "input line is too long" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
166 }
executed 249 times by 1 test: end of block
Executed by:
  • expand
249
167-
168 convert &= convert_entire_line || !! isblank (c);
convert_entire_lineDescription
TRUEevaluated 376 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 5 times by 1 test
Evaluated by:
  • expand
!! ((*__ctype_...int) _ISblank)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 2 times by 1 test
Evaluated by:
  • expand
2-376
169 }
executed 381 times by 1 test: end of block
Executed by:
  • expand
381
170-
171 if (c < 0)
c < 0Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 338 times by 1 test
Evaluated by:
  • expand
49-338
172 return;
executed 49 times by 1 test: return;
Executed by:
  • expand
49
173-
174 if (putchar (c) < 0)
putchar_unlocked (c) < 0Description
TRUEnever evaluated
FALSEevaluated 338 times by 1 test
Evaluated by:
  • expand
0-338
175 die (EXIT_FAILURE, errno, _("write error"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"write error\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "write error" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "write error" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
176 }
executed 338 times by 1 test: end of block
Executed by:
  • expand
338
177 while (c != '\n');
c != '\n'Description
TRUEevaluated 325 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 13 times by 1 test
Evaluated by:
  • expand
13-325
178 }
executed 13 times by 1 test: end of block
Executed by:
  • expand
13
179}
never executed: end of block
0
180-
181int-
182main (int argc, char **argv)-
183{-
184 int c;-
185-
186 initialize_main (&argc, &argv);-
187 set_program_name (argv[0]);-
188 setlocale (LC_ALL, "");-
189 bindtextdomain (PACKAGE, LOCALEDIR);-
190 textdomain (PACKAGE);-
191-
192 atexit (close_stdout);-
193 convert_entire_line = true;-
194-
195 while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 51 times by 1 test
Evaluated by:
  • expand
51-79
196 {-
197 switch (c)-
198 {-
199 case 'i':
executed 4 times by 1 test: case 'i':
Executed by:
  • expand
4
200 convert_entire_line = false;-
201 break;
executed 4 times by 1 test: break;
Executed by:
  • expand
4
202-
203 case 't':
executed 54 times by 1 test: case 't':
Executed by:
  • expand
54
204 parse_tab_stops (optarg);-
205 break;
executed 45 times by 1 test: break;
Executed by:
  • expand
45
206-
207 case '0': case '1': case '2': case '3': case '4':
never executed: case '0':
executed 1 time by 1 test: case '1':
Executed by:
  • expand
executed 1 time by 1 test: case '2':
Executed by:
  • expand
executed 2 times by 1 test: case '3':
Executed by:
  • expand
executed 1 time by 1 test: case '4':
Executed by:
  • expand
0-2
208 case '5': case '6': case '7': case '8': case '9':
never executed: case '5':
executed 1 time by 1 test: case '6':
Executed by:
  • expand
executed 1 time by 1 test: case '7':
Executed by:
  • expand
executed 1 time by 1 test: case '8':
Executed by:
  • expand
executed 1 time by 1 test: case '9':
Executed by:
  • expand
0-1
209 if (optarg)
optargDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • expand
FALSEevaluated 7 times by 1 test
Evaluated by:
  • expand
2-7
210 parse_tab_stops (optarg - 1);
executed 2 times by 1 test: parse_tab_stops (optarg - 1);
Executed by:
  • expand
2
211 else-
212 {-
213 char tab_stop[2];-
214 tab_stop[0] = c;-
215 tab_stop[1] = '\0';-
216 parse_tab_stops (tab_stop);-
217 }
executed 7 times by 1 test: end of block
Executed by:
  • expand
7
218 break;
executed 9 times by 1 test: break;
Executed by:
  • expand
9
219-
220 case_GETOPT_HELP_CHAR;
never executed: break;
executed 5 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • expand
0-5
221-
222 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • expand
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • expand
0-4
223-
224 default:
executed 3 times by 1 test: default:
Executed by:
  • expand
3
225 usage (EXIT_FAILURE);-
226 }
never executed: end of block
0
227 }-
228-
229 finalize_tab_stops ();-
230-
231 set_file_list ( (optind < argc) ? &argv[optind] : NULL);-
232-
233 expand ();-
234-
235 cleanup_file_list_stdin ();-
236-
237 return exit_status;
executed 49 times by 1 test: return exit_status;
Executed by:
  • expand
49
238}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2