OpenCoverage

comm.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/comm.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* comm -- compare two sorted files line by line.-
2 Copyright (C) 1986-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/* Written by Richard Stallman and David MacKenzie. */-
18-
19#include <config.h>-
20-
21#include <getopt.h>-
22#include <sys/types.h>-
23#include "system.h"-
24#include "linebuffer.h"-
25#include "die.h"-
26#include "error.h"-
27#include "fadvise.h"-
28#include "hard-locale.h"-
29#include "quote.h"-
30#include "stdio--.h"-
31#include "memcmp2.h"-
32#include "xmemcoll.h"-
33-
34/* The official name of this program (e.g., no 'g' prefix). */-
35#define PROGRAM_NAME "comm"-
36-
37#define AUTHORS \-
38 proper_name ("Richard M. Stallman"), \-
39 proper_name ("David MacKenzie")-
40-
41/* Undefine, to avoid warning about redefinition on some systems. */-
42#undef min-
43#define min(x, y) ((x) < (y) ? (x) : (y))-
44-
45/* True if the LC_COLLATE locale is hard. */-
46static bool hard_LC_COLLATE;-
47-
48/* If true, print lines that are found only in file 1. */-
49static bool only_file_1;-
50-
51/* If true, print lines that are found only in file 2. */-
52static bool only_file_2;-
53-
54/* If true, print lines that are found in both files. */-
55static bool both;-
56-
57/* If nonzero, we have seen at least one unpairable line. */-
58static bool seen_unpairable;-
59-
60/* If nonzero, we have warned about disorder in that file. */-
61static bool issued_disorder_warning[2];-
62-
63/* line delimiter. */-
64static unsigned char delim = '\n';-
65-
66/* If true, print a summary. */-
67static bool total_option;-
68-
69/* If nonzero, check that the input is correctly ordered. */-
70static enum-
71 {-
72 CHECK_ORDER_DEFAULT,-
73 CHECK_ORDER_ENABLED,-
74 CHECK_ORDER_DISABLED-
75 } check_input_order;-
76-
77/* Output columns will be delimited with this string, which may be set-
78 on the command-line with --output-delimiter=STR. */-
79static char const *col_sep = "\t";-
80static size_t col_sep_len = 0;-
81-
82/* For long options that have no equivalent short option, use a-
83 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
84enum-
85{-
86 CHECK_ORDER_OPTION = CHAR_MAX + 1,-
87 NOCHECK_ORDER_OPTION,-
88 OUTPUT_DELIMITER_OPTION,-
89 TOTAL_OPTION-
90};-
91-
92static struct option const long_options[] =-
93{-
94 {"check-order", no_argument, NULL, CHECK_ORDER_OPTION},-
95 {"nocheck-order", no_argument, NULL, NOCHECK_ORDER_OPTION},-
96 {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION},-
97 {"total", no_argument, NULL, TOTAL_OPTION},-
98 {"zero-terminated", no_argument, NULL, 'z'},-
99 {GETOPT_HELP_OPTION_DECL},-
100 {GETOPT_VERSION_OPTION_DECL},-
101 {NULL, 0, NULL, 0}-
102};-
103-
104-
105void-
106usage (int status)-
107{-
108 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 12 times by 1 test
Evaluated by:
  • comm
6-12
109 emit_try_help ();
executed 6 times by 1 test: end of block
Executed by:
  • comm
6
110 else-
111 {-
112 printf (_("\-
113Usage: %s [OPTION]... FILE1 FILE2\n\-
114"),-
115 program_name);-
116 fputs (_("\-
117Compare sorted files FILE1 and FILE2 line by line.\n\-
118"), stdout);-
119 fputs (_("\-
120\n\-
121When FILE1 or FILE2 (not both) is -, read standard input.\n\-
122"), stdout);-
123 fputs (_("\-
124\n\-
125With no options, produce three-column output. Column one contains\n\-
126lines unique to FILE1, column two contains lines unique to FILE2,\n\-
127and column three contains lines common to both files.\n\-
128"), stdout);-
129 fputs (_("\-
130\n\-
131 -1 suppress column 1 (lines unique to FILE1)\n\-
132 -2 suppress column 2 (lines unique to FILE2)\n\-
133 -3 suppress column 3 (lines that appear in both files)\n\-
134"), stdout);-
135 fputs (_("\-
136\n\-
137 --check-order check that the input is correctly sorted, even\n\-
138 if all input lines are pairable\n\-
139 --nocheck-order do not check that the input is correctly sorted\n\-
140"), stdout);-
141 fputs (_("\-
142 --output-delimiter=STR separate columns with STR\n\-
143"), stdout);-
144 fputs (_("\-
145 --total output a summary\n\-
146"), stdout);-
147 fputs (_("\-
148 -z, --zero-terminated line delimiter is NUL, not newline\n\-
149"), stdout);-
150 fputs (HELP_OPTION_DESCRIPTION, stdout);-
151 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
152 fputs (_("\-
153\n\-
154Note, comparisons honor the rules specified by 'LC_COLLATE'.\n\-
155"), stdout);-
156 printf (_("\-
157\n\-
158Examples:\n\-
159 %s -12 file1 file2 Print only lines present in both file1 and file2.\n\-
160 %s -3 file1 file2 Print lines in file1 not in file2, and vice versa.\n\-
161"),-
162 program_name, program_name);-
163 emit_ancillary_info (PROGRAM_NAME);-
164 }
executed 12 times by 1 test: end of block
Executed by:
  • comm
12
165 exit (status);
executed 18 times by 1 test: exit (status);
Executed by:
  • comm
18
166}-
167-
168/* Output the line in linebuffer LINE to stream STREAM-
169 provided the switches say it should be output.-
170 CLASS is 1 for a line found only in file 1,-
171 2 for a line only in file 2, 3 for a line in both. */-
172-
173static void-
174writeline (struct linebuffer const *line, FILE *stream, int class)-
175{-
176 switch (class)-
177 {-
178 case 1:
executed 34 times by 1 test: case 1:
Executed by:
  • comm
34
179 if (!only_file_1)
!only_file_1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 25 times by 1 test
Evaluated by:
  • comm
9-25
180 return;
executed 9 times by 1 test: return;
Executed by:
  • comm
9
181 break;
executed 25 times by 1 test: break;
Executed by:
  • comm
25
182-
183 case 2:
executed 56 times by 1 test: case 2:
Executed by:
  • comm
56
184 if (!only_file_2)
!only_file_2Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 38 times by 1 test
Evaluated by:
  • comm
18-38
185 return;
executed 18 times by 1 test: return;
Executed by:
  • comm
18
186 if (only_file_1)
only_file_1Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 8 times by 1 test
Evaluated by:
  • comm
8-30
187 fwrite (col_sep, 1, col_sep_len, stream);
executed 30 times by 1 test: (__extension__ ((__builtin_constant_p ( 1 ) && __builtin_constant_p ( col_sep_len ) && (size_t) ( 1 ) * (size_t) ( col_sep_len ) <= 8 && (size_t) ( 1 ) != 0) ? ({ const char *__ptr = (const char *) ( col_sep ); FILE *__stream = ( stream ); size_t __cnt; f...) && (size_t) ( 1 ) == 0) || (__builtin_constant_p ( col_sep_len ) && (size_t) ( col_sep_len ) == 0)) ? ((void) ( col_sep ), (void) ( stream ), (void) ( 1 ), (void) ( col_sep_len ), (size_t) 0) : fwrite_unlocked ( col_sep , 1 , col_sep_len , stream )))) ;
Executed by:
  • comm
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-30
188 break;
executed 38 times by 1 test: break;
Executed by:
  • comm
