Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/cut.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* cut - remove parts of lines of files | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | Copyright (C) 1997-2018 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | Copyright (C) 1984 David M. Ihnat | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 | /* Written by David Ihnat. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20 | /* POSIX changes, bug fixes, long-named options, and cleanup | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21 | by David MacKenzie <djm@gnu.ai.mit.edu>. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
23 | Rewrite cut_fields and cut_bytes -- Jim Meyering. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
25 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
27 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
28 | #include <assert.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
29 | #include <getopt.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
30 | #include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
31 | #include "system.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33 | #include "error.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
34 | #include "fadvise.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
35 | #include "getndelim2.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36 | #include "hash.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37 | #include "xstrndup.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39 | #include "set-fields.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41 | /* The official name of this program (e.g., no 'g' prefix). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42 | #define PROGRAM_NAME "cut" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44 | #define AUTHORS \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
45 | proper_name ("David M. Ihnat"), \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
46 | proper_name ("David MacKenzie"), \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
47 | proper_name ("Jim Meyering") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49 | #define FATAL_ERROR(Message) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
50 | do \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
51 | { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 | error (0, 0, (Message)); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
53 | usage (EXIT_FAILURE); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
54 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
55 | while (0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
58 | /* Pointer inside RP. When checking if a byte or field is selected | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 | by a finite range, we check if it is between CURRENT_RP.LO | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
60 | and CURRENT_RP.HI. If the byte or field index is greater than | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
61 | CURRENT_RP.HI then we make CURRENT_RP to point to the next range pair. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
62 | static struct field_range_pair *current_rp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
64 | /* This buffer is used to support the semantics of the -s option | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
65 | (or lack of same) when the specified field list includes (does | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
66 | not include) the first field. In both of those cases, the entire | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
67 | first field must be read into this buffer to determine whether it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
68 | is followed by a delimiter or a newline before any of it may be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
69 | output. Otherwise, cut_fields can do the job without using this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
70 | buffer. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
71 | static char *field_1_buffer; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
73 | /* The number of bytes allocated for FIELD_1_BUFFER. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
74 | static size_t field_1_bufsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
76 | enum operating_mode | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
78 | undefined_mode, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
80 | /* Output characters that are in the given bytes. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81 | byte_mode, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
83 | /* Output the given delimiter-separated fields. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
84 | field_mode | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
85 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
87 | static enum operating_mode operating_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
89 | /* If true do not output lines containing no delimiter characters. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
90 | Otherwise, all such lines are printed. This option is valid only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 | with field mode. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
92 | static bool suppress_non_delimited; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
93 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
94 | /* If true, print all bytes, characters, or fields _except_ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
95 | those that were specified. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
96 | static bool complement; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
98 | /* The delimiter character for field mode. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
99 | static unsigned char delim; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
100 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
101 | /* The delimiter for each line/record. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
102 | static unsigned char line_delim = '\n'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
104 | /* True if the --output-delimiter=STRING option was specified. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
105 | static bool output_delimiter_specified; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
107 | /* The length of output_delimiter_string. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
108 | static size_t output_delimiter_length; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
110 | /* The output field separator string. Defaults to the 1-character | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
111 | string consisting of the input delimiter. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
112 | static char *output_delimiter_string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
114 | /* True if we have ever read standard input. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
115 | static bool have_read_stdin; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
117 | /* For long options that have no equivalent short option, use a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
118 | non-character as a pseudo short option, starting with CHAR_MAX + 1. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
119 | enum | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
120 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
121 | OUTPUT_DELIMITER_OPTION = CHAR_MAX + 1, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
122 | COMPLEMENT_OPTION | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
123 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
125 | static struct option const longopts[] = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
126 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
127 | {"bytes", required_argument, NULL, 'b'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
128 | {"characters", required_argument, NULL, 'c'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
129 | {"fields", required_argument, NULL, 'f'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
130 | {"delimiter", required_argument, NULL, 'd'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
131 | {"only-delimited", no_argument, NULL, 's'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
132 | {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
133 | {"complement", no_argument, NULL, COMPLEMENT_OPTION}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
134 | {"zero-terminated", no_argument, NULL, 'z'}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
135 | {GETOPT_HELP_OPTION_DECL}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
136 | {GETOPT_VERSION_OPTION_DECL}, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
137 | {NULL, 0, NULL, 0} | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
138 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
140 | void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
141 | usage (int status) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
142 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
143 | if (status != EXIT_SUCCESS)
| 2-46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
144 | emit_try_help (); executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
145 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
146 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
147 | printf (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
148 | Usage: %s OPTION... [FILE]...\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
149 | "), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
150 | program_name); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
151 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
152 | Print selected parts of lines from each FILE to standard output.\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
153 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
155 | emit_stdin_note (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
156 | emit_mandatory_arg_note (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
158 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
159 | -b, --bytes=LIST select only these bytes\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
160 | -c, --characters=LIST select only these characters\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
161 | -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
162 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
163 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
164 | -f, --fields=LIST select only these fields; also print any line\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
165 | that contains no delimiter character, unless\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
166 | the -s option is specified\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
167 | -n (ignored)\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
168 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
169 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
170 | --complement complement the set of selected bytes, characters\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
171 | or fields\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
172 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
173 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
174 | -s, --only-delimited do not print lines not containing delimiters\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
175 | --output-delimiter=STRING use STRING as the output delimiter\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
176 | the default is to use the input delimiter\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
177 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
178 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
179 | -z, --zero-terminated line delimiter is NUL, not newline\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
180 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
181 | fputs (HELP_OPTION_DESCRIPTION, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
182 | fputs (VERSION_OPTION_DESCRIPTION, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
183 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
184 | \n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
185 | Use one, and only one of -b, -c or -f. Each LIST is made up of one\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
186 | range, or many ranges separated by commas. Selected input is written\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
187 | in the same order that it is read, and is written exactly once.\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
188 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
189 | fputs (_("\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
190 | Each range is one of:\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
191 | \n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
192 | N N'th byte, character or field, counted from 1\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
193 | N- from N'th byte, character or field, to end of line\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
194 | N-M from N'th to M'th (included) byte, character or field\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
195 | -M from first to M'th (included) byte, character or field\n\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
196 | "), stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
197 | emit_ancillary_info (PROGRAM_NAME); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
198 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
199 | exit (status); executed 48 times by 1 test: exit (status); Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
200 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
203 | /* Increment *ITEM_IDX (i.e., a field or byte index), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
204 | and if required CURRENT_RP. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
206 | static inline void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
207 | next_item (uintmax_t *item_idx) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
208 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
209 | (*item_idx)++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
210 | if ((*item_idx) > current_rp->hi)
| 168-549 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
211 | current_rp++; executed 168 times by 1 test: current_rp++; Executed by:
| 168 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
212 | } executed 717 times by 1 test: end of block Executed by:
| 717 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
214 | /* Return nonzero if the K'th field or byte is printable. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
216 | static inline bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
217 | print_kth (uintmax_t k) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
218 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
219 | return current_rp->lo <= k; executed 1166 times by 1 test: return current_rp->lo <= k; Executed by:
| 1166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
220 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
222 | /* Return nonzero if K'th byte is the beginning of a range. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
224 | static inline bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
225 | is_range_start_index (uintmax_t k) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
226 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
227 | return k == current_rp->lo; executed 171 times by 1 test: return k == current_rp->lo; Executed by:
| 171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
228 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
230 | /* Read from stream STREAM, printing to standard output any selected bytes. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
232 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
233 | cut_bytes (FILE *stream) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
234 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
235 | uintmax_t byte_idx; /* Number of bytes in the line so far. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
236 | /* Whether to begin printing delimiters between ranges for the current line. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
237 | Set after we've begun printing data corresponding to the first range. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
238 | bool print_delimiter; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
240 | byte_idx = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
241 | print_delimiter = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
242 | current_rp = frp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
243 | while (true) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
244 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
245 | int c; /* Each character from the file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
247 | c = getc (stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
249 | if (c == line_delim)
| 72-471 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
250 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
251 | putchar (c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
252 | byte_idx = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
253 | print_delimiter = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
254 | current_rp = frp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
255 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
256 | else if (c == EOF)
| 96-375 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
257 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
258 | if (byte_idx > 0)
| 12-84 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
259 | putchar (line_delim); executed 12 times by 1 test: putchar_unlocked (line_delim); Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
260 | break; executed 96 times by 1 test: break; Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
261 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
262 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
263 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
264 | next_item (&byte_idx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
265 | if (print_kth (byte_idx))
| 120-255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
266 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
267 | if (output_delimiter_specified)
| 33-222 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
268 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
269 | if (print_delimiter && is_range_start_index (byte_idx))
| 24-171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
270 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
271 | fwrite (output_delimiter_string, sizeof (char), never executed: break;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
272 | output_delimiter_length, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
273 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
274 | print_delimiter = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
275 | } executed 222 times by 1 test: end of block Executed by:
| 222 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
277 | putchar (c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
278 | } executed 255 times by 1 test: end of block Executed by:
| 255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
279 | } executed 375 times by 1 test: end of block Executed by:
| 375 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
280 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
281 | } executed 96 times by 1 test: end of block Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
282 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
283 | /* Read from stream STREAM, printing to standard output any selected fields. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
285 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
286 | cut_fields (FILE *stream) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
287 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
288 | int c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
289 | uintmax_t field_idx = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
290 | bool found_any_selected_field = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
291 | bool buffer_first_field; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
293 | current_rp = frp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
295 | c = getc (stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
296 | if (c == EOF)
| 24-174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
297 | return; executed 24 times by 1 test: return; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
299 | ungetc (c, stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
300 | c = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
302 | /* To support the semantics of the -s flag, we may have to buffer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
303 | all of the first field to determine whether it is 'delimited.' | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
304 | But that is unnecessary if all non-delimited lines must be printed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
305 | and the first field has been selected, or if non-delimited lines | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
306 | must be suppressed and the first field has *not* been selected. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
307 | That is because a non-delimited line has exactly one field. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
308 | buffer_first_field = (suppress_non_delimited ^ !print_kth (1)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
310 | while (1) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
311 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
312 | if (field_idx == 1 && buffer_first_field)
| 166-339 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
313 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
314 | ssize_t len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
315 | size_t n_bytes; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
316 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
317 | len = getndelim2 (&field_1_buffer, &field_1_bufsize, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
318 | GETNLINE_NO_LIMIT, delim, line_delim, stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
319 | if (len < 0)
| 56-110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
320 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
321 | free (field_1_buffer); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
322 | field_1_buffer = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
323 | if (ferror (stream) || feof (stream))
| 0-56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
324 | break; executed 56 times by 1 test: break; Executed by:
| 56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
325 | xalloc_die (); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
326 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
328 | n_bytes = len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
329 | assert (n_bytes != 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
331 | c = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
333 | /* If the first field extends to the end of line (it is not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
334 | delimited) and we are printing all non-delimited lines, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
335 | print this one. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
336 | if (to_uchar (field_1_buffer[n_bytes - 1]) != delim)
| 8-102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
337 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
338 | if (suppress_non_delimited)
| 2-6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
339 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
340 | /* Empty. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
341 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
342 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
343 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
344 | fwrite (field_1_buffer, sizeof (char), n_bytes, stdout); never executed: break;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
345 | /* Make sure the output line is newline terminated. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
346 | if (field_1_buffer[n_bytes - 1] != line_delim)
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
347 | putchar (line_delim); executed 2 times by 1 test: putchar_unlocked (line_delim); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
348 | c = line_delim; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
349 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
350 | continue; executed 8 times by 1 test: continue; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
352 | if (print_kth (1))
| 42-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
353 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
354 | /* Print the field, but not the trailing delimiter. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
355 | fwrite (field_1_buffer, sizeof (char), n_bytes - 1, stdout); never executed: break;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
357 | /* With -d$'\n' don't treat the last '\n' as a delimiter. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
358 | if (delim == line_delim)
| 12-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
359 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
360 | int last_c = getc (stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
361 | if (last_c != EOF)
| 3-9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
362 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
363 | ungetc (last_c, stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
364 | found_any_selected_field = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
365 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
366 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
367 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
368 | found_any_selected_field = true; executed 48 times by 1 test: found_any_selected_field = 1 ; Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
369 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
370 | next_item (&field_idx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
371 | } executed 102 times by 1 test: end of block Executed by:
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
373 | int prev_c = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
374 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
375 | if (print_kth (field_idx))
| 186-329 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
376 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
377 | if (found_any_selected_field)
| 156-173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
378 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
379 | fwrite (output_delimiter_string, sizeof (char), never executed: break;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
380 | output_delimiter_length, stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
381 | } executed 156 times by 1 test: end of block Executed by:
| 156 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
382 | found_any_selected_field = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
384 | while ((c = getc (stream)) != delim && c != line_delim && c != EOF)
| 49-355 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
385 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
386 | putchar (c); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
387 | prev_c = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
388 | } executed 200 times by 1 test: end of block Executed by:
| 200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
389 | } executed 329 times by 1 test: end of block Executed by:
| 329 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
390 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
391 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
392 | while ((c = getc (stream)) != delim && c != line_delim && c != EOF)
| 51-422 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
393 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
394 | prev_c = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
395 | } executed 311 times by 1 test: end of block Executed by:
| 311 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
396 | } executed 186 times by 1 test: end of block Executed by:
| 186 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
398 | /* With -d$'\n' don't treat the last '\n' as a delimiter. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
399 | if (delim == line_delim && c == delim)
| 27-458 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
400 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
401 | int last_c = getc (stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
402 | if (last_c != EOF)
| 9-21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
403 | ungetc (last_c, stream); executed 21 times by 1 test: ungetc (last_c, stream); Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
404 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
405 | c = last_c; executed 9 times by 1 test: c = last_c; Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
406 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
408 | if (c == delim)
| 240-275 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
409 | next_item (&field_idx); executed 240 times by 1 test: next_item (&field_idx); Executed by:
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
410 | else if (c == line_delim || c == EOF)
| 0-157 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
411 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
412 | if (found_any_selected_field
| 45-230 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
413 | || !(suppress_non_delimited && field_idx == 1))
| 3-42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
414 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
415 | if (c == line_delim || prev_c != line_delim
| 19-154 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
416 | || delim == line_delim)
| 0-19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
417 | putchar (line_delim); executed 217 times by 1 test: putchar_unlocked (line_delim); Executed by:
| 217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
418 | } executed 236 times by 1 test: end of block Executed by:
| 236 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
419 | if (c == EOF)
| 118-157 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
420 | break; executed 118 times by 1 test: break; Executed by:
| 118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
421 | field_idx = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
422 | current_rp = frp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
423 | found_any_selected_field = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
424 | } executed 157 times by 1 test: end of block Executed by:
| 157 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
425 | } executed 397 times by 1 test: end of block Executed by:
| 397 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
426 | } executed 174 times by 1 test: end of block Executed by:
| 174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
428 | static void | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
429 | cut_stream (FILE *stream) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
430 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
431 | if (operating_mode == byte_mode)
| 96-198 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
432 | cut_bytes (stream); executed 96 times by 1 test: cut_bytes (stream); Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
433 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
434 | cut_fields (stream); executed 198 times by 1 test: cut_fields (stream); Executed by:
| 198 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
435 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
437 | /* Process file FILE to standard output. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
438 | Return true if successful. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
440 | static bool | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
441 | cut_file (char const *file) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
442 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
443 | FILE *stream; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
445 | if (STREQ (file, "-")) never executed: __result = (((const unsigned char *) (const char *) ( file ))[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 executed 192 times by 1 test: end of block Executed by:
| 0-294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
446 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
447 | have_read_stdin = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
448 | stream = stdin; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
449 | } executed 192 times by 1 test: end of block Executed by:
| 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
450 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
452 | stream = fopen (file, "r"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
453 | if (stream == NULL)
| 0-102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
454 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
455 | error (0, errno, "%s", quotef (file)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
456 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
457 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
458 | } executed 102 times by 1 test: end of block Executed by:
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
460 | fadvise (stream, FADVISE_SEQUENTIAL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
462 | cut_stream (stream); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
463 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
464 | if (ferror (stream))
| 0-294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
465 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
466 | error (0, errno, "%s", quotef (file)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
467 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
468 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
469 | if (STREQ (file, "-")) never executed: __result = (((const unsigned char *) (const char *) ( file ))[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 executed 192 times by 1 test: end of block Executed by:
| 0-294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
470 | clearerr (stream); /* Also clear EOF. */ executed 192 times by 1 test: clearerr_unlocked (stream); Executed by:
| 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
471 | else if (fclose (stream) == EOF)
| 0-102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
472 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
473 | error (0, errno, "%s", quotef (file)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
474 | return false; never executed: return 0 ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
475 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
476 | return true; executed 294 times by 1 test: return 1 ; Executed by:
| 294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
477 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
479 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
480 | main (int argc, char **argv) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
481 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
482 | int optc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
483 | bool ok; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
484 | bool delim_specified = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
485 | char *spec_list_string IF_LINT ( = NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
487 | initialize_main (&argc, &argv); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
488 | set_program_name (argv[0]); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
489 | setlocale (LC_ALL, ""); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
490 | bindtextdomain (PACKAGE, LOCALEDIR); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
491 | textdomain (PACKAGE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
493 | atexit (close_stdout); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
495 | operating_mode = undefined_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
497 | /* By default, all non-delimited lines are printed. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
498 | suppress_non_delimited = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
499 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
500 | delim = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
501 | have_read_stdin = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
503 | while ((optc = getopt_long (argc, argv, "b:c:d:f:nsz", longopts, NULL)) != -1)
| 338-714 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
504 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
505 | switch (optc) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
506 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
507 | case 'b': executed 69 times by 1 test: case 'b': Executed by:
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
508 | case 'c': executed 43 times by 1 test: case 'c': Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
509 | /* Build the byte list. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
510 | if (operating_mode != undefined_mode)
| 0-112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
511 | FATAL_ERROR (_("only one type of list may be specified")); never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
512 | operating_mode = byte_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
513 | spec_list_string = optarg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
514 | break; executed 112 times by 1 test: break; Executed by:
| 112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
516 | case 'f': executed 223 times by 1 test: case 'f': Executed by:
| 223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
517 | /* Build the field list. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
518 | if (operating_mode != undefined_mode)
| 0-223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
519 | FATAL_ERROR (_("only one type of list may be specified")); never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
520 | operating_mode = field_mode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
521 | spec_list_string = optarg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
522 | break; executed 223 times by 1 test: break; Executed by:
| 223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
524 | case 'd': executed 173 times by 1 test: case 'd': Executed by:
| 173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
525 | /* New delimiter. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
526 | /* Interpret -d '' to mean 'use the NUL byte as the delimiter.' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
527 | if (optarg[0] != '\0' && optarg[1] != '\0')
| 0-166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
528 | FATAL_ERROR (_("the delimiter must be a single character")); never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
529 | delim = optarg[0]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
530 | delim_specified = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
531 | break; executed 173 times by 1 test: break; Executed by:
| 173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
533 | case OUTPUT_DELIMITER_OPTION: executed 87 times by 1 test: case OUTPUT_DELIMITER_OPTION: Executed by:
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
534 | output_delimiter_specified = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
535 | /* Interpret --output-delimiter='' to mean | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
536 | 'use the NUL byte as the delimiter.' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
537 | output_delimiter_length = (optarg[0] == '\0'
| 3-84 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
538 | ? 1 : strlen (optarg)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
539 | output_delimiter_string = xstrdup (optarg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
540 | break; executed 87 times by 1 test: break; Executed by:
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
542 | case 'n': never executed: case 'n': | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
543 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
545 | case 's': executed 90 times by 1 test: case 's': Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
546 | suppress_non_delimited = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
547 | break; executed 90 times by 1 test: break; Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
549 | case 'z': executed 18 times by 1 test: case 'z': Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
550 | line_delim = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
551 | break; executed 18 times by 1 test: break; Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
553 | case COMPLEMENT_OPTION: executed 3 times by 1 test: case COMPLEMENT_OPTION: Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
554 | complement = true; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
555 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
556 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
557 | case_GETOPT_HELP_CHAR; never executed: break; executed 2 times by 1 test: case GETOPT_HELP_CHAR: Executed by:
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
558 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
559 | case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); executed 5 times by 1 test: exit ( 0 ); Executed by:
never executed: break; executed 5 times by 1 test: case GETOPT_VERSION_CHAR: Executed by:
| 0-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
560 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
561 | default: executed 1 time by 1 test: default: Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
562 | usage (EXIT_FAILURE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
563 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
564 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
566 | if (operating_mode == undefined_mode)
| 3-335 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
567 | FATAL_ERROR (_("you must specify a list of bytes, characters, or fields")); never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
568 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
569 | if (delim_specified && operating_mode != field_mode)
| 2-173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
570 | FATAL_ERROR (_("an input delimiter may be specified only\ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
571 | when operating on fields")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
573 | if (suppress_non_delimited && operating_mode != field_mode)
| 3-243 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
574 | FATAL_ERROR (_("suppressing non-delimited lines makes sense\n\ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
575 | \tonly when operating on fields")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
576 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
577 | set_fields (spec_list_string, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
578 | ( (operating_mode == field_mode) ? 0 : SETFLD_ERRMSG_USE_POS) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
579 | | (complement ? SETFLD_COMPLEMENT : 0) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
581 | if (!delim_specified)
| 122-171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
582 | delim = '\t'; executed 122 times by 1 test: delim = '\t'; Executed by:
| 122 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
584 | if (output_delimiter_string == NULL)
| 87-206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
585 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
586 | static char dummy[2]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
587 | dummy[0] = delim; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
588 | dummy[1] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
589 | output_delimiter_string = dummy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
590 | output_delimiter_length = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
591 | } executed 206 times by 1 test: end of block Executed by:
| 206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
592 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
593 | if (optind == argc)
| 101-192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
594 | ok = cut_file ("-"); executed 192 times by 1 test: ok = cut_file ("-"); Executed by:
| 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
595 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
596 | for (ok = true; optind < argc; optind++)
| 101-102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
597 | ok &= cut_file (argv[optind]); executed 102 times by 1 test: ok &= cut_file (argv[optind]); Executed by:
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
598 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
599 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
600 | if (have_read_stdin && fclose (stdin) == EOF)
| 0-192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
601 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
602 | error (0, errno, "-"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
603 | ok = false; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
606 | IF_LINT (reset_fields ()); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
607 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
608 | return ok ? EXIT_SUCCESS : EXIT_FAILURE; executed 293 times by 1 test: return ok ? 0 : 1 ; Executed by:
| 293 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
609 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |