OpenCoverage

paste.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/paste.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* paste - merge 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/* The list of valid escape sequences has been expanded over the Unix-
21 version, to include \b, \f, \r, and \v.-
22-
23 POSIX changes, bug fixes, long-named options, and cleanup-
24 by David MacKenzie <djm@gnu.ai.mit.edu>.-
25-
26 Options:-
27 --serial-
28 -s Paste one file at a time rather than-
29 one line from each file.-
30 --delimiters=delim-list-
31 -d delim-list Consecutively use the characters in-
32 DELIM-LIST instead of tab to separate-
33 merged lines. When DELIM-LIST is exhausted,-
34 start again at its beginning.-
35 A FILE of '-' means standard input.-
36 If no FILEs are given, standard input is used. */-
37-
38#include <config.h>-
39-
40#include <stdio.h>-
41#include <getopt.h>-
42#include <sys/types.h>-
43#include "system.h"-
44#include "die.h"-
45#include "error.h"-
46#include "fadvise.h"-
47-
48/* The official name of this program (e.g., no 'g' prefix). */-
49#define PROGRAM_NAME "paste"-
50-
51#define AUTHORS \-
52 proper_name ("David M. Ihnat"), \-
53 proper_name ("David MacKenzie")-
54-
55/* Indicates that no delimiter should be added in the current position. */-
56#define EMPTY_DELIM '\0'-
57-
58/* If nonzero, we have read standard input at some point. */-
59static bool have_read_stdin;-
60-
61/* If nonzero, merge subsequent lines of each file rather than-
62 corresponding lines from each file in parallel. */-
63static bool serial_merge;-
64-
65/* The delimiters between lines of input files (used cyclically). */-
66static char *delims;-
67-
68/* A pointer to the character after the end of 'delims'. */-
69static char const *delim_end;-
70-
71static unsigned char line_delim = '\n';-
72-
73static struct option const longopts[] =-
74{-
75 {"serial", no_argument, NULL, 's'},-
76 {"delimiters", required_argument, NULL, 'd'},-
77 {"zero-terminated", no_argument, NULL, 'z'},-
78 {GETOPT_HELP_OPTION_DECL},-
79 {GETOPT_VERSION_OPTION_DECL},-
80 {NULL, 0, NULL, 0}-
81};-
82-
83/* Set globals delims and delim_end. Copy STRPTR to DELIMS, converting-
84 backslash representations of special characters in STRPTR to their actual-
85 values. The set of possible backslash characters has been expanded beyond-
86 that recognized by the Unix version.-
87 Return 0 upon success.-
88 If the string ends in an odd number of backslashes, ignore the-
89 final backslash and return nonzero. */-
90-
91static int-
92collapse_escapes (char const *strptr)-
93{-
94 char *strout = xstrdup (strptr);-
95 bool backslash_at_end = false;-
96-
97 delims = strout;-
98-
99 while (*strptr)
*strptrDescription
TRUEevaluated 319 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 317 times by 1 test
Evaluated by:
  • paste
317-319
100 {-
101 if (*strptr != '\\') /* Is it an escape character? */
*strptr != '\\'Description
TRUEevaluated 243 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 76 times by 1 test
Evaluated by:
  • paste
76-243
102 *strout++ = *strptr++; /* No, just transfer it. */
executed 243 times by 1 test: *strout++ = *strptr++;
Executed by:
  • paste
243
103 else-
104 {-
105 switch (*++strptr)-
106 {-
107 case '0':
executed 74 times by 1 test: case '0':
Executed by:
  • paste
74
108 *strout++ = EMPTY_DELIM;-
109 break;
executed 74 times by 1 test: break;
Executed by:
  • paste
74
110-
111 case 'b':
never executed: case 'b':
0
112 *strout++ = '\b';-
113 break;
never executed: break;
0
114-
115 case 'f':
never executed: case 'f':
0
116 *strout++ = '\f';-
117 break;
never executed: break;
0
118-
119 case 'n':
never executed: case 'n':
0
120 *strout++ = '\n';-
121 break;
never executed: break;
0
122-
123 case 'r':
never executed: case 'r':
0
124 *strout++ = '\r';-
125 break;
never executed: break;
0
126-
127 case 't':
never executed: case 't':
0
128 *strout++ = '\t';-
129 break;
never executed: break;
0
130-
131 case 'v':
never executed: case 'v':
0
132 *strout++ = '\v';-
133 break;
never executed: break;
0
134-
135 case '\\':
never executed: case '\\':
0
136 *strout++ = '\\';-
137 break;
never executed: break;
0
138-
139 case '\0':
executed 2 times by 1 test: case '\0':
Executed by:
  • paste
2
140 backslash_at_end = true;-
141 goto done;
executed 2 times by 1 test: goto done;
Executed by:
  • paste
2
142-
143 default:
never executed: default:
0
144 *strout++ = *strptr;-
145 break;
never executed: break;
0
146 }-
147 strptr++;-
148 }
executed 74 times by 1 test: end of block
Executed by:
  • paste
74
149 }-
150-
151 done:
code before this statement executed 317 times by 1 test: done:
Executed by:
  • paste
317
152-
153 delim_end = strout;-
154 return backslash_at_end ? 1 : 0;
executed 319 times by 1 test: return backslash_at_end ? 1 : 0;
Executed by:
  • paste
319
155}-
156-
157/* Report a write error and exit. */-
158-
159static void write_error (void) ATTRIBUTE_NORETURN;-
160static void-
161write_error (void)-
162{-
163 die (EXIT_FAILURE, errno, _("write error"));-
164}
never executed: end of block
0
165-
166/* Output a single byte, reporting any write errors. */-
167-
168static inline void-
169xputchar (char c)-
170{-
171 if (putchar (c) < 0)
putchar_unlocked (c) < 0Description
TRUEnever evaluated
FALSEevaluated 21184 times by 1 test
Evaluated by:
  • paste
0-21184
172 write_error ();
never executed: write_error ();
0
173}
executed 21184 times by 1 test: end of block
Executed by:
  • paste