38
189-
190 case 3:
executed 84 times by 1 test: case 3:
Executed by:
  • comm
84
191 if (!both)
!bothDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 57 times by 1 test
Evaluated by:
  • comm
27-57
192 return;
executed 27 times by 1 test: return;
Executed by:
  • comm
27
193 if (only_file_1)
only_file_1Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 12 times by 1 test
Evaluated by:
  • comm
12-45
194 fwrite (col_sep, 1, col_sep_len, stream);
executed 45 times by 1 test: (__extension__ ((__builtin_constant_p ( 1 ) && __builtin_constant_p ( col_sep_len ) && (size_t) ( 1 ) * (size_t) ( col_sep_len ) <= 8 && (size_t) ( 1 ) != 0) ? ({ const char *__ptr = (const char *) ( col_sep ); FILE *__stream = ( stream ); size_t __cnt; f...) && (size_t) ( 1 ) == 0) || (__builtin_constant_p ( col_sep_len ) && (size_t) ( col_sep_len ) == 0)) ? ((void) ( col_sep ), (void) ( stream ), (void) ( 1 ), (void) ( col_sep_len ), (size_t) 0) : fwrite_unlocked ( col_sep , 1 , col_sep_len , stream )))) ;
Executed by:
  • comm
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-45
195 if (only_file_2)
only_file_2Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 12 times by 1 test
Evaluated by:
  • comm
