OpenCoverage

pr.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/pr.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* pr -- convert text files for printing.-
2 Copyright (C) 1988-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* By Pete TerMaat, with considerable refinement by Roland Huebner. */-
18-
19/* Things to watch: Sys V screws up on ...-
20 pr -n -3 -s: /usr/dict/words-
21 pr -m -o10 -n /usr/dict/words{,,,}-
22 pr -6 -a -n -o5 /usr/dict/words-
23-
24 Ideas:-
25-
26 Keep a things_to_do list of functions to call when we know we have-
27 something to print. Cleaner than current series of checks.-
28-
29 Improve the printing of control prefixes.-
30-
31 Expand the file name in the centered header line to a full file name.-
32-
33-
34 Concept:-
35-
36 If the input_tab_char differs from the default value TAB-
37 ('-e[CHAR[...]]' is used), any input text tab is expanded to the-
38 default width of 8 spaces (compare char_to_clump). - Same as SunOS-
39 does.-
40-
41 The treatment of the number_separator (compare add_line_number):-
42 The default value TAB of the number_separator ('-n[SEP[...]]') doesn't-
43 be thought to be an input character. An optional '-e'-input has no-
44 effect.-
45 - With single column output-
46 only one POSIX requirement has to be met:-
47 The default n-separator should be a TAB. The consequence is a-
48 different width between the number and the text if the output position-
49 of the separator changes, i.e., it depends upon the left margin used.-
50 That's not nice but easy-to-use together with the defaults of other-
51 utilities, e.g. sort or cut. - Same as SunOS does.-
52 - With multicolumn output-
53 two conflicting POSIX requirements exist:-
54 First "default n-separator is TAB", second "output text columns shall-
55 be of equal width". Moreover POSIX specifies the number+separator a-
56 part of the column, together with '-COLUMN' and '-a -COLUMN'.-
57 (With -m output the number shall occupy each line only once. Exactly-
58 the same situation as single column output exists.)-
59 GNU pr gives priority to the 2nd requirement and observes POSIX-
60 column definition. The n-separator TAB is expanded to the same number-
61 of spaces in each column using the default value 8. Tabification is-
62 only performed if it is compatible with the output position.-
63 Consequence: The output text columns are of equal width. The layout-
64 of a page does not change if the left margin varies. - Looks better-
65 than the SunOS approach.-
66 SunOS pr gives priority to the 1st requirement. n-separator TAB-
67 width varies with each column. Only the width of text part of the-
68 column is fixed.-
69 Consequence: The output text columns don't have equal width. The-
70 widths and the layout of the whole page varies with the left margin.-
71 An overflow of the line length (without margin) over the input value-
72 PAGE_WIDTH may occur.-
73-
74 The interference of the POSIX-compliant small letter options -w and -s:-
75 ("interference" means "setting a _separator_ with -s switches off the-
76 column structure and the default - not generally - page_width,-
77 acts on -w option")-
78 options: text form / separator: equivalent new options:-
79 -w l -s[x]-
80 ---------------------------------------------------------------------
81 1. -- -- columns / space ---
82 trunc. to page_width = 72-
83 2. -- -s[:] full lines / TAB[:] -J --sep-string[="<TAB>"|:]-
84 no truncation-
85 3. -w l -- columns / space -W l-
86 trunc. to page_width = l-
87 4. -w l -s[:] columns / no sep.[:] -W l --sep-string[=:]-
88 trunc. to page_width = l-
89 ---------------------------------------------------------------------
90-
91-
92 Options:-
93-
94 Including version 1.22i:-
95 Some SMALL LETTER options have been redefined with the object of a-
96 better POSIX compliance. The output of some further cases has been-
97 adapted to other UNIXes. A violation of downward compatibility has to-
98 be accepted.-
99 Some NEW CAPITAL LETTER options ( -J, -S, -W) has been introduced to-
100 turn off unexpected interferences of small letter options (-s and -w-
101 together with the three column options).-
102 -N option and the second argument LAST_PAGE of +FIRST_PAGE offer more-
103 flexibility; The detailed handling of form feeds set in the input-
104 files requires -T option.-
105-
106 Capital letter options dominate small letter ones.-
107-
108 Some of the option-arguments cannot be specified as separate arguments-
109 from the preceding option letter (already stated in POSIX specification).-
110-
111 Form feeds in the input cause page breaks in the output. Multiple-
112 form feeds produce empty pages.-
113-
114 +FIRST_PAGE[:LAST_PAGE], --pages=FIRST_PAGE[:LAST_PAGE]-
115 begin [stop] printing with page FIRST_[LAST_]PAGE-
116-
117 -COLUMN, --columns=COLUMN-
118 Produce output that is COLUMN columns wide and-
119 print columns down, unless -a is used. Balance number of-
120 lines in the columns on each page.-
121-
122 -a, --across Print columns across rather than down, used-
123 together with -COLUMN. The input-
124 one-
125 two-
126 three-
127 four-
128 will be printed with '-a -3' as-
129 one two three-
130 four-
131-
132 -b Balance columns on the last page.-
133 -b is no longer an independent option. It's always used-
134 together with -COLUMN (unless -a is used) to get a-
135 consistent formulation with "FF set by hand" in input-
136 files. Each formfeed found terminates the number of lines-
137 to be read with the actual page. The situation for-
138 printing columns down is equivalent to that on the last-
139 page. So we need a balancing.-
140-
141 Keeping -b as an underground option guarantees some-
142 downward compatibility. Utilities using pr with -b-
143 (a most frequently used form) still work as usual.-
144-
145 -c, --show-control-chars-
146 Print unprintable characters as control prefixes.-
147 Control-g is printed as ^G (use hat notation) and-
148 octal backslash notation.-
149-
150 -d, --double-space Double space the output.-
151-
152 -D FORMAT, --date-format=FORMAT Use FORMAT for the header date.-
153-
154 -e[CHAR[WIDTH]], --expand-tabs[=CHAR[WIDTH]]-
155 Expand tabs to spaces on input. Optional argument CHAR-
156 is the input TAB character. (Default is TAB). Optional-
157 argument WIDTH is the input TAB character's width.-
158 (Default is 8.)-
159-
160 -F, -f, --form-feed Use formfeeds instead of newlines to separate-
161 pages. A three line HEADER is used, no TRAILER with -F,-
162 without -F both HEADER and TRAILER are made of five lines.-
163-
164 -h HEADER, --header=HEADER-
165 Replace the filename in the header with the string HEADER.-
166 A centered header is used.-
167-
168 -i[CHAR[WIDTH]], --output-tabs[=CHAR[WIDTH]]-
169 Replace spaces with tabs on output. Optional argument-
170 CHAR is the output TAB character. (Default is TAB).-
171 Optional argument WIDTH is the output TAB character's-
172 width. (Default is 8)-
173-
174 -J, --join-lines Merge lines of full length, turns off -W/-w-
175 line truncation, no column alignment, --sep-string[=STRING]-
176 sets separators, works with all column options-
177 (-COLUMN | -a -COLUMN | -m).-
178 -J has been introduced (together with -W and --sep-string) to-
179 disentangle the old (POSIX compliant) options -w, -s-
180 along with the 3 column options.-
181-
182 -l PAGE_LENGTH, --length=PAGE_LENGTH-
183 Set the page length to PAGE_LENGTH lines. Default is 66,-
184 including 5 lines of HEADER and 5 lines of TRAILER-
185 without -F, but only 3 lines of HEADER and no TRAILER-
186 with -F (i.e the number of text lines defaults to 56 or-
187 63 respectively).-
188-
189 -m, --merge Print files in parallel; pad_across_to align-
190 columns; truncate lines and print separator strings;-
191 Do it also with empty columns to get a continuous line-
192 numbering and column marking by separators throughout-
193 the whole merged file.-
194-
195 Empty pages in some input files produce empty columns-
196 [marked by separators] in the merged pages. Completely-
197 empty merged pages show no column separators at all.-
198-
199 The layout of a merged page is ruled by the largest form-
200 feed distance of the single pages at that page. Shorter-
201 columns will be filled up with empty lines.-
202-
203 Together with -J option join lines of full length and-
204 set separators when -S option is used.-
205-
206 -n[SEP[DIGITS]], --number-lines[=SEP[DIGITS]]-
207 Provide DIGITS digit line numbering (default for DIGITS-
208 is 5). With multicolumn output the number occupies the-
209 first DIGITS column positions of each text column or only-
210 each line of -m output.-
211 With single column output the number precedes each line-
212 just as -m output.-
213 Optional argument SEP is the character appended to the-
214 line number to separate it from the text followed.-
215 The default separator is a TAB. In a strict sense a TAB-
216 is always printed with single column output only. The-
217 TAB-width varies with the TAB-position, e.g. with the-
218 left margin specified by -o option.-
219 With multicolumn output priority is given to "equal width-
220 of output columns" (a POSIX specification). The TAB-width-
221 is fixed to the value of the 1st column and does not-
222 change with different values of left margin. That means a-
223 fixed number of spaces is always printed in the place of-
224 a TAB. The tabification depends upon the output-
225 position.-
226-
227 Default counting of the line numbers starts with 1st-
228 line of the input file (not the 1st line printed,-
229 compare the --page option and -N option).-
230-
231 -N NUMBER, --first-line-number=NUMBER-
232 Start line counting with the number NUMBER at the 1st-
233 line of first page printed (mostly not the 1st line of-
234 the input file).-
235-
236 -o MARGIN, --indent=MARGIN-
237 Offset each line with a margin MARGIN spaces wide.-
238 Total page width is the size of the margin plus the-
239 PAGE_WIDTH set with -W/-w option.-
240-
241 -r, --no-file-warnings-
242 Omit warning when a file cannot be opened.-
243-
244 -s[CHAR], --separator[=CHAR]-
245 Separate columns by a single character CHAR, default for-
246 CHAR is the TAB character without -w and 'no char' with -w.-
247 Without '-s' default separator 'space' is set.-
248 -s[CHAR] turns off line truncation of all 3 column options-
249 (-COLUMN|-a -COLUMN|-m) except -w is set. That is a POSIX-
250 compliant formulation. The source code translates -s into-
251 the new options -S and -J, also -W if required.-
252-
253 -S[STRING], --sep-string[=STRING]-
254 Separate columns by any string STRING. The -S option-
255 doesn't react upon the -W/-w option (unlike -s option-
256 does). It defines a separator nothing else.-
257 Without -S: Default separator TAB is used with -J and-
258 'space' otherwise (same as -S" ").-
259 With -S "": No separator is used.-
260 Quotes should be used with blanks and some shell active-
261 characters.-
262 -S is problematic because in its obsolete form you-
263 cannot use -S "STRING", but in its standard form you-
264 must use -S "STRING" if STRING is empty. Use-
265 --sep-string to avoid the ambiguity.-
266-
267 -t, --omit-header Do not print headers or footers but retain form-
268 feeds set in the input files.-
269-
270 -T, --omit-pagination-
271 Do not print headers or footers, eliminate any pagination-
272 by form feeds set in the input files.-
273-
274 -v, --show-nonprinting-
275 Print unprintable characters as escape sequences. Use-
276 octal backslash notation. Control-G becomes \007.-
277-
278 -w PAGE_WIDTH, --width=PAGE_WIDTH-
279 Set page width to PAGE_WIDTH characters for multiple-
280 text-column output only (default for PAGE_WIDTH is 72).-
281 -s[CHAR] turns off the default page width and any line-
282 truncation. Lines of full length will be merged,-
283 regardless of the column options set. A POSIX compliant-
284 formulation.-
285-
286 -W PAGE_WIDTH, --page-width=PAGE_WIDTH-
287 Set the page width to PAGE_WIDTH characters. That's valid-
288 with and without a column option. Text lines will be-
289 truncated, unless -J is used. Together with one of the-
290 column options (-COLUMN| -a -COLUMN| -m) column alignment-
291 is always used.-
292 Default is 72 characters.-
293 Without -W PAGE_WIDTH-
294 - but with one of the column options default truncation of-
295 72 characters is used (to keep downward compatibility-
296 and to simplify most frequently met column tasks).-
297 Column alignment and column separators are used.-
298 - and without any of the column options NO line truncation-
299 is used (to keep downward compatibility and to meet most-
300 frequent tasks). That's equivalent to -W 72 -J .-
301-
302 With/without -W PAGE_WIDTH the header line is always-
303 truncated to avoid line overflow.-
304-
305 (In pr versions newer than 1.14 -S option does no longer-
306 affect -W option.)-
307-
308*/-
309-
310#include <config.h>-
311-
312#include <getopt.h>-
313#include <sys/types.h>-
314#include "system.h"-
315#include "die.h"-
316#include "error.h"-
317#include "fadvise.h"-
318#include "hard-locale.h"-
319#include "mbswidth.h"-
320#include "quote.h"-
321#include "stat-time.h"-
322#include "stdio--.h"-
323#include "strftime.h"-
324#include "xstrtol.h"-
325#include "xdectoint.h"-
326-
327/* The official name of this program (e.g., no 'g' prefix). */-
328#define PROGRAM_NAME "pr"-
329-
330#define AUTHORS \-
331 proper_name ("Pete TerMaat"), \-
332 proper_name ("Roland Huebner")-
333-
334/* Used with start_position in the struct COLUMN described below.-
335 If start_position == ANYWHERE, we aren't truncating columns and-
336 can begin printing a column anywhere. Otherwise we must pad to-
337 the horizontal position start_position. */-
338#define ANYWHERE 0-
339-
340/* Each column has one of these structures allocated for it.-
341 If we're only dealing with one file, fp is the same for all-
342 columns.-
343-
344 The general strategy is to spend time setting up these column-
345 structures (storing columns if necessary), after which printing-
346 is a matter of flitting from column to column and calling-
347 print_func.-
348-
349 Parallel files, single files printing across in multiple-
350 columns, and single files printing down in multiple columns all-
351 fit the same printing loop.-
352-
353 print_func Function used to print lines in this column.-
354 If we're storing this column it will be-
355 print_stored(), Otherwise it will be read_line().-
356-
357 char_func Function used to process characters in this column.-
358 If we're storing this column it will be store_char(),-
359 otherwise it will be print_char().-
360-
361 current_line Index of the current entry in line_vector, which-
362 contains the index of the first character of the-
363 current line in buff[].-
364-
365 lines_stored Number of lines in this column which are stored in-
366 buff.-
367-
368 lines_to_print If we're storing this column, lines_to_print is-
369 the number of stored_lines which remain to be-
370 printed. Otherwise it is the number of lines-
371 we can print without exceeding lines_per_body.-
372-
373 start_position The horizontal position we want to be in before we-
374 print the first character in this column.-
375-
376 numbered True means precede this column with a line number. */-
377-
378/* FIXME: There are many unchecked integer overflows in this file,-
379 that will cause this command to misbehave given large inputs or-
380 options. Many of the "int" values below should be "size_t" or-
381 something else like that. */-
382-
383struct COLUMN;-
384struct COLUMN-
385 {-
386 FILE *fp; /* Input stream for this column. */-
387 char const *name; /* File name. */-
388 enum-
389 {-
390 OPEN,-
391 FF_FOUND, /* used with -b option, set with \f, changed-
392 to ON_HOLD after print_header */-
393 ON_HOLD, /* Hit a form feed. */-
394 CLOSED-
395 }-
396 status; /* Status of the file pointer. */-
397-
398 /* Func to print lines in this col. */-
399 bool (*print_func) (struct COLUMN *);-
400-
401 /* Func to print/store chars in this col. */-
402 void (*char_func) (char);-
403-
404 int current_line; /* Index of current place in line_vector. */-
405 int lines_stored; /* Number of lines stored in buff. */-
406 int lines_to_print; /* No. lines stored or space left on page. */-
407 int start_position; /* Horizontal position of first char. */-
408 bool numbered;-
409 bool full_page_printed; /* True means printed without a FF found. */-
410-
411 /* p->full_page_printed controls a special case of "FF set by hand":-
412 True means a full page has been printed without FF found. To avoid an-
413 additional empty page we have to ignore a FF immediately following in-
414 the next line. */-
415 };-
416-
417typedef struct COLUMN COLUMN;-
418-
419static int char_to_clump (char c);-
420static bool read_line (COLUMN *p);-
421static bool print_page (void);-
422static bool print_stored (COLUMN *p);-
423static bool open_file (char *name, COLUMN *p);-
424static bool skip_to_page (uintmax_t page);-
425static void print_header (void);-
426static void pad_across_to (int position);-
427static void add_line_number (COLUMN *p);-
428static void getoptnum (const char *n_str, int min, int *num,-
429 const char *errfmt);-
430static void getoptarg (char *arg, char switch_char, char *character,-
431 int *number);-
432static void print_files (int number_of_files, char **av);-
433static void init_parameters (int number_of_files);-
434static void init_header (char const *filename, int desc);-
435static bool init_fps (int number_of_files, char **av);-
436static void init_funcs (void);-
437static void init_store_cols (void);-
438static void store_columns (void);-
439static void balance (int total_stored);-
440static void store_char (char c);-
441static void pad_down (unsigned int lines);-
442static void read_rest_of_line (COLUMN *p);-
443static void skip_read (COLUMN *p, int column_number);-
444static void print_char (char c);-
445static void cleanup (void);-
446static void print_sep_string (void);-
447static void separator_string (const char *optarg_S);-
448-
449/* All of the columns to print. */-
450static COLUMN *column_vector;-
451-
452/* When printing a single file in multiple downward columns,-
453 we store the leftmost columns contiguously in buff.-
454 To print a line from buff, get the index of the first character-
455 from line_vector[i], and print up to line_vector[i + 1]. */-
456static char *buff;-
457-
458/* Index of the position in buff where the next character-
459 will be stored. */-
460static unsigned int buff_current;-
461-
462/* The number of characters in buff.-
463 Used for allocation of buff and to detect overflow of buff. */-
464static size_t buff_allocated;-
465-
466/* Array of indices into buff.-
467 Each entry is an index of the first character of a line.-
468 This is used when storing lines to facilitate shuffling when-
469 we do column balancing on the last page. */-
470static int *line_vector;-
471-
472/* Array of horizontal positions.-
473 For each line in line_vector, end_vector[line] is the horizontal-
474 position we are in after printing that line. We keep track of this-
475 so that we know how much we need to pad to prepare for the next-
476 column. */-
477static int *end_vector;-
478-
479/* (-m) True means we're printing multiple files in parallel. */-
480static bool parallel_files = false;-
481-
482/* (-m) True means a line starts with some empty columns (some files-
483 already CLOSED or ON_HOLD) which we have to align. */-
484static bool align_empty_cols;-
485-
486/* (-m) True means we have not yet found any printable column in a line.-
487 align_empty_cols = true has to be maintained. */-
488static bool empty_line;-
489-
490/* (-m) False means printable column output precedes a form feed found.-
491 Column alignment is done only once. No additional action with that form-
492 feed.-
493 True means we found only a form feed in a column. Maybe we have to do-
494 some column alignment with that form feed. */-
495static bool FF_only;-
496-
497/* (-[0-9]+) True means we're given an option explicitly specifying-
498 number of columns. Used to detect when this option is used with -m-
499 and when translating old options to new/long options. */-
500static bool explicit_columns = false;-
501-
502/* (-t|-T) False means we aren't printing headers and footers. */-
503static bool extremities = true;-
504-
505/* (-t) True means we retain all FF set by hand in input files.-
506 False is set with -T option. */-
507static bool keep_FF = false;-
508static bool print_a_FF = false;-
509-
510/* True means we need to print a header as soon as we know we've got input-
511 to print after it. */-
512static bool print_a_header;-
513-
514/* (-f) True means use formfeeds instead of newlines to separate pages. */-
515static bool use_form_feed = false;-
516-
517/* True means we have read the standard input. */-
518static bool have_read_stdin = false;-
519-
520/* True means the -a flag has been given. */-
521static bool print_across_flag = false;-
522-
523/* True means we're printing one file in multiple (>1) downward columns. */-
524static bool storing_columns = true;-
525-
526/* (-b) True means balance columns on the last page as Sys V does. */-
527/* That's no longer an independent option. With storing_columns = true-
528 balance_columns = true is used too (s. function init_parameters).-
529 We get a consistent formulation with "FF set by hand" in input files. */-
530static bool balance_columns = false;-
531-
532/* (-l) Number of lines on a page, including header and footer lines. */-
533static int lines_per_page = 66;-
534-
535/* Number of lines in the header and footer can be reset to 0 using-
536 the -t flag. */-
537enum { lines_per_header = 5 };-
538static int lines_per_body;-
539enum { lines_per_footer = 5 };-
540-
541/* (-w|-W) Width in characters of the page. Does not include the width of-
542 the margin. */-
543static int chars_per_line = 72;-
544-
545/* (-w|W) True means we truncate lines longer than chars_per_column. */-
546static bool truncate_lines = false;-
547-
548/* (-J) True means we join lines without any line truncation. -J-
549 dominates -w option. */-
550static bool join_lines = false;-
551-
552/* Number of characters in a column. Based on col_sep_length and-
553 page width. */-
554static int chars_per_column;-
555-
556/* (-e) True means convert tabs to spaces on input. */-
557static bool untabify_input = false;-
558-
559/* (-e) The input tab character. */-
560static char input_tab_char = '\t';-
561-
562/* (-e) Tabstops are at chars_per_tab, 2*chars_per_tab, 3*chars_per_tab, ...-
563 where the leftmost column is 1. */-
564static int chars_per_input_tab = 8;-
565-
566/* (-i) True means convert spaces to tabs on output. */-
567static bool tabify_output = false;-
568-
569/* (-i) The output tab character. */-
570static char output_tab_char = '\t';-
571-
572/* (-i) The width of the output tab. */-
573static int chars_per_output_tab = 8;-
574-
575/* Keeps track of pending white space. When we hit a nonspace-
576 character after some whitespace, we print whitespace, tabbing-
577 if necessary to get to output_position + spaces_not_printed. */-
578static int spaces_not_printed;-
579-
580/* (-o) Number of spaces in the left margin (tabs used when possible). */-
581static int chars_per_margin = 0;-
582-
583/* Position where the next character will fall.-
584 Leftmost position is 0 + chars_per_margin.-
585 Rightmost position is chars_per_margin + chars_per_line - 1.-
586 This is important for converting spaces to tabs on output. */-
587static int output_position;-
588-
589/* Horizontal position relative to the current file.-
590 (output_position depends on where we are on the page;-
591 input_position depends on where we are in the file.)-
592 Important for converting tabs to spaces on input. */-
593static int input_position;-
594-
595/* True if there were any failed opens so we can exit with nonzero-
596 status. */-
597static bool failed_opens = false;-
598-
599/* The number of spaces taken up if we print a tab character with width-
600 c_ from position h_. */-
601#define TAB_WIDTH(c_, h_) ((c_) - ((h_) % (c_)))-
602-
603/* The horizontal position we'll be at after printing a tab character-
604 of width c_ from the position h_. */-
605#define POS_AFTER_TAB(c_, h_) ((h_) + TAB_WIDTH (c_, h_))-
606-
607/* (-NNN) Number of columns of text to print. */-
608static int columns = 1;-
609-
610/* (+NNN:MMM) Page numbers on which to begin and stop printing.-
611 first_page_number = 0 will be used to check input only. */-
612static uintmax_t first_page_number = 0;-
613static uintmax_t last_page_number = UINTMAX_MAX;-
614-
615/* Number of files open (not closed, not on hold). */-
616static int files_ready_to_read = 0;-
617-
618/* Current page number. Displayed in header. */-
619static uintmax_t page_number;-
620-
621/* Current line number. Displayed when -n flag is specified.-
622-
623 When printing files in parallel (-m flag), line numbering is as follows:-
624 1 foo goo moo-
625 2 hoo too zoo-
626-
627 When printing files across (-a flag), ...-
628 1 foo 2 moo 3 goo-
629 4 hoo 5 too 6 zoo-
630-
631 Otherwise, line numbering is as follows:-
632 1 foo 3 goo 5 too-
633 2 moo 4 hoo 6 zoo */-
634static int line_number;-
635-
636/* (-n) True means lines should be preceded by numbers. */-
637static bool numbered_lines = false;-
638-
639/* (-n) Character which follows each line number. */-
640static char number_separator = '\t';-
641-
642/* (-n) line counting starts with 1st line of input file (not with 1st-
643 line of 1st page printed). */-
644static int line_count = 1;-
645-
646/* (-n) True means counting of skipped lines starts with 1st line of-
647 input file. False means -N option is used in addition, counting of-
648 skipped lines not required. */-
649static bool skip_count = true;-
650-
651/* (-N) Counting starts with start_line_number = NUMBER at 1st line of-
652 first page printed, usually not 1st page of input file. */-
653static int start_line_num = 1;-
654-
655/* (-n) Width in characters of a line number. */-
656static int chars_per_number = 5;-
657-
658/* Used when widening the first column to accommodate numbers -- only-
659 needed when printing files in parallel. Includes width of both the-
660 number and the number_separator. */-
661static int number_width;-
662-
663/* Buffer sprintf uses to format a line number. */-
664static char *number_buff;-
665-
666/* (-v) True means unprintable characters are printed as escape sequences.-
667 control-g becomes \007. */-
668static bool use_esc_sequence = false;-
669-
670/* (-c) True means unprintable characters are printed as control prefixes.-
671 control-g becomes ^G. */-
672static bool use_cntrl_prefix = false;-
673-
674/* (-d) True means output is double spaced. */-
675static bool double_space = false;-
676-
677/* Number of files opened initially in init_files. Should be 1-
678 unless we're printing multiple files in parallel. */-
679static int total_files = 0;-
680-
681/* (-r) True means don't complain if we can't open a file. */-
682static bool ignore_failed_opens = false;-
683-
684/* (-S) True means we separate columns with a specified string.-
685 -S option does not affect line truncation nor column alignment. */-
686static bool use_col_separator = false;-
687-
688/* String used to separate columns if the -S option has been specified.-
689 Default without -S but together with one of the column options-
690 -a|COLUMN|-m is a 'space' and with the -J option a 'tab'. */-
691static char const *col_sep_string = "";-
692static int col_sep_length = 0;-
693static char *column_separator = (char *) " ";-
694static char *line_separator = (char *) "\t";-
695-
696/* Number of separator characters waiting to be printed as soon as we-
697 know that we have any input remaining to be printed. */-
698static int separators_not_printed;-
699-
700/* Position we need to pad to, as soon as we know that we have input-
701 remaining to be printed. */-
702static int padding_not_printed;-
703-
704/* True means we should pad the end of the page. Remains false until we-
705 know we have a page to print. */-
706static bool pad_vertically;-
707-
708/* (-h) String of characters used in place of the filename in the header. */-
709static char *custom_header;-
710-
711/* (-D) Date format for the header. */-
712static char const *date_format;-
713-
714/* The local time zone rules, as per the TZ environment variable. */-
715static timezone_t localtz;-
716-
717/* Date and file name for the header. */-
718static char *date_text;-
719static char const *file_text;-
720-
721/* Output columns available, not counting the date and file name. */-
722static int header_width_available;-
723-
724static char *clump_buff;-
725-
726/* True means we read the line no. lines_per_body in skip_read-
727 called by skip_to_page. That variable controls the coincidence of a-
728 "FF set by hand" and "full_page_printed", see above the definition of-
729 structure COLUMN. */-
730static bool last_line = false;-
731-
732/* For long options that have no equivalent short option, use a-
733 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
734enum-
735{-
736 COLUMNS_OPTION = CHAR_MAX + 1,-
737 PAGES_OPTION-
738};-
739-
740static char const short_options[] =-
741 "-0123456789D:FJN:S::TW:abcde::fh:i::l:mn::o:rs::tvw:";-
742-
743static struct option const long_options[] =-
744{-
745 {"pages", required_argument, NULL, PAGES_OPTION},-
746 {"columns", required_argument, NULL, COLUMNS_OPTION},-
747 {"across", no_argument, NULL, 'a'},-
748 {"show-control-chars", no_argument, NULL, 'c'},-
749 {"double-space", no_argument, NULL, 'd'},-
750 {"date-format", required_argument, NULL, 'D'},-
751 {"expand-tabs", optional_argument, NULL, 'e'},-
752 {"form-feed", no_argument, NULL, 'f'},-
753 {"header", required_argument, NULL, 'h'},-
754 {"output-tabs", optional_argument, NULL, 'i'},-
755 {"join-lines", no_argument, NULL, 'J'},-
756 {"length", required_argument, NULL, 'l'},-
757 {"merge", no_argument, NULL, 'm'},-
758 {"number-lines", optional_argument, NULL, 'n'},-
759 {"first-line-number", required_argument, NULL, 'N'},-
760 {"indent", required_argument, NULL, 'o'},-
761 {"no-file-warnings", no_argument, NULL, 'r'},-
762 {"separator", optional_argument, NULL, 's'},-
763 {"sep-string", optional_argument, NULL, 'S'},-
764 {"omit-header", no_argument, NULL, 't'},-
765 {"omit-pagination", no_argument, NULL, 'T'},-
766 {"show-nonprinting", no_argument, NULL, 'v'},-
767 {"width", required_argument, NULL, 'w'},-
768 {"page-width", required_argument, NULL, 'W'},-
769 {GETOPT_HELP_OPTION_DECL},-
770 {GETOPT_VERSION_OPTION_DECL},-
771 {NULL, 0, NULL, 0}-
772};-
773-
774static void-
775integer_overflow (void)-
776{-
777 die (EXIT_FAILURE, 0, _("integer overflow"));-
778}
never executed: end of block
0
779-
780/* Return the number of columns that have either an open file or-
781 stored lines. */-
782-
783static unsigned int _GL_ATTRIBUTE_PURE-
784cols_ready_to_print (void)-
785{-
786 COLUMN *q;-
787 unsigned int i;-
788 unsigned int n;-
789-
790 n = 0;-
791 for (q = column_vector, i = 0; i < columns; ++q, ++i)
i < columnsDescription
TRUEevaluated 101299 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 56091 times by 1 test
Evaluated by:
  • pr
56091-101299
792 if (q->status == OPEN
q->status == OPENDescription
TRUEevaluated 58960 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 42339 times by 1 test
Evaluated by:
  • pr
42339-58960
793 || q->status == FF_FOUND /* With -b: To print a header only */
q->status == FF_FOUNDDescription
TRUEevaluated 4884 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 37455 times by 1 test
Evaluated by:
  • pr
4884-37455
794 || (storing_columns && q->lines_stored > 0 && q->lines_to_print > 0))
storing_columnsDescription
TRUEevaluated 22986 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 14469 times by 1 test
Evaluated by:
  • pr
q->lines_stored > 0Description
TRUEevaluated 18537 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4449 times by 1 test
Evaluated by:
  • pr
q->lines_to_print > 0Description
TRUEevaluated 11292 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 7245 times by 1 test
Evaluated by:
  • pr
4449-22986
795 ++n;
executed 75136 times by 1 test: ++n;
Executed by:
  • pr
75136
796 return n;
executed 56091 times by 1 test: return n;
Executed by:
  • pr
56091
797}-
798-
799/* Estimate first_ / last_page_number-
800 using option +FIRST_PAGE:LAST_PAGE */-
801-
802static bool-
803first_last_page (int oi, char c, char const *pages)-
804{-
805 char *p;-
806 uintmax_t first;-
807 uintmax_t last = UINTMAX_MAX;-
808 strtol_error err = xstrtoumax (pages, &p, 10, &first, "");-
809 if (err != LONGINT_OK && err != LONGINT_INVALID_SUFFIX_CHAR)
err != LONGINT_OKDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 221 times by 1 test
Evaluated by:
  • pr
err != LONGINT...ID_SUFFIX_CHARDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 25 times by 1 test
Evaluated by:
  • pr
3-221
810 xstrtol_fatal (err, oi, c, long_options, pages);
executed 3 times by 1 test: xstrtol_fatal (err, oi, c, long_options, pages);
Executed by:
  • pr
3
811-
812 if (p == pages || !first)
p == pagesDescription
TRUEnever evaluated
FALSEevaluated 246 times by 1 test
Evaluated by:
  • pr
!firstDescription
TRUEnever evaluated
FALSEevaluated 246 times by 1 test
Evaluated by:
  • pr
0-246
813 return false;
never executed: return 0 ;
0
814-
815 if (*p == ':')
*p == ':'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 222 times by 1 test
Evaluated by:
  • pr
24-222
816 {-
817 char const *p1 = p + 1;-
818 err = xstrtoumax (p1, &p, 10, &last, "");-
819 if (err != LONGINT_OK)
err != LONGINT_OKDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 21 times by 1 test
Evaluated by:
  • pr
3-21
820 xstrtol_fatal (err, oi, c, long_options, pages);
executed 3 times by 1 test: xstrtol_fatal (err, oi, c, long_options, pages);
Executed by:
  • pr
3
821 if (p1 == p || last < first)
p1 == pDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • pr
last < firstDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • pr
0-21
822 return false;
never executed: return 0 ;
0
823 }
executed 21 times by 1 test: end of block
Executed by:
  • pr
21
824-
825 if (*p)
*pDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pr
FALSEevaluated 242 times by 1 test
Evaluated by:
  • pr
1-242
826 return false;
executed 1 time by 1 test: return 0 ;
Executed by:
  • pr
1
827-
828 first_page_number = first;-
829 last_page_number = last;-
830 return true;
executed 242 times by 1 test: return 1 ;
Executed by:
  • pr
242
831}-
832-
833/* Parse column count string S, and if it's valid (1 or larger and-
834 within range of the type of 'columns') set the global variables-
835 columns and explicit_columns. Otherwise, exit with a diagnostic. */-
836-
837static void-
838parse_column_count (char const *s)-
839{-
840 getoptnum (s, 1, &columns, _("invalid number of columns"));-
841 explicit_columns = true;-
842}
executed 420 times by 1 test: end of block
Executed by:
  • pr
420
843-
844/* Estimate length of col_sep_string with option -S. */-
845-
846static void-
847separator_string (const char *optarg_S)-
848{-
849 size_t len = strlen (optarg_S);-
850 if (INT_MAX < len)
0x7fffffff < lenDescription
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • pr
0-45
851 integer_overflow ();
never executed: integer_overflow ();
0
852 col_sep_length = len;-
853 col_sep_string = optarg_S;-
854}
executed 45 times by 1 test: end of block
Executed by:
  • pr
45
855-
856int-
857main (int argc, char **argv)-
858{-
859 unsigned int n_files;-
860 bool old_options = false;-
861 bool old_w = false;-
862 bool old_s = false;-
863 char **file_names;-
864-
865 /* Accumulate the digits of old-style options like -99. */-
866 char *column_count_string = NULL;-
867 size_t n_digits = 0;-
868 size_t n_alloc = 0;-
869-
870 initialize_main (&argc, &argv);-
871 set_program_name (argv[0]);-
872 setlocale (LC_ALL, "");-
873 bindtextdomain (PACKAGE, LOCALEDIR);-
874 textdomain (PACKAGE);-
875-
876 atexit (close_stdout);-
877-
878 n_files = 0;-
879 file_names = (argc > 1
argc > 1Description
TRUEevaluated 790 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2 times by 1 test
Evaluated by:
  • pr
2-790
880 ? xnmalloc (argc - 1, sizeof (char *))-
881 : NULL);-
882-
883 while (true)-
884 {-
885 int oi = -1;-
886 int c = getopt_long (argc, argv, short_options, long_options, &oi);-
887 if (c == -1)
c == -1Description
TRUEevaluated 731 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4637 times by 1 test
Evaluated by:
  • pr
731-4637
888 break;
executed 731 times by 1 test: break;
Executed by:
  • pr
731
889-
890 if (ISDIGIT (c))
((unsigned int...c) - '0' <= 9)Description
TRUEevaluated 726 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3911 times by 1 test
Evaluated by:
  • pr
726-3911
891 {-
892 /* Accumulate column-count digits specified via old-style options. */-
893 if (n_digits + 1 >= n_alloc)
n_digits + 1 >= n_allocDescription
TRUEevaluated 426 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 300 times by 1 test
Evaluated by:
  • pr
300-426
894 column_count_string
executed 426 times by 1 test: column_count_string = ((void) (!!sizeof (struct { _Static_assert (sizeof *(column_count_string) == 1, "verify_true (" "sizeof *(column_count_string) == 1" ")"); int _gl_dummy; })), x2realloc (column_count_string, &n_alloc));
Executed by:
  • pr
426
895 = X2REALLOC (column_count_string, &n_alloc);
executed 426 times by 1 test: column_count_string = ((void) (!!sizeof (struct { _Static_assert (sizeof *(column_count_string) == 1, "verify_true (" "sizeof *(column_count_string) == 1" ")"); int _gl_dummy; })), x2realloc (column_count_string, &n_alloc));
Executed by:
  • pr
426
896 column_count_string[n_digits++] = c;-
897 column_count_string[n_digits] = '\0';-
898 continue;
executed 726 times by 1 test: continue;
Executed by:
  • pr
726
899 }-
900-
901 n_digits = 0;-
902-
903 switch (c)-
904 {-
905 case 1: /* Non-option argument. */
executed 561 times by 1 test: case 1:
Executed by:
  • pr
561
906 /* long option --page dominates old '+FIRST_PAGE ...'. */-
907 if (! (first_page_number == 0
first_page_number == 0Description
TRUEevaluated 467 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 94 times by 1 test
Evaluated by:
  • pr
94-467
908 && *optarg == '+' && first_last_page (-2, '+', optarg + 1)))
*optarg == '+'Description
TRUEevaluated 242 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 225 times by 1 test
Evaluated by:
  • pr
first_last_pag...', optarg + 1)Description
TRUEevaluated 242 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-242
909 file_names[n_files++] = optarg;
executed 319 times by 1 test: file_names[n_files++] = optarg;
Executed by:
  • pr
319
910 break;
executed 561 times by 1 test: break;
Executed by:
  • pr
561
911-
912 case PAGES_OPTION: /* --pages=FIRST_PAGE[:LAST_PAGE] */
executed 7 times by 1 test: case PAGES_OPTION:
Executed by:
  • pr
7
913 { /* dominates old opt +... */-
914 if (! optarg)
! optargDescription
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • pr
0-7
915 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
916 _("'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
917 else if (! first_last_page (oi, 0, optarg))
! first_last_p...oi, 0, optarg)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1
918 die (EXIT_FAILURE, 0, _("invalid page range %s"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid page range %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid page range %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid page range %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • pr
1
919 quote (optarg));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid page range %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid page range %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid page range %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • pr
1
920 break;
never executed: break;
0
921 }-
922-
923 case COLUMNS_OPTION: /* --columns=COLUMN */
executed 7 times by 1 test: case COLUMNS_OPTION:
Executed by:
  • pr
7
924 {-
925 parse_column_count (optarg);-
926-
927 /* If there was a prior column count specified via the-
928 short-named option syntax, e.g., -9, ensure that this-
929 long-name-specified value overrides it. */-
930 free (column_count_string);-
931 column_count_string = NULL;-
932 n_alloc = 0;-
933 break;
executed 6 times by 1 test: break;
Executed by:
  • pr
6
934 }-
935-
936 case 'a':
executed 161 times by 1 test: case 'a':
Executed by:
  • pr
161
937 print_across_flag = true;-
938 storing_columns = false;-
939 break;
executed 161 times by 1 test: break;
Executed by:
  • pr
161
940 case 'b':
executed 186 times by 1 test: case 'b':
Executed by:
  • pr
186
941 balance_columns = true;-
942 break;
executed 186 times by 1 test: break;
Executed by:
  • pr
186
943 case 'c':
executed 2 times by 1 test: case 'c':
Executed by:
  • pr
2
944 use_cntrl_prefix = true;-
945 break;
executed 2 times by 1 test: break;
Executed by:
  • pr
2
946 case 'd':
executed 8 times by 1 test: case 'd':
Executed by:
  • pr
8
947 double_space = true;-
948 break;
executed 8 times by 1 test: break;
Executed by:
  • pr
8
949 case 'D':
executed 732 times by 1 test: case 'D':
Executed by:
  • pr
732
950 date_format = optarg;-
951 break;
executed 732 times by 1 test: break;
Executed by:
  • pr
732
952 case 'e':
executed 37 times by 1 test: case 'e':
Executed by:
  • pr
37
953 if (optarg)
optargDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 10 times by 1 test
Evaluated by:
  • pr
10-27
954 getoptarg (optarg, 'e', &input_tab_char,
executed 27 times by 1 test: getoptarg (optarg, 'e', &input_tab_char, &chars_per_input_tab);
Executed by:
  • pr
27
955 &chars_per_input_tab);
executed 27 times by 1 test: getoptarg (optarg, 'e', &input_tab_char, &chars_per_input_tab);
Executed by:
  • pr
27
956 /* Could check tab width > 0. */-
957 untabify_input = true;-
958 break;
executed 37 times by 1 test: break;
Executed by:
  • pr
37
959 case 'f':
executed 334 times by 1 test: case 'f':
Executed by:
  • pr
334
960 case 'F':
executed 1 time by 1 test: case 'F':
Executed by:
  • pr
1
961 use_form_feed = true;-
962 break;
executed 335 times by 1 test: break;
Executed by:
  • pr
335
963 case 'h':
executed 733 times by 1 test: case 'h':
Executed by:
  • pr
733
964 custom_header = optarg;-
965 break;
executed 733 times by 1 test: break;
Executed by:
  • pr
733
966 case 'i':
executed 7 times by 1 test: case 'i':
Executed by:
  • pr
7
967 if (optarg)
optargDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1 time by 1 test
Evaluated by:
  • pr
1-6
968 getoptarg (optarg, 'i', &output_tab_char,
executed 6 times by 1 test: getoptarg (optarg, 'i', &output_tab_char, &chars_per_output_tab);
Executed by:
  • pr
6
969 &chars_per_output_tab);
executed 6 times by 1 test: getoptarg (optarg, 'i', &output_tab_char, &chars_per_output_tab);
Executed by:
  • pr
6
970 /* Could check tab width > 0. */-
971 tabify_output = true;-
972 break;
executed 7 times by 1 test: break;
Executed by:
  • pr
7
973 case 'J':
executed 32 times by 1 test: case 'J':
Executed by:
  • pr
32
974 join_lines = true;-
975 break;
executed 32 times by 1 test: break;
Executed by:
  • pr
32
976 case 'l':
executed 472 times by 1 test: case 'l':
Executed by:
  • pr
472
977 getoptnum (optarg, 1, &lines_per_page,-
978 _("'-l PAGE_LENGTH' invalid number of lines"));-
979 break;
executed 470 times by 1 test: break;
Executed by:
  • pr
470
980 case 'm':
executed 39 times by 1 test: case 'm':
Executed by:
  • pr
39
981 parallel_files = true;-
982 storing_columns = false;-
983 break;
executed 39 times by 1 test: break;
Executed by:
  • pr
39
984 case 'n':
executed 193 times by 1 test: case 'n':
Executed by:
  • pr
193
985 numbered_lines = true;-
986 if (optarg)
optargDescription
TRUEevaluated 168 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 25 times by 1 test
Evaluated by:
  • pr
25-168
987 getoptarg (optarg, 'n', &number_separator,
executed 168 times by 1 test: getoptarg (optarg, 'n', &number_separator, &chars_per_number);
Executed by:
  • pr
168
988 &chars_per_number);
executed 168 times by 1 test: getoptarg (optarg, 'n', &number_separator, &chars_per_number);
Executed by:
  • pr
168
989 break;
executed 193 times by 1 test: break;
Executed by:
  • pr
193
990 case 'N':
executed 17 times by 1 test: case 'N':
Executed by:
  • pr
17
991 skip_count = false;-
992 getoptnum (optarg, INT_MIN, &start_line_num,-
993 _("'-N NUMBER' invalid starting line number"));-
994 break;
executed 15 times by 1 test: break;
Executed by:
  • pr
15
995 case 'o':
executed 39 times by 1 test: case 'o':
Executed by:
  • pr
39
996 getoptnum (optarg, 0, &chars_per_margin,-
997 _("'-o MARGIN' invalid line offset"));-
998 break;
executed 37 times by 1 test: break;
Executed by:
  • pr
37
999 case 'r':
executed 2 times by 1 test: case 'r':
Executed by:
  • pr
2
1000 ignore_failed_opens = true;-
1001 break;
executed 2 times by 1 test: break;
Executed by:
  • pr
2
1002 case 's':
executed 17 times by 1 test: case 's':
Executed by:
  • pr
17
1003 old_options = true;-
1004 old_s = true;-
1005 if (!use_col_separator && optarg)
!use_col_separatorDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
optargDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8 times by 1 test
Evaluated by:
  • pr
0-17
1006 separator_string (optarg);
executed 9 times by 1 test: separator_string (optarg);
Executed by:
  • pr
9
1007 break;
executed 17 times by 1 test: break;
Executed by:
  • pr
17
1008 case 'S':
executed 43 times by 1 test: case 'S':
Executed by:
  • pr
43
1009 old_s = false;-
1010 /* Reset an additional input of -s, -S dominates -s */-
1011 col_sep_string = "";-
1012 col_sep_length = 0;-
1013 use_col_separator = true;-
1014 if (optarg)
optargDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 7 times by 1 test
Evaluated by:
  • pr
7-36
1015 separator_string (optarg);
executed 36 times by 1 test: separator_string (optarg);
Executed by:
  • pr
36
1016 break;
executed 43 times by 1 test: break;
Executed by:
  • pr
43
1017 case 't':
executed 118 times by 1 test: case 't':
Executed by:
  • pr
118
1018 extremities = false;-
1019 keep_FF = true;-
1020 break;
executed 118 times by 1 test: break;
Executed by:
  • pr
118
1021 case 'T':
executed 41 times by 1 test: case 'T':
Executed by:
  • pr
41
1022 extremities = false;-
1023 keep_FF = false;-
1024 break;
executed 41 times by 1 test: break;
Executed by:
  • pr
41
1025 case 'v':
executed 2 times by 1 test: case 'v':
Executed by:
  • pr
2
1026 use_esc_sequence = true;-
1027 break;
executed 2 times by 1 test: break;
Executed by:
  • pr
2
1028 case 'w':
executed 19 times by 1 test: case 'w':
Executed by:
  • pr
19
1029 old_options = true;-
1030 old_w = true;-
1031 {-
1032 int tmp_cpl;-
1033 getoptnum (optarg, 1, &tmp_cpl,-
1034 _("'-w PAGE_WIDTH' invalid number of characters"));-
1035 if (! truncate_lines)
! truncate_linesDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-17
1036 chars_per_line = tmp_cpl;
executed 17 times by 1 test: chars_per_line = tmp_cpl;
Executed by:
  • pr
17
1037 }-
1038 break;
executed 17 times by 1 test: break;
Executed by:
  • pr
17
1039 case 'W':
executed 58 times by 1 test: case 'W':
Executed by:
  • pr
58
1040 old_w = false; /* dominates -w */-
1041 truncate_lines = true;-
1042 getoptnum (optarg, 1, &chars_per_line,-
1043 _("'-W PAGE_WIDTH' invalid number of characters"));-
1044 break;
executed 56 times by 1 test: break;
Executed by:
  • pr
56
1045 case_GETOPT_HELP_CHAR;
never executed: break;
executed 33 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • pr
0-33
1046 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 6 times by 1 test: exit ( 0 );
Executed by:
  • pr
never executed: break;
executed 6 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • pr
0-6
1047 default:
executed 4 times by 1 test: default:
Executed by:
  • pr
4
1048 usage (EXIT_FAILURE);-
1049 break;
never executed: break;
0
1050 }-
1051 }-
1052-
1053 if (column_count_string)
column_count_stringDescription
TRUEevaluated 420 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 311 times by 1 test
Evaluated by:
  • pr
311-420
1054 {-
1055 parse_column_count (column_count_string);-
1056 free (column_count_string);-
1057 }
executed 414 times by 1 test: end of block
Executed by:
  • pr
414
1058-
1059 if (! date_format)
! date_formatDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 721 times by 1 test
Evaluated by:
  • pr
4-721
1060 date_format = (getenv ("POSIXLY_CORRECT") && !hard_locale (LC_TIME)
executed 4 times by 1 test: date_format = (getenv ("POSIXLY_CORRECT") && !hard_locale ( 2 ) ? "%b %e %H:%M %Y" : "%Y-%m-%d %H:%M");
Executed by:
  • pr
getenv ("POSIXLY_CORRECT")Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • pr
!hard_locale ( 2 )Description
TRUEnever evaluated
FALSEnever evaluated
0-4
1061 ? "%b %e %H:%M %Y"
executed 4 times by 1 test: date_format = (getenv ("POSIXLY_CORRECT") && !hard_locale ( 2 ) ? "%b %e %H:%M %Y" : "%Y-%m-%d %H:%M");
Executed by:
  • pr
4
1062 : "%Y-%m-%d %H:%M");
executed 4 times by 1 test: date_format = (getenv ("POSIXLY_CORRECT") && !hard_locale ( 2 ) ? "%b %e %H:%M %Y" : "%Y-%m-%d %H:%M");
Executed by:
  • pr
4
1063-
1064 localtz = tzalloc (getenv ("TZ"));-
1065-
1066 /* Now we can set a reasonable initial value: */-
1067 if (first_page_number == 0)
first_page_number == 0Description
TRUEevaluated 483 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 242 times by 1 test
Evaluated by:
  • pr
242-483
1068 first_page_number = 1;
executed 483 times by 1 test: first_page_number = 1;
Executed by:
  • pr
483
1069-
1070 if (parallel_files && explicit_columns)
parallel_filesDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 688 times by 1 test
Evaluated by:
  • pr
explicit_columnsDescription
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • pr
0-688
1071 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot specify number of columns when printing in parallel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *...f columns when printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot specify number of columns when printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1072 _("cannot specify number of columns when printing in parallel"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot specify number of columns when printing in parallel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *...f columns when printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot specify number of columns when printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1073-
1074 if (parallel_files && print_across_flag)
parallel_filesDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 688 times by 1 test
Evaluated by:
  • pr
print_across_flagDescription
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • pr
0-688
1075 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot specify both printing across and printing in parallel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void...g across and printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot specify both printing across and printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1076 _("cannot specify both printing across and printing in parallel"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot specify both printing across and printing in parallel\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void...g across and printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot specify both printing across and printing in parallel" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1077-
1078/* Translate some old short options to new/long options.-
1079 To meet downward compatibility with other UNIX pr utilities-
1080 and some POSIX specifications. */-
1081-
1082 if (old_options)
old_optionsDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 698 times by 1 test
Evaluated by:
  • pr
27-698
1083 {-
1084 if (old_w)
old_wDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 10 times by 1 test
Evaluated by:
  • pr
10-17
1085 {-
1086 if (parallel_files || explicit_columns)
parallel_filesDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 15 times by 1 test
Evaluated by:
  • pr
explicit_columnsDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 6 times by 1 test
Evaluated by:
  • pr
2-15
1087 {-
1088 /* activate -W */-
1089 truncate_lines = true;-
1090 if (old_s)
old_sDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 5 times by 1 test
Evaluated by:
  • pr
5-6
1091 /* adapt HP-UX and SunOS: -s = no separator;-
1092 activate -S */-
1093 use_col_separator = true;
executed 6 times by 1 test: use_col_separator = 1 ;
Executed by:
  • pr
6
1094 }
executed 11 times by 1 test: end of block
Executed by:
  • pr
11
1095 else-
1096 /* old -w sets width with columns only-
1097 activate -J */-
1098 join_lines = true;
executed 6 times by 1 test: join_lines = 1 ;
Executed by:
  • pr
6
1099 }-
1100 else if (!use_col_separator)
!use_col_separatorDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-10
1101 {-
1102 /* No -S option read */-
1103 if (old_s && (parallel_files || explicit_columns))
old_sDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
parallel_filesDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • pr
FALSEevaluated 9 times by 1 test
Evaluated by:
  • pr
explicit_columnsDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-10
1104 {-
1105 if (!truncate_lines)
!truncate_linesDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-10
1106 {-
1107 /* old -s (without -w and -W) annuls column alignment,-
1108 uses fields, activate -J */-
1109 join_lines = true;-
1110 if (col_sep_length > 0)
col_sep_length > 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4 times by 1 test
Evaluated by:
  • pr
4-6
1111 /* activate -S */-
1112 use_col_separator = true;
executed 6 times by 1 test: use_col_separator = 1 ;
Executed by:
  • pr
6
1113 }
executed 10 times by 1 test: end of block
Executed by:
  • pr
10
1114 else-
1115 /* with -W */-
1116 /* adapt HP-UX and SunOS: -s = no separator;-
1117 activate -S */-
1118 use_col_separator = true;
never executed: use_col_separator = 1 ;
0
1119 }-
1120 }
executed 10 times by 1 test: end of block
Executed by:
  • pr
10
1121 }
executed 27 times by 1 test: end of block
Executed by:
  • pr
27
1122-
1123 for (; optind < argc; optind++)
optind < argcDescription
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
0-725
1124 {-
1125 file_names[n_files++] = argv[optind];-
1126 }
never executed: end of block
0
1127-
1128 if (n_files == 0)
n_files == 0Description
TRUEevaluated 454 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 271 times by 1 test
Evaluated by:
  • pr
271-454
1129 {-
1130 /* No file arguments specified; read from standard input. */-
1131 print_files (0, NULL);-
1132 }
executed 454 times by 1 test: end of block
Executed by:
  • pr
454
1133 else-
1134 {-
1135 if (parallel_files)
parallel_filesDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 234 times by 1 test
Evaluated by:
  • pr
37-234
1136 print_files (n_files, file_names);
executed 37 times by 1 test: print_files (n_files, file_names);
Executed by:
  • pr
37
1137 else-
1138 {-
1139 for (unsigned int i = 0; i < n_files; i++)
i < n_filesDescription
TRUEevaluated 234 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 234 times by 1 test
Evaluated by:
  • pr
234
1140 print_files (1, &file_names[i]);
executed 234 times by 1 test: print_files (1, &file_names[i]);
Executed by:
  • pr
234
1141 }
executed 234 times by 1 test: end of block
Executed by:
  • pr
234
1142 }-
1143-
1144 cleanup ();-
1145 IF_LINT (free (file_names));-
1146-
1147 if (have_read_stdin && fclose (stdin) == EOF)
have_read_stdinDescription
TRUEevaluated 454 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 271 times by 1 test
Evaluated by:
  • pr
rpl_fclose ( stdin ) == (-1)Description
TRUEnever evaluated
FALSEevaluated 454 times by 1 test
Evaluated by:
  • pr
0-454
1148 die (EXIT_FAILURE, errno, _("standard input"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"standard input\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "standard input" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "standard input" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1149 return failed_opens ? EXIT_FAILURE : EXIT_SUCCESS;
executed 725 times by 1 test: return failed_opens ? 1 : 0 ;
Executed by:
  • pr
725
1150}-
1151-
1152/* Parse numeric arguments, ensuring MIN <= number <= INT_MAX. */-
1153-
1154static void-
1155getoptnum (const char *n_str, int min, int *num, const char *err)-
1156{-
1157 intmax_t tnum = xdectoimax (n_str, min, INT_MAX, "", err, 0);-
1158 *num = tnum;-
1159}
executed 1015 times by 1 test: end of block
Executed by:
  • pr
1015
1160-
1161/* Parse options of the form -scNNN.-
1162-
1163 Example: -nck, where 'n' is the option, c is the optional number-
1164 separator, and k is the optional width of the field used when printing-
1165 a number. */-
1166-
1167static void-
1168getoptarg (char *arg, char switch_char, char *character, int *number)-
1169{-
1170 if (!ISDIGIT (*arg))
!((unsigned in...g) - '0' <= 9)Description
TRUEevaluated 168 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 33 times by 1 test
Evaluated by:
  • pr
33-168
1171 *character = *arg++;
executed 168 times by 1 test: *character = *arg++;
Executed by:
  • pr
168
1172 if (*arg)
*argDescription
TRUEevaluated 188 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 13 times by 1 test
Evaluated by:
  • pr
13-188
1173 {-
1174 long int tmp_long;-
1175 if (xstrtol (arg, NULL, 10, &tmp_long, "") != LONGINT_OK
xstrtol (arg, ... != LONGINT_OKDescription
TRUEnever evaluated
FALSEevaluated 188 times by 1 test
Evaluated by:
  • pr
0-188
1176 || tmp_long <= 0 || INT_MAX < tmp_long)
tmp_long <= 0Description
TRUEnever evaluated
FALSEevaluated 188 times by 1 test
Evaluated by:
  • pr
0x7fffffff < tmp_longDescription
TRUEnever evaluated
FALSEevaluated 188 times by 1 test
Evaluated by:
  • pr
0-188
1177 {-
1178 error (0, INT_MAX < tmp_long ? EOVERFLOW : errno,-
1179 _("'-%c' extra characters or invalid number in the argument: %s"),-
1180 switch_char, quote (arg));-
1181 usage (EXIT_FAILURE);-
1182 }
never executed: end of block
0
1183 *number = tmp_long;-
1184 }
executed 188 times by 1 test: end of block
Executed by:
  • pr
188
1185}
executed 201 times by 1 test: end of block
Executed by:
  • pr
201
1186-
1187/* Set parameters related to formatting. */-
1188-
1189static void-
1190init_parameters (int number_of_files)-
1191{-
1192 int chars_used_by_number = 0;-
1193-
1194 lines_per_body = lines_per_page - lines_per_header - lines_per_footer;-
1195 if (lines_per_body <= 0)
lines_per_body <= 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 722 times by 1 test
Evaluated by:
  • pr
3-722
1196 {-
1197 extremities = false;-
1198 keep_FF = true;-
1199 }
executed 3 times by 1 test: end of block
Executed by:
  • pr
3
1200 if (extremities == false)
extremities == 0Description
TRUEevaluated 158 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 567 times by 1 test
Evaluated by:
  • pr
158-567
1201 lines_per_body = lines_per_page;
executed 158 times by 1 test: lines_per_body = lines_per_page;
Executed by:
  • pr
158
1202-
1203 if (double_space)
double_spaceDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 719 times by 1 test
Evaluated by:
  • pr
6-719
1204 lines_per_body = lines_per_body / 2;
executed 6 times by 1 test: lines_per_body = lines_per_body / 2;
Executed by:
  • pr
6
1205-
1206 /* If input is stdin, cannot print parallel files. BSD dumps core-
1207 on this. */-
1208 if (number_of_files == 0)
number_of_files == 0Description
TRUEevaluated 454 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 271 times by 1 test
Evaluated by:
  • pr
271-454
1209 parallel_files = false;
executed 454 times by 1 test: parallel_files = 0 ;
Executed by:
  • pr
454
1210-
1211 if (parallel_files)
parallel_filesDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 688 times by 1 test
Evaluated by:
  • pr
37-688
1212 columns = number_of_files;
executed 37 times by 1 test: columns = number_of_files;
Executed by:
  • pr
37
1213-
1214 /* One file, multi columns down: -b option is set to get a consistent-
1215 formulation with "FF set by hand" in input files. */-
1216 if (storing_columns)
storing_columnsDescription
TRUEevaluated 529 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 196 times by 1 test
Evaluated by:
  • pr
196-529
1217 balance_columns = true;
executed 529 times by 1 test: balance_columns = 1 ;
Executed by:
  • pr
529
1218-
1219 /* Tabification is assumed for multiple columns. */-
1220 if (columns > 1)
columns > 1Description
TRUEevaluated 454 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 271 times by 1 test
Evaluated by:
  • pr
271-454
1221 {-
1222 if (!use_col_separator)
!use_col_separatorDescription
TRUEevaluated 400 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 54 times by 1 test
Evaluated by:
  • pr
54-400
1223 {-
1224 /* Use default separator */-
1225 if (join_lines)
join_linesDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 378 times by 1 test
Evaluated by:
  • pr
22-378
1226 col_sep_string = line_separator;
executed 22 times by 1 test: col_sep_string = line_separator;
Executed by:
  • pr
22
1227 else-
1228 col_sep_string = column_separator;
executed 378 times by 1 test: col_sep_string = column_separator;
Executed by:
  • pr
378
1229-
1230 col_sep_length = 1;-
1231 use_col_separator = true;-
1232 }
executed 400 times by 1 test: end of block
Executed by:
  • pr
400
1233 /* It's rather pointless to define a TAB separator with column-
1234 alignment */-
1235 else if (!join_lines && col_sep_length == 1 && *col_sep_string == '\t')
!join_linesDescription
TRUEevaluated 42 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pr
col_sep_length == 1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 33 times by 1 test
Evaluated by:
  • pr
*col_sep_string == '\t'Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • pr
0-42
1236 col_sep_string = column_separator;
never executed: col_sep_string = column_separator;
0
1237-
1238 truncate_lines = true;-
1239 tabify_output = true;-
1240 }
executed 454 times by 1 test: end of block
Executed by:
  • pr
454
1241 else-
1242 storing_columns = false;
executed 271 times by 1 test: storing_columns = 0 ;
Executed by:
  • pr
271
1243-
1244 /* -J dominates -w in any case */-
1245 if (join_lines)
join_linesDescription
TRUEevaluated 43 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 682 times by 1 test
Evaluated by:
  • pr
43-682
1246 truncate_lines = false;
executed 43 times by 1 test: truncate_lines = 0 ;
Executed by:
  • pr
43
1247-
1248 if (numbered_lines)
numbered_linesDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 533 times by 1 test
Evaluated by:
  • pr
192-533
1249 {-
1250 int chars_per_default_tab = 8;-
1251-
1252 line_count = start_line_num;-
1253-
1254 /* To allow input tab-expansion (-e sensitive) use:-
1255 if (number_separator == input_tab_char)-
1256 number_width = chars_per_number-
1257 + TAB_WIDTH (chars_per_input_tab, chars_per_number); */-
1258-
1259 /* Estimate chars_per_text without any margin and keep it constant. */-
1260 if (number_separator == '\t')
number_separator == '\t'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 165 times by 1 test
Evaluated by:
  • pr
27-165
1261 number_width = (chars_per_number
executed 27 times by 1 test: number_width = (chars_per_number + ((chars_per_default_tab) - ((chars_per_number) % (chars_per_default_tab))));
Executed by:
  • pr
27
1262 + TAB_WIDTH (chars_per_default_tab, chars_per_number));
executed 27 times by 1 test: number_width = (chars_per_number + ((chars_per_default_tab) - ((chars_per_number) % (chars_per_default_tab))));
Executed by:
  • pr
27
1263 else-
1264 number_width = chars_per_number + 1;
executed 165 times by 1 test: number_width = chars_per_number + 1;
Executed by:
  • pr
165
1265-
1266 /* The number is part of the column width unless we are-
1267 printing files in parallel. */-
1268 if (parallel_files)
parallel_filesDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 180 times by 1 test
Evaluated by:
  • pr
12-180
1269 chars_used_by_number = number_width;
executed 12 times by 1 test: chars_used_by_number = number_width;
Executed by:
  • pr
12
1270 }
executed 192 times by 1 test: end of block
Executed by:
  • pr
192
1271-
1272 int sep_chars, useful_chars;-
1273 if (INT_MULTIPLY_WRAPV (columns - 1, col_sep_length, &sep_chars))
__builtin_mul_...h, &sep_chars)Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
0-725
1274 sep_chars = INT_MAX;
never executed: sep_chars = 0x7fffffff;
0
1275 if (INT_SUBTRACT_WRAPV (chars_per_line - chars_used_by_number, sep_chars,
__builtin_sub_...&useful_chars)Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
0-725
1276 &useful_chars))-
1277 useful_chars = 0;
never executed: useful_chars = 0;
0
1278 chars_per_column = useful_chars / columns;-
1279-
1280 if (chars_per_column < 1)
chars_per_column < 1Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
0-725
1281 die (EXIT_FAILURE, 0, _("page width too narrow"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"page width too narrow\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "page width too narrow" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "page width too narrow" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1282-
1283 if (numbered_lines)
numbered_linesDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 533 times by 1 test
Evaluated by:
  • pr
192-533
1284 {-
1285 free (number_buff);-
1286 number_buff = xmalloc (MAX (chars_per_number,-
1287 INT_STRLEN_BOUND (line_number)) + 1);-
1288 }
executed 192 times by 1 test: end of block
Executed by:
  • pr
192
1289-
1290 /* Pick the maximum between the tab width and the width of an-
1291 escape sequence.-
1292 The width of an escape sequence (4) isn't the lower limit any longer.-
1293 We've to use 8 as the lower limit, if we use chars_per_default_tab = 8-
1294 to expand a tab which is not an input_tab-char. */-
1295 free (clump_buff);-
1296 clump_buff = xmalloc (MAX (8, chars_per_input_tab));-
1297}
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
1298-
1299/* Open the necessary files,-
1300 maintaining a COLUMN structure for each column.-
1301-
1302 With multiple files, each column p has a different p->fp.-
1303 With single files, each column p has the same p->fp.-
1304 Return false if (number_of_files > 0) and no files can be opened,-
1305 true otherwise.-
1306-
1307 With each column/file p, p->full_page_printed is initialized,-
1308 see also open_file. */-
1309-
1310static bool-
1311init_fps (int number_of_files, char **av)-
1312{-
1313 COLUMN *p;-
1314-
1315 total_files = 0;-
1316-
1317 free (column_vector);-
1318 column_vector = xnmalloc (columns, sizeof (COLUMN));-
1319-
1320 if (parallel_files)
parallel_filesDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 688 times by 1 test
Evaluated by:
  • pr
37-688
1321 {-
1322 int files_left = number_of_files;-
1323 for (p = column_vector; files_left--; ++p, ++av)
files_left--Description
TRUEevaluated 83 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 37 times by 1 test
Evaluated by:
  • pr
37-83
1324 {-
1325 if (! open_file (*av, p))
! open_file (*av, p)Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • pr
0-83
1326 {-
1327 --p;-
1328 --columns;-
1329 }
never executed: end of block
0
1330 }
executed 83 times by 1 test: end of block
Executed by:
  • pr
83
1331 if (columns == 0)
columns == 0Description
TRUEnever evaluated
FALSEevaluated 37 times by 1 test
Evaluated by:
  • pr
0-37
1332 return false;
never executed: return 0 ;
0
1333 init_header ("", -1);-
1334 }
executed 37 times by 1 test: end of block
Executed by:
  • pr
37
1335 else-
1336 {-
1337 p = column_vector;-
1338 if (number_of_files > 0)
number_of_files > 0Description
TRUEevaluated 234 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 454 times by 1 test
Evaluated by:
  • pr
234-454
1339 {-
1340 if (! open_file (*av, p))
! open_file (*av, p)Description
TRUEnever evaluated
FALSEevaluated 234 times by 1 test
Evaluated by:
  • pr
0-234
1341 return false;
never executed: return 0 ;
0
1342 init_header (*av, fileno (p->fp));-
1343 p->lines_stored = 0;-
1344 }
executed 234 times by 1 test: end of block
Executed by:
  • pr
234
1345 else-
1346 {-
1347 p->name = _("standard input");-
1348 p->fp = stdin;-
1349 have_read_stdin = true;-
1350 p->status = OPEN;-
1351 p->full_page_printed = false;-
1352 ++total_files;-
1353 init_header ("", -1);-
1354 p->lines_stored = 0;-
1355 }
executed 454 times by 1 test: end of block
Executed by:
  • pr
454
1356-
1357 char const *firstname = p->name;-
1358 FILE *firstfp = p->fp;-
1359 int i;-
1360 for (i = columns - 1, ++p; i; --i, ++p)
iDescription
TRUEevaluated 627 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 688 times by 1 test
Evaluated by:
  • pr
627-688
1361 {-
1362 p->name = firstname;-
1363 p->fp = firstfp;-
1364 p->status = OPEN;-
1365 p->full_page_printed = false;-
1366 p->lines_stored = 0;-
1367 }
executed 627 times by 1 test: end of block
Executed by:
  • pr
627
1368 }
executed 688 times by 1 test: end of block
Executed by:
  • pr
688
1369 files_ready_to_read = total_files;-
1370 return true;
executed 725 times by 1 test: return 1 ;
Executed by:
  • pr
725
1371}-
1372-
1373/* Determine print_func and char_func, the functions-
1374 used by each column for printing and/or storing.-
1375-
1376 Determine the horizontal position desired when we begin-
1377 printing a column (p->start_position). */-
1378-
1379static void-
1380init_funcs (void)-
1381{-
1382 int i, h, h_next;-
1383 COLUMN *p;-
1384-
1385 h = chars_per_margin;-
1386-
1387 if (!truncate_lines)
!truncate_linesDescription
TRUEevaluated 287 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 438 times by 1 test
Evaluated by:
  • pr
287-438
1388 h_next = ANYWHERE;
executed 287 times by 1 test: h_next = 0;
Executed by:
  • pr
287
1389 else-
1390 {-
1391 /* When numbering lines of parallel files, we enlarge the-
1392 first column to accommodate the number. Looks better than-
1393 the Sys V approach. */-
1394 if (parallel_files && numbered_lines)
parallel_filesDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 408 times by 1 test
Evaluated by:
  • pr
numbered_linesDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 20 times by 1 test
Evaluated by:
  • pr
10-408
1395 h_next = h + chars_per_column + number_width;
executed 10 times by 1 test: h_next = h + chars_per_column + number_width;
Executed by:
  • pr
10
1396 else-
1397 h_next = h + chars_per_column;
executed 428 times by 1 test: h_next = h + chars_per_column;
Executed by:
  • pr
428
1398 }-
1399-
1400 /* Enlarge p->start_position of first column to use the same form of-
1401 padding_not_printed with all columns. */-
1402 h = h + col_sep_length;-
1403-
1404 /* This loop takes care of all but the rightmost column. */-
1405-
1406 for (p = column_vector, i = 1; i < columns; ++p, ++i)
i < columnsDescription
TRUEevaluated 673 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
673-725
1407 {-
1408 if (storing_columns) /* One file, multi columns down. */
storing_columnsDescription
TRUEevaluated 381 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 292 times by 1 test
Evaluated by:
  • pr
292-381
1409 {-
1410 p->char_func = store_char;-
1411 p->print_func = print_stored;-
1412 }
executed 381 times by 1 test: end of block
Executed by:
  • pr
381
1413 else-
1414 /* One file, multi columns across; or parallel files. */-
1415 {-
1416 p->char_func = print_char;-
1417 p->print_func = read_line;-
1418 }
executed 292 times by 1 test: end of block
Executed by:
  • pr
292
1419-
1420 /* Number only the first column when printing files in-
1421 parallel. */-
1422 p->numbered = numbered_lines && (!parallel_files || i == 1);
numbered_linesDescription
TRUEevaluated 149 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 524 times by 1 test
Evaluated by:
  • pr
!parallel_filesDescription
TRUEevaluated 129 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 20 times by 1 test
Evaluated by:
  • pr
i == 1Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8 times by 1 test
Evaluated by:
  • pr
8-524
1423 p->start_position = h;-
1424-
1425 /* If we don't truncate lines, all start_positions are-
1426 ANYWHERE, except the first column's start_position when-
1427 using a margin. */-
1428-
1429 if (!truncate_lines)
!truncate_linesDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 624 times by 1 test
Evaluated by:
  • pr
49-624
1430 {-
1431 h = ANYWHERE;-
1432 h_next = ANYWHERE;-
1433 }
executed 49 times by 1 test: end of block
Executed by:
  • pr
49
1434 else-
1435 {-
1436 h = h_next + col_sep_length;-
1437 h_next = h + chars_per_column;-
1438 }
executed 624 times by 1 test: end of block
Executed by:
  • pr
624
1439 }-
1440-
1441 /* The rightmost column.-
1442-
1443 Doesn't need to be stored unless we intend to balance-
1444 columns on the last page. */-
1445 if (storing_columns && balance_columns)
storing_columnsDescription
TRUEevaluated 258 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 467 times by 1 test
Evaluated by:
  • pr
balance_columnsDescription
TRUEevaluated 258 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-467
1446 {-
1447 p->char_func = store_char;-
1448 p->print_func = print_stored;-
1449 }
executed 258 times by 1 test: end of block
Executed by:
  • pr
258
1450 else-
1451 {-
1452 p->char_func = print_char;-
1453 p->print_func = read_line;-
1454 }
executed 467 times by 1 test: end of block
Executed by:
  • pr
467
1455-
1456 p->numbered = numbered_lines && (!parallel_files || i == 1);
numbered_linesDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 533 times by 1 test
Evaluated by:
  • pr
!parallel_filesDescription
TRUEevaluated 180 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pr
i == 1Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pr
0-533
1457 p->start_position = h;-
1458}
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
1459-
1460/* Open a file. Return true if successful.-
1461-
1462 With each file p, p->full_page_printed is initialized,-
1463 see also init_fps. */-
1464-
1465static bool-
1466open_file (char *name, COLUMN *p)-
1467{-
1468 if (STREQ (name, "-"))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[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 317 times by 1 test
Evaluated by:
  • pr
__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 317 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 317 times by 1 test
Evaluated by:
  • pr
__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-317
1469 {-
1470 p->name = _("standard input");-
1471 p->fp = stdin;-
1472 have_read_stdin = true;-
1473 }
never executed: end of block
0
1474 else-
1475 {-
1476 p->name = name;-
1477 p->fp = fopen (name, "r");-
1478 }
executed 317 times by 1 test: end of block
Executed by:
  • pr
317
1479 if (p->fp == NULL)
p->fp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 317 times by 1 test
Evaluated by:
  • pr
0-317
1480 {-
1481 failed_opens = true;-
1482 if (!ignore_failed_opens)
!ignore_failed_opensDescription
TRUEnever evaluated
FALSEnever evaluated
0
1483 error (0, errno, "%s", quotef (name));
never executed: error (0, (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, name));
0
1484 return false;
never executed: return 0 ;
0
1485 }-
1486 fadvise (p->fp, FADVISE_SEQUENTIAL);-
1487 p->status = OPEN;-
1488 p->full_page_printed = false;-
1489 ++total_files;-
1490 return true;
executed 317 times by 1 test: return 1 ;
Executed by:
  • pr
317
1491}-
1492-
1493/* Close the file in P.-
1494-
1495 If we aren't dealing with multiple files in parallel, we change-
1496 the status of all columns in the column list to reflect the close. */-
1497-
1498static void-
1499close_file (COLUMN *p)-
1500{-
1501 COLUMN *q;-
1502 int i;-
1503-
1504 if (p->status == CLOSED)
p->status == CLOSEDDescription
TRUEnever evaluated
FALSEevaluated 753 times by 1 test
Evaluated by:
  • pr
0-753
1505 return;
never executed: return;
0
1506 if (ferror (p->fp))
ferror_unlocked (p->fp)Description
TRUEnever evaluated
FALSEevaluated 753 times by 1 test
Evaluated by:
  • pr
0-753
1507 die (EXIT_FAILURE, errno, "%s", quotef (p->name));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, p->name)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location (...n (0, shell_escape_quoting_style, p->name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, p->name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1508 if (fileno (p->fp) != STDIN_FILENO && fclose (p->fp) != 0)
fileno (p->fp) != 0Description
TRUEevaluated 311 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 442 times by 1 test
Evaluated by:
  • pr
rpl_fclose (p->fp) != 0Description
TRUEnever evaluated
FALSEevaluated 311 times by 1 test
Evaluated by:
  • pr
0-442
1509 die (EXIT_FAILURE, errno, "%s", quotef (p->name));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, p->name)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location (...n (0, shell_escape_quoting_style, p->name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, p->name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1510-
1511 if (!parallel_files)
!parallel_filesDescription
TRUEevaluated 670 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 83 times by 1 test
Evaluated by:
  • pr
83-670
1512 {-
1513 for (q = column_vector, i = columns; i; ++q, --i)
iDescription
TRUEevaluated 1285 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 670 times by 1 test
Evaluated by:
  • pr
670-1285
1514 {-
1515 q->status = CLOSED;-
1516 if (q->lines_stored == 0)
q->lines_stored == 0Description
TRUEevaluated 1006 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 279 times by 1 test
Evaluated by:
  • pr
279-1006
1517 {-
1518 q->lines_to_print = 0;-
1519 }
executed 1006 times by 1 test: end of block
Executed by:
  • pr
1006
1520 }
executed 1285 times by 1 test: end of block
Executed by:
  • pr
1285
1521 }
executed 670 times by 1 test: end of block
Executed by:
  • pr
670
1522 else-
1523 {-
1524 p->status = CLOSED;-
1525 p->lines_to_print = 0;-
1526 }
executed 83 times by 1 test: end of block
Executed by:
  • pr
83
1527-
1528 --files_ready_to_read;-
1529}
executed 753 times by 1 test: end of block
Executed by:
  • pr
753
1530-
1531/* Put a file on hold until we start a new page,-
1532 since we've hit a form feed.-
1533-
1534 If we aren't dealing with parallel files, we must change the-
1535 status of all columns in the column list. */-
1536-
1537static void-
1538hold_file (COLUMN *p)-
1539{-
1540 COLUMN *q;-
1541 int i;-
1542-
1543 if (!parallel_files)
!parallel_filesDescription
TRUEevaluated 3084 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 284 times by 1 test
Evaluated by:
  • pr
284-3084
1544 for (q = column_vector, i = columns; i; ++q, --i)
iDescription
TRUEevaluated 6132 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3084 times by 1 test
Evaluated by:
  • pr
3084-6132
1545 {-
1546 if (storing_columns)
storing_columnsDescription
TRUEevaluated 2832 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3300 times by 1 test
Evaluated by:
  • pr
2832-3300
1547 q->status = FF_FOUND;
executed 2832 times by 1 test: q->status = FF_FOUND;
Executed by:
  • pr
2832
1548 else-
1549 q->status = ON_HOLD;
executed 3300 times by 1 test: q->status = ON_HOLD;
Executed by:
  • pr
3300
1550 }-
1551 else-
1552 p->status = ON_HOLD;
executed 284 times by 1 test: p->status = ON_HOLD;
Executed by:
  • pr
284
1553-
1554 p->lines_to_print = 0;-
1555 --files_ready_to_read;-
1556}
executed 3368 times by 1 test: end of block
Executed by:
  • pr
3368
1557-
1558/* Undo hold_file -- go through the column list and change any-
1559 ON_HOLD columns to OPEN. Used at the end of each page. */-
1560-
1561static void-
1562reset_status (void)-
1563{-
1564 int i = columns;-
1565 COLUMN *p;-
1566-
1567 for (p = column_vector; i; --i, ++p)
iDescription
TRUEevaluated 9727 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4919 times by 1 test
Evaluated by:
  • pr
4919-9727
1568 if (p->status == ON_HOLD)
p->status == ON_HOLDDescription
TRUEevaluated 6581 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3146 times by 1 test
Evaluated by:
  • pr
3146-6581
1569 {-
1570 p->status = OPEN;-
1571 files_ready_to_read++;-
1572 }
executed 6581 times by 1 test: end of block
Executed by:
  • pr
6581
1573-
1574 if (storing_columns)
storing_columnsDescription
TRUEevaluated 1602 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3317 times by 1 test
Evaluated by:
  • pr
1602-3317
1575 {-
1576 if (column_vector->status == CLOSED)
column_vector-...atus == CLOSEDDescription
TRUEevaluated 252 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1350 times by 1 test
Evaluated by:
  • pr
252-1350
1577 /* We use the info to output an error message in skip_to_page. */-
1578 files_ready_to_read = 0;
executed 252 times by 1 test: files_ready_to_read = 0;
Executed by:
  • pr
252
1579 else-
1580 files_ready_to_read = 1;
executed 1350 times by 1 test: files_ready_to_read = 1;
Executed by:
  • pr
1350
1581 }-
1582}
executed 4919 times by 1 test: end of block
Executed by:
  • pr
4919
1583-
1584/* Print a single file, or multiple files in parallel.-
1585-
1586 Set up the list of columns, opening the necessary files.-
1587 Allocate space for storing columns, if necessary.-
1588 Skip to first_page_number, if user has asked to skip leading pages.-
1589 Determine which functions are appropriate to store/print lines-
1590 in each column.-
1591 Print the file(s). */-
1592-
1593static void-
1594print_files (int number_of_files, char **av)-
1595{-
1596 init_parameters (number_of_files);-
1597 if (! init_fps (number_of_files, av))
! init_fps (nu..._of_files, av)Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
0-725
1598 return;
never executed: return;
0
1599 if (storing_columns)
storing_columnsDescription
TRUEevaluated 258 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 467 times by 1 test
Evaluated by:
  • pr
258-467
1600 init_store_cols ();
executed 258 times by 1 test: init_store_cols ();
Executed by:
  • pr
258
1601-
1602 if (first_page_number > 1)
first_page_number > 1Description
TRUEevaluated 239 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 486 times by 1 test
Evaluated by:
  • pr
239-486
1603 {-
1604 if (!skip_to_page (first_page_number))
!skip_to_page ...t_page_number)Description
TRUEnever evaluated
FALSEevaluated 239 times by 1 test
Evaluated by:
  • pr
0-239
1605 return;
never executed: return;
0
1606 else-
1607 page_number = first_page_number;
executed 239 times by 1 test: page_number = first_page_number;
Executed by:
  • pr
239
1608 }-
1609 else-
1610 page_number = 1;
executed 486 times by 1 test: page_number = 1;
Executed by:
  • pr
486
1611-
1612 init_funcs ();-
1613-
1614 line_number = line_count;-
1615 while (print_page ())
print_page ()Description
TRUEevaluated 4204 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
725-4204
1616 ;
executed 4204 times by 1 test: ;
Executed by:
  • pr
4204
1617}
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
1618-
1619/* Initialize header information.-
1620 If DESC is non-negative, it is a file descriptor open to-
1621 FILENAME for reading. */-
1622-
1623static void-
1624init_header (char const *filename, int desc)-
1625{-
1626 char *buf = NULL;-
1627 struct stat st;-
1628 struct timespec t;-
1629 int ns;-
1630 struct tm tm;-
1631-
1632 /* If parallel files or standard input, use current date. */-
1633 if (STREQ (filename, "-"))
never executed: __result = (((const unsigned char *) (const char *) ( filename ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
__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 725 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 725 times by 1 test
Evaluated by:
  • pr
__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-725
1634 desc = -1;
never executed: desc = -1;
0
1635 if (0 <= desc && fstat (desc, &st) == 0)
0 <= descDescription
TRUEevaluated 234 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 491 times by 1 test
Evaluated by:
  • pr
fstat (desc, &st) == 0Description
TRUEevaluated 234 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-491
1636 t = get_stat_mtime (&st);
executed 234 times by 1 test: t = get_stat_mtime (&st);
Executed by:
  • pr
234
1637 else-
1638 {-
1639 static struct timespec timespec;-
1640 if (! timespec.tv_sec)
! timespec.tv_secDescription
TRUEevaluated 491 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-491
1641 gettime (&timespec);
executed 491 times by 1 test: gettime (&timespec);
Executed by:
  • pr
491
1642 t = timespec;-
1643 }
executed 491 times by 1 test: end of block
Executed by:
  • pr
491
1644-
1645 ns = t.tv_nsec;-
1646 if (localtime_rz (localtz, &t.tv_sec, &tm))
localtime_rz (...t.tv_sec, &tm)Description
TRUEevaluated 725 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-725
1647 {-
1648 size_t bufsize-
1649 = nstrftime (NULL, SIZE_MAX, date_format, &tm, localtz, ns) + 1;-
1650 buf = xmalloc (bufsize);-
1651 nstrftime (buf, bufsize, date_format, &tm, localtz, ns);-
1652 }
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
1653 else-
1654 {-
1655 char secbuf[INT_BUFSIZE_BOUND (intmax_t)];-
1656 buf = xmalloc (sizeof secbuf + MAX (10, INT_BUFSIZE_BOUND (int)));-
1657 sprintf (buf, "%s.%09d", timetostr (t.tv_sec, secbuf), ns);-
1658 }
never executed: end of block
0
1659-
1660 free (date_text);-
1661 date_text = buf;-
1662 file_text = custom_header ? custom_header : desc < 0 ? "" : filename;
custom_headerDescription
TRUEevaluated 713 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pr
desc < 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8 times by 1 test
Evaluated by:
  • pr
4-713
1663 header_width_available = (chars_per_line-
1664 - mbswidth (date_text, 0)-
1665 - mbswidth (file_text, 0));-
1666}
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
1667-
1668/* Set things up for printing a page-
1669-
1670 Scan through the columns ...-
1671 Determine which are ready to print-
1672 (i.e., which have lines stored or open files)-
1673 Set p->lines_to_print appropriately-
1674 (to p->lines_stored if we're storing, or lines_per_body-
1675 if we're reading straight from the file)-
1676 Keep track of this total so we know when to stop printing */-
1677-
1678static void-
1679init_page (void)-
1680{-
1681 int j;-
1682 COLUMN *p;-
1683-
1684 if (storing_columns)
storing_columnsDescription
TRUEevaluated 1644 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3285 times by 1 test
Evaluated by:
  • pr
1644-3285
1685 {-
1686 store_columns ();-
1687 for (j = columns - 1, p = column_vector; j; --j, ++p)
jDescription
TRUEevaluated 2565 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1644 times by 1 test
Evaluated by:
  • pr
1644-2565
1688 {-
1689 p->lines_to_print = p->lines_stored;-
1690 }
executed 2565 times by 1 test: end of block
Executed by:
  • pr
2565
1691-
1692 /* Last column. */-
1693 if (balance_columns)
balance_columnsDescription
TRUEevaluated 1644 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1644
1694 {-
1695 p->lines_to_print = p->lines_stored;-
1696 }
executed 1644 times by 1 test: end of block
Executed by:
  • pr
1644
1697 /* Since we're not balancing columns, we don't need to store-
1698 the rightmost column. Read it straight from the file. */-
1699 else-
1700 {-
1701 if (p->status == OPEN)
p->status == OPENDescription
TRUEnever evaluated
FALSEnever evaluated
0
1702 {-
1703 p->lines_to_print = lines_per_body;-
1704 }
never executed: end of block
0
1705 else-
1706 p->lines_to_print = 0;
never executed: p->lines_to_print = 0;
0
1707 }-
1708 }-
1709 else-
1710 for (j = columns, p = column_vector; j; --j, ++p)
jDescription
TRUEevaluated 5558 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3285 times by 1 test
Evaluated by:
  • pr
3285-5558
1711 if (p->status == OPEN)
p->status == OPENDescription
TRUEevaluated 4691 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 867 times by 1 test
Evaluated by:
  • pr
867-4691
1712 {-
1713 p->lines_to_print = lines_per_body;-
1714 }
executed 4691 times by 1 test: end of block
Executed by:
  • pr
4691
1715 else-
1716 p->lines_to_print = 0;
executed 867 times by 1 test: p->lines_to_print = 0;
Executed by:
  • pr
867
1717}
executed 4929 times by 1 test: end of block
Executed by:
  • pr
4929
1718-
1719/* Align empty columns and print separators.-
1720 Empty columns will be formed by files with status ON_HOLD or CLOSED-
1721 when printing multiple files in parallel. */-
1722-
1723static void-
1724align_column (COLUMN *p)-
1725{-
1726 padding_not_printed = p->start_position;-
1727 if (col_sep_length < padding_not_printed)
col_sep_length...ng_not_printedDescription
TRUEevaluated 781 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 665 times by 1 test
Evaluated by:
  • pr
665-781
1728 {-
1729 pad_across_to (padding_not_printed - col_sep_length);-
1730 padding_not_printed = ANYWHERE;-
1731 }
executed 781 times by 1 test: end of block
Executed by:
  • pr
781
1732-
1733 if (use_col_separator)
use_col_separatorDescription
TRUEevaluated 1446 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1446
1734 print_sep_string ();
executed 1446 times by 1 test: print_sep_string ();
Executed by:
  • pr
1446
1735-
1736 if (p->numbered)
p->numberedDescription
TRUEevaluated 247 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1199 times by 1 test
Evaluated by:
  • pr
247-1199
1737 add_line_number (p);
executed 247 times by 1 test: add_line_number (p);
Executed by:
  • pr
247
1738}
executed 1446 times by 1 test: end of block
Executed by:
  • pr
1446
1739-
1740/* Print one page.-
1741-
1742 As long as there are lines left on the page and columns ready to print,-
1743 Scan across the column list-
1744 if the column has stored lines or the file is open-
1745 pad to the appropriate spot-
1746 print the column-
1747 pad the remainder of the page with \n or \f as requested-
1748 reset the status of all files -- any files which where on hold because-
1749 of formfeeds are now put back into the lineup. */-
1750-
1751static bool-
1752print_page (void)-
1753{-
1754 int j;-
1755 int lines_left_on_page;-
1756 COLUMN *p;-
1757-
1758 /* Used as an accumulator (with | operator) of successive values of-
1759 pad_vertically. The trick is to set pad_vertically-
1760 to false before each run through the inner loop, then after that-
1761 loop, it tells us whether a line was actually printed (whether a-
1762 newline needs to be output -- or two for double spacing). But those-
1763 values have to be accumulated (in pv) so we can invoke pad_down-
1764 properly after the outer loop completes. */-
1765 bool pv;-
1766-
1767 init_page ();-
1768-
1769 if (cols_ready_to_print () == 0)
cols_ready_to_print () == 0Description
TRUEevaluated 704 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4225 times by 1 test
Evaluated by:
  • pr
704-4225
1770 return false;
executed 704 times by 1 test: return 0 ;
Executed by:
  • pr
704
1771-
1772 if (extremities)
extremitiesDescription
TRUEevaluated 3563 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 662 times by 1 test
Evaluated by:
  • pr
662-3563
1773 print_a_header = true;
executed 3563 times by 1 test: print_a_header = 1 ;
Executed by:
  • pr
3563
1774-
1775 /* Don't pad unless we know a page was printed. */-
1776 pad_vertically = false;-
1777 pv = false;-
1778-
1779 lines_left_on_page = lines_per_body;-
1780 if (double_space)
double_spaceDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4216 times by 1 test
Evaluated by:
  • pr
9-4216
1781 lines_left_on_page *= 2;
executed 9 times by 1 test: lines_left_on_page *= 2;
Executed by:
  • pr
9
1782-
1783 while (lines_left_on_page > 0 && cols_ready_to_print () > 0)
lines_left_on_page > 0Description
TRUEevaluated 23710 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1150 times by 1 test
Evaluated by:
  • pr
cols_ready_to_print () > 0Description
TRUEevaluated 21270 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2440 times by 1 test
Evaluated by:
  • pr
1150-23710
1784 {-
1785 output_position = 0;-
1786 spaces_not_printed = 0;-
1787 separators_not_printed = 0;-
1788 pad_vertically = false;-
1789 align_empty_cols = false;-
1790 empty_line = true;-
1791-
1792 for (j = 1, p = column_vector; j <= columns; ++j, ++p)
j <= columnsDescription
TRUEevaluated 34201 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 17831 times by 1 test
Evaluated by:
  • pr
17831-34201
1793 {-
1794 input_position = 0;-
1795 if (p->lines_to_print > 0 || p->status == FF_FOUND)
p->lines_to_print > 0Description
TRUEevaluated 32279 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1922 times by 1 test
Evaluated by:
  • pr
p->status == FF_FOUNDDescription
TRUEevaluated 513 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1409 times by 1 test
Evaluated by:
  • pr
513-32279
1796 {-
1797 FF_only = false;-
1798 padding_not_printed = p->start_position;-
1799 if (!(p->print_func) (p))
!(p->print_func) (p)Description
TRUEevaluated 8005 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 24787 times by 1 test
Evaluated by:
  • pr
8005-24787
1800 read_rest_of_line (p);
executed 8005 times by 1 test: read_rest_of_line (p);
Executed by:
  • pr
8005
1801 pv |= pad_vertically;-
1802-
1803 --p->lines_to_print;-
1804 if (p->lines_to_print <= 0)
p->lines_to_print <= 0Description
TRUEevaluated 6182 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 26610 times by 1 test
Evaluated by:
  • pr
6182-26610
1805 {-
1806 if (cols_ready_to_print () == 0)
cols_ready_to_print () == 0Description
TRUEevaluated 3439 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2743 times by 1 test
Evaluated by:
  • pr
2743-3439
1807 break;
executed 3439 times by 1 test: break;
Executed by:
  • pr
3439
1808 }
executed 2743 times by 1 test: end of block
Executed by:
  • pr
2743
1809-
1810 /* File p changed its status to ON_HOLD or CLOSED */-
1811 if (parallel_files && p->status != OPEN)
parallel_filesDescription
TRUEevaluated 4563 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 24790 times by 1 test
Evaluated by:
  • pr
p->status != OPENDescription
TRUEevaluated 193 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4370 times by 1 test
Evaluated by:
  • pr
193-24790
1812 {-
1813 if (empty_line)
empty_lineDescription
TRUEevaluated 101 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 92 times by 1 test
Evaluated by:
  • pr
92-101
1814 align_empty_cols = true;
executed 101 times by 1 test: align_empty_cols = 1 ;
Executed by:
  • pr
101
1815 else if (p->status == CLOSED
p->status == CLOSEDDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 74 times by 1 test
Evaluated by:
  • pr
18-74
1816 || (p->status == ON_HOLD && FF_only))
p->status == ON_HOLDDescription
TRUEevaluated 74 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
FF_onlyDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 48 times by 1 test
Evaluated by:
  • pr
0-74
1817 align_column (p);
executed 44 times by 1 test: align_column (p);
Executed by:
  • pr
44
1818 }
executed 193 times by 1 test: end of block
Executed by:
  • pr
193
1819 }
executed 29353 times by 1 test: end of block
Executed by:
  • pr
29353
1820 else if (parallel_files)
parallel_filesDescription
TRUEevaluated 1409 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1409
1821 {-
1822 /* File status ON_HOLD or CLOSED */-
1823 if (empty_line)
empty_lineDescription
TRUEevaluated 724 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 685 times by 1 test
Evaluated by:
  • pr
685-724
1824 align_empty_cols = true;
executed 724 times by 1 test: align_empty_cols = 1 ;
Executed by:
  • pr
724
1825 else-
1826 align_column (p);
executed 685 times by 1 test: align_column (p);
Executed by:
  • pr
685
1827 }-
1828-
1829 /* We need it also with an empty column */-
1830 if (use_col_separator)
use_col_separatorDescription
TRUEevaluated 21209 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 9553 times by 1 test
Evaluated by:
  • pr
9553-21209
1831 ++separators_not_printed;
executed 21209 times by 1 test: ++separators_not_printed;
Executed by:
  • pr
21209
1832 }
executed 30762 times by 1 test: end of block
Executed by:
  • pr
30762
1833-
1834 if (pad_vertically)
pad_verticallyDescription
TRUEevaluated 20439 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 831 times by 1 test
Evaluated by:
  • pr
831-20439
1835 {-
1836 putchar ('\n');-
1837 --lines_left_on_page;-
1838 }
executed 20439 times by 1 test: end of block
Executed by:
  • pr
20439
1839-
1840 if (cols_ready_to_print () == 0 && !extremities)
cols_ready_to_print () == 0Description
TRUEevaluated 3439 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 17831 times by 1 test
Evaluated by:
  • pr
!extremitiesDescription
TRUEevaluated 635 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2804 times by 1 test
Evaluated by:
  • pr
635-17831
1841 break;
executed 635 times by 1 test: break;
Executed by:
  • pr
635
1842-
1843 if (double_space && pv)
double_spaceDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 20620 times by 1 test
Evaluated by:
  • pr
pvDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3 times by 1 test
Evaluated by:
  • pr
3-20620
1844 {-
1845 putchar ('\n');-
1846 --lines_left_on_page;-
1847 }
executed 12 times by 1 test: end of block
Executed by:
  • pr
12
1848 }
executed 20635 times by 1 test: end of block
Executed by:
  • pr
20635
1849-
1850 if (lines_left_on_page == 0)
lines_left_on_page == 0Description
TRUEevaluated 1150 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3075 times by 1 test
Evaluated by:
  • pr
1150-3075
1851 for (j = 1, p = column_vector; j <= columns; ++j, ++p)
j <= columnsDescription
TRUEevaluated 2072 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1150 times by 1 test
Evaluated by:
  • pr
1150-2072
1852 if (p->status == OPEN)
p->status == OPENDescription
TRUEevaluated 1407 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 665 times by 1 test
Evaluated by:
  • pr
665-1407
1853 p->full_page_printed = true;
executed 1407 times by 1 test: p->full_page_printed = 1 ;
Executed by:
  • pr
1407
1854-
1855 pad_vertically = pv;-
1856-
1857 if (pad_vertically && extremities)
pad_verticallyDescription
TRUEevaluated 3944 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 281 times by 1 test
Evaluated by:
  • pr
extremitiesDescription
TRUEevaluated 3534 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 410 times by 1 test
Evaluated by:
  • pr
281-3944
1858 pad_down (lines_left_on_page + lines_per_footer);
executed 3534 times by 1 test: pad_down (lines_left_on_page + lines_per_footer);
Executed by:
  • pr
3534
1859 else if (keep_FF && print_a_FF)
keep_FFDescription
TRUEevaluated 371 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 320 times by 1 test
Evaluated by:
  • pr
print_a_FFDescription
TRUEevaluated 240 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 131 times by 1 test
Evaluated by:
  • pr
131-371
1860 {-
1861 putchar ('\f');-
1862 print_a_FF = false;-
1863 }
executed 240 times by 1 test: end of block
Executed by:
  • pr
240
1864-
1865 if (last_page_number < ++page_number)
last_page_numb... ++page_numberDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4204 times by 1 test
Evaluated by:
  • pr
21-4204
1866 return false; /* Stop printing with LAST_PAGE */
executed 21 times by 1 test: return 0 ;
Executed by:
  • pr
21
1867-
1868 reset_status (); /* Change ON_HOLD to OPEN. */-
1869-
1870 return true; /* More pages to go. */
executed 4204 times by 1 test: return 1 ;
Executed by:
  • pr
4204
1871}-
1872-
1873/* Allocate space for storing columns.-
1874-
1875 This is necessary when printing multiple columns from a single file.-
1876 Lines are stored consecutively in buff, separated by '\0'.-
1877-
1878 The following doesn't apply any longer - any tuning possible?-
1879 (We can't use a fixed offset since with the '-s' flag lines aren't-
1880 truncated.)-
1881-
1882 We maintain a list (line_vector) of pointers to the beginnings-
1883 of lines in buff. We allocate one more than the number of lines-
1884 because the last entry tells us the index of the last character,-
1885 which we need to know in order to print the last line in buff. */-
1886-
1887static void-
1888init_store_cols (void)-
1889{-
1890 int total_lines, total_lines_1, chars_per_column_1, chars_if_truncate;-
1891 if (INT_MULTIPLY_WRAPV (lines_per_body, columns, &total_lines)
__builtin_mul_... &total_lines)Description
TRUEnever evaluated
FALSEevaluated 258 times by 1 test
Evaluated by:
  • pr
0-258
1892 || INT_ADD_WRAPV (total_lines, 1, &total_lines_1)
__builtin_add_...total_lines_1)Description
TRUEnever evaluated
FALSEevaluated 258 times by 1 test
Evaluated by:
  • pr
0-258
1893 || INT_ADD_WRAPV (chars_per_column, 1, &chars_per_column_1)
__builtin_add_..._per_column_1)Description
TRUEnever evaluated
FALSEevaluated 258 times by 1 test
Evaluated by:
  • pr
0-258
1894 || INT_MULTIPLY_WRAPV (total_lines, chars_per_column_1,
__builtin_mul_...s_if_truncate)Description
TRUEnever evaluated
FALSEevaluated 258 times by 1 test
Evaluated by:
  • pr
0-258
1895 &chars_if_truncate))-
1896 integer_overflow ();
never executed: integer_overflow ();
0
1897-
1898 free (line_vector);-
1899 /* FIXME: here's where it was allocated. */-
1900 line_vector = xnmalloc (total_lines_1, sizeof *line_vector);-
1901-
1902 free (end_vector);-
1903 end_vector = xnmalloc (total_lines, sizeof *end_vector);-
1904-
1905 free (buff);-
1906 buff = xnmalloc (chars_if_truncate, use_col_separator + 1);-
1907 buff_allocated = chars_if_truncate; /* Tune this. */-
1908 buff_allocated *= use_col_separator + 1;-
1909}
executed 258 times by 1 test: end of block
Executed by:
  • pr
258
1910-
1911/* Store all but the rightmost column.-
1912 (Used when printing a single file in multiple downward columns)-
1913-
1914 For each column-
1915 set p->current_line to be the index in line_vector of the-
1916 first line in the column-
1917 For each line in the column-
1918 store the line in buff-
1919 add to line_vector the index of the line's first char-
1920 buff_start is the index in buff of the first character in the-
1921 current line. */-
1922-
1923static void-
1924store_columns (void)-
1925{-
1926 int i, j;-
1927 unsigned int line = 0;-
1928 unsigned int buff_start;-
1929 int last_col; /* The rightmost column which will be saved in buff */-
1930 COLUMN *p;-
1931-
1932 buff_current = 0;-
1933 buff_start = 0;-
1934-
1935 if (balance_columns)
balance_columnsDescription
TRUEevaluated 1644 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1644
1936 last_col = columns;
executed 1644 times by 1 test: last_col = columns;
Executed by:
  • pr
1644
1937 else-
1938 last_col = columns - 1;
never executed: last_col = columns - 1;
0
1939-
1940 for (i = 1, p = column_vector; i <= last_col; ++i, ++p)
i <= last_colDescription
TRUEevaluated 4209 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1644 times by 1 test
Evaluated by:
  • pr
1644-4209
1941 p->lines_stored = 0;
executed 4209 times by 1 test: p->lines_stored = 0;
Executed by:
  • pr
4209
1942-
1943 for (i = 1, p = column_vector; i <= last_col && files_ready_to_read;
i <= last_colDescription
TRUEevaluated 3186 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 288 times by 1 test
Evaluated by:
  • pr
files_ready_to_readDescription
TRUEevaluated 1830 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1356 times by 1 test
Evaluated by:
  • pr
288-3186
1944 ++i, ++p)-
1945 {-
1946 p->current_line = line;-
1947 for (j = lines_per_body; j && files_ready_to_read; --j)
jDescription
TRUEevaluated 10899 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 837 times by 1 test
Evaluated by:
  • pr
files_ready_to_readDescription
TRUEevaluated 9906 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 993 times by 1 test
Evaluated by:
  • pr
837-10899
1948-
1949 if (p->status == OPEN) /* Redundant. Clean up. */
p->status == OPENDescription
TRUEevaluated 9906 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-9906
1950 {-
1951 input_position = 0;-
1952-
1953 if (!read_line (p))
!read_line (p)Description
TRUEevaluated 6630 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3276 times by 1 test
Evaluated by:
  • pr
3276-6630
1954 read_rest_of_line (p);
executed 6630 times by 1 test: read_rest_of_line (p);
Executed by:
  • pr
6630
1955-
1956 if (p->status == OPEN
p->status == OPENDescription
TRUEevaluated 8733 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1173 times by 1 test
Evaluated by:
  • pr
1173-8733
1957 || buff_start != buff_current)
buff_start != buff_currentDescription
TRUEevaluated 177 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 996 times by 1 test
Evaluated by:
  • pr
177-996
1958 {-
1959 ++p->lines_stored;-
1960 line_vector[line] = buff_start;-
1961 end_vector[line++] = input_position;-
1962 buff_start = buff_current;-
1963 }
executed 8910 times by 1 test: end of block
Executed by:
  • pr
8910
1964 }
executed 9906 times by 1 test: end of block
Executed by:
  • pr
9906
1965 }
executed 1830 times by 1 test: end of block
Executed by:
  • pr
1830
1966-
1967 /* Keep track of the location of the last char in buff. */-
1968 line_vector[line] = buff_start;-
1969-
1970 if (balance_columns)
balance_columnsDescription
TRUEevaluated 1644 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1644
1971 balance (line);
executed 1644 times by 1 test: balance (line);
Executed by:
  • pr
1644
1972}
executed 1644 times by 1 test: end of block
Executed by:
  • pr
1644
1973-
1974static void-
1975balance (int total_stored)-
1976{-
1977 COLUMN *p;-
1978 int i, lines;-
1979 int first_line = 0;-
1980-
1981 for (i = 1, p = column_vector; i <= columns; ++i, ++p)
i <= columnsDescription
TRUEevaluated 4209 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1644 times by 1 test
Evaluated by:
  • pr
1644-4209
1982 {-
1983 lines = total_stored / columns;-
1984 if (i <= total_stored % columns)
i <= total_stored % columnsDescription
TRUEevaluated 768 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3441 times by 1 test
Evaluated by:
  • pr
768-3441
1985 ++lines;
executed 768 times by 1 test: ++lines;
Executed by:
  • pr
768
1986-
1987 p->lines_stored = lines;-
1988 p->current_line = first_line;-
1989-
1990 first_line += lines;-
1991 }
executed 4209 times by 1 test: end of block
Executed by:
  • pr
4209
1992}
executed 1644 times by 1 test: end of block
Executed by:
  • pr
1644
1993-
1994/* Store a character in the buffer. */-
1995-
1996static void-
1997store_char (char c)-
1998{-
1999 if (buff_current >= buff_allocated)
buff_current >= buff_allocatedDescription
TRUEnever evaluated
FALSEevaluated 223917 times by 1 test
Evaluated by:
  • pr
0-223917
2000 {-
2001 /* May be too generous. */-
2002 buff = X2REALLOC (buff, &buff_allocated);-
2003 }
never executed: end of block
0
2004 buff[buff_current++] = c;-
2005}
executed 223917 times by 1 test: end of block
Executed by:
  • pr
223917
2006-
2007static void-
2008add_line_number (COLUMN *p)-
2009{-
2010 int i;-
2011 char *s;-
2012 int num_width;-
2013-
2014 /* Cutting off the higher-order digits is more informative than-
2015 lower-order cut off. */-
2016 num_width = sprintf (number_buff, "%*d", chars_per_number, line_number);-
2017 line_number++;-
2018 s = number_buff + (num_width - chars_per_number);-
2019 for (i = chars_per_number; i > 0; i--)
i > 0Description
TRUEevaluated 17500 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 5383 times by 1 test
Evaluated by:
  • pr
5383-17500
2020 (p->char_func) (*s++);
executed 17500 times by 1 test: (p->char_func) (*s++);
Executed by:
  • pr
17500
2021-
2022 if (columns > 1)
columns > 1Description
TRUEevaluated 2980 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2403 times by 1 test
Evaluated by:
  • pr
2403-2980
2023 {-
2024 /* Tabification is assumed for multiple columns, also for n-separators,-
2025 but 'default n-separator = TAB' hasn't been given priority over-
2026 equal column_width also specified by POSIX. */-
2027 if (number_separator == '\t')
number_separator == '\t'Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2932 times by 1 test
Evaluated by:
  • pr
48-2932
2028 {-
2029 i = number_width - chars_per_number;-
2030 while (i-- > 0)
i-- > 0Description
TRUEevaluated 144 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 48 times by 1 test
Evaluated by:
  • pr
48-144
2031 (p->char_func) (' ');
executed 144 times by 1 test: (p->char_func) (' ');
Executed by:
  • pr
144
2032 }
executed 48 times by 1 test: end of block
Executed by:
  • pr
48
2033 else-
2034 (p->char_func) (number_separator);
executed 2932 times by 1 test: (p->char_func) (number_separator);
Executed by:
  • pr
2932
2035 }-
2036 else-
2037 /* To comply with POSIX, we avoid any expansion of default TAB-
2038 separator with a single column output. No column_width requirement-
2039 has to be considered. */-
2040 {-
2041 (p->char_func) (number_separator);-
2042 if (number_separator == '\t')
number_separator == '\t'Description
TRUEevaluated 45 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2358 times by 1 test
Evaluated by:
  • pr
45-2358
2043 output_position = POS_AFTER_TAB (chars_per_output_tab,
executed 45 times by 1 test: output_position = ((output_position) + ((chars_per_output_tab) - ((output_position) % (chars_per_output_tab)))) ;
Executed by:
  • pr
45
2044 output_position);
executed 45 times by 1 test: output_position = ((output_position) + ((chars_per_output_tab) - ((output_position) % (chars_per_output_tab)))) ;
Executed by:
  • pr
45
2045 }
executed 2403 times by 1 test: end of block
Executed by:
  • pr
2403
2046-
2047 if (truncate_lines && !parallel_files)
truncate_linesDescription
TRUEevaluated 2804 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2579 times by 1 test
Evaluated by:
  • pr
!parallel_filesDescription
TRUEevaluated 1974 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 830 times by 1 test
Evaluated by:
  • pr
830-2804
2048 input_position += number_width;
executed 1974 times by 1 test: input_position += number_width;
Executed by:
  • pr
1974
2049}
executed 5383 times by 1 test: end of block
Executed by:
  • pr
5383
2050-
2051/* Print (or store) padding until the current horizontal position-
2052 is position. */-
2053-
2054static void-
2055pad_across_to (int position)-
2056{-
2057 int h = output_position;-
2058-
2059 if (tabify_output)
tabify_outputDescription
TRUEevaluated 14692 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1096 times by 1 test
Evaluated by:
  • pr
1096-14692
2060 spaces_not_printed = position - output_position;
executed 14692 times by 1 test: spaces_not_printed = position - output_position;
Executed by:
  • pr
14692
2061 else-
2062 {-
2063 while (++h <= position)
++h <= positionDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1096 times by 1 test
Evaluated by:
  • pr
36-1096
2064 putchar (' ');
executed 36 times by 1 test: putchar_unlocked (' ');
Executed by:
  • pr
36
2065 output_position = position;-
2066 }
executed 1096 times by 1 test: end of block
Executed by:
  • pr
1096
2067}-
2068-
2069/* Pad to the bottom of the page.-
2070-
2071 If the user has requested a formfeed, use one.-
2072 Otherwise, use newlines. */-
2073-
2074static void-
2075pad_down (unsigned int lines)-
2076{-
2077 if (use_form_feed)
use_form_feedDescription
TRUEevaluated 1784 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1750 times by 1 test
Evaluated by:
  • pr
1750-1784
2078 putchar ('\f');
executed 1784 times by 1 test: putchar_unlocked ('\f');
Executed by:
  • pr
1784
2079 else-
2080 for (unsigned int i = lines; i; --i)
iDescription
TRUEevaluated 23903 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1750 times by 1 test
Evaluated by:
  • pr
1750-23903
2081 putchar ('\n');
executed 23903 times by 1 test: putchar_unlocked ('\n');
Executed by:
  • pr
23903
2082}
executed 3534 times by 1 test: end of block
Executed by:
  • pr
3534
2083-
2084/* Read the rest of the line.-
2085-
2086 Read from the current column's file until an end of line is-
2087 hit. Used when we've truncated a line and we no longer need-
2088 to print or store its characters. */-
2089-
2090static void-
2091read_rest_of_line (COLUMN *p)-
2092{-
2093 int c;-
2094 FILE *f = p->fp;-
2095-
2096 while ((c = getc (f)) != '\n')
(c = getc_unlo...d (f)) != '\n'Description
TRUEevaluated 242757 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 14331 times by 1 test
Evaluated by:
  • pr
14331-242757
2097 {-
2098 if (c == '\f')
c == '\f'Description
TRUEevaluated 304 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 242453 times by 1 test
Evaluated by:
  • pr
304-242453
2099 {-
2100 if ((c = getc (f)) != '\n')
(c = getc_unlo...d (f)) != '\n'Description
TRUEevaluated 197 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 107 times by 1 test
Evaluated by:
  • pr
107-197
2101 ungetc (c, f);
executed 197 times by 1 test: ungetc (c, f);
Executed by:
  • pr
197
2102 if (keep_FF)
keep_FFDescription
TRUEnever evaluated
FALSEevaluated 304 times by 1 test
Evaluated by:
  • pr
0-304
2103 print_a_FF = true;
never executed: print_a_FF = 1 ;
0
2104 hold_file (p);-
2105 break;
executed 304 times by 1 test: break;
Executed by:
  • pr
304
2106 }-
2107 else if (c == EOF)
c == (-1)Description
TRUEnever evaluated
FALSEevaluated 242453 times by 1 test
Evaluated by:
  • pr
0-242453
2108 {-
2109 close_file (p);-
2110 break;
never executed: break;
0
2111 }-
2112 }
executed 242453 times by 1 test: end of block
Executed by:
  • pr
242453
2113}
executed 14635 times by 1 test: end of block
Executed by:
  • pr
14635
2114-
2115/* Read a line with skip_to_page.-
2116-
2117 Read from the current column's file until an end of line is-
2118 hit. Used when we read full lines to skip pages.-
2119 With skip_to_page we have to check for FF-coincidence which is done-
2120 in function read_line otherwise.-
2121 Count lines of skipped pages to find the line number of 1st page-
2122 printed relative to 1st line of input file (start_line_num). */-
2123-
2124static void-
2125skip_read (COLUMN *p, int column_number)-
2126{-
2127 int c;-
2128 FILE *f = p->fp;-
2129 int i;-
2130 bool single_ff = false;-
2131 COLUMN *q;-
2132-
2133 /* Read 1st character in a line or any character succeeding a FF */-
2134 if ((c = getc (f)) == '\f' && p->full_page_printed)
(c = getc_unlo...d (f)) == '\f'Description
TRUEevaluated 365 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 5014 times by 1 test
Evaluated by:
  • pr
p->full_page_printedDescription
TRUEevaluated 79 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 286 times by 1 test
Evaluated by:
  • pr
79-5014
2135 /* A FF-coincidence with a previous full_page_printed.-
2136 To avoid an additional empty page, eliminate the FF */-
2137 if ((c = getc (f)) == '\n')
(c = getc_unlo...d (f)) == '\n'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 51 times by 1 test
Evaluated by:
  • pr
28-51
2138 c = getc (f);
executed 28 times by 1 test: c = getc_unlocked (f);
Executed by:
  • pr
28
2139-
2140 p->full_page_printed = false;-
2141-
2142 /* 1st character a FF means a single FF without any printable-
2143 characters. Don't count it as a line with -n option. */-
2144 if (c == '\f')
c == '\f'Description
TRUEevaluated 365 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 5014 times by 1 test
Evaluated by:
  • pr
365-5014
2145 single_ff = true;
executed 365 times by 1 test: single_ff = 1 ;
Executed by:
  • pr
365
2146-
2147 /* Preparing for a FF-coincidence: Maybe we finish that page-
2148 without a FF found */-
2149 if (last_line)
last_lineDescription
TRUEevaluated 581 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4798 times by 1 test
Evaluated by:
  • pr
581-4798
2150 p->full_page_printed = true;
executed 581 times by 1 test: p->full_page_printed = 1 ;
Executed by:
  • pr
581
2151-
2152 while (c != '\n')
c != '\n'Description
TRUEevaluated 191560 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4890 times by 1 test
Evaluated by:
  • pr
4890-191560
2153 {-
2154 if (c == '\f')
c == '\f'Description
TRUEevaluated 489 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 191071 times by 1 test
Evaluated by:
  • pr
489-191071
2155 {-
2156 /* No FF-coincidence possible,-
2157 no catching up of a FF-coincidence with next page */-
2158 if (last_line)
last_lineDescription
TRUEevaluated 87 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 402 times by 1 test
Evaluated by:
  • pr
87-402
2159 {-
2160 if (!parallel_files)
!parallel_filesDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3 times by 1 test
Evaluated by:
  • pr
3-84
2161 for (q = column_vector, i = columns; i; ++q, --i)
iDescription
TRUEevaluated 135 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 84 times by 1 test
Evaluated by:
  • pr
84-135
2162 q->full_page_printed = false;
executed 135 times by 1 test: q->full_page_printed = 0 ;
Executed by:
  • pr
135
2163 else-
2164 p->full_page_printed = false;
executed 3 times by 1 test: p->full_page_printed = 0 ;
Executed by:
  • pr
3
2165 }
executed 87 times by 1 test: end of block
Executed by:
  • pr
87
2166-
2167 if ((c = getc (f)) != '\n')
(c = getc_unlo...d (f)) != '\n'Description
TRUEevaluated 276 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 213 times by 1 test
Evaluated by:
  • pr
213-276
2168 ungetc (c, f);
executed 276 times by 1 test: ungetc (c, f);
Executed by:
  • pr
276
2169 hold_file (p);-
2170 break;
executed 489 times by 1 test: break;
Executed by:
  • pr
489
2171 }-
2172 else if (c == EOF)
c == (-1)Description
TRUEnever evaluated
FALSEevaluated 191071 times by 1 test
Evaluated by:
  • pr
0-191071
2173 {-
2174 close_file (p);-
2175 break;
never executed: break;
0
2176 }-
2177 c = getc (f);-
2178 }
executed 191071 times by 1 test: end of block
Executed by:
  • pr
191071
2179-
2180 if (skip_count)
skip_countDescription
TRUEevaluated 5334 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 45 times by 1 test
Evaluated by:
  • pr
45-5334
2181 if ((!parallel_files || column_number == 1) && !single_ff)
!parallel_filesDescription
TRUEevaluated 5004 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 330 times by 1 test
Evaluated by:
  • pr
column_number == 1Description
TRUEevaluated 171 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 159 times by 1 test
Evaluated by:
  • pr
!single_ffDescription
TRUEevaluated 4818 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 357 times by 1 test
Evaluated by:
  • pr
159-5004
2182 ++line_count;
executed 4818 times by 1 test: ++line_count;
Executed by:
  • pr
4818
2183}
executed 5379 times by 1 test: end of block
Executed by:
  • pr
5379
2184-
2185/* If we're tabifying output,-
2186-
2187 When print_char encounters white space it keeps track-
2188 of our desired horizontal position and delays printing-
2189 until this function is called. */-
2190-
2191static void-
2192print_white_space (void)-
2193{-
2194 int h_new;-
2195 int h_old = output_position;-
2196 int goal = h_old + spaces_not_printed;-
2197-
2198 while (goal - h_old > 1
goal - h_old > 1Description
TRUEevaluated 34115 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 39096 times by 1 test
Evaluated by:
  • pr
34115-39096
2199 && (h_new = POS_AFTER_TAB (chars_per_output_tab, h_old)) <= goal)
(h_new = ((h_o...b))))) <= goalDescription
TRUEevaluated 23703 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 10412 times by 1 test
Evaluated by:
  • pr
10412-23703
2200 {-
2201 putchar (output_tab_char);-
2202 h_old = h_new;-
2203 }
executed 23703 times by 1 test: end of block
Executed by:
  • pr
23703
2204 while (++h_old <= goal)
++h_old <= goalDescription
TRUEevaluated 63789 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 49508 times by 1 test
Evaluated by:
  • pr
49508-63789
2205 putchar (' ');
executed 63789 times by 1 test: putchar_unlocked (' ');
Executed by:
  • pr
63789
2206-
2207 output_position = goal;-
2208 spaces_not_printed = 0;-
2209}
executed 49508 times by 1 test: end of block
Executed by:
  • pr
49508
2210-
2211/* Print column separators.-
2212-
2213 We keep a count until we know that we'll be printing a line,-
2214 then print_sep_string() is called. */-
2215-
2216static void-
2217print_sep_string (void)-
2218{-
2219 char const *s = col_sep_string;-
2220 int l = col_sep_length;-
2221-
2222 if (separators_not_printed <= 0)
separators_not_printed <= 0Description
TRUEevaluated 9323 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12628 times by 1 test
Evaluated by:
  • pr
9323-12628
2223 {-
2224 /* We'll be starting a line with chars_per_margin, anything else? */-
2225 if (spaces_not_printed > 0)
spaces_not_printed > 0Description
TRUEevaluated 790 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8533 times by 1 test
Evaluated by:
  • pr
790-8533
2226 print_white_space ();
executed 790 times by 1 test: print_white_space ();
Executed by:
  • pr
790
2227 }
executed 9323 times by 1 test: end of block
Executed by:
  • pr
9323
2228 else-
2229 {-
2230 for (; separators_not_printed > 0; --separators_not_printed)
separators_not_printed > 0Description
TRUEevaluated 12628 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12628 times by 1 test
Evaluated by:
  • pr
12628
2231 {-
2232 while (l-- > 0)
l-- > 0Description
TRUEevaluated 17898 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 12628 times by 1 test
Evaluated by:
  • pr
12628-17898
2233 {-
2234 /* 3 types of sep_strings: spaces only, spaces and chars,-
2235 chars only */-
2236 if (*s == ' ')
*s == ' 'Description
TRUEevaluated 9653 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8245 times by 1 test
Evaluated by:
  • pr
8245-9653
2237 {-
2238 /* We're tabifying output; consecutive spaces in-
2239 sep_string may have to be converted to tabs */-
2240 s++;-
2241 ++spaces_not_printed;-
2242 }
executed 9653 times by 1 test: end of block
Executed by:
  • pr
9653
2243 else-
2244 {-
2245 if (spaces_not_printed > 0)
spaces_not_printed > 0Description
TRUEevaluated 1290 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 6955 times by 1 test
Evaluated by:
  • pr
1290-6955
2246 print_white_space ();
executed 1290 times by 1 test: print_white_space ();
Executed by:
  • pr
1290
2247 putchar (*s++);-
2248 ++output_position;-
2249 }
executed 8245 times by 1 test: end of block
Executed by:
  • pr
8245
2250 }-
2251 /* sep_string ends with some spaces */-
2252 if (spaces_not_printed > 0)
spaces_not_printed > 0Description
TRUEevaluated 9653 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2975 times by 1 test
Evaluated by:
  • pr
2975-9653
2253 print_white_space ();
executed 9653 times by 1 test: print_white_space ();
Executed by:
  • pr
9653
2254 }
executed 12628 times by 1 test: end of block
Executed by:
  • pr
12628
2255 }
executed 12628 times by 1 test: end of block
Executed by:
  • pr
12628
2256}-
2257-
2258/* Print (or store, depending on p->char_func) a clump of N-
2259 characters. */-
2260-
2261static void-
2262print_clump (COLUMN *p, int n, char *clump)-
2263{-
2264 while (n--)
n--Description
TRUEevaluated 851093 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 849176 times by 1 test
Evaluated by:
  • pr
849176-851093
2265 (p->char_func) (*clump++);
executed 851093 times by 1 test: (p->char_func) (*clump++);
Executed by:
  • pr
851093
2266}
executed 849176 times by 1 test: end of block
Executed by:
  • pr
849176
2267-
2268/* Print a character.-
2269-
2270 Update the following comment: process-char hasn't been used any-
2271 longer.-
2272 If we're tabifying, all tabs have been converted to spaces by-
2273 process_char(). Keep a count of consecutive spaces, and when-
2274 a nonspace is encountered, call print_white_space() to print the-
2275 required number of tabs and spaces. */-
2276-
2277static void-
2278print_char (char c)-
2279{-
2280 if (tabify_output)
tabify_outputDescription
TRUEevaluated 523560 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 350512 times by 1 test
Evaluated by:
  • pr
350512-523560
2281 {-
2282 if (c == ' ')
c == ' 'Description
TRUEevaluated 269135 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 254425 times by 1 test
Evaluated by:
  • pr
254425-269135
2283 {-
2284 ++spaces_not_printed;-
2285 return;
executed 269135 times by 1 test: return;
Executed by:
  • pr
269135
2286 }-
2287 else if (spaces_not_printed > 0)
spaces_not_printed > 0Description
TRUEevaluated 34241 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 220184 times by 1 test
Evaluated by:
  • pr
34241-220184
2288 print_white_space ();
executed 34241 times by 1 test: print_white_space ();
Executed by:
  • pr
34241
2289-
2290 /* Nonprintables are assumed to have width 0, except '\b'. */-
2291 if (! isprint (to_uchar (c)))
! ((*__ctype_b...int) _ISprint)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 254413 times by 1 test
Evaluated by:
  • pr
12-254413
2292 {-
2293 if (c == '\b')
c == '\b'Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • pr
0-12
2294 --output_position;
never executed: --output_position;
0
2295 }
executed 12 times by 1 test: end of block
Executed by:
  • pr
12
2296 else-
2297 ++output_position;
executed 254413 times by 1 test: ++output_position;
Executed by:
  • pr
254413
2298 }-
2299 putchar (c);-
2300}
executed 604937 times by 1 test: end of block
Executed by:
  • pr
604937
2301-
2302/* Skip to page PAGE before printing.-
2303 PAGE may be larger than total number of pages. */-
2304-
2305static bool-
2306skip_to_page (uintmax_t page)-
2307{-
2308 for (uintmax_t n = 1; n < page; ++n)
n < pageDescription
TRUEevaluated 715 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 239 times by 1 test
Evaluated by:
  • pr
239-715
2309 {-
2310 COLUMN *p;-
2311 int j;-
2312-
2313 for (int i = 1; i < lines_per_body; ++i)
i < lines_per_bodyDescription
TRUEevaluated 8288 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 715 times by 1 test
Evaluated by:
  • pr
715-8288
2314 {-
2315 for (j = 1, p = column_vector; j <= columns; ++j, ++p)
j <= columnsDescription
TRUEevaluated 14578 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8288 times by 1 test
Evaluated by:
  • pr
8288-14578
2316 if (p->status == OPEN)
p->status == OPENDescription
TRUEevaluated 4798 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 9780 times by 1 test
Evaluated by:
  • pr
4798-9780
2317 skip_read (p, j);
executed 4798 times by 1 test: skip_read (p, j);
Executed by:
  • pr
4798
2318 }
executed 8288 times by 1 test: end of block
Executed by:
  • pr
8288
2319 last_line = true;-
2320 for (j = 1, p = column_vector; j <= columns; ++j, ++p)
j <= columnsDescription
TRUEevaluated 1358 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 715 times by 1 test
Evaluated by:
  • pr
715-1358
2321 if (p->status == OPEN)
p->status == OPENDescription
TRUEevaluated 581 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 777 times by 1 test
Evaluated by:
  • pr
581-777
2322 skip_read (p, j);
executed 581 times by 1 test: skip_read (p, j);
Executed by:
  • pr
581
2323-
2324 if (storing_columns) /* change FF_FOUND to ON_HOLD */
storing_columnsDescription
TRUEevaluated 216 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 499 times by 1 test
Evaluated by:
  • pr
216-499
2325 for (j = 1, p = column_vector; j <= columns; ++j, ++p)
j <= columnsDescription
TRUEevaluated 576 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 216 times by 1 test
Evaluated by:
  • pr
216-576
2326 if (p->status != CLOSED)
p->status != CLOSEDDescription
TRUEevaluated 576 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-576
2327 p->status = ON_HOLD;
executed 576 times by 1 test: p->status = ON_HOLD;
Executed by:
  • pr
576
2328-
2329 reset_status ();-
2330 last_line = false;-
2331-
2332 if (files_ready_to_read < 1)
files_ready_to_read < 1Description
TRUEnever evaluated
FALSEevaluated 715 times by 1 test
Evaluated by:
  • pr
0-715
2333 {-
2334 /* It's very helpful, normally the total number of pages is-
2335 not known in advance. */-
2336 error (0, 0,-
2337 _("starting page number %"PRIuMAX-
2338 " exceeds page count %"PRIuMAX),-
2339 page, n);-
2340 break;
never executed: break;
0
2341 }-
2342 }
executed 715 times by 1 test: end of block
Executed by:
  • pr
715
2343 return files_ready_to_read > 0;
executed 239 times by 1 test: return files_ready_to_read > 0;
Executed by:
  • pr
239
2344}-
2345-
2346/* Print a header.-
2347-
2348 Formfeeds are assumed to use up two lines at the beginning of-
2349 the page. */-
2350-
2351static void-
2352print_header (void)-
2353{-
2354 char page_text[256 + INT_STRLEN_BOUND (page_number)];-
2355 int available_width;-
2356 int lhs_spaces;-
2357 int rhs_spaces;-
2358-
2359 output_position = 0;-
2360 pad_across_to (chars_per_margin);-
2361 print_white_space ();-
2362-
2363 if (page_number == 0)
page_number == 0Description
TRUEnever evaluated
FALSEevaluated 3534 times by 1 test
Evaluated by:
  • pr
0-3534
2364 die (EXIT_FAILURE, 0, _("page number overflow"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"page number overflow\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "page number overflow" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "page number overflow" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
2365-
2366 /* The translator must ensure that formatting the translation of-
2367 "Page %"PRIuMAX does not generate more than (sizeof page_text - 1)-
2368 bytes. */-
2369 sprintf (page_text, _("Page %"PRIuMAX), page_number);-
2370 available_width = header_width_available - mbswidth (page_text, 0);-
2371 available_width = MAX (0, available_width);
(( 0 )>( available_width ))Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3507 times by 1 test
Evaluated by:
  • pr
27-3507
2372 lhs_spaces = available_width >> 1;-
2373 rhs_spaces = available_width - lhs_spaces;-
2374-
2375 printf ("\n\n%*s%s%*s%s%*s%s\n\n\n",-
2376 chars_per_margin, "",-
2377 date_text, lhs_spaces, " ",-
2378 file_text, rhs_spaces, " ", page_text);-
2379-
2380 print_a_header = false;-
2381 output_position = 0;-
2382}
executed 3534 times by 1 test: end of block
Executed by:
  • pr
3534
2383-
2384/* Print (or store, if p->char_func is store_char()) a line.-
2385-
2386 Read a character to determine whether we have a line or not.-
2387 (We may hit EOF, \n, or \f)-
2388-
2389 Once we know we have a line,-
2390 set pad_vertically = true, meaning it's safe-
2391 to pad down at the end of the page, since we do have a page.-
2392 print a header if needed.-
2393 pad across to padding_not_printed if needed.-
2394 print any separators which need to be printed.-
2395 print a line number if it needs to be printed.-
2396-
2397 Print the clump which corresponds to the first character.-
2398-
2399 Enter a loop and keep printing until an end of line condition-
2400 exists, or until we exceed chars_per_column.-
2401-
2402 Return false if we exceed chars_per_column before reading-
2403 an end of line character, true otherwise. */-
2404-
2405static bool-
2406read_line (COLUMN *p)-
2407{-
2408 int c;-
2409 int chars IF_LINT ( = 0);-
2410 int last_input_position;-
2411 int j, k;-
2412 COLUMN *q;-
2413-
2414 /* read 1st character in each line or any character succeeding a FF: */-
2415 c = getc (p->fp);-
2416-
2417 last_input_position = input_position;-
2418-
2419 if (c == '\f' && p->full_page_printed)
c == '\f'Description
TRUEevaluated 2341 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 30934 times by 1 test
Evaluated by:
  • pr
p->full_page_printedDescription
TRUEevaluated 364 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1977 times by 1 test
Evaluated by:
  • pr
364-30934
2420 if ((c = getc (p->fp)) == '\n')
(c = getc_unlo...->fp)) == '\n'Description
TRUEevaluated 167 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 197 times by 1 test
Evaluated by:
  • pr
167-197
2421 c = getc (p->fp);
executed 167 times by 1 test: c = getc_unlocked (p->fp);
Executed by:
  • pr
167
2422 p->full_page_printed = false;-
2423-
2424 switch (c)-
2425 {-
2426 case '\f':
executed 2218 times by 1 test: case '\f':
Executed by:
  • pr
2218
2427 if ((c = getc (p->fp)) != '\n')
(c = getc_unlo...->fp)) != '\n'Description
TRUEevaluated 1042 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1176 times by 1 test
Evaluated by:
  • pr
1042-1176
2428 ungetc (c, p->fp);
executed 1042 times by 1 test: ungetc (c, p->fp);
Executed by:
  • pr
1042
2429 FF_only = true;-
2430 if (print_a_header && !storing_columns)
print_a_headerDescription
TRUEevaluated 888 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1330 times by 1 test
Evaluated by:
  • pr
!storing_columnsDescription
TRUEevaluated 888 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-1330
2431 {-
2432 pad_vertically = true;-
2433 print_header ();-
2434 }
executed 888 times by 1 test: end of block
Executed by:
  • pr
888
2435 else if (keep_FF)
keep_FFDescription
TRUEevaluated 228 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 1102 times by 1 test
Evaluated by:
  • pr
228-1102
2436 print_a_FF = true;
executed 228 times by 1 test: print_a_FF = 1 ;
Executed by:
  • pr
228
2437 hold_file (p);-
2438 return true;
executed 2218 times by 1 test: return 1 ;
Executed by:
  • pr
2218
2439 case EOF:
executed 744 times by 1 test: case (-1) :
Executed by:
  • pr
744
2440 close_file (p);-
2441 return true;
executed 744 times by 1 test: return 1 ;
Executed by:
  • pr
744
2442 case '\n':
executed 501 times by 1 test: case '\n':
Executed by:
  • pr
501
2443 break;
executed 501 times by 1 test: break;
Executed by:
  • pr
501
2444 default:
executed 29812 times by 1 test: default:
Executed by:
  • pr
29812
2445 chars = char_to_clump (c);-
2446 }
executed 29812 times by 1 test: end of block
Executed by:
  • pr
29812
2447-
2448 if (truncate_lines && input_position > chars_per_column)
truncate_linesDescription
TRUEevaluated 19761 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 10552 times by 1 test
Evaluated by:
  • pr
input_position...ars_per_columnDescription
TRUEnever evaluated
FALSEevaluated 19761 times by 1 test
Evaluated by:
  • pr
0-19761
2449 {-
2450 input_position = last_input_position;-
2451 return false;
never executed: return 0 ;
0
2452 }-
2453-
2454 if (p->char_func != store_char)
p->char_func != store_charDescription
TRUEevaluated 21403 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8910 times by 1 test
Evaluated by:
  • pr
8910-21403
2455 {-
2456 pad_vertically = true;-
2457-
2458 if (print_a_header && !storing_columns)
print_a_headerDescription
TRUEevaluated 1431 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 19972 times by 1 test
Evaluated by:
  • pr
!storing_columnsDescription
TRUEevaluated 1431 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-19972
2459 print_header ();
executed 1431 times by 1 test: print_header ();
Executed by:
  • pr
1431
2460-
2461 if (parallel_files && align_empty_cols)
parallel_filesDescription
TRUEevaluated 4458 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 16945 times by 1 test
Evaluated by:
  • pr
align_empty_colsDescription
TRUEevaluated 581 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3877 times by 1 test
Evaluated by:
  • pr
581-16945
2462 {-
2463 /* We have to align empty columns at the beginning of a line. */-
2464 k = separators_not_printed;-
2465 separators_not_printed = 0;-
2466 for (j = 1, q = column_vector; j <= k; ++j, ++q)
j <= kDescription
TRUEevaluated 717 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 581 times by 1 test
Evaluated by:
  • pr
581-717
2467 {-
2468 align_column (q);-
2469 separators_not_printed += 1;-
2470 }
executed 717 times by 1 test: end of block
Executed by:
  • pr
717
2471 padding_not_printed = p->start_position;-
2472 if (truncate_lines)
truncate_linesDescription
TRUEevaluated 413 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 168 times by 1 test
Evaluated by:
  • pr
168-413
2473 spaces_not_printed = chars_per_column;
executed 413 times by 1 test: spaces_not_printed = chars_per_column;
Executed by:
  • pr
413
2474 else-
2475 spaces_not_printed = 0;
executed 168 times by 1 test: spaces_not_printed = 0;
Executed by:
  • pr
168
2476 align_empty_cols = false;-
2477 }
executed 581 times by 1 test: end of block
Executed by:
  • pr
581
2478-
2479 if (col_sep_length < padding_not_printed)
col_sep_length...ng_not_printedDescription
TRUEevaluated 6325 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 15078 times by 1 test
Evaluated by:
  • pr
6325-15078
2480 {-
2481 pad_across_to (padding_not_printed - col_sep_length);-
2482 padding_not_printed = ANYWHERE;-
2483 }
executed 6325 times by 1 test: end of block
Executed by:
  • pr
6325
2484-
2485 if (use_col_separator)
use_col_separatorDescription
TRUEevaluated 11595 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 9808 times by 1 test
Evaluated by:
  • pr
9808-11595
2486 print_sep_string ();
executed 11595 times by 1 test: print_sep_string ();
Executed by:
  • pr
11595
2487 }
executed 21403 times by 1 test: end of block
Executed by:
  • pr
21403
2488-
2489 if (p->numbered)
p->numberedDescription
TRUEevaluated 5136 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 25177 times by 1 test
Evaluated by:
  • pr
5136-25177
2490 add_line_number (p);
executed 5136 times by 1 test: add_line_number (p);
Executed by:
  • pr
5136
2491-
2492 empty_line = false;-
2493 if (c == '\n')
c == '\n'Description
TRUEevaluated 501 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 29812 times by 1 test
Evaluated by:
  • pr
501-29812
2494 return true;
executed 501 times by 1 test: return 1 ;
Executed by:
  • pr
501
2495-
2496 print_clump (p, chars, clump_buff);-
2497-
2498 while (true)-
2499 {-
2500 c = getc (p->fp);-
2501-
2502 switch (c)-
2503 {-
2504 case '\n':
executed 14811 times by 1 test: case '\n':
Executed by:
  • pr
14811
2505 return true;
executed 14811 times by 1 test: return 1 ;
Executed by:
  • pr
14811
2506 case '\f':
executed 357 times by 1 test: case '\f':
Executed by:
  • pr
357
2507 if ((c = getc (p->fp)) != '\n')
(c = getc_unlo...->fp)) != '\n'Description
TRUEevaluated 281 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 76 times by 1 test
Evaluated by:
  • pr
76-281
2508 ungetc (c, p->fp);
executed 281 times by 1 test: ungetc (c, p->fp);
Executed by:
  • pr
281
2509 if (keep_FF)
keep_FFDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 345 times by 1 test
Evaluated by:
  • pr
12-345
2510 print_a_FF = true;
executed 12 times by 1 test: print_a_FF = 1 ;
Executed by:
  • pr
12
2511 hold_file (p);-
2512 return true;
executed 357 times by 1 test: return 1 ;
Executed by:
  • pr
357
2513 case EOF:
executed 9 times by 1 test: case (-1) :
Executed by:
  • pr
9
2514 close_file (p);-
2515 return true;
executed 9 times by 1 test: return 1 ;
Executed by:
  • pr
9
2516 }-
2517-
2518 last_input_position = input_position;-
2519 chars = char_to_clump (c);-
2520 if (truncate_lines && input_position > chars_per_column)
truncate_linesDescription
TRUEevaluated 475708 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 358291 times by 1 test
Evaluated by:
  • pr
input_position...ars_per_columnDescription
TRUEevaluated 14635 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 461073 times by 1 test
Evaluated by:
  • pr
14635-475708
2521 {-
2522 input_position = last_input_position;-
2523 return false;
executed 14635 times by 1 test: return 0 ;
Executed by:
  • pr
14635
2524 }-
2525-
2526 print_clump (p, chars, clump_buff);-
2527 }
executed 819364 times by 1 test: end of block
Executed by:
  • pr
819364
2528}
never executed: end of block
0
2529-
2530/* Print a line from buff.-
2531-
2532 If this function has been called, we know we have "something to-
2533 print". But it remains to be seen whether we have a real text page-
2534 or an empty page (a single form feed) with/without a header only.-
2535 Therefore first we set pad_vertically to true and print a header-
2536 if necessary.-
2537 If FF_FOUND and we are using -t|-T option we omit any newline by-
2538 setting pad_vertically to false (see print_page).-
2539 Otherwise we pad across if necessary, print separators if necessary-
2540 and text of COLUMN *p.-
2541-
2542 Return true, meaning there is no need to call read_rest_of_line. */-
2543-
2544static bool-
2545print_stored (COLUMN *p)-
2546{-
2547 COLUMN *q;-
2548-
2549 int line = p->current_line++;-
2550 char *first = &buff[line_vector[line]];-
2551 /* FIXME-
2552 UMR: Uninitialized memory read:-
2553 * This is occurring while in:-
2554 print_stored [pr.c:2239]-
2555 * Reading 4 bytes from 0x5148c in the heap.-
2556 * Address 0x5148c is 4 bytes into a malloc'd block at 0x51488 of 676 bytes-
2557 * This block was allocated from:-
2558 malloc [rtlib.o]-
2559 xmalloc [xmalloc.c:94]-
2560 init_store_cols [pr.c:1648]-
2561 */-
2562 char *last = &buff[line_vector[line + 1]];-
2563-
2564 pad_vertically = true;-
2565-
2566 if (print_a_header)
print_a_headerDescription
TRUEevaluated 1215 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8208 times by 1 test
Evaluated by:
  • pr
1215-8208
2567 print_header ();
executed 1215 times by 1 test: print_header ();
Executed by:
  • pr
1215
2568-
2569 if (p->status == FF_FOUND)
p->status == FF_FOUNDDescription
TRUEevaluated 921 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8502 times by 1 test
Evaluated by:
  • pr
921-8502
2570 {-
2571 int i;-
2572 for (i = 1, q = column_vector; i <= columns; ++i, ++q)
i <= columnsDescription
TRUEevaluated 2442 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 921 times by 1 test
Evaluated by:
  • pr
921-2442
2573 q->status = ON_HOLD;
executed 2442 times by 1 test: q->status = ON_HOLD;
Executed by:
  • pr
2442
2574 if (column_vector->lines_to_print <= 0)
column_vector-..._to_print <= 0Description
TRUEevaluated 513 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 408 times by 1 test
Evaluated by:
  • pr
408-513
2575 {-
2576 if (!extremities)
!extremitiesDescription
TRUEevaluated 66 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 447 times by 1 test
Evaluated by:
  • pr
66-447
2577 pad_vertically = false;
executed 66 times by 1 test: pad_vertically = 0 ;
Executed by:
  • pr
66
2578 return true; /* print a header only */
executed 513 times by 1 test: return 1 ;
Executed by:
  • pr
513
2579 }-
2580 }
executed 408 times by 1 test: end of block
Executed by:
  • pr
408
2581-
2582 if (col_sep_length < padding_not_printed)
col_sep_length...ng_not_printedDescription
TRUEevaluated 5148 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 3762 times by 1 test
Evaluated by:
  • pr
3762-5148
2583 {-
2584 pad_across_to (padding_not_printed - col_sep_length);-
2585 padding_not_printed = ANYWHERE;-
2586 }
executed 5148 times by 1 test: end of block
Executed by:
  • pr
5148
2587-
2588 if (use_col_separator)
use_col_separatorDescription
TRUEevaluated 8910 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-8910
2589 print_sep_string ();
executed 8910 times by 1 test: print_sep_string ();
Executed by:
  • pr
8910
2590-
2591 while (first != last)
first != lastDescription
TRUEevaluated 223917 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 8910 times by 1 test
Evaluated by:
  • pr
8910-223917
2592 print_char (*first++);
executed 223917 times by 1 test: print_char (*first++);
Executed by:
  • pr
223917
2593-
2594 if (spaces_not_printed == 0)
spaces_not_printed == 0Description
TRUEevaluated 4626 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 4284 times by 1 test
Evaluated by:
  • pr
4284-4626
2595 {-
2596 output_position = p->start_position + end_vector[line];-
2597 if (p->start_position - col_sep_length == chars_per_margin)
p->start_posit...ars_per_marginDescription
TRUEevaluated 2130 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 2496 times by 1 test
Evaluated by:
  • pr
2130-2496
2598 output_position -= col_sep_length;
executed 2130 times by 1 test: output_position -= col_sep_length;
Executed by:
  • pr
2130
2599 }
executed 4626 times by 1 test: end of block
Executed by:
  • pr
4626
2600-
2601 return true;
executed 8910 times by 1 test: return 1 ;
Executed by:
  • pr
8910
2602}-
2603-
2604/* Convert a character to the proper format and return the number of-
2605 characters in the resulting clump. Increment input_position by-
2606 the width of the clump.-
2607-
2608 Tabs are converted to clumps of spaces.-
2609 Nonprintable characters may be converted to clumps of escape-
2610 sequences or control prefixes.-
2611-
2612 Note: the width of a clump is not necessarily equal to the number of-
2613 characters in clump_buff. (e.g, the width of '\b' is -1, while the-
2614 number of characters is 1.) */-
2615-
2616static int-
2617char_to_clump (char c)-
2618{-
2619 unsigned char uc = c;-
2620 char *s = clump_buff;-
2621 int i;-
2622 char esc_buff[4];-
2623 int width;-
2624 int chars;-
2625 int chars_per_c = 8;-
2626-
2627 if (c == input_tab_char)
c == input_tab_charDescription
TRUEevaluated 276 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863535 times by 1 test
Evaluated by:
  • pr
276-863535
2628 chars_per_c = chars_per_input_tab;
executed 276 times by 1 test: chars_per_c = chars_per_input_tab;
Executed by:
  • pr
276
2629-
2630 if (c == input_tab_char || c == '\t')
c == input_tab_charDescription
TRUEevaluated 276 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863535 times by 1 test
Evaluated by:
  • pr
c == '\t'Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863505 times by 1 test
Evaluated by:
  • pr
30-863535
2631 {-
2632 width = TAB_WIDTH (chars_per_c, input_position);-
2633-
2634 if (untabify_input)
untabify_inputDescription
TRUEevaluated 300 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 6 times by 1 test
Evaluated by:
  • pr
6-300
2635 {-
2636 for (i = width; i; --i)
iDescription
TRUEevaluated 2532 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 300 times by 1 test
Evaluated by:
  • pr
300-2532
2637 *s++ = ' ';
executed 2532 times by 1 test: *s++ = ' ';
Executed by:
  • pr
2532
2638 chars = width;-
2639 }
executed 300 times by 1 test: end of block
Executed by:
  • pr
300
2640 else-
2641 {-
2642 *s = c;-
2643 chars = 1;-
2644 }
executed 6 times by 1 test: end of block
Executed by:
  • pr
6
2645-
2646 }-
2647 else if (! isprint (uc))
! ((*__ctype_b...int) _ISprint)Description
TRUEevaluated 330 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863175 times by 1 test
Evaluated by:
  • pr
330-863175
2648 {-
2649 if (use_esc_sequence)
use_esc_sequenceDescription
TRUEnever evaluated
FALSEevaluated 330 times by 1 test
Evaluated by:
  • pr
0-330
2650 {-
2651 width = 4;-
2652 chars = 4;-
2653 *s++ = '\\';-
2654 sprintf (esc_buff, "%03o", uc);-
2655 for (i = 0; i <= 2; ++i)
i <= 2Description
TRUEnever evaluated
FALSEnever evaluated
0
2656 *s++ = esc_buff[i];
never executed: *s++ = esc_buff[i];
0
2657 }
never executed: end of block
0
2658 else if (use_cntrl_prefix)
use_cntrl_prefixDescription
TRUEnever evaluated
FALSEevaluated 330 times by 1 test
Evaluated by:
  • pr
0-330
2659 {-
2660 if (uc < 0200)
uc < 0200Description
TRUEnever evaluated
FALSEnever evaluated
0
2661 {-
2662 width = 2;-
2663 chars = 2;-
2664 *s++ = '^';-
2665 *s = c ^ 0100;-
2666 }
never executed: end of block
0
2667 else-
2668 {-
2669 width = 4;-
2670 chars = 4;-
2671 *s++ = '\\';-
2672 sprintf (esc_buff, "%03o", uc);-
2673 for (i = 0; i <= 2; ++i)
i <= 2Description
TRUEnever evaluated
FALSEnever evaluated
0
2674 *s++ = esc_buff[i];
never executed: *s++ = esc_buff[i];
0
2675 }
never executed: end of block
0
2676 }-
2677 else if (c == '\b')
c == '\b'Description
TRUEevaluated 330 times by 1 test
Evaluated by:
  • pr
FALSEnever evaluated
0-330
2678 {-
2679 width = -1;-
2680 chars = 1;-
2681 *s = c;-
2682 }
executed 330 times by 1 test: end of block
Executed by:
  • pr
330
2683 else-
2684 {-
2685 width = 0;-
2686 chars = 1;-
2687 *s = c;-
2688 }
never executed: end of block
0
2689 }-
2690 else-
2691 {-
2692 width = 1;-
2693 chars = 1;-
2694 *s = c;-
2695 }
executed 863175 times by 1 test: end of block
Executed by:
  • pr
863175
2696-
2697 /* Too many backspaces must put us in position 0 -- never negative. */-
2698 if (width < 0 && input_position == 0)
width < 0Description
TRUEevaluated 330 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863481 times by 1 test
Evaluated by:
  • pr
input_position == 0Description
TRUEevaluated 315 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 15 times by 1 test
Evaluated by:
  • pr
15-863481
2699 {-
2700 chars = 0;-
2701 input_position = 0;-
2702 }
executed 315 times by 1 test: end of block
Executed by:
  • pr
315
2703 else if (width < 0 && input_position <= -width)
width < 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 863481 times by 1 test
Evaluated by:
  • pr
input_position <= -widthDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 6 times by 1 test
Evaluated by:
  • pr
6-863481
2704 input_position = 0;
executed 9 times by 1 test: input_position = 0;
Executed by:
  • pr
9
2705 else-
2706 input_position += width;
executed 863487 times by 1 test: input_position += width;
Executed by:
  • pr
863487
2707-
2708 return chars;
executed 863811 times by 1 test: return chars;
Executed by:
  • pr
863811
2709}-
2710-
2711/* We've just printed some files and need to clean up things before-
2712 looking for more options and printing the next batch of files.-
2713-
2714 Free everything we've xmalloc'ed, except 'header'. */-
2715-
2716static void-
2717cleanup (void)-
2718{-
2719 free (number_buff);-
2720 free (clump_buff);-
2721 free (column_vector);-
2722 free (line_vector);-
2723 free (end_vector);-
2724 free (buff);-
2725}
executed 725 times by 1 test: end of block
Executed by:
  • pr
725
2726-
2727/* Complain, print a usage message, and die. */-
2728-
2729void-
2730usage (int status)-
2731{-
2732 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • pr
FALSEevaluated 33 times by 1 test
Evaluated by:
  • pr
4-33
2733 emit_try_help ();
executed 4 times by 1 test: end of block
Executed by:
  • pr
4
2734 else-
2735 {-
2736 printf (_("\-
2737Usage: %s [OPTION]... [FILE]...\n\-
2738"),-
2739 program_name);-
2740-
2741 fputs (_("\-
2742Paginate or columnate FILE(s) for printing.\n\-
2743"), stdout);-
2744-
2745 emit_stdin_note ();-
2746 emit_mandatory_arg_note ();-
2747-
2748 fputs (_("\-
2749 +FIRST_PAGE[:LAST_PAGE], --pages=FIRST_PAGE[:LAST_PAGE]\n\-
2750 begin [stop] printing with page FIRST_[LAST_]PAGE\n\-
2751 -COLUMN, --columns=COLUMN\n\-
2752 output COLUMN columns and print columns down,\n\-
2753 unless -a is used. Balance number of lines in the\n\-
2754 columns on each page\n\-
2755"), stdout);-
2756 fputs (_("\-
2757 -a, --across print columns across rather than down, used together\n\-
2758 with -COLUMN\n\-
2759 -c, --show-control-chars\n\-
2760 use hat notation (^G) and octal backslash notation\n\-
2761 -d, --double-space\n\-
2762 double space the output\n\-
2763"), stdout);-
2764 fputs (_("\-
2765 -D, --date-format=FORMAT\n\-
2766 use FORMAT for the header date\n\-
2767 -e[CHAR[WIDTH]], --expand-tabs[=CHAR[WIDTH]]\n\-
2768 expand input CHARs (TABs) to tab WIDTH (8)\n\-
2769 -F, -f, --form-feed\n\-
2770 use form feeds instead of newlines to separate pages\n\-
2771 (by a 3-line page header with -F or a 5-line header\n\-
2772 and trailer without -F)\n\-
2773"), stdout);-
2774 fputs (_("\-
2775 -h, --header=HEADER\n\-
2776 use a centered HEADER instead of filename in page header,\n\-
2777 -h \"\" prints a blank line, don't use -h\"\"\n\-
2778 -i[CHAR[WIDTH]], --output-tabs[=CHAR[WIDTH]]\n\-
2779 replace spaces with CHARs (TABs) to tab WIDTH (8)\n\-
2780 -J, --join-lines merge full lines, turns off -W line truncation, no column\n\-
2781 alignment, --sep-string[=STRING] sets separators\n\-
2782"), stdout);-
2783 fputs (_("\-
2784 -l, --length=PAGE_LENGTH\n\-
2785 set the page length to PAGE_LENGTH (66) lines\n\-
2786 (default number of lines of text 56, and with -F 63).\n\-
2787 implies -t if PAGE_LENGTH <= 10\n\-
2788"), stdout);-
2789 fputs (_("\-
2790 -m, --merge print all files in parallel, one in each column,\n\-
2791 truncate lines, but join lines of full length with -J\n\-
2792"), stdout);-
2793 fputs (_("\-
2794 -n[SEP[DIGITS]], --number-lines[=SEP[DIGITS]]\n\-
2795 number lines, use DIGITS (5) digits, then SEP (TAB),\n\-
2796 default counting starts with 1st line of input file\n\-
2797 -N, --first-line-number=NUMBER\n\-
2798 start counting with NUMBER at 1st line of first\n\-
2799 page printed (see +FIRST_PAGE)\n\-
2800"), stdout);-
2801 fputs (_("\-
2802 -o, --indent=MARGIN\n\-
2803 offset each line with MARGIN (zero) spaces, do not\n\-
2804 affect -w or -W, MARGIN will be added to PAGE_WIDTH\n\-
2805 -r, --no-file-warnings\n\-
2806 omit warning when a file cannot be opened\n\-
2807"), stdout);-
2808 fputs (_("\-
2809 -s[CHAR], --separator[=CHAR]\n\-
2810 separate columns by a single character, default for CHAR\n\-
2811 is the <TAB> character without -w and \'no char\' with -w.\-
2812\n\-
2813 -s[CHAR] turns off line truncation of all 3 column\n\-
2814 options (-COLUMN|-a -COLUMN|-m) except -w is set\n\-
2815"), stdout);-
2816 fputs (_("\-
2817 -S[STRING], --sep-string[=STRING]\n\-
2818 separate columns by STRING,\n\-
2819 without -S: Default separator <TAB> with -J and <space>\n\-
2820 otherwise (same as -S\" \"), no effect on column options\n\-
2821"), stdout);-
2822 fputs (_("\-
2823 -t, --omit-header omit page headers and trailers;\n\-
2824 implied if PAGE_LENGTH <= 10\n\-
2825"), stdout);-
2826 fputs (_("\-
2827 -T, --omit-pagination\n\-
2828 omit page headers and trailers, eliminate any pagination\n\-
2829 by form feeds set in input files\n\-
2830 -v, --show-nonprinting\n\-
2831 use octal backslash notation\n\-
2832 -w, --width=PAGE_WIDTH\n\-
2833 set page width to PAGE_WIDTH (72) characters for\n\-
2834 multiple text-column output only, -s[char] turns off (72)\n\-
2835"), stdout);-
2836 fputs (_("\-
2837 -W, --page-width=PAGE_WIDTH\n\-
2838 set page width to PAGE_WIDTH (72) characters always,\n\-
2839 truncate lines, except -J option is set, no interference\n\-
2840 with -S or -s\n\-
2841"), stdout);-
2842 fputs (HELP_OPTION_DESCRIPTION, stdout);-
2843 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
2844 emit_ancillary_info (PROGRAM_NAME);-
2845 }
executed 33 times by 1 test: end of block
Executed by:
  • pr
33
2846 exit (status);
executed 37 times by 1 test: exit (status);
Executed by:
  • pr
37
2847}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2