21184
174-
175/* Perform column paste on the NFILES files named in FNAMPTR.-
176 Return true if successful, false if one or more files could not be-
177 opened or read. */-
178-
179static bool-
180paste_parallel (size_t nfiles, char **fnamptr)-
181{-
182 bool ok = true;-
183 /* If all files are just ready to be closed, or will be on this-
184 round, the string of delimiters must be preserved.-
185 delbuf[0] through delbuf[nfiles]-
186 store the delimiters for closed files. */-
187 char *delbuf = xmalloc (nfiles + 2);-
188-
189 /* Streams open to the files to process; NULL if the corresponding-
190 stream is closed. */-
191 FILE **fileptr = xnmalloc (nfiles + 1, sizeof *fileptr);-
192-
193 /* Number of files still open to process. */-
194 size_t files_open;-
195-
196 /* True if any fopen got fd == STDIN_FILENO. */-
197 bool opened_stdin = false;-
198-
199 /* Attempt to open all files. This could be expanded to an infinite-
200 number of files, but at the (considerable) expense of remembering-
201 each file and its current offset, then opening/reading/closing. */-
202-
203 for (files_open = 0; files_open < nfiles; ++files_open)
files_open < nfilesDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
18-34
204 {-
205 if (STREQ (fnamptr[files_open], "-"))
never executed: __result = (((const unsigned char *) (const char *) ( fnamptr[files_open] ))[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 2 times by 1 test: end of block
Executed by:
  • paste
( __extension_...)))); }) == 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
__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 34 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
__result == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • paste
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-34
206 {-
207 have_read_stdin = true;-
208 fileptr[files_open] = stdin;-
209 }
executed 2 times by 1 test: end of block
Executed by:
  • paste
2
210 else-
211 {-
212 fileptr[files_open] = fopen (fnamptr[files_open], "r");-
213 if (fileptr[files_open] == NULL)
fileptr[files_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
0-32
214 die (EXIT_FAILURE, errno, "%s", quotef (fnamptr[files_open]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, fnamptr[files_open])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errn...ng_style, fnamptr[files_open])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, fnamptr[files_open])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
215 else if (fileno (fileptr[files_open]) == STDIN_FILENO)
fileno (filept...es_open]) == 0Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
0-32
216 opened_stdin = true;
never executed: opened_stdin = 1 ;
0
217 fadvise (fileptr[files_open], FADVISE_SEQUENTIAL);-
218 }
executed 32 times by 1 test: end of block
Executed by:
  • paste
32
219 }-
220-
221 if (opened_stdin && have_read_stdin)
opened_stdinDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
have_read_stdinDescription
TRUEnever evaluated
FALSEnever evaluated
0-18
222 die (EXIT_FAILURE, 0, _("standard input is closed"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"standard input is closed\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "standard input is closed" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "standard input is closed" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
223-
224 /* Read a line from each file and output it to stdout separated by a-
225 delimiter, until we go through the loop without successfully-
226 reading from any of the files. */-
227-
228 while (files_open)
files_openDescription
TRUEevaluated 44 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
18-44
229 {-
230 /* Set up for the next line. */-
231 bool somedone = false;-
232 char const *delimptr = delims;-
233 size_t delims_saved = 0; /* Number of delims saved in 'delbuf'. */-
234-
235 for (size_t i = 0; i < nfiles && files_open; i++)
i < nfilesDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 44 times by 1 test
Evaluated by:
  • paste
files_openDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-84
236 {-
237 int chr IF_LINT ( = 0); /* Input character. */-
238 int err IF_LINT ( = 0); /* Input errno value. */-
239 bool sometodo = false; /* Input chars to process. */-
240-
241 if (fileptr[i])
fileptr[i]Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-84
242 {-
243 chr = getc (fileptr[i]);-
244 err = errno;-
245 if (chr != EOF && delims_saved)
chr != (-1)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 34 times by 1 test
Evaluated by:
  • paste
delims_savedDescription
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • paste
0-50
246 {-
247 if (fwrite (delbuf, 1, delims_saved, stdout) != delims_saved)
never executed: break;
(__extension__...= delims_savedDescription
TRUEnever evaluated
FALSEnever evaluated
(__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
__builtin_constant_p ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...delims_saved )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 )...s_saved ) <= 8Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 ) != 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...delims_saved )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( delims_saved ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
248 write_error ();
never executed: write_error ();
0
249 delims_saved = 0;-
250 }
never executed: end of block
0
251-
252 while (chr != EOF)
chr != (-1)Description
TRUEevaluated 97 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 50 times by 1 test
Evaluated by:
  • paste
50-97
253 {-
254 sometodo = true;-
255 if (chr == line_delim)
chr == line_delimDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 63 times by 1 test
Evaluated by:
  • paste
34-63
256 break;
executed 34 times by 1 test: break;
Executed by:
  • paste
34
257 xputchar (chr);-
258 chr = getc (fileptr[i]);-
259 err = errno;-
260 }
executed 63 times by 1 test: end of block
Executed by:
  • paste
63
261 }
executed 84 times by 1 test: end of block
Executed by:
  • paste
84
262-
263 if (! sometodo)
! sometodoDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 50 times by 1 test
Evaluated by:
  • paste
34-50
264 {-
265 /* EOF, read error, or closed file.-
266 If an EOF or error, close the file. */-
267 if (fileptr[i])
fileptr[i]Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-34
268 {-
269 if (ferror (fileptr[i]))
ferror_unlocked (fileptr[i])Description
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • paste
0-34
270 {-
271 error (0, err, "%s", quotef (fnamptr[i]));-
272 ok = false;-
273 }
never executed: end of block
0
274 if (fileptr[i] == stdin)
fileptr[i] == stdinDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
2-32
275 clearerr (fileptr[i]); /* Also clear EOF. */
executed 2 times by 1 test: clearerr_unlocked (fileptr[i]);
Executed by:
  • paste
2
276 else if (fclose (fileptr[i]) == EOF)
rpl_fclose (fi...tr[i]) == (-1)Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • paste
0-32
277 {-
278 error (0, errno, "%s", quotef (fnamptr[i]));-
279 ok = false;-
280 }
never executed: end of block
0
281-
282 fileptr[i] = NULL;-
283 files_open--;-
284 }
executed 34 times by 1 test: end of block
Executed by:
  • paste
34
285-
286 if (i + 1 == nfiles)
i + 1 == nfilesDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 16 times by 1 test
Evaluated by:
  • paste
16-18
287 {-
288 /* End of this output line.-
289 Is this the end of the whole thing? */-
290 if (somedone)
somedoneDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
0-18
291 {-
292 /* No. Some files were not closed for this line. */-
293 if (delims_saved)
delims_savedDescription
TRUEnever evaluated
FALSEnever evaluated
0
294 {-
295 if (fwrite (delbuf, 1, delims_saved, stdout)
never executed: break;
(__extension__...= delims_savedDescription
TRUEnever evaluated
FALSEnever evaluated
(__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
__builtin_constant_p ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...delims_saved )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 )...s_saved ) <= 8Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 ) != 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( 1 )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( 1 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...delims_saved )Description
TRUEnever evaluated
FALSEnever evaluated
(size_t) ( delims_saved ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
296 != delims_saved)
(__extension__...= delims_savedDescription
TRUEnever evaluated
FALSEnever evaluated
0
297 write_error ();
never executed: write_error ();
0
298 delims_saved = 0;-
299 }
never executed: end of block
0
300 xputchar (line_delim);-
301 }
never executed: end of block
0
302 continue; /* Next read of files, or exit. */
executed 18 times by 1 test: continue;
Executed by:
  • paste
18
303 }-
304 else-
305 {-
306 /* Closed file; add delimiter to 'delbuf'. */-
307 if (*delimptr != EMPTY_DELIM)
*delimptr != '\0'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-16
308 delbuf[delims_saved++] = *delimptr;
executed 16 times by 1 test: delbuf[delims_saved++] = *delimptr;
Executed by:
  • paste
16
309 if (++delimptr == delim_end)
++delimptr == delim_endDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-16
310 delimptr = delims;
executed 16 times by 1 test: delimptr = delims;
Executed by:
  • paste
16
311 }
executed 16 times by 1 test: end of block
Executed by:
  • paste
16
312 }-
313 else-
314 {-
315 /* Some data read. */-
316 somedone = true;-
317-
318 /* Except for last file, replace last newline with delim. */-
319 if (i + 1 != nfiles)
i + 1 != nfilesDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 26 times by 1 test
Evaluated by:
  • paste
24-26
320 {-
321 if (chr != line_delim && chr != EOF)
chr != line_delimDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 16 times by 1 test
Evaluated by:
  • paste
chr != (-1)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • paste
0-16
322 xputchar (chr);
never executed: xputchar (chr);
0
323 if (*delimptr != EMPTY_DELIM)
*delimptr != '\0'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-24
324 xputchar (*delimptr);
executed 24 times by 1 test: xputchar (*delimptr);
Executed by:
  • paste
24
325 if (++delimptr == delim_end)
++delimptr == delim_endDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-24
326 delimptr = delims;
executed 24 times by 1 test: delimptr = delims;
Executed by:
  • paste
24
327 }
executed 24 times by 1 test: end of block
Executed by:
  • paste
24
328 else-
329 {-
330 /* If the last line of the last file lacks a newline,-
331 print one anyhow. POSIX requires this. */-
332 char c = (chr == EOF ? line_delim : chr);
chr == (-1)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
8-18
333 xputchar (c);-
334 }
executed 26 times by 1 test: end of block
Executed by:
  • paste
26
335 }-
336 }-
337 }
executed 44 times by 1 test: end of block
Executed by:
  • paste