12-45
196 fwrite (col_sep, 1, col_sep_len, stream);
executed 45 times by 1 test: (__extension__ ((__builtin_constant_p ( 1 ) && __builtin_constant_p ( col_sep_len ) && (size_t) ( 1 ) * (size_t) ( col_sep_len ) <= 8 && (size_t) ( 1 ) != 0) ? ({ const char *__ptr = (const char *) ( col_sep ); FILE *__stream = ( stream ); size_t __cnt; f...) && (size_t) ( 1 ) == 0) || (__builtin_constant_p ( col_sep_len ) && (size_t) ( col_sep_len ) == 0)) ? ((void) ( col_sep ), (void) ( stream ), (void) ( 1 ), (void) ( col_sep_len ), (size_t) 0) : fwrite_unlocked ( col_sep , 1 , col_sep_len , stream )))) ;
Executed by:
  • comm
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-45
197 break;
executed 57 times by 1 test: break;
Executed by:
  • comm
57
198 }-
199-
200 fwrite (line->buffer, sizeof (char), line->length, stream);
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
201}
executed 120 times by 1 test: end of block
Executed by:
  • comm
120
202-
203/* Check that successive input lines PREV and CURRENT from input file-
204 WHATFILE are presented in order.-
205-
206 If the user specified --nocheck-order, the check is not made.-
207 If the user specified --check-order, the problem is fatal.-
208 Otherwise (the default), the message is simply a warning.-
209-
210 A message is printed at most once per input file.-
211-
212 This function was copied (nearly) verbatim from 'src/join.c'. */-
213-
214static void-
215check_order (struct linebuffer const *prev,-
216 struct linebuffer const *current,-
217 int whatfile)-
218{-
219-
220 if (check_input_order != CHECK_ORDER_DISABLED
check_input_or...ORDER_DISABLEDDescription
TRUEevaluated 253 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 4 times by 1 test
Evaluated by:
  • comm
4-253
221 && ((check_input_order == CHECK_ORDER_ENABLED) || seen_unpairable))
(check_input_o...ORDER_ENABLED)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 248 times by 1 test
Evaluated by:
  • comm
seen_unpairableDescription
TRUEevaluated 236 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 12 times by 1 test
Evaluated by:
  • comm
5-248
222 {-
223 if (!issued_disorder_warning[whatfile - 1])
!issued_disord...[whatfile - 1]Description
TRUEevaluated 236 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 5 times by 1 test
Evaluated by:
  • comm
5-236
224 {-
225 int order;-
226-
227 if (hard_LC_COLLATE)
hard_LC_COLLATEDescription
TRUEnever evaluated
FALSEevaluated 236 times by 1 test
Evaluated by:
  • comm
0-236
228 order = xmemcoll (prev->buffer, prev->length - 1,
never executed: order = xmemcoll (prev->buffer, prev->length - 1, current->buffer, current->length - 1);
0
229 current->buffer, current->length - 1);
never executed: order = xmemcoll (prev->buffer, prev->length - 1, current->buffer, current->length - 1);
0
230 else-
231 order = memcmp2 (prev->buffer, prev->length - 1,
executed 236 times by 1 test: order = memcmp2 (prev->buffer, prev->length - 1, current->buffer, current->length - 1);
Executed by:
  • comm
236
232 current->buffer, current->length - 1);
executed 236 times by 1 test: order = memcmp2 (prev->buffer, prev->length - 1, current->buffer, current->length - 1);
Executed by:
  • comm
236
233-
234 if (0 < order)
0 < orderDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 226 times by 1 test
Evaluated by:
  • comm
10-226
235 {-
236 error ((check_input_order == CHECK_ORDER_ENABLED-
237 ? EXIT_FAILURE : 0),-
238 0, _("file %d is not in sorted order"), whatfile);-
239-
240 /* If we get to here, the message was just a warning, but we-
241 want only to issue it once. */-
242 issued_disorder_warning[whatfile - 1] = true;-
243 }
executed 7 times by 1 test: end of block
Executed by:
  • comm
7
244 }
executed 233 times by 1 test: end of block
Executed by:
  • comm
233
245 }
executed 238 times by 1 test: end of block
Executed by:
  • comm
238
246}
executed 254 times by 1 test: end of block
Executed by:
  • comm
254
247-
248/* Compare INFILES[0] and INFILES[1].-
249 If either is "-", use the standard input for that file.-
250 Assume that each input file is sorted;-
251 merge them and output the result. */-
252-
253static void-
254compare_files (char **infiles)-
255{-
256 /* For each file, we have four linebuffers in lba. */-
257 struct linebuffer lba[2][4];-
258-
259 /* thisline[i] points to the linebuffer holding the next available line-
260 in file i, or is NULL if there are no lines left in that file. */-
261 struct linebuffer *thisline[2];-
262-
263 /* all_line[i][alt[i][0]] also points to the linebuffer holding the-
264 current line in file i. We keep two buffers of history around so we-
265 can look two lines back when we get to the end of a file. */-
266 struct linebuffer *all_line[2][4];-
267-
268 /* This is used to rotate through the buffers for each input file. */-
269 int alt[2][3];-
270-
271 /* streams[i] holds the input stream for file i. */-
272 FILE *streams[2];-
273-
274 /* Counters for the summary. */-
275 uintmax_t total[] = {0, 0, 0};-
276-
277 int i, j;-
278-
279 /* Initialize the storage. */-
280 for (i = 0; i < 2; i++)
i < 2Description
TRUEevaluated 70 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 35 times by 1 test
Evaluated by:
  • comm
35-70
281 {-
282 for (j = 0; j < 4; j++)
j < 4Description
TRUEevaluated 280 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 70 times by 1 test
Evaluated by:
  • comm
70-280
283 {-
284 initbuffer (&lba[i][j]);-
285 all_line[i][j] = &lba[i][j];-
286 }
executed 280 times by 1 test: end of block
Executed by:
  • comm
280
287 alt[i][0] = 0;-
288 alt[i][1] = 0;-
289 alt[i][2] = 0;-
290 streams[i] = (STREQ (infiles[i], "-") ? stdin : fopen (infiles[i], "r"));
never executed: __result = (((const unsigned char *) (const char *) ( infiles[i] ))[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
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • comm
__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 70 times by 1 test
Evaluated by:
  • comm
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • comm
__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-70
291 if (!streams[i])
!streams[i]Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • comm
0-70
292 die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_locatio...shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
293-
294 fadvise (streams[i], FADVISE_SEQUENTIAL);-
295-
296 thisline[i] = readlinebuffer_delim (all_line[i][alt[i][0]], streams[i],-
297 delim);-
298 if (ferror (streams[i]))
ferror_unlocked (streams[i])Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • comm
0-70
299 die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_locatio...shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
300 }
executed 70 times by 1 test: end of block
Executed by:
  • comm
70
301-
302 while (thisline[0] || thisline[1])
thisline[0]Description
TRUEevaluated 168 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 38 times by 1 test
Evaluated by:
  • comm
thisline[1]Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 32 times by 1 test
Evaluated by:
  • comm
6-168
303 {-
304 int order;-
305 bool fill_up[2] = { false, false };-
306-
307 /* Compare the next available lines of the two files. */-
308-
309 if (!thisline[0])
!thisline[0]Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 168 times by 1 test
Evaluated by:
  • comm
6-168
310 order = 1;
executed 6 times by 1 test: order = 1;
Executed by:
  • comm
6
311 else if (!thisline[1])
!thisline[1]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 166 times by 1 test
Evaluated by:
  • comm
2-166
312 order = -1;
executed 2 times by 1 test: order = -1;
Executed by:
  • comm
2
313 else-
314 {-
315 if (hard_LC_COLLATE)
hard_LC_COLLATEDescription
TRUEnever evaluated
FALSEevaluated 166 times by 1 test
Evaluated by:
  • comm
0-166
316 order = xmemcoll (thisline[0]->buffer, thisline[0]->length - 1,
never executed: order = xmemcoll (thisline[0]->buffer, thisline[0]->length - 1, thisline[1]->buffer, thisline[1]->length - 1);
0
317 thisline[1]->buffer, thisline[1]->length - 1);
never executed: order = xmemcoll (thisline[0]->buffer, thisline[0]->length - 1, thisline[1]->buffer, thisline[1]->length - 1);
0
318 else-
319 {-
320 size_t len = min (thisline[0]->length, thisline[1]->length) - 1;
(thisline[0]->...ne[1]->length)Description
TRUEnever evaluated
FALSEevaluated 166 times by 1 test
Evaluated by:
  • comm
0-166
321 order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len);-
322 if (order == 0)
order == 0Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 82 times by 1 test
Evaluated by:
  • comm
82-84
323 order = (thisline[0]->length < thisline[1]->length
executed 84 times by 1 test: order = (thisline[0]->length < thisline[1]->length ? -1 : thisline[0]->length != thisline[1]->length);
Executed by:
  • comm
thisline[0]->l...ine[1]->lengthDescription
TRUEnever evaluated
FALSEevaluated 84 times by 1 test
Evaluated by:
  • comm
0-84
324 ? -1
executed 84 times by 1 test: order = (thisline[0]->length < thisline[1]->length ? -1 : thisline[0]->length != thisline[1]->length);
Executed by:
  • comm
84
325 : thisline[0]->length != thisline[1]->length);
executed 84 times by 1 test: order = (thisline[0]->length < thisline[1]->length ? -1 : thisline[0]->length != thisline[1]->length);
Executed by:
  • comm
84
326 }
executed 166 times by 1 test: end of block
Executed by:
  • comm
166
327 }-
328-
329 /* Output the line that is lesser. */-
330 if (order == 0)
order == 0Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 90 times by 1 test
Evaluated by:
  • comm
84-90
331 {-
332 /* Line is seen in both files. */-
333 total[2]++;-
334 writeline (thisline[1], stdout, 3);-
335 }
executed 84 times by 1 test: end of block
Executed by:
  • comm
84
336 else-
337 {-
338 seen_unpairable = true;-
339 if (order <= 0)
order <= 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 56 times by 1 test
Evaluated by:
  • comm
34-56
340 {-
341 /* Line is seen in file 1 only. */-
342 total[0]++;-
343 writeline (thisline[0], stdout, 1);-
344 }
executed 34 times by 1 test: end of block
Executed by:
  • comm
34
345 else-
346 {-
347 /* Line is seen in file 2 only. */-
348 total[1]++;-
349 writeline (thisline[1], stdout, 2);-
350 }
executed 56 times by 1 test: end of block
Executed by:
  • comm
56
351 }-
352-
353 /* Step the file the line came from.-
354 If the files match, step both files. */-
355 if (0 <= order)
0 <= orderDescription
TRUEevaluated 140 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 34 times by 1 test
Evaluated by:
  • comm
34-140
356 fill_up[1] = true;
executed 140 times by 1 test: fill_up[1] = 1 ;
Executed by:
  • comm
140
357 if (order <= 0)
order <= 0Description
TRUEevaluated 118 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 56 times by 1 test
Evaluated by:
  • comm
56-118
358 fill_up[0] = true;
executed 118 times by 1 test: fill_up[0] = 1 ;
Executed by:
  • comm
118
359-
360 for (i = 0; i < 2; i++)
i < 2Description
TRUEevaluated 346 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 171 times by 1 test
Evaluated by:
  • comm
171-346
361 if (fill_up[i])
fill_up[i]Description
TRUEevaluated 257 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 89 times by 1 test
Evaluated by:
  • comm
89-257
362 {-
363 /* Rotate the buffers for this file. */-
364 alt[i][2] = alt[i][1];-
365 alt[i][1] = alt[i][0];-
366 alt[i][0] = (alt[i][0] + 1) & 0x03;-
367-
368 thisline[i] = readlinebuffer_delim (all_line[i][alt[i][0]],-
369 streams[i], delim);-
370-
371 if (thisline[i])
thisline[i]Description
TRUEevaluated 192 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 65 times by 1 test
Evaluated by:
  • comm
65-192
372 check_order (all_line[i][alt[i][1]], thisline[i], i + 1);
executed 192 times by 1 test: check_order (all_line[i][alt[i][1]], thisline[i], i + 1);
Executed by:
  • comm
192
373-
374 /* If this is the end of the file we may need to re-check-
375 the order of the previous two lines, since we might have-
376 discovered an unpairable match since we checked before. */-
377 else if (all_line[i][alt[i][2]]->buffer)
all_line[i][alt[i][2]]->bufferDescription
TRUEevaluated 65 times by 1 test
Evaluated by:
  • comm
FALSEnever evaluated
0-65
378 check_order (all_line[i][alt[i][2]],
executed 65 times by 1 test: check_order (all_line[i][alt[i][2]], all_line[i][alt[i][1]], i + 1);
Executed by:
  • comm
65
379 all_line[i][alt[i][1]], i + 1);
executed 65 times by 1 test: check_order (all_line[i][alt[i][2]], all_line[i][alt[i][1]], i + 1);
Executed by:
  • comm
65
380-
381 if (ferror (streams[i]))
ferror_unlocked (streams[i])Description
TRUEnever evaluated
FALSEevaluated 254 times by 1 test
Evaluated by:
  • comm
0-254
382 die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_locatio...shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
383-
384 fill_up[i] = false;-
385 }
executed 254 times by 1 test: end of block
Executed by:
  • comm
254
386 }
executed 171 times by 1 test: end of block
Executed by:
  • comm
171
387-
388 for (i = 0; i < 2; i++)
i < 2Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 32 times by 1 test
Evaluated by:
  • comm
32-64
389 if (fclose (streams[i]) != 0)
rpl_fclose (streams[i]) != 0Description
TRUEnever evaluated
FALSEevaluated 64 times by 1 test
Evaluated by:
  • comm
0-64
390 die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_locatio...shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, infiles[i])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
391-
392 if (total_option)
total_optionDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 28 times by 1 test
Evaluated by:
  • comm
4-28
393 {-
394 /* Print the summary, minding the column and line delimiters. */-
395 char buf1[INT_BUFSIZE_BOUND (uintmax_t)];-
396 char buf2[INT_BUFSIZE_BOUND (uintmax_t)];-
397 char buf3[INT_BUFSIZE_BOUND (uintmax_t)];-
398 printf ("%s%s%s%s%s%s%s%c",-
399 umaxtostr (total[0], buf1), col_sep,-
400 umaxtostr (total[1], buf2), col_sep,-
401 umaxtostr (total[2], buf3), col_sep,-
402 _("total"), delim);-
403 }
executed 4 times by 1 test: end of block
Executed by:
  • comm
4
404}
executed 32 times by 1 test: end of block
Executed by:
  • comm