44
338 free (fileptr);-
339 free (delbuf);-
340 return ok;
executed 18 times by 1 test: return ok;
Executed by:
  • paste
18
341}-
342-
343/* Perform serial paste on the NFILES files named in FNAMPTR.-
344 Return true if no errors, false if one or more files could not be-
345 opened or read. */-
346-
347static bool-
348paste_serial (size_t nfiles, char **fnamptr)-
349{-
350 bool ok = true; /* false if open or read errors occur. */-
351 int charnew, charold; /* Current and previous char read. */-
352 char const *delimptr; /* Current delimiter char. */-
353 FILE *fileptr; /* Open for reading current file. */-
354-
355 for (; nfiles; nfiles--, fnamptr++)
nfilesDescription
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 299 times by 1 test
Evaluated by:
  • paste
299
356 {-
357 int saved_errno;-
358 bool is_stdin = STREQ (*fnamptr, "-");
never executed: __result = (((const unsigned char *) (const char *) ( *fnamptr ))[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 299 times by 1 test: end of block
Executed by:
  • paste
__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 299 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
__result == 0Description
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 299 times by 1 test
Evaluated by:
  • paste
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-299
359 if (is_stdin)
is_stdinDescription
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-299
360 {-
361 have_read_stdin = true;-
362 fileptr = stdin;-
363 }
executed 299 times by 1 test: end of block
Executed by:
  • paste
299
364 else-
365 {-
366 fileptr = fopen (*fnamptr, "r");-
367 if (fileptr == NULL)
fileptr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
368 {-
369 error (0, errno, "%s", quotef (*fnamptr));-
370 ok = false;-
371 continue;
never executed: continue;
0
372 }-
373 fadvise (fileptr, FADVISE_SEQUENTIAL);-
374 }
never executed: end of block
0
375-
376 delimptr = delims; /* Set up for delimiter string. */-
377-
378 charold = getc (fileptr);-
379 saved_errno = errno;-
380 if (charold != EOF)
charold != (-1)Description
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-299
381 {-
382 /* 'charold' is set up. Hit it!-
383 Keep reading characters, stashing them in 'charnew';-
384 output 'charold', converting to the appropriate delimiter-
385 character if needed. After the EOF, output 'charold'-
386 if it's a newline; otherwise, output it and then a newline. */-
387-
388 while ((charnew = getc (fileptr)) != EOF)
(charnew = get...eptr)) != (-1)Description
TRUEevaluated 20922 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 299 times by 1 test
Evaluated by:
  • paste
299-20922
389 {-
390 /* Process the old character. */-
391 if (charold == line_delim)
charold == line_delimDescription
TRUEevaluated 4792 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 16130 times by 1 test
Evaluated by:
  • paste
4792-16130
392 {-
393 if (*delimptr != EMPTY_DELIM)
*delimptr != '\0'Description
TRUEevaluated 4642 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 150 times by 1 test
Evaluated by:
  • paste
150-4642
394 xputchar (*delimptr);
executed 4642 times by 1 test: xputchar (*delimptr);
Executed by:
  • paste
4642
395-
396 if (++delimptr == delim_end)
++delimptr == delim_endDescription
TRUEevaluated 4792 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-4792
397 delimptr = delims;
executed 4792 times by 1 test: delimptr = delims;
Executed by:
  • paste
4792
398 }
executed 4792 times by 1 test: end of block
Executed by:
  • paste
4792
399 else-
400 xputchar (charold);
executed 16130 times by 1 test: xputchar (charold);
Executed by:
  • paste
16130
401-
402 charold = charnew;-
403 }
executed 20922 times by 1 test: end of block
Executed by:
  • paste
20922
404 saved_errno = errno;-
405-
406 /* Hit EOF. Process that last character. */-
407 xputchar (charold);-
408 }
executed 299 times by 1 test: end of block
Executed by:
  • paste
299
409-
410 if (charold != line_delim)
charold != line_delimDescription
TRUEnever evaluated
FALSEevaluated 299 times by 1 test
Evaluated by:
  • paste
0-299
411 xputchar (line_delim);
never executed: xputchar (line_delim);
0
412-
413 if (ferror (fileptr))
ferror_unlocked (fileptr)Description
TRUEnever evaluated
FALSEevaluated 299 times by 1 test
Evaluated by:
  • paste
0-299
414 {-
415 error (0, saved_errno, "%s", quotef (*fnamptr));-
416 ok = false;-
417 }
never executed: end of block
0
418 if (is_stdin)
is_stdinDescription
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEnever evaluated
0-299
419 clearerr (fileptr); /* Also clear EOF. */
executed 299 times by 1 test: clearerr_unlocked (fileptr);
Executed by:
  • paste
299
420 else if (fclose (fileptr) == EOF)
rpl_fclose (fileptr) == (-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
421 {-
422 error (0, errno, "%s", quotef (*fnamptr));-
423 ok = false;-
424 }
never executed: end of block
0
425 }
executed 299 times by 1 test: end of block
Executed by:
  • paste
299
426 return ok;
executed 299 times by 1 test: return ok;
Executed by:
  • paste
299
427}-
428-
429void-
430usage (int status)-
431{-
432 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 9 times by 1 test
Evaluated by:
  • paste
3-9
433 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • paste
3
434 else-
435 {-
436 printf (_("\-
437Usage: %s [OPTION]... [FILE]...\n\-
438"),-
439 program_name);-
440 fputs (_("\-
441Write lines consisting of the sequentially corresponding lines from\n\-
442each FILE, separated by TABs, to standard output.\n\-
443"), stdout);-
444-
445 emit_stdin_note ();-
446 emit_mandatory_arg_note ();-
447-
448 fputs (_("\-
449 -d, --delimiters=LIST reuse characters from LIST instead of TABs\n\-
450 -s, --serial paste one file at a time instead of in parallel\n\-
451"), stdout);-
452 fputs (_("\-
453 -z, --zero-terminated line delimiter is NUL, not newline\n\-
454"), stdout);-
455 fputs (HELP_OPTION_DESCRIPTION, stdout);-
456 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
457 /* FIXME: add a couple of examples. */-
458 emit_ancillary_info (PROGRAM_NAME);-
459 }
executed 9 times by 1 test: end of block
Executed by:
  • paste
9
460 exit (status);
executed 12 times by 1 test: exit (status);
Executed by:
  • paste
12
461}-
462-
463int-
464main (int argc, char **argv)-
465{-
466 int optc;-
467 char const *delim_arg = "\t";-
468-
469 initialize_main (&argc, &argv);-
470 set_program_name (argv[0]);-
471 setlocale (LC_ALL, "");-
472 bindtextdomain (PACKAGE, LOCALEDIR);-
473 textdomain (PACKAGE);-
474-
475 atexit (close_stdout);-
476-
477 have_read_stdin = false;-
478 serial_merge = false;-
479-
480 while ((optc = getopt_long (argc, argv, "d:sz", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 638 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 319 times by 1 test
Evaluated by:
  • paste
319-638
481 {-
482 switch (optc)-
483 {-
484 case 'd':
executed 311 times by 1 test: case 'd':
Executed by:
  • paste
311
485 /* Delimiter character(s). */-
486 delim_arg = (optarg[0] == '\0' ? "\\0" : optarg);
optarg[0] == '\0'Description
TRUEevaluated 74 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 237 times by 1 test
Evaluated by:
  • paste
74-237
487 break;
executed 311 times by 1 test: break;
Executed by:
  • paste
311
488-
489 case 's':
executed 301 times by 1 test: case 's':
Executed by:
  • paste
301
490 serial_merge = true;-
491 break;
executed 301 times by 1 test: break;
Executed by:
  • paste
301
492-
493 case 'z':
executed 10 times by 1 test: case 'z':
Executed by:
  • paste
10
494 line_delim = '\0';-
495 break;
executed 10 times by 1 test: break;
Executed by:
  • paste
10
496-
497 case_GETOPT_HELP_CHAR;
never executed: break;
executed 9 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • paste
0-9
498-
499 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • paste
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • paste
0-4
500-
501 default:
executed 3 times by 1 test: default:
Executed by:
  • paste
3
502 usage (EXIT_FAILURE);-
503 }
never executed: end of block
0
504 }-
505-
506 int nfiles = argc - optind;-
507 if (nfiles == 0)
nfiles == 0Description
TRUEevaluated 301 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
18-301
508 {-
509 argv[optind] = bad_cast ("-");-
510 nfiles++;-
511 }
executed 301 times by 1 test: end of block
Executed by:
  • paste
301
512-
513 if (collapse_escapes (delim_arg))
collapse_escapes (delim_arg)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 317 times by 1 test
Evaluated by:
  • paste
2-317
514 {-
515 /* Don't use the quote() quoting style, because that would double the-
516 number of displayed backslashes, making the diagnostic look bogus. */-
517 die (EXIT_FAILURE, 0,-
518 _("delimiter list ends with an unescaped backslash: %s"),-
519 quotearg_n_style_colon (0, c_maybe_quoting_style, delim_arg));-
520 }
never executed: end of block
0
521-
522 bool ok = ((serial_merge ? paste_serial : paste_parallel)
serial_mergeDescription
TRUEevaluated 299 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 18 times by 1 test
Evaluated by:
  • paste
18-299
523 (nfiles, &argv[optind]));-
524-
525 free (delims);-
526-
527 if (have_read_stdin && fclose (stdin) == EOF)
have_read_stdinDescription
TRUEevaluated 301 times by 1 test
Evaluated by:
  • paste
FALSEevaluated 16 times by 1 test
Evaluated by:
  • paste
rpl_fclose ( stdin ) == (-1)Description
TRUEnever evaluated
FALSEevaluated 301 times by 1 test
Evaluated by:
  • paste
0-301
528 die (EXIT_FAILURE, errno, "-");
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"-\"), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , "-"), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "-"), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
529 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 317 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • paste
317
530}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2