32
405-
406int-
407main (int argc, char **argv)-
408{-
409 int c;-
410-
411 initialize_main (&argc, &argv);-
412 set_program_name (argv[0]);-
413 setlocale (LC_ALL, "");-
414 bindtextdomain (PACKAGE, LOCALEDIR);-
415 textdomain (PACKAGE);-
416 hard_LC_COLLATE = hard_locale (LC_COLLATE);-
417-
418 atexit (close_stdout);-
419-
420 only_file_1 = true;-
421 only_file_2 = true;-
422 both = true;-
423-
424 seen_unpairable = false;-
425 issued_disorder_warning[0] = issued_disorder_warning[1] = false;-
426 check_input_order = CHECK_ORDER_DEFAULT;-
427 total_option = false;-
428-
429 while ((c = getopt_long (argc, argv, "123z", long_options, NULL)) != -1)
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 83 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 38 times by 1 test
Evaluated by:
  • comm
38-83
430 switch (c)-
431 {-
432 case '1':
executed 10 times by 1 test: case '1':
Executed by:
  • comm
10
433 only_file_1 = false;-
434 break;
executed 10 times by 1 test: break;
Executed by:
  • comm
10
435-
436 case '2':
executed 10 times by 1 test: case '2':
Executed by:
  • comm
10
437 only_file_2 = false;-
438 break;
executed 10 times by 1 test: break;
Executed by:
  • comm
10
439-
440 case '3':
executed 10 times by 1 test: case '3':
Executed by:
  • comm
10
441 both = false;-
442 break;
executed 10 times by 1 test: break;
Executed by:
  • comm
10
443-
444 case 'z':
executed 13 times by 1 test: case 'z':
Executed by:
  • comm
13
445 delim = '\0';-
446 break;
executed 13 times by 1 test: break;
Executed by:
  • comm
13
447-
448 case NOCHECK_ORDER_OPTION:
executed 2 times by 1 test: case NOCHECK_ORDER_OPTION:
Executed by:
  • comm
2
449 check_input_order = CHECK_ORDER_DISABLED;-
450 break;
executed 2 times by 1 test: break;
Executed by:
  • comm
2
451-
452 case CHECK_ORDER_OPTION:
executed 4 times by 1 test: case CHECK_ORDER_OPTION:
Executed by:
  • comm
4
453 check_input_order = CHECK_ORDER_ENABLED;-
454 break;
executed 4 times by 1 test: break;
Executed by:
  • comm
4
455-
456 case OUTPUT_DELIMITER_OPTION:
executed 10 times by 1 test: case OUTPUT_DELIMITER_OPTION:
Executed by:
  • comm
10
457 if (col_sep_len && !STREQ (col_sep, optarg))
never executed: __result = (((const unsigned char *) (const char *) ( col_sep ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( optarg ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
col_sep_lenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 8 times by 1 test
Evaluated by:
  • comm
!( __extension...)))); }) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • comm
FALSEevaluated 1 time by 1 test
Evaluated by:
  • comm
__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-8
458 die (EXIT_FAILURE, 0, _("multiple output delimiters specified"));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"multiple output delimiters specified\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "multiple output delimiters specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "multiple output delimiters specified" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • comm
1
459 col_sep = optarg;-
460 col_sep_len = *optarg ? strlen (optarg) : 1;
*optargDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 2 times by 1 test
Evaluated by:
  • comm
2-7
461 break;
executed 9 times by 1 test: break;
Executed by:
  • comm
9
462-
463 case TOTAL_OPTION:
executed 5 times by 1 test: case TOTAL_OPTION:
Executed by:
  • comm
5
464 total_option = true;-
465 break;
executed 5 times by 1 test: break;
Executed by:
  • comm
5
466-
467 case_GETOPT_HELP_CHAR;
never executed: break;
executed 12 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • comm
0-12
468-
469 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • comm
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • comm
0-4
470-
471 default:
executed 3 times by 1 test: default:
Executed by:
  • comm
3
472 usage (EXIT_FAILURE);-
473 }
never executed: end of block
0
474-
475 if (! col_sep_len)
! col_sep_lenDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 6 times by 1 test
Evaluated by:
  • comm
6-32
476 col_sep_len = 1;
executed 32 times by 1 test: col_sep_len = 1;
Executed by:
  • comm
32
477-
478 if (argc - optind < 2)
argc - optind < 2Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 36 times by 1 test
Evaluated by:
  • comm
2-36
479 {-
480 if (argc <= optind)
argc <= optindDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • comm
FALSEevaluated 1 time by 1 test
Evaluated by:
  • comm
1
481 error (0, 0, _("missing operand"));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "missing operand" , 5) );
Executed by:
  • comm
1
482 else-
483 error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
executed 1 time by 1 test: error (0, 0, dcgettext (((void *)0), "missing operand after %s" , 5) , quote (argv[argc - 1]));
Executed by:
  • comm
1
484 usage (EXIT_FAILURE);-
485 }
never executed: end of block
0
486-
487 if (2 < argc - optind)
2 < argc - optindDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • comm
FALSEevaluated 35 times by 1 test
Evaluated by:
  • comm
1-35
488 {-
489 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));-
490 usage (EXIT_FAILURE);-
491 }
never executed: end of block
0
492-
493 compare_files (argv + optind);-
494-
495 if (issued_disorder_warning[0] || issued_disorder_warning[1])
issued_disorder_warning[0]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 29 times by 1 test
Evaluated by:
  • comm
issued_disorder_warning[1]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • comm
FALSEevaluated 27 times by 1 test
Evaluated by:
  • comm
2-29
496 return EXIT_FAILURE;
executed 5 times by 1 test: return 1 ;
Executed by:
  • comm
5
497 else-
498 return EXIT_SUCCESS;
executed 27 times by 1 test: return 0 ;
Executed by:
  • comm
27
499}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2