OpenCoverage

ptx.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/ptx.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* Permuted index for GNU, with keywords in their context.-
2 Copyright (C) 1990-2018 Free Software Foundation, Inc.-
3 François Pinard <pinard@iro.umontreal.ca>, 1988.-
4-
5 This program is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation, either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 This program is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with this program. If not, see <https://www.gnu.org/licenses/>.-
17-
18 François Pinard <pinard@iro.umontreal.ca> */-
19-
20#include <config.h>-
21-
22#include <getopt.h>-
23#include <sys/types.h>-
24#include "system.h"-
25#include "die.h"-
26#include <regex.h>-
27#include "argmatch.h"-
28#include "diacrit.h"-
29#include "error.h"-
30#include "fadvise.h"-
31#include "quote.h"-
32#include "read-file.h"-
33#include "stdio--.h"-
34#include "xstrtol.h"-
35-
36/* The official name of this program (e.g., no 'g' prefix). */-
37#define PROGRAM_NAME "ptx"-
38-
39/* TRANSLATORS: Please translate "F. Pinard" to "François Pinard"-
40 if "ç" (c-with-cedilla) is available in the translation's character-
41 set and encoding. */-
42#define AUTHORS proper_name_utf8 ("F. Pinard", "Fran\xc3\xa7ois Pinard")-
43-
44/* Number of possible characters in a byte. */-
45#define CHAR_SET_SIZE 256-
46-
47#define ISODIGIT(C) ((C) >= '0' && (C) <= '7')-
48#define HEXTOBIN(C) ((C) >= 'a' && (C) <= 'f' ? (C)-'a'+10 \-
49 : (C) >= 'A' && (C) <= 'F' ? (C)-'A'+10 : (C)-'0')-
50#define OCTTOBIN(C) ((C) - '0')-
51-
52/* Debugging the memory allocator. */-
53-
54#if WITH_DMALLOC-
55# define MALLOC_FUNC_CHECK 1-
56# include <dmalloc.h>-
57#endif-
58-
59/* Global definitions. */-
60-
61/* FIXME: There are many unchecked integer overflows in this file,-
62 and in theory they could cause this command to have undefined-
63 behavior given large inputs or options. This command should-
64 diagnose any such overflow and exit. */-
65-
66/* Program options. */-
67-
68enum Format-
69{-
70 UNKNOWN_FORMAT, /* output format still unknown */-
71 DUMB_FORMAT, /* output for a dumb terminal */-
72 ROFF_FORMAT, /* output for 'troff' or 'nroff' */-
73 TEX_FORMAT /* output for 'TeX' or 'LaTeX' */-
74};-
75-
76static bool gnu_extensions = true; /* trigger all GNU extensions */-
77static bool auto_reference = false; /* refs are 'file_name:line_number:' */-
78static bool input_reference = false; /* refs at beginning of input lines */-
79static bool right_reference = false; /* output refs after right context */-
80static ptrdiff_t line_width = 72; /* output line width in characters */-
81static ptrdiff_t gap_size = 3; /* number of spaces between output fields */-
82static const char *truncation_string = "/";-
83 /* string used to mark line truncations */-
84static const char *macro_name = "xx"; /* macro name for roff or TeX output */-
85static enum Format output_format = UNKNOWN_FORMAT;-
86 /* output format */-
87-
88static bool ignore_case = false; /* fold lower to upper for sorting */-
89static const char *break_file = NULL; /* name of the 'Break chars' file */-
90static const char *only_file = NULL; /* name of the 'Only words' file */-
91static const char *ignore_file = NULL; /* name of the 'Ignore words' file */-
92-
93/* Options that use regular expressions. */-
94struct regex_data-
95{-
96 /* The original regular expression, as a string. */-
97 char const *string;-
98-
99 /* The compiled regular expression, and its fastmap. */-
100 struct re_pattern_buffer pattern;-
101 char fastmap[UCHAR_MAX + 1];-
102};-
103-
104static struct regex_data context_regex; /* end of context */-
105static struct regex_data word_regex; /* keyword */-
106-
107/* A BLOCK delimit a region in memory of arbitrary size, like the copy of a-
108 whole file. A WORD is similar, except it is intended for smaller regions.-
109 A WORD_TABLE may contain several WORDs. */-
110-
111typedef struct-
112 {-
113 char *start; /* pointer to beginning of region */-
114 char *end; /* pointer to end + 1 of region */-
115 }-
116BLOCK;-
117-
118typedef struct-
119 {-
120 char *start; /* pointer to beginning of region */-
121 ptrdiff_t size; /* length of the region */-
122 }-
123WORD;-
124-
125typedef struct-
126 {-
127 WORD *start; /* array of WORDs */-
128 size_t alloc; /* allocated length */-
129 ptrdiff_t length; /* number of used entries */-
130 }-
131WORD_TABLE;-
132-
133/* Pattern description tables. */-
134-
135/* For each character, provide its folded equivalent. */-
136static unsigned char folded_chars[CHAR_SET_SIZE];-
137-
138/* End of context pattern register indices. */-
139static struct re_registers context_regs;-
140-
141/* Keyword pattern register indices. */-
142static struct re_registers word_regs;-
143-
144/* A word characters fastmap is used only when no word regexp has been-
145 provided. A word is then made up of a sequence of one or more characters-
146 allowed by the fastmap. Contains !0 if character allowed in word. Not-
147 only this is faster in most cases, but it simplifies the implementation-
148 of the Break files. */-
149static char word_fastmap[CHAR_SET_SIZE];-
150-
151/* Maximum length of any word read. */-
152static ptrdiff_t maximum_word_length;-
153-
154/* Maximum width of any reference used. */-
155static ptrdiff_t reference_max_width;-
156-
157/* Ignore and Only word tables. */-
158-
159static WORD_TABLE ignore_table; /* table of words to ignore */-
160static WORD_TABLE only_table; /* table of words to select */-
161-
162/* Source text table, and scanning macros. */-
163-
164static int number_input_files; /* number of text input files */-
165static intmax_t total_line_count; /* total number of lines seen so far */-
166static const char **input_file_name; /* array of text input file names */-
167static intmax_t *file_line_count; /* array of line count values at end */-
168-
169static BLOCK *text_buffers; /* files to study */-
170-
171/* SKIP_NON_WHITE used only for getting or skipping the reference. */-
172-
173#define SKIP_NON_WHITE(cursor, limit) \-
174 while (cursor < limit && ! isspace (to_uchar (*cursor))) \-
175 cursor++-
176-
177#define SKIP_WHITE(cursor, limit) \-
178 while (cursor < limit && isspace (to_uchar (*cursor))) \-
179 cursor++-
180-
181#define SKIP_WHITE_BACKWARDS(cursor, start) \-
182 while (cursor > start && isspace (to_uchar (cursor[-1]))) \-
183 cursor---
184-
185#define SKIP_SOMETHING(cursor, limit) \-
186 if (word_regex.string) \-
187 { \-
188 regoff_t count; \-
189 count = re_match (&word_regex.pattern, cursor, limit - cursor, 0, NULL); \-
190 if (count == -2) \-
191 matcher_error (); \-
192 cursor += count == -1 ? 1 : count; \-
193 } \-
194 else if (word_fastmap[to_uchar (*cursor)]) \-
195 while (cursor < limit && word_fastmap[to_uchar (*cursor)]) \-
196 cursor++; \-
197 else \-
198 cursor++-
199-
200/* Occurrences table.-
201-
202 The 'keyword' pointer provides the central word, which is surrounded-
203 by a left context and a right context. The 'keyword' and 'length'-
204 field allow full 8-bit characters keys, even including NULs. At other-
205 places in this program, the name 'keyafter' refers to the keyword-
206 followed by its right context.-
207-
208 The left context does not extend, towards the beginning of the file,-
209 further than a distance given by the 'left' value. This value is-
210 relative to the keyword beginning, it is usually negative. This-
211 insures that, except for white space, we will never have to backward-
212 scan the source text, when it is time to generate the final output-
213 lines.-
214-
215 The right context, indirectly attainable through the keyword end, does-
216 not extend, towards the end of the file, further than a distance given-
217 by the 'right' value. This value is relative to the keyword-
218 beginning, it is usually positive.-
219-
220 When automatic references are used, the 'reference' value is the-
221 overall line number in all input files read so far, in this case, it-
222 is of type intmax_t. When input references are used, the 'reference'-
223 value indicates the distance between the keyword beginning and the-
224 start of the reference field, and it fits in ptrdiff_t and is usually-
225 negative. */-
226-
227typedef struct-
228 {-
229 WORD key; /* description of the keyword */-
230 ptrdiff_t left; /* distance to left context start */-
231 ptrdiff_t right; /* distance to right context end */-
232 intmax_t reference; /* reference descriptor */-
233 int file_index; /* corresponding file */-
234 }-
235OCCURS;-
236-
237/* The various OCCURS tables are indexed by the language. But the time-
238 being, there is no such multiple language support. */-
239-
240static OCCURS *occurs_table[1]; /* all words retained from the read text */-
241static size_t occurs_alloc[1]; /* allocated size of occurs_table */-
242static ptrdiff_t number_of_occurs[1]; /* number of used slots in occurs_table */-
243-
244-
245/* Communication among output routines. */-
246-
247/* Indicate if special output processing is requested for each character. */-
248static char edited_flag[CHAR_SET_SIZE];-
249-
250/* Half of line width, reference excluded. */-
251static ptrdiff_t half_line_width;-
252-
253/* Maximum width of before field. */-
254static ptrdiff_t before_max_width;-
255-
256/* Maximum width of keyword-and-after field. */-
257static ptrdiff_t keyafter_max_width;-
258-
259/* Length of string that flags truncation. */-
260static ptrdiff_t truncation_string_length;-
261-
262/* When context is limited by lines, wraparound may happen on final output:-
263 the 'head' pointer gives access to some supplementary left context which-
264 will be seen at the end of the output line, the 'tail' pointer gives-
265 access to some supplementary right context which will be seen at the-
266 beginning of the output line. */-
267-
268static BLOCK tail; /* tail field */-
269static bool tail_truncation; /* flag truncation after the tail field */-
270-
271static BLOCK before; /* before field */-
272static bool before_truncation; /* flag truncation before the before field */-
273-
274static BLOCK keyafter; /* keyword-and-after field */-
275static bool keyafter_truncation; /* flag truncation after the keyafter field */-
276-
277static BLOCK head; /* head field */-
278static bool head_truncation; /* flag truncation before the head field */-
279-
280static BLOCK reference; /* reference field for input reference mode */-
281-
282/* Miscellaneous routines. */-
283-
284/* Diagnose an error in the regular expression matcher. Then exit. */-
285-
286static void ATTRIBUTE_NORETURN-
287matcher_error (void)-
288{-
289 die (EXIT_FAILURE, errno, _("error in regular expression matcher"));-
290}
never executed: end of block
0
291-
292/*------------------------------------------------------.-
293| Duplicate string STRING, while evaluating \-escapes. |-
294`------------------------------------------------------*/-
295-
296/* Loosely adapted from GNU sh-utils printf.c code. */-
297-
298static char *-
299copy_unescaped_string (const char *string)-
300{-
301 char *result; /* allocated result */-
302 char *cursor; /* cursor in result */-
303 int value; /* value of \nnn escape */-
304 int length; /* length of \nnn escape */-
305-
306 result = xmalloc (strlen (string) + 1);-
307 cursor = result;-
308-
309 while (*string)
*stringDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 12 times by 1 test
Evaluated by:
  • ptx
12-49
310 {-
311 if (*string == '\\')
*string == '\\'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 45 times by 1 test
Evaluated by:
  • ptx
4-45
312 {-
313 string++;-
314 switch (*string)-
315 {-
316 case 'x': /* \xhhh escape, 3 chars maximum */
never executed: case 'x':
0
317 value = 0;-
318 for (length = 0, string++;-
319 length < 3 && isxdigit (to_uchar (*string));
length < 3Description
TRUEnever evaluated
FALSEnever evaluated
((*__ctype_b_l...nt) _ISxdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
320 length++, string++)-
321 value = value * 16 + HEXTOBIN (*string);
never executed: value = value * 16 + ((*string) >= 'a' && (*string) <= 'f' ? (*string)-'a'+10 : (*string) >= 'A' && (*string) <= 'F' ? (*string)-'A'+10 : (*string)-'0');
(*string) >= 'a'Description
TRUEnever evaluated
FALSEnever evaluated
(*string) <= 'f'Description
TRUEnever evaluated
FALSEnever evaluated
(*string) >= 'A'Description
TRUEnever evaluated
FALSEnever evaluated
(*string) <= 'F'Description
TRUEnever evaluated
FALSEnever evaluated
0
322 if (length == 0)
length == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
323 {-
324 *cursor++ = '\\';-
325 *cursor++ = 'x';-
326 }
never executed: end of block
0
327 else-
328 *cursor++ = value;
never executed: *cursor++ = value;
0
329 break;
never executed: break;
0
330-
331 case '0': /* \0ooo escape, 3 chars maximum */
never executed: case '0':
0
332 value = 0;-
333 for (length = 0, string++;-
334 length < 3 && ISODIGIT (*string);
length < 3Description
TRUEnever evaluated
FALSEnever evaluated
(*string) >= '0'Description
TRUEnever evaluated
FALSEnever evaluated
(*string) <= '7'Description
TRUEnever evaluated
FALSEnever evaluated
0
335 length++, string++)-
336 value = value * 8 + OCTTOBIN (*string);
never executed: value = value * 8 + ((*string) - '0');
0
337 *cursor++ = value;-
338 break;
never executed: break;
0
339-
340 case 'a': /* alert */
never executed: case 'a':
0
341#if __STDC__-
342 *cursor++ = '\a';-
343#else-
344 *cursor++ = 7;-
345#endif-
346 string++;-
347 break;
never executed: break;
0
348-
349 case 'b': /* backspace */
never executed: case 'b':
0
350 *cursor++ = '\b';-
351 string++;-
352 break;
never executed: break;
0
353-
354 case 'c': /* cancel the rest of the output */
never executed: case 'c':
0
355 while (*string)
*stringDescription
TRUEnever evaluated
FALSEnever evaluated
0
356 string++;
never executed: string++;
0
357 break;
never executed: break;
0
358-
359 case 'f': /* form feed */
never executed: case 'f':
0
360 *cursor++ = '\f';-
361 string++;-
362 break;
never executed: break;
0
363-
364 case 'n': /* new line */
never executed: case 'n':
0
365 *cursor++ = '\n';-
366 string++;-
367 break;
never executed: break;
0
368-
369 case 'r': /* carriage return */
never executed: case 'r':
0
370 *cursor++ = '\r';-
371 string++;-
372 break;
never executed: break;
0
373-
374 case 't': /* horizontal tab */
never executed: case 't':
0
375 *cursor++ = '\t';-
376 string++;-
377 break;
never executed: break;
0
378-
379 case 'v': /* vertical tab */
never executed: case 'v':
0
380#if __STDC__-
381 *cursor++ = '\v';-
382#else-
383 *cursor++ = 11;-
384#endif-
385 string++;-
386 break;
never executed: break;
0
387-
388 case '\0': /* lone backslash at end of string */
executed 3 times by 1 test: case '\0':
Executed by:
  • ptx
3
389 /* ignore it */-
390 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
391-
392 default:
executed 1 time by 1 test: default:
Executed by:
  • ptx
1
393 *cursor++ = '\\';-
394 *cursor++ = *string++;-
395 break;
executed 1 time by 1 test: break;
Executed by:
  • ptx
1
396 }-
397 }-
398 else-
399 *cursor++ = *string++;
executed 45 times by 1 test: *cursor++ = *string++;
Executed by:
  • ptx
45
400 }-
401-
402 *cursor = '\0';-
403 return result;
executed 12 times by 1 test: return result;
Executed by:
  • ptx
12
404}-
405-
406/*--------------------------------------------------------------------------.-
407| Compile the regex represented by REGEX, diagnose and abort if any error. |-
408`--------------------------------------------------------------------------*/-
409-
410static void-
411compile_regex (struct regex_data *regex)-
412{-
413 struct re_pattern_buffer *pattern = &regex->pattern;-
414 char const *string = regex->string;-
415 char const *message;-
416-
417 pattern->buffer = NULL;-
418 pattern->allocated = 0;-
419 pattern->fastmap = regex->fastmap;-
420 pattern->translate = ignore_case ? folded_chars : NULL;
ignore_caseDescription
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • ptx
0-30
421-
422 message = re_compile_pattern (string, strlen (string), pattern);-
423 if (message)
messageDescription
TRUEnever evaluated
FALSEevaluated 30 times by 1 test
Evaluated by:
  • ptx
0-30
424 die (EXIT_FAILURE, 0, _("%s (for regexp %s)"), message, quote (string));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"%s (for regexp %s)\", 5), message, quote (string)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "%s (for regexp %s)" , 5) , message, quote (string)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "%s (for regexp %s)" , 5) , message, quote (string)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
425-
426 /* The fastmap should be compiled before 're_match'. The following-
427 call is not mandatory, because 're_search' is always called sooner,-
428 and it compiles the fastmap if this has not been done yet. */-
429-
430 re_compile_fastmap (pattern);-
431}
executed 30 times by 1 test: end of block
Executed by:
  • ptx
30
432-
433/*------------------------------------------------------------------------.-
434| This will initialize various tables for pattern match and compiles some |-
435| regexps. |-
436`------------------------------------------------------------------------*/-
437-
438static void-
439initialize_regex (void)-
440{-
441 int character; /* character value */-
442-
443 /* Initialize the case folding table. */-
444-
445 if (ignore_case)
ignore_caseDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
0-29
446 for (character = 0; character < CHAR_SET_SIZE; character++)
character < 256Description
TRUEnever evaluated
FALSEnever evaluated
0
447 folded_chars[character] = toupper (character);
never executed: folded_chars[character] = (__extension__ ({ int __res; if (sizeof ( character ) > 1) { if (__builtin_constant_p ( character )) { int __c = ( character ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_toupper_loc ())[__c]; } else __res = toupper ( character ); } else __res = (*__ctype_toupper_loc ())[(int) ( character )]; __res; })) ;
never executed: end of block
never executed: __res = toupper ( character );
never executed: __res = (*__ctype_toupper_loc ())[(int) ( character )];
sizeof ( character ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... ( character )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
448-
449 /* Unless the user already provided a description of the end of line or-
450 end of sentence sequence, select an end of line sequence to compile.-
451 If the user provided an empty definition, thus disabling end of line-
452 or sentence feature, make it NULL to speed up tests. If GNU-
453 extensions are enabled, use end of sentence like in GNU emacs. If-
454 disabled, use end of lines. */-
455-
456 if (context_regex.string)
context_regex.stringDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
4-25
457 {-
458 if (!*context_regex.string)
!*context_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • ptx
0-4
459 context_regex.string = NULL;
never executed: context_regex.string = ((void *)0) ;
0
460 }
executed 4 times by 1 test: end of block
Executed by:
  • ptx
4
461 else if (gnu_extensions && !input_reference)
gnu_extensionsDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
!input_referenceDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-25
462 context_regex.string = "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*";
executed 25 times by 1 test: context_regex.string = "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*";
Executed by:
  • ptx
25
463 else-
464 context_regex.string = "\n";
never executed: context_regex.string = "\n";
0
465-
466 if (context_regex.string)
context_regex.stringDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-29
467 compile_regex (&context_regex);
executed 29 times by 1 test: compile_regex (&context_regex);
Executed by:
  • ptx
29
468-
469 /* If the user has already provided a non-empty regexp to describe-
470 words, compile it. Else, unless this has already been done through-
471 a user provided Break character file, construct a fastmap of-
472 characters that may appear in a word. If GNU extensions enabled,-
473 include only letters of the underlying character set. If disabled,-
474 include almost everything, even punctuations; stop only on white-
475 space. */-
476-
477 if (word_regex.string)
word_regex.stringDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 28 times by 1 test
Evaluated by:
  • ptx
1-28
478 compile_regex (&word_regex);
executed 1 time by 1 test: compile_regex (&word_regex);
Executed by:
  • ptx
1
479 else if (!break_file)
!break_fileDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-28
480 {-
481 if (gnu_extensions)
gnu_extensionsDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-28
482 {-
483-
484 /* Simulate \w+. */-
485-
486 for (character = 0; character < CHAR_SET_SIZE; character++)
character < 256Description
TRUEevaluated 7168 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 28 times by 1 test
Evaluated by:
  • ptx
28-7168
487 word_fastmap[character] = !! isalpha (character);
executed 7168 times by 1 test: word_fastmap[character] = !! ((*__ctype_b_loc ())[(int) (( character ))] & (unsigned short int) _ISalpha) ;
Executed by:
  • ptx
7168
488 }
executed 28 times by 1 test: end of block
Executed by:
  • ptx
28
489 else-
490 {-
491-
492 /* Simulate [^ \t\n]+. */-
493-
494 memset (word_fastmap, 1, CHAR_SET_SIZE);-
495 word_fastmap[' '] = 0;-
496 word_fastmap['\t'] = 0;-
497 word_fastmap['\n'] = 0;-
498 }
never executed: end of block
0
499 }-
500}
executed 29 times by 1 test: end of block
Executed by:
  • ptx
29
501-
502/*------------------------------------------------------------------------.-
503| This routine will attempt to swallow a whole file name FILE_NAME into a |-
504| contiguous region of memory and return a description of it into BLOCK. |-
505| Standard input is assumed whenever FILE_NAME is NULL, empty or "-". |-
506| |-
507| Previously, in some cases, white space compression was attempted while |-
508| inputting text. This was defeating some regexps like default end of |-
509| sentence, which checks for two consecutive spaces. If white space |-
510| compression is ever reinstated, it should be in output routines. |-
511`------------------------------------------------------------------------*/-
512-
513static void-
514swallow_file_in_memory (const char *file_name, BLOCK *block)-
515{-
516 size_t used_length; /* used length in memory buffer */-
517-
518 /* As special cases, a file name which is NULL or "-" indicates standard-
519 input, which is already opened. In all other cases, open the file from-
520 its name. */-
521 bool using_stdin = !file_name || !*file_name || STREQ (file_name, "-");
never executed: __result = (((const unsigned char *) (const char *) ( file_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
!file_nameDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
!*file_nameDescription
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
__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 15 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
__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-16
522 if (using_stdin)
using_stdinDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
15-16
523 block->start = fread_file (stdin, &used_length);
executed 16 times by 1 test: block->start = fread_file ( stdin , &used_length);
Executed by:
  • ptx
16
524 else-
525 block->start = read_file (file_name, &used_length);
executed 15 times by 1 test: block->start = read_file (file_name, &used_length);
Executed by:
  • ptx
15
526-
527 if (!block->start)
!block->startDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
0-31
528 die (EXIT_FAILURE, errno, "%s", quotef (using_stdin ? "-" : file_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, using_stdin ? \"-\" : file_name)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( ...n ? "-" : file_name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, using_stdin ? "-" : file_name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
529-
530 block->end = block->start + used_length;-
531}
executed 31 times by 1 test: end of block
Executed by:
  • ptx
31
532-
533/* Sort and search routines. */-
534-
535/*--------------------------------------------------------------------------.-
536| Compare two words, FIRST and SECOND, and return 0 if they are identical. |-
537| Return less than 0 if the first word goes before the second; return |-
538| greater than 0 if the first word goes after the second. |-
539| |-
540| If a word is indeed a prefix of the other, the shorter should go first. |-
541`--------------------------------------------------------------------------*/-
542-
543static int-
544compare_words (const void *void_first, const void *void_second)-
545{-
546#define first ((const WORD *) void_first)-
547#define second ((const WORD *) void_second)-
548 ptrdiff_t length; /* minimum of two lengths */-
549 ptrdiff_t counter; /* cursor in words */-
550 int value; /* value of comparison */-
551-
552 length = first->size < second->size ? first->size : second->size;
((const WORD *..._second)->sizeDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 21 times by 1 test
Evaluated by:
  • ptx
19-21
553-
554 if (ignore_case)
ignore_caseDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-40
555 {-
556 for (counter = 0; counter < length; counter++)
counter < lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
557 {-
558 value = (folded_chars [to_uchar (first->start[counter])]-
559 - folded_chars [to_uchar (second->start[counter])]);-
560 if (value != 0)
value != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
561 return value;
never executed: return value;
0
562 }
never executed: end of block
0
563 }
never executed: end of block
0
564 else-
565 {-
566 for (counter = 0; counter < length; counter++)
counter < lengthDescription
TRUEevaluated 68 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 7 times by 1 test
Evaluated by:
  • ptx
7-68
567 {-
568 value = (to_uchar (first->start[counter])-
569 - to_uchar (second->start[counter]));-
570 if (value != 0)
value != 0Description
TRUEevaluated 33 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 35 times by 1 test
Evaluated by:
  • ptx
33-35
571 return value;
executed 33 times by 1 test: return value;
Executed by:
  • ptx
33
572 }
executed 35 times by 1 test: end of block
Executed by:
  • ptx
35
573 }
executed 7 times by 1 test: end of block
Executed by:
  • ptx
7
574-
575 return first->size < second->size ? -1 : first->size > second->size;
executed 7 times by 1 test: return ((const WORD *) void_first)->size < ((const WORD *) void_second)->size ? -1 : ((const WORD *) void_first)->size > ((const WORD *) void_second)->size;
Executed by:
  • ptx
7
576#undef first-
577#undef second-
578}-
579-
580/*-----------------------------------------------------------------------.-
581| Decides which of two OCCURS, FIRST or SECOND, should lexicographically |-
582| go first. In case of a tie, preserve the original order through a |-
583| pointer comparison. |-
584`-----------------------------------------------------------------------*/-
585-
586static int-
587compare_occurs (const void *void_first, const void *void_second)-
588{-
589#define first ((const OCCURS *) void_first)-
590#define second ((const OCCURS *) void_second)-
591 int value;-
592-
593 value = compare_words (&first->key, &second->key);-
594 return (value ? value
executed 40 times by 1 test: return (value ? value : ((const OCCURS *) void_first)->key.start < ((const OCCURS *) void_second)->key.start ? -1 : ((const OCCURS *) void_first)->key.start > ((const OCCURS *) void_second)->key.start);
Executed by:
  • ptx
40
595 : first->key.start < second->key.start ? -1
executed 40 times by 1 test: return (value ? value : ((const OCCURS *) void_first)->key.start < ((const OCCURS *) void_second)->key.start ? -1 : ((const OCCURS *) void_first)->key.start > ((const OCCURS *) void_second)->key.start);
Executed by:
  • ptx
40
596 : first->key.start > second->key.start);
executed 40 times by 1 test: return (value ? value : ((const OCCURS *) void_first)->key.start < ((const OCCURS *) void_second)->key.start ? -1 : ((const OCCURS *) void_first)->key.start > ((const OCCURS *) void_second)->key.start);
Executed by:
  • ptx
40
597#undef first-
598#undef second-
599}-
600-
601/* True if WORD appears in TABLE. Uses a binary search. */-
602-
603static bool _GL_ATTRIBUTE_PURE-
604search_table (WORD *word, WORD_TABLE *table)-
605{-
606 ptrdiff_t lowest; /* current lowest possible index */-
607 ptrdiff_t highest; /* current highest possible index */-
608 ptrdiff_t middle; /* current middle index */-
609 int value; /* value from last comparison */-
610-
611 lowest = 0;-
612 highest = table->length - 1;-
613 while (lowest <= highest)
lowest <= highestDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 {-
615 middle = (lowest + highest) / 2;-
616 value = compare_words (word, table->start + middle);-
617 if (value < 0)
value < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
618 highest = middle - 1;
never executed: highest = middle - 1;
0
619 else if (value > 0)
value > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
620 lowest = middle + 1;
never executed: lowest = middle + 1;
0
621 else-
622 return true;
never executed: return 1 ;
0
623 }-
624 return false;
never executed: return 0 ;
0
625}-
626-
627/*---------------------------------------------------------------------.-
628| Sort the whole occurs table in memory. Presumably, 'qsort' does not |-
629| take intermediate copies or table elements, so the sort will be |-
630| stabilized throughout the comparison routine. |-
631`---------------------------------------------------------------------*/-
632-
633static void-
634sort_found_occurs (void)-
635{-
636-
637 /* Only one language for the time being. */-
638 if (number_of_occurs[0])
number_of_occurs[0]Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 4 times by 1 test
Evaluated by:
  • ptx
4-22
639 qsort (occurs_table[0], number_of_occurs[0], sizeof **occurs_table,
executed 22 times by 1 test: qsort (occurs_table[0], number_of_occurs[0], sizeof **occurs_table, compare_occurs);
Executed by:
  • ptx
22
640 compare_occurs);
executed 22 times by 1 test: qsort (occurs_table[0], number_of_occurs[0], sizeof **occurs_table, compare_occurs);
Executed by:
  • ptx
22
641}
executed 26 times by 1 test: end of block
Executed by:
  • ptx
26
642-
643/* Parameter files reading routines. */-
644-
645/*----------------------------------------------------------------------.-
646| Read a file named FILE_NAME, containing a set of break characters. |-
647| Build a content to the array word_fastmap in which all characters are |-
648| allowed except those found in the file. Characters may be repeated. |-
649`----------------------------------------------------------------------*/-
650-
651static void-
652digest_break_file (const char *file_name)-
653{-
654 BLOCK file_contents; /* to receive a copy of the file */-
655 char *cursor; /* cursor in file copy */-
656-
657 swallow_file_in_memory (file_name, &file_contents);-
658-
659 /* Make the fastmap and record the file contents in it. */-
660-
661 memset (word_fastmap, 1, CHAR_SET_SIZE);-
662 for (cursor = file_contents.start; cursor < file_contents.end; cursor++)
cursor < file_contents.endDescription
TRUEnever evaluated
FALSEnever evaluated
0
663 word_fastmap[to_uchar (*cursor)] = 0;
never executed: word_fastmap[to_uchar (*cursor)] = 0;
0
664-
665 if (!gnu_extensions)
!gnu_extensionsDescription
TRUEnever evaluated
FALSEnever evaluated
0
666 {-
667-
668 /* If GNU extensions are enabled, the only way to avoid newline as-
669 a break character is to write all the break characters in the-
670 file with no newline at all, not even at the end of the file.-
671 If disabled, spaces, tabs and newlines are always considered as-
672 break characters even if not included in the break file. */-
673-
674 word_fastmap[' '] = 0;-
675 word_fastmap['\t'] = 0;-
676 word_fastmap['\n'] = 0;-
677 }
never executed: end of block
0
678-
679 /* Return the space of the file, which is no more required. */-
680-
681 free (file_contents.start);-
682}
never executed: end of block
0
683-
684/*-----------------------------------------------------------------------.-
685| Read a file named FILE_NAME, containing one word per line, then |-
686| construct in TABLE a table of WORD descriptors for them. The routine |-
687| swallows the whole file in memory; this is at the expense of space |-
688| needed for newlines, which are useless; however, the reading is fast. |-
689`-----------------------------------------------------------------------*/-
690-
691static void-
692digest_word_file (const char *file_name, WORD_TABLE *table)-
693{-
694 BLOCK file_contents; /* to receive a copy of the file */-
695 char *cursor; /* cursor in file copy */-
696 char *word_start; /* start of the current word */-
697-
698 swallow_file_in_memory (file_name, &file_contents);-
699-
700 table->start = NULL;-
701 table->alloc = 0;-
702 table->length = 0;-
703-
704 /* Read the whole file. */-
705-
706 cursor = file_contents.start;-
707 while (cursor < file_contents.end)
cursor < file_contents.endDescription
TRUEnever evaluated
FALSEnever evaluated
0
708 {-
709-
710 /* Read one line, and save the word in contains. */-
711-
712 word_start = cursor;-
713 while (cursor < file_contents.end && *cursor != '\n')
cursor < file_contents.endDescription
TRUEnever evaluated
FALSEnever evaluated
*cursor != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
714 cursor++;
never executed: cursor++;
0
715-
716 /* Record the word in table if it is not empty. */-
717-
718 if (cursor > word_start)
cursor > word_startDescription
TRUEnever evaluated
FALSEnever evaluated
0
719 {-
720 if (table->length == table->alloc)
table->length == table->allocDescription
TRUEnever evaluated
FALSEnever evaluated
0
721 table->start = x2nrealloc (table->start, &table->alloc,
never executed: table->start = x2nrealloc (table->start, &table->alloc, sizeof *table->start);
0
722 sizeof *table->start);
never executed: table->start = x2nrealloc (table->start, &table->alloc, sizeof *table->start);
0
723 table->start[table->length].start = word_start;-
724 table->start[table->length].size = cursor - word_start;-
725 table->length++;-
726 }
never executed: end of block
0
727-
728 /* This test allows for an incomplete line at end of file. */-
729-
730 if (cursor < file_contents.end)
cursor < file_contents.endDescription
TRUEnever evaluated
FALSEnever evaluated
0
731 cursor++;
never executed: cursor++;
0
732 }
never executed: end of block
0
733-
734 /* Finally, sort all the words read. */-
735-
736 qsort (table->start, table->length, sizeof table->start[0], compare_words);-
737}
never executed: end of block
0
738-
739/* Keyword recognition and selection. */-
740-
741/*----------------------------------------------------------------------.-
742| For each keyword in the source text, constructs an OCCURS structure. |-
743`----------------------------------------------------------------------*/-
744-
745static void-
746find_occurs_in_text (int file_index)-
747{-
748 char *cursor; /* for scanning the source text */-
749 char *scan; /* for scanning the source text also */-
750 char *line_start; /* start of the current input line */-
751 char *line_scan; /* newlines scanned until this point */-
752 ptrdiff_t reference_length; /* length of reference in input mode */-
753 WORD possible_key; /* possible key, to ease searches */-
754 OCCURS *occurs_cursor; /* current OCCURS under construction */-
755-
756 char *context_start; /* start of left context */-
757 char *context_end; /* end of right context */-
758 char *word_start; /* start of word */-
759 char *word_end; /* end of word */-
760 char *next_context_start; /* next start of left context */-
761-
762 const BLOCK *text_buffer = &text_buffers[file_index];-
763-
764 /* reference_length is always used within 'if (input_reference)'.-
765 However, GNU C diagnoses that it may be used uninitialized. The-
766 following assignment is merely to shut it up. */-
767-
768 reference_length = 0;-
769-
770 /* Tracking where lines start is helpful for reference processing. In-
771 auto reference mode, this allows counting lines. In input reference-
772 mode, this permits finding the beginning of the references.-
773-
774 The first line begins with the file, skip immediately this very first-
775 reference in input reference mode, to help further rejection any word-
776 found inside it. Also, unconditionally assigning these variable has-
777 the happy effect of shutting up lint. */-
778-
779 line_start = text_buffer->start;-
780 line_scan = line_start;-
781 if (input_reference)
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
0-31
782 {-
783 SKIP_NON_WHITE (line_scan, text_buffer->end);
never executed: line_scan++;
line_scan < text_buffer->endDescription
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
784 reference_length = line_scan - line_start;-
785 SKIP_WHITE (line_scan, text_buffer->end);
never executed: line_scan++;
line_scan < text_buffer->endDescription
TRUEnever evaluated
FALSEnever evaluated
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
786 }
never executed: end of block
0
787-
788 /* Process the whole buffer, one line or one sentence at a time. */-
789-
790 for (cursor = text_buffer->start;-
791 cursor < text_buffer->end;
cursor < text_buffer->endDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 28 times by 1 test
Evaluated by:
  • ptx
28
792 cursor = next_context_start)-
793 {-
794-
795 /* 'context_start' gets initialized before the processing of each-
796 line, or once for the whole buffer if no end of line or sentence-
797 sequence separator. */-
798-
799 context_start = cursor;-
800-
801 /* If an end of line or end of sentence sequence is defined and-
802 non-empty, 'next_context_start' will be recomputed to be the end of-
803 each line or sentence, before each one is processed. If no such-
804 sequence, then 'next_context_start' is set at the end of the whole-
805 buffer, which is then considered to be a single line or sentence.-
806 This test also accounts for the case of an incomplete line or-
807 sentence at the end of the buffer. */-
808-
809 next_context_start = text_buffer->end;-
810 if (context_regex.string)
context_regex.stringDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-28
811 switch (re_search (&context_regex.pattern, cursor,-
812 text_buffer->end - cursor,-
813 0, text_buffer->end - cursor, &context_regs))-
814 {-
815 case -2:
never executed: case -2:
0
816 matcher_error ();-
817-
818 case -1:
code before this statement never executed: case -1:
executed 25 times by 1 test: case -1:
Executed by:
  • ptx
0-25
819 break;
executed 25 times by 1 test: break;
Executed by:
  • ptx
25
820-
821 case 0:
executed 3 times by 1 test: case 0:
Executed by:
  • ptx
3
822 die (EXIT_FAILURE, 0,-
823 _("error: regular expression has a match of length zero: %s"),-
824 quote (context_regex.string));-
825-
826 default:
code before this statement never executed: default:
never executed: default:
0
827 next_context_start = cursor + context_regs.end[0];-
828 break;
never executed: break;
0
829 }-
830-
831 /* Include the separator into the right context, but not any suffix-
832 white space in this separator; this insures it will be seen in-
833 output and will not take more space than necessary. */-
834-
835 context_end = next_context_start;-
836 SKIP_WHITE_BACKWARDS (context_end, context_start);
executed 23 times by 1 test: context_end--;
Executed by:
  • ptx
context_end > context_startDescription
TRUEevaluated 48 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
0-48
837-
838 /* Read and process a single input line or sentence, one word at a-
839 time. */-
840-
841 while (1)-
842 {-
843 if (word_regex.string)
word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 65 times by 1 test
Evaluated by:
  • ptx
0-65
844-
845 /* If a word regexp has been compiled, use it to skip at the-
846 beginning of the next word. If there is no such word, exit-
847 the loop. */-
848-
849 {-
850 regoff_t r = re_search (&word_regex.pattern, cursor,-
851 context_end - cursor,-
852 0, context_end - cursor, &word_regs);-
853 if (r == -2)
r == -2Description
TRUEnever evaluated
FALSEnever evaluated
0
854 matcher_error ();
never executed: matcher_error ();
0
855 if (r == -1)
r == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
856 break;
never executed: break;
0
857 word_start = cursor + word_regs.start[0];-
858 word_end = cursor + word_regs.end[0];-
859 }
never executed: end of block
0
860 else-
861-
862 /* Avoid re_search and use the fastmap to skip to the-
863 beginning of the next word. If there is no more word in-
864 the buffer, exit the loop. */-
865-
866 {-
867 scan = cursor;-
868 while (scan < context_end
scan < context_endDescription
TRUEevaluated 68 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
25-68
869 && !word_fastmap[to_uchar (*scan)])
!word_fastmap[...uchar (*scan)]Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
28-40
870 scan++;
executed 28 times by 1 test: scan++;
Executed by:
  • ptx
28
871-
872 if (scan == context_end)
scan == context_endDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
25-40
873 break;
executed 25 times by 1 test: break;
Executed by:
  • ptx
25
874-
875 word_start = scan;-
876-
877 while (scan < context_end
scan < context_endDescription
TRUEevaluated 145 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ptx
24-145
878 && word_fastmap[to_uchar (*scan)])
word_fastmap[to_uchar (*scan)]Description
TRUEevaluated 129 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 16 times by 1 test
Evaluated by:
  • ptx
16-129
879 scan++;
executed 129 times by 1 test: scan++;
Executed by:
  • ptx
129
880-
881 word_end = scan;-
882 }
executed 40 times by 1 test: end of block
Executed by:
  • ptx
40
883-
884 /* Skip right to the beginning of the found word. */-
885-
886 cursor = word_start;-
887-
888 /* Skip any zero length word. Just advance a single position,-
889 then go fetch the next word. */-
890-
891 if (word_end == word_start)
word_end == word_startDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-40
892 {-
893 cursor++;-
894 continue;
never executed: continue;
0
895 }-
896-
897 /* This is a genuine, non empty word, so save it as a possible-
898 key. Then skip over it. Also, maintain the maximum length of-
899 all words read so far. It is mandatory to take the maximum-
900 length of all words in the file, without considering if they-
901 are actually kept or rejected, because backward jumps at output-
902 generation time may fall in *any* word. */-
903-
904 possible_key.start = cursor;-
905 possible_key.size = word_end - word_start;-
906 cursor += possible_key.size;-
907-
908 if (possible_key.size > maximum_word_length)
possible_key.s...um_word_lengthDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 17 times by 1 test
Evaluated by:
  • ptx
17-23
909 maximum_word_length = possible_key.size;
executed 23 times by 1 test: maximum_word_length = possible_key.size;
Executed by:
  • ptx
23
910-
911 /* In input reference mode, update 'line_start' from its previous-
912 value. Count the lines just in case auto reference mode is-
913 also selected. If it happens that the word just matched is-
914 indeed part of a reference; just ignore it. */-
915-
916 if (input_reference)
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-40
917 {-
918 while (line_scan < possible_key.start)
line_scan < possible_key.startDescription
TRUEnever evaluated
FALSEnever evaluated
0
919 if (*line_scan == '\n')
*line_scan == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
920 {-
921 total_line_count++;-
922 line_scan++;-
923 line_start = line_scan;-
924 SKIP_NON_WHITE (line_scan, text_buffer->end);
never executed: line_scan++;
line_scan < text_buffer->endDescription
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
925 reference_length = line_scan - line_start;-
926 }
never executed: end of block
0
927 else-
928 line_scan++;
never executed: line_scan++;
0
929 if (line_scan > possible_key.start)
line_scan > possible_key.startDescription
TRUEnever evaluated
FALSEnever evaluated
0
930 continue;
never executed: continue;
0
931 }
never executed: end of block
0
932-
933 /* Ignore the word if an 'Ignore words' table exists and if it is-
934 part of it. Also ignore the word if an 'Only words' table and-
935 if it is *not* part of it.-
936-
937 It is allowed that both tables be used at once, even if this-
938 may look strange for now. Just ignore a word that would appear-
939 in both. If regexps are eventually implemented for these-
940 tables, the Ignore table could then reject words that would-
941 have been previously accepted by the Only table. */-
942-
943 if (ignore_file && search_table (&possible_key, &ignore_table))
ignore_fileDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
search_table (...&ignore_table)Description
TRUEnever evaluated
FALSEnever evaluated
0-40
944 continue;
never executed: continue;
0
945 if (only_file && !search_table (&possible_key, &only_table))
only_fileDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
!search_table ..., &only_table)Description
TRUEnever evaluated
FALSEnever evaluated
0-40
946 continue;
never executed: continue;
0
947-
948 /* A non-empty word has been found. First of all, insure-
949 proper allocation of the next OCCURS, and make a pointer to-
950 where it will be constructed. */-
951-
952 if (number_of_occurs[0] == occurs_alloc[0])
number_of_occu...ccurs_alloc[0]Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 14 times by 1 test
Evaluated by:
  • ptx
14-26
953 occurs_table[0] = x2nrealloc (occurs_table[0],
executed 26 times by 1 test: occurs_table[0] = x2nrealloc (occurs_table[0], &occurs_alloc[0], sizeof *occurs_table[0]);
Executed by:
  • ptx
26
954 &occurs_alloc[0],
executed 26 times by 1 test: occurs_table[0] = x2nrealloc (occurs_table[0], &occurs_alloc[0], sizeof *occurs_table[0]);
Executed by:
  • ptx
26
955 sizeof *occurs_table[0]);
executed 26 times by 1 test: occurs_table[0] = x2nrealloc (occurs_table[0], &occurs_alloc[0], sizeof *occurs_table[0]);
Executed by:
  • ptx
26
956 occurs_cursor = occurs_table[0] + number_of_occurs[0];-
957-
958 /* Define the reference field, if any. */-
959-
960 if (auto_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 39 times by 1 test
Evaluated by:
  • ptx
1-39
961 {-
962-
963 /* While auto referencing, update 'line_start' from its-
964 previous value, counting lines as we go. If input-
965 referencing at the same time, 'line_start' has been-
966 advanced earlier, and the following loop is never really-
967 executed. */-
968-
969 while (line_scan < possible_key.start)
line_scan < possible_key.startDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-1
970 if (*line_scan == '\n')
*line_scan == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
971 {-
972 total_line_count++;-
973 line_scan++;-
974 line_start = line_scan;-
975 SKIP_NON_WHITE (line_scan, text_buffer->end);
never executed: line_scan++;
line_scan < text_buffer->endDescription
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
976 }
never executed: end of block
0
977 else-
978 line_scan++;
never executed: line_scan++;
0
979-
980 occurs_cursor->reference = total_line_count;-
981 }
executed 1 time by 1 test: end of block
Executed by:
  • ptx
1
982 else if (input_reference)
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 39 times by 1 test
Evaluated by:
  • ptx
0-39
983 {-
984-
985 /* If only input referencing, 'line_start' has been computed-
986 earlier to detect the case the word matched would be part-
987 of the reference. The reference position is simply the-
988 value of 'line_start'. */-
989-
990 occurs_cursor->reference = line_start - possible_key.start;-
991 if (reference_length > reference_max_width)
reference_leng...ence_max_widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
992 reference_max_width = reference_length;
never executed: reference_max_width = reference_length;
0
993 }
never executed: end of block
0
994-
995 /* Exclude the reference from the context in simple cases. */-
996-
997 if (input_reference && line_start == context_start)
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
line_start == context_startDescription
TRUEnever evaluated
FALSEnever evaluated
0-40
998 {-
999 SKIP_NON_WHITE (context_start, context_end);
never executed: context_start++;
context_start < context_endDescription
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
1000 SKIP_WHITE (context_start, context_end);
never executed: context_start++;
context_start < context_endDescription
TRUEnever evaluated
FALSEnever evaluated
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
1001 }
never executed: end of block
0
1002-
1003 /* Completes the OCCURS structure. */-
1004-
1005 occurs_cursor->key = possible_key;-
1006 occurs_cursor->left = context_start - possible_key.start;-
1007 occurs_cursor->right = context_end - possible_key.start;-
1008 occurs_cursor->file_index = file_index;-
1009-
1010 number_of_occurs[0]++;-
1011 }
executed 40 times by 1 test: end of block
Executed by:
  • ptx
40
1012 }
executed 25 times by 1 test: end of block
Executed by:
  • ptx
25
1013}
executed 28 times by 1 test: end of block
Executed by:
  • ptx
28
1014-
1015/* Formatting and actual output - service routines. */-
1016-
1017/*-----------------------------------------.-
1018| Prints some NUMBER of spaces on stdout. |-
1019`-----------------------------------------*/-
1020-
1021static void-
1022print_spaces (ptrdiff_t number)-
1023{-
1024 for (ptrdiff_t counter = number; counter > 0; counter--)
counter > 0Description
TRUEevaluated 606 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 104 times by 1 test
Evaluated by:
  • ptx
104-606
1025 putchar (' ');
executed 606 times by 1 test: putchar_unlocked (' ');
Executed by:
  • ptx
606
1026}
executed 104 times by 1 test: end of block
Executed by:
  • ptx
104
1027-
1028/*-------------------------------------.-
1029| Prints the field provided by FIELD. |-
1030`-------------------------------------*/-
1031-
1032static void-
1033print_field (BLOCK field)-
1034{-
1035 char *cursor; /* Cursor in field to print */-
1036 int base; /* Base character, without diacritic */-
1037 int diacritic; /* Diacritic code for the character */-
1038-
1039 /* Whitespace is not really compressed. Instead, each white space-
1040 character (tab, vt, ht etc.) is printed as one single space. */-
1041-
1042 for (cursor = field.start; cursor < field.end; cursor++)
cursor < field.endDescription
TRUEevaluated 670 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 133 times by 1 test
Evaluated by:
  • ptx
133-670
1043 {-
1044 unsigned char character = *cursor;-
1045 if (edited_flag[character])
edited_flag[character]Description
TRUEevaluated 69 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 601 times by 1 test
Evaluated by:
  • ptx
69-601
1046 {-
1047-
1048 /* First check if this is a diacriticized character.-
1049-
1050 This works only for TeX. I do not know how diacriticized-
1051 letters work with 'roff'. Please someone explain it to me! */-
1052-
1053 diacritic = todiac (character);-
1054 if (diacritic != 0 && output_format == TEX_FORMAT)
diacritic != 0Description
TRUEnever evaluated
FALSEevaluated 69 times by 1 test
Evaluated by:
  • ptx
output_format == TEX_FORMATDescription
TRUEnever evaluated
FALSEnever evaluated
0-69
1055 {-
1056 base = tobase (character);-
1057 switch (diacritic)-
1058 {-
1059-
1060 case 1: /* Latin diphthongs */
never executed: case 1:
0
1061 switch (base)-
1062 {-
1063 case 'o':
never executed: case 'o':
0
1064 fputs ("\\oe{}", stdout);-
1065 break;
never executed: break;
0
1066-
1067 case 'O':
never executed: case 'O':
0
1068 fputs ("\\OE{}", stdout);-
1069 break;
never executed: break;
0
1070-
1071 case 'a':
never executed: case 'a':
0
1072 fputs ("\\ae{}", stdout);-
1073 break;
never executed: break;
0
1074-
1075 case 'A':
never executed: case 'A':
0
1076 fputs ("\\AE{}", stdout);-
1077 break;
never executed: break;
0
1078-
1079 default:
never executed: default:
0
1080 putchar (' ');-
1081 }
never executed: end of block
0
1082 break;
never executed: break;
0
1083-
1084 case 2: /* Acute accent */
never executed: case 2:
0
1085 printf ("\\'%s%c", (base == 'i' ? "\\" : ""), base);-
1086 break;
never executed: break;
0
1087-
1088 case 3: /* Grave accent */
never executed: case 3:
0
1089 printf ("\\'%s%c", (base == 'i' ? "\\" : ""), base);-
1090 break;
never executed: break;
0
1091-
1092 case 4: /* Circumflex accent */
never executed: case 4:
0
1093 printf ("\\^%s%c", (base == 'i' ? "\\" : ""), base);-
1094 break;
never executed: break;
0
1095-
1096 case 5: /* Diaeresis */
never executed: case 5:
0
1097 printf ("\\\"%s%c", (base == 'i' ? "\\" : ""), base);-
1098 break;
never executed: break;
0
1099-
1100 case 6: /* Tilde accent */
never executed: case 6:
0
1101 printf ("\\~%s%c", (base == 'i' ? "\\" : ""), base);-
1102 break;
never executed: break;
0
1103-
1104 case 7: /* Cedilla */
never executed: case 7:
0
1105 printf ("\\c{%c}", base);-
1106 break;
never executed: break;
0
1107-
1108 case 8: /* Small circle beneath */
never executed: case 8:
0
1109 switch (base)-
1110 {-
1111 case 'a':
never executed: case 'a':
0
1112 fputs ("\\aa{}", stdout);-
1113 break;
never executed: break;
0
1114-
1115 case 'A':
never executed: case 'A':
0
1116 fputs ("\\AA{}", stdout);-
1117 break;
never executed: break;
0
1118-
1119 default:
never executed: default:
0
1120 putchar (' ');-
1121 }
never executed: end of block
0
1122 break;
never executed: break;
0
1123-
1124 case 9: /* Strike through */
never executed: case 9:
0
1125 switch (base)-
1126 {-
1127 case 'o':
never executed: case 'o':
0
1128 fputs ("\\o{}", stdout);-
1129 break;
never executed: break;
0
1130-
1131 case 'O':
never executed: case 'O':
0
1132 fputs ("\\O{}", stdout);-
1133 break;
never executed: break;
0
1134-
1135 default:
never executed: default:
0
1136 putchar (' ');-
1137 }
never executed: end of block
0
1138 break;
never executed: break;
0
1139 }-
1140 }
never executed: end of block
0
1141 else-
1142-
1143 /* This is not a diacritic character, so handle cases which are-
1144 really specific to 'roff' or TeX. All white space processing-
1145 is done as the default case of this switch. */-
1146-
1147 switch (character)-
1148 {-
1149 case '"':
never executed: case '"':
0
1150 /* In roff output format, double any quote. */-
1151 putchar ('"');-
1152 putchar ('"');-
1153 break;
never executed: break;
0
1154-
1155 case '$':
never executed: case '$':
0
1156 case '%':
never executed: case '%':
0
1157 case '&':
never executed: case '&':
0
1158 case '#':
never executed: case '#':
0
1159 case '_':
never executed: case '_':
0
1160 /* In TeX output format, precede these with a backslash. */-
1161 putchar ('\\');-
1162 putchar (character);-
1163 break;
never executed: break;
0
1164-
1165 case '{':
never executed: case '{':
0
1166 case '}':
never executed: case '}':
0
1167 /* In TeX output format, precede these with a backslash and-
1168 force mathematical mode. */-
1169 printf ("$\\%c$", character);-
1170 break;
never executed: break;
0
1171-
1172 case '\\':
never executed: case '\\':
0
1173 /* In TeX output mode, request production of a backslash. */-
1174 fputs ("\\backslash{}", stdout);-
1175 break;
never executed: break;
0
1176-
1177 default:
executed 69 times by 1 test: default:
Executed by:
  • ptx
69
1178 /* Any other flagged character produces a single space. */-
1179 putchar (' ');-
1180 }
executed 69 times by 1 test: end of block
Executed by:
  • ptx
69
1181 }-
1182 else-
1183 putchar (*cursor);
executed 601 times by 1 test: putchar_unlocked (*cursor);
Executed by:
  • ptx
601
1184 }-
1185}
executed 133 times by 1 test: end of block
Executed by:
  • ptx
133
1186-
1187/* Formatting and actual output - planning routines. */-
1188-
1189/*--------------------------------------------------------------------.-
1190| From information collected from command line options and input file |-
1191| readings, compute and fix some output parameter values. |-
1192`--------------------------------------------------------------------*/-
1193-
1194static void-
1195fix_output_parameters (void)-
1196{-
1197 size_t file_index; /* index in text input file arrays */-
1198 intmax_t line_ordinal; /* line ordinal value for reference */-
1199 ptrdiff_t reference_width; /* width for the whole reference */-
1200 int character; /* character ordinal */-
1201 const char *cursor; /* cursor in some constant strings */-
1202-
1203 /* In auto reference mode, the maximum width of this field is-
1204 precomputed and subtracted from the overall line width. Add one for-
1205 the column which separate the file name from the line number. */-
1206-
1207 if (auto_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
1-25
1208 {-
1209 reference_max_width = 0;-
1210 for (file_index = 0; file_index < number_input_files; file_index++)
file_index < n...er_input_filesDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
1
1211 {-
1212 line_ordinal = file_line_count[file_index] + 1;-
1213 if (file_index > 0)
file_index > 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-1
1214 line_ordinal -= file_line_count[file_index - 1];
never executed: line_ordinal -= file_line_count[file_index - 1];
0
1215 char ordinal_string[INT_BUFSIZE_BOUND (intmax_t)];-
1216 reference_width = sprintf (ordinal_string, "%"PRIdMAX, line_ordinal);-
1217 if (input_file_name[file_index])
input_file_name[file_index]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-1
1218 reference_width += strlen (input_file_name[file_index]);
executed 1 time by 1 test: reference_width += strlen (input_file_name[file_index]);
Executed by:
  • ptx
1
1219 if (reference_width > reference_max_width)
reference_widt...ence_max_widthDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-1
1220 reference_max_width = reference_width;
executed 1 time by 1 test: reference_max_width = reference_width;
Executed by:
  • ptx
1
1221 }
executed 1 time by 1 test: end of block
Executed by:
  • ptx
1
1222 reference_max_width++;-
1223 reference.start = xmalloc (reference_max_width + 1);-
1224 }
executed 1 time by 1 test: end of block
Executed by:
  • ptx
1
1225-
1226 /* If the reference appears to the left of the output line, reserve some-
1227 space for it right away, including one gap size. */-
1228-
1229 if ((auto_reference || input_reference) && !right_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
!right_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-25
1230 line_width -= reference_max_width + gap_size;
executed 1 time by 1 test: line_width -= reference_max_width + gap_size;
Executed by:
  • ptx
1
1231 if (line_width < 0)
line_width < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 25 times by 1 test
Evaluated by:
  • ptx
1-25
1232 line_width = 0;
executed 1 time by 1 test: line_width = 0;
Executed by:
  • ptx
1
1233-
1234 /* The output lines, minimally, will contain from left to right a left-
1235 context, a gap, and a keyword followed by the right context with no-
1236 special intervening gap. Half of the line width is dedicated to the-
1237 left context and the gap, the other half is dedicated to the keyword-
1238 and the right context; these values are computed once and for all here.-
1239 There also are tail and head wrap around fields, used when the keyword-
1240 is near the beginning or the end of the line, or when some long word-
1241 cannot fit in, but leave place from wrapped around shorter words. The-
1242 maximum width of these fields are recomputed separately for each line,-
1243 on a case by case basis. It is worth noting that it cannot happen that-
1244 both the tail and head fields are used at once. */-
1245-
1246 half_line_width = line_width / 2;-
1247 before_max_width = half_line_width - gap_size;-
1248 keyafter_max_width = half_line_width;-
1249-
1250 /* If truncation_string is the empty string, make it NULL to speed up-
1251 tests. In this case, truncation_string_length will never get used, so-
1252 there is no need to set it. */-
1253-
1254 if (truncation_string && *truncation_string)
truncation_stringDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
*truncation_stringDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-26
1255 truncation_string_length = strlen (truncation_string);
executed 25 times by 1 test: truncation_string_length = strlen (truncation_string);
Executed by:
  • ptx
25
1256 else-
1257 truncation_string = NULL;
executed 1 time by 1 test: truncation_string = ((void *)0) ;
Executed by:
  • ptx
1
1258-
1259 if (gnu_extensions)
gnu_extensionsDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-26
1260 {-
1261-
1262 /* When flagging truncation at the left of the keyword, the-
1263 truncation mark goes at the beginning of the before field,-
1264 unless there is a head field, in which case the mark goes at the-
1265 left of the head field. When flagging truncation at the right-
1266 of the keyword, the mark goes at the end of the keyafter field,-
1267 unless there is a tail field, in which case the mark goes at the-
1268 end of the tail field. Only eight combination cases could arise-
1269 for truncation marks:-
1270-
1271 . None.-
1272 . One beginning the before field.-
1273 . One beginning the head field.-
1274 . One ending the keyafter field.-
1275 . One ending the tail field.-
1276 . One beginning the before field, another ending the keyafter field.-
1277 . One ending the tail field, another beginning the before field.-
1278 . One ending the keyafter field, another beginning the head field.-
1279-
1280 So, there is at most two truncation marks, which could appear both-
1281 on the left side of the center of the output line, both on the-
1282 right side, or one on either side. */-
1283-
1284 before_max_width -= 2 * truncation_string_length;-
1285 if (before_max_width < 0)
before_max_width < 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ptx
8-18
1286 before_max_width = 0;
executed 8 times by 1 test: before_max_width = 0;
Executed by:
  • ptx
8
1287 keyafter_max_width -= 2 * truncation_string_length;-
1288 }
executed 26 times by 1 test: end of block
Executed by:
  • ptx
26
1289 else-
1290 {-
1291-
1292 /* I never figured out exactly how UNIX' ptx plans the output width-
1293 of its various fields. If GNU extensions are disabled, do not-
1294 try computing the field widths correctly; instead, use the-
1295 following formula, which does not completely imitate UNIX' ptx,-
1296 but almost. */-
1297-
1298 keyafter_max_width -= 2 * truncation_string_length + 1;-
1299 }
never executed: end of block
0
1300-
1301 /* Compute which characters need special output processing. Initialize-
1302 by flagging any white space character. Some systems do not consider-
1303 form feed as a space character, but we do. */-
1304-
1305 for (character = 0; character < CHAR_SET_SIZE; character++)
character < 256Description
TRUEevaluated 6656 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 26 times by 1 test
Evaluated by:
  • ptx
26-6656
1306 edited_flag[character] = !! isspace (character);
executed 6656 times by 1 test: edited_flag[character] = !! ((*__ctype_b_loc ())[(int) (( character ))] & (unsigned short int) _ISspace) ;
Executed by:
  • ptx
6656
1307 edited_flag['\f'] = 1;-
1308-
1309 /* Complete the special character flagging according to selected output-
1310 format. */-
1311-
1312 switch (output_format)-
1313 {-
1314 case UNKNOWN_FORMAT:
never executed: case UNKNOWN_FORMAT:
0
1315 /* Should never happen. */-
1316-
1317 case DUMB_FORMAT:
executed 20 times by 1 test: case DUMB_FORMAT:
Executed by:
  • ptx
20
1318 break;
executed 20 times by 1 test: break;
Executed by:
  • ptx
20
1319-
1320 case ROFF_FORMAT:
executed 3 times by 1 test: case ROFF_FORMAT:
Executed by:
  • ptx
3
1321-
1322 /* 'Quote' characters should be doubled. */-
1323-
1324 edited_flag['"'] = 1;-
1325 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1326-
1327 case TEX_FORMAT:
executed 3 times by 1 test: case TEX_FORMAT:
Executed by:
  • ptx
3
1328-
1329 /* Various characters need special processing. */-
1330-
1331 for (cursor = "$%&#_{}\\"; *cursor; cursor++)
*cursorDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
3-24
1332 edited_flag[to_uchar (*cursor)] = 1;
executed 24 times by 1 test: edited_flag[to_uchar (*cursor)] = 1;
Executed by:
  • ptx
24
1333-
1334 /* Any character with 8th bit set will print to a single space, unless-
1335 it is diacriticized. */-
1336-
1337 for (character = 0200; character < CHAR_SET_SIZE; character++)
character < 256Description
TRUEevaluated 384 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
3-384
1338 edited_flag[character] = todiac (character) != 0;
executed 384 times by 1 test: edited_flag[character] = (diacrit_diac[(unsigned char) (character)]) != 0;
Executed by:
  • ptx
384
1339 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1340 }-
1341}
executed 26 times by 1 test: end of block
Executed by:
  • ptx
26
1342-
1343/*------------------------------------------------------------------.-
1344| Compute the position and length of all the output fields, given a |-
1345| pointer to some OCCURS. |-
1346`------------------------------------------------------------------*/-
1347-
1348static void-
1349define_all_fields (OCCURS *occurs)-
1350{-
1351 ptrdiff_t tail_max_width; /* allowable width of tail field */-
1352 ptrdiff_t head_max_width; /* allowable width of head field */-
1353 char *cursor; /* running cursor in source text */-
1354 char *left_context_start; /* start of left context */-
1355 char *right_context_end; /* end of right context */-
1356 char *left_field_start; /* conservative start for 'head'/'before' */-
1357 const char *file_name; /* file name for reference */-
1358 intmax_t line_ordinal; /* line ordinal for reference */-
1359 const char *buffer_start; /* start of buffered file for this occurs */-
1360 const char *buffer_end; /* end of buffered file for this occurs */-
1361-
1362 /* Define 'keyafter', start of left context and end of right context.-
1363 'keyafter' starts at the saved position for keyword and extend to the-
1364 right from the end of the keyword, eating separators or full words, but-
1365 not beyond maximum allowed width for 'keyafter' field or limit for the-
1366 right context. Suffix spaces will be removed afterwards. */-
1367-
1368 keyafter.start = occurs->key.start;-
1369 keyafter.end = keyafter.start + occurs->key.size;-
1370 left_context_start = keyafter.start + occurs->left;-
1371 right_context_end = keyafter.start + occurs->right;-
1372-
1373 buffer_start = text_buffers[occurs->file_index].start;-
1374 buffer_end = text_buffers[occurs->file_index].end;-
1375-
1376 cursor = keyafter.end;-
1377 while (cursor < right_context_end
cursor < right_context_endDescription
TRUEevaluated 92 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 37 times by 1 test
Evaluated by:
  • ptx
37-92
1378 && cursor <= keyafter.start + keyafter_max_width)
cursor <= keya...fter_max_widthDescription
TRUEevaluated 89 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
3-89
1379 {-
1380 keyafter.end = cursor;-
1381 SKIP_SOMETHING (cursor, right_context_end);
never executed: matcher_error ();
never executed: end of block
executed 235 times by 1 test: cursor++;
Executed by:
  • ptx
executed 46 times by 1 test: cursor++;
Executed by:
  • ptx
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 89 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 43 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 46 times by 1 test
Evaluated by:
  • ptx
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
cursor < right_context_endDescription
TRUEevaluated 265 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 13 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 235 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 30 times by 1 test
Evaluated by:
  • ptx
0-265
1382 }
executed 89 times by 1 test: end of block
Executed by:
  • ptx
89
1383 if (cursor <= keyafter.start + keyafter_max_width)
cursor <= keya...fter_max_widthDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 14 times by 1 test
Evaluated by:
  • ptx
14-26
1384 keyafter.end = cursor;
executed 26 times by 1 test: keyafter.end = cursor;
Executed by:
  • ptx
26
1385-
1386 keyafter_truncation = truncation_string && keyafter.end < right_context_end;
truncation_stringDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
keyafter.end <...ht_context_endDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 35 times by 1 test
Evaluated by:
  • ptx
0-40
1387-
1388 SKIP_WHITE_BACKWARDS (keyafter.end, keyafter.start);
executed 2 times by 1 test: keyafter.end--;
Executed by:
  • ptx
keyafter.end > keyafter.startDescription
TRUEevaluated 42 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-42
1389-
1390 /* When the left context is wide, it might take some time to catch up from-
1391 the left context boundary to the beginning of the 'head' or 'before'-
1392 fields. So, in this case, to speed the catchup, we jump back from the-
1393 keyword, using some secure distance, possibly falling in the middle of-
1394 a word. A secure backward jump would be at least half the maximum-
1395 width of a line, plus the size of the longest word met in the whole-
1396 input. We conclude this backward jump by a skip forward of at least-
1397 one word. In this manner, we should not inadvertently accept only part-
1398 of a word. From the reached point, when it will be time to fix the-
1399 beginning of 'head' or 'before' fields, we will skip forward words or-
1400 delimiters until we get sufficiently near. */-
1401-
1402 if (-occurs->left > half_line_width + maximum_word_length)
-occurs->left ...um_word_lengthDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-40
1403 {-
1404 left_field_start-
1405 = keyafter.start - (half_line_width + maximum_word_length);-
1406 SKIP_SOMETHING (left_field_start, keyafter.start);
never executed: matcher_error ();
never executed: end of block
never executed: left_field_start++;
never executed: left_field_start++;
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEnever evaluated
word_fastmap[t..._field_start)]Description
TRUEnever evaluated
FALSEnever evaluated
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
left_field_sta...keyafter.startDescription
TRUEnever evaluated
FALSEnever evaluated
word_fastmap[t..._field_start)]Description
TRUEnever evaluated
FALSEnever evaluated
0
1407 }
never executed: end of block
0
1408 else-
1409 left_field_start = keyafter.start + occurs->left;
executed 40 times by 1 test: left_field_start = keyafter.start + occurs->left;
Executed by:
  • ptx
40
1410-
1411 /* 'before' certainly ends at the keyword, but not including separating-
1412 spaces. It starts after than the saved value for the left context, by-
1413 advancing it until it falls inside the maximum allowed width for the-
1414 before field. There will be no prefix spaces either. 'before' only-
1415 advances by skipping single separators or whole words. */-
1416-
1417 before.start = left_field_start;-
1418 before.end = keyafter.start;-
1419 SKIP_WHITE_BACKWARDS (before.end, before.start);
executed 16 times by 1 test: before.end--;
Executed by:
  • ptx
before.end > before.startDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 24 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 16 times by 1 test
Evaluated by:
  • ptx
16-32
1420-
1421 while (before.start + before_max_width < before.end)
before.start +...h < before.endDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
5-40
1422 SKIP_SOMETHING (before.start, before.end);
never executed: matcher_error ();
never executed: end of block
executed 17 times by 1 test: before.start++;
Executed by:
  • ptx
never executed: before.start++;
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...before.start)]Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
before.start < before.endDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...before.start)]Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-19
1423-
1424 if (truncation_string)
truncation_stringDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-40
1425 {-
1426 cursor = before.start;-
1427 SKIP_WHITE_BACKWARDS (cursor, buffer_start);
never executed: cursor--;
cursor > buffer_startDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 35 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • ptx
0-35
1428 before_truncation = cursor > left_context_start;-
1429 }
executed 40 times by 1 test: end of block
Executed by:
  • ptx
40
1430 else-
1431 before_truncation = false;
never executed: before_truncation = 0 ;
0
1432-
1433 SKIP_WHITE (before.start, buffer_end);
executed 5 times by 1 test: before.start++;
Executed by:
  • ptx
before.start < buffer_endDescription
TRUEevaluated 45 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 40 times by 1 test
Evaluated by:
  • ptx
0-45
1434-
1435 /* The tail could not take more columns than what has been left in the-
1436 left context field, and a gap is mandatory. It starts after the-
1437 right context, and does not contain prefixed spaces. It ends at-
1438 the end of line, the end of buffer or when the tail field is full,-
1439 whichever comes first. It cannot contain only part of a word, and-
1440 has no suffixed spaces. */-
1441-
1442 tail_max_width-
1443 = before_max_width - (before.end - before.start) - gap_size;-
1444-
1445 if (tail_max_width > 0)
tail_max_width > 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 20 times by 1 test
Evaluated by:
  • ptx
20
1446 {-
1447 tail.start = keyafter.end;-
1448 SKIP_WHITE (tail.start, buffer_end);
executed 20 times by 1 test: tail.start++;
Executed by:
  • ptx
tail.start < buffer_endDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
2-22
1449-
1450 tail.end = tail.start;-
1451 cursor = tail.end;-
1452 while (cursor < right_context_end
cursor < right_context_endDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 20 times by 1 test
Evaluated by:
  • ptx
2-20
1453 && cursor < tail.start + tail_max_width)
cursor < tail....tail_max_widthDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-2
1454 {-
1455 tail.end = cursor;-
1456 SKIP_SOMETHING (cursor, right_context_end);
never executed: matcher_error ();
never executed: end of block
executed 8 times by 1 test: cursor++;
Executed by:
  • ptx
never executed: cursor++;
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
cursor < right_context_endDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-8
1457 }
executed 2 times by 1 test: end of block
Executed by:
  • ptx
2
1458-
1459 if (cursor < tail.start + tail_max_width)
cursor < tail....tail_max_widthDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-20
1460 tail.end = cursor;
executed 20 times by 1 test: tail.end = cursor;
Executed by:
  • ptx
20
1461-
1462 if (tail.end > tail.start)
tail.end > tail.startDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ptx
2-18
1463 {-
1464 keyafter_truncation = false;-
1465 tail_truncation = truncation_string && tail.end < right_context_end;
truncation_stringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
tail.end < right_context_endDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-2
1466 }
executed 2 times by 1 test: end of block
Executed by:
  • ptx
2
1467 else-
1468 tail_truncation = false;
executed 18 times by 1 test: tail_truncation = 0 ;
Executed by:
  • ptx
18
1469-
1470 SKIP_WHITE_BACKWARDS (tail.end, tail.start);
never executed: tail.end--;
tail.end > tail.startDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-18
1471 }
executed 20 times by 1 test: end of block
Executed by:
  • ptx
20
1472 else-
1473 {-
1474-
1475 /* No place left for a tail field. */-
1476-
1477 tail.start = NULL;-
1478 tail.end = NULL;-
1479 tail_truncation = false;-
1480 }
executed 20 times by 1 test: end of block
Executed by:
  • ptx
20
1481-
1482 /* 'head' could not take more columns than what has been left in the right-
1483 context field, and a gap is mandatory. It ends before the left-
1484 context, and does not contain suffixed spaces. Its pointer is advanced-
1485 until the head field has shrunk to its allowed width. It cannot-
1486 contain only part of a word, and has no suffixed spaces. */-
1487-
1488 head_max_width-
1489 = keyafter_max_width - (keyafter.end - keyafter.start) - gap_size;-
1490-
1491 if (head_max_width > 0)
head_max_width > 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 22 times by 1 test
Evaluated by:
  • ptx
18-22
1492 {-
1493 head.end = before.start;-
1494 SKIP_WHITE_BACKWARDS (head.end, buffer_start);
executed 2 times by 1 test: head.end--;
Executed by:
  • ptx
head.end > buffer_startDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 16 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
2-16
1495-
1496 head.start = left_field_start;-
1497 while (head.start + head_max_width < head.end)
head.start + h...dth < head.endDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ptx
0-18
1498 SKIP_SOMETHING (head.start, head.end);
never executed: matcher_error ();
never executed: end of block
never executed: head.start++;
never executed: head.start++;
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEnever evaluated
word_fastmap[t...(*head.start)]Description
TRUEnever evaluated
FALSEnever evaluated
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
head.start < head.endDescription
TRUEnever evaluated
FALSEnever evaluated
word_fastmap[t...(*head.start)]Description
TRUEnever evaluated
FALSEnever evaluated
0
1499-
1500 if (head.end > head.start)
head.end > head.startDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 16 times by 1 test
Evaluated by:
  • ptx
2-16
1501 {-
1502 before_truncation = false;-
1503 head_truncation = (truncation_string
truncation_stringDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-2
1504 && head.start > left_context_start);
head.start > l..._context_startDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-2
1505 }
executed 2 times by 1 test: end of block
Executed by:
  • ptx
2
1506 else-
1507 head_truncation = false;
executed 16 times by 1 test: head_truncation = 0 ;
Executed by:
  • ptx
16
1508-
1509 SKIP_WHITE (head.start, head.end);
never executed: head.start++;
head.start < head.endDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 16 times by 1 test
Evaluated by:
  • ptx
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-16
1510 }
executed 18 times by 1 test: end of block
Executed by:
  • ptx
18
1511 else-
1512 {-
1513-
1514 /* No place left for a head field. */-
1515-
1516 head.start = NULL;-
1517 head.end = NULL;-
1518 head_truncation = false;-
1519 }
executed 22 times by 1 test: end of block
Executed by:
  • ptx
22
1520-
1521 if (auto_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 39 times by 1 test
Evaluated by:
  • ptx
1-39
1522 {-
1523-
1524 /* Construct the reference text in preallocated space from the file-
1525 name and the line number. Standard input yields an empty file name.-
1526 Ensure line numbers are 1 based, even if they are computed 0 based. */-
1527-
1528 file_name = input_file_name[occurs->file_index];-
1529 if (!file_name)
!file_nameDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-1
1530 file_name = "";
never executed: file_name = "";
0
1531-
1532 line_ordinal = occurs->reference + 1;-
1533 if (occurs->file_index > 0)
occurs->file_index > 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-1
1534 line_ordinal -= file_line_count[occurs->file_index - 1];
never executed: line_ordinal -= file_line_count[occurs->file_index - 1];
0
1535-
1536 char *file_end = stpcpy (reference.start, file_name);-
1537 reference.end = file_end + sprintf (file_end, ":%"PRIdMAX, line_ordinal);-
1538 }
executed 1 time by 1 test: end of block
Executed by:
  • ptx
1
1539 else if (input_reference)
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 39 times by 1 test
Evaluated by:
  • ptx
0-39
1540 {-
1541-
1542 /* Reference starts at saved position for reference and extends right-
1543 until some white space is met. */-
1544-
1545 reference.start = keyafter.start + occurs->reference;-
1546 reference.end = reference.start;-
1547 SKIP_NON_WHITE (reference.end, right_context_end);
never executed: reference.end++;
reference.end ...ht_context_endDescription
TRUEnever evaluated
FALSEnever evaluated
! ((*__ctype_b...int) _ISspace)Description
TRUEnever evaluated
FALSEnever evaluated
0
1548 }
never executed: end of block
0
1549}
executed 40 times by 1 test: end of block
Executed by:
  • ptx
40
1550-
1551/* Formatting and actual output - control routines. */-
1552-
1553/*----------------------------------------------------------------------.-
1554| Output the current output fields as one line for 'troff' or 'nroff'. |-
1555`----------------------------------------------------------------------*/-
1556-
1557static void-
1558output_one_roff_line (void)-
1559{-
1560 /* Output the 'tail' field. */-
1561-
1562 printf (".%s \"", macro_name);-
1563 print_field (tail);-
1564 if (tail_truncation)
tail_truncationDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1565 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1566 putchar ('"');-
1567-
1568 /* Output the 'before' field. */-
1569-
1570 fputs (" \"", stdout);-
1571 if (before_truncation)
before_truncationDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1572 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1573 print_field (before);-
1574 putchar ('"');-
1575-
1576 /* Output the 'keyafter' field. */-
1577-
1578 fputs (" \"", stdout);-
1579 print_field (keyafter);-
1580 if (keyafter_truncation)
keyafter_truncationDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1581 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1582 putchar ('"');-
1583-
1584 /* Output the 'head' field. */-
1585-
1586 fputs (" \"", stdout);-
1587 if (head_truncation)
head_truncationDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1588 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1589 print_field (head);-
1590 putchar ('"');-
1591-
1592 /* Conditionally output the 'reference' field. */-
1593-
1594 if (auto_reference || input_reference)
auto_referenceDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1595 {-
1596 fputs (" \"", stdout);-
1597 print_field (reference);-
1598 putchar ('"');-
1599 }
never executed: end of block
0
1600-
1601 putchar ('\n');-
1602}
executed 3 times by 1 test: end of block
Executed by:
  • ptx
3
1603-
1604/*---------------------------------------------------------.-
1605| Output the current output fields as one line for 'TeX'. |-
1606`---------------------------------------------------------*/-
1607-
1608static void-
1609output_one_tex_line (void)-
1610{-
1611 BLOCK key; /* key field, isolated */-
1612 BLOCK after; /* after field, isolated */-
1613 char *cursor; /* running cursor in source text */-
1614-
1615 printf ("\\%s ", macro_name);-
1616 putchar ('{');-
1617 print_field (tail);-
1618 fputs ("}{", stdout);-
1619 print_field (before);-
1620 fputs ("}{", stdout);-
1621 key.start = keyafter.start;-
1622 after.end = keyafter.end;-
1623 cursor = keyafter.start;-
1624 SKIP_SOMETHING (cursor, keyafter.end);
never executed: matcher_error ();
never executed: end of block
executed 9 times by 1 test: cursor++;
Executed by:
  • ptx
never executed: cursor++;
count == -2Description
TRUEnever evaluated
FALSEnever evaluated
word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
count == -1Description
TRUEnever evaluated
FALSEnever evaluated
cursor < keyafter.endDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
word_fastmap[t...har (*cursor)]Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-9
1625 key.end = cursor;-
1626 after.start = cursor;-
1627 print_field (key);-
1628 fputs ("}{", stdout);-
1629 print_field (after);-
1630 fputs ("}{", stdout);-
1631 print_field (head);-
1632 putchar ('}');-
1633 if (auto_reference || input_reference)
auto_referenceDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
1634 {-
1635 putchar ('{');-
1636 print_field (reference);-
1637 putchar ('}');-
1638 }
never executed: end of block
0
1639 putchar ('\n');-
1640}
executed 3 times by 1 test: end of block
Executed by:
  • ptx
3
1641-
1642/*-------------------------------------------------------------------.-
1643| Output the current output fields as one line for a dumb terminal. |-
1644`-------------------------------------------------------------------*/-
1645-
1646static void-
1647output_one_dumb_line (void)-
1648{-
1649 if (!right_reference)
!right_referenceDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-34
1650 {-
1651 if (auto_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 33 times by 1 test
Evaluated by:
  • ptx
1-33
1652 {-
1653-
1654 /* Output the 'reference' field, in such a way that GNU emacs-
1655 next-error will handle it. The ending colon is taken from the-
1656 gap which follows. */-
1657-
1658 print_field (reference);-
1659 putchar (':');-
1660 print_spaces (reference_max_width-
1661 + gap_size-
1662 - (reference.end - reference.start)-
1663 - 1);-
1664 }
executed 1 time by 1 test: end of block
Executed by:
  • ptx
1
1665 else-
1666 {-
1667-
1668 /* Output the 'reference' field and its following gap. */-
1669-
1670 print_field (reference);-
1671 print_spaces (reference_max_width-
1672 + gap_size-
1673 - (reference.end - reference.start));-
1674 }
executed 33 times by 1 test: end of block
Executed by:
  • ptx
33
1675 }-
1676-
1677 if (tail.start < tail.end)
tail.start < tail.endDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 32 times by 1 test
Evaluated by:
  • ptx
2-32
1678 {-
1679 /* Output the 'tail' field. */-
1680-
1681 print_field (tail);-
1682 if (tail_truncation)
tail_truncationDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-2
1683 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1684-
1685 print_spaces (half_line_width - gap_size-
1686 - (before.end - before.start)-
1687 - (before_truncation ? truncation_string_length : 0)-
1688 - (tail.end - tail.start)-
1689 - (tail_truncation ? truncation_string_length : 0));-
1690 }
executed 2 times by 1 test: end of block
Executed by:
  • ptx
2
1691 else-
1692 print_spaces (half_line_width - gap_size
executed 32 times by 1 test: print_spaces (half_line_width - gap_size - (before.end - before.start) - (before_truncation ? truncation_string_length : 0));
Executed by:
  • ptx
32
1693 - (before.end - before.start)
executed 32 times by 1 test: print_spaces (half_line_width - gap_size - (before.end - before.start) - (before_truncation ? truncation_string_length : 0));
Executed by:
  • ptx
32
1694 - (before_truncation ? truncation_string_length : 0));
executed 32 times by 1 test: print_spaces (half_line_width - gap_size - (before.end - before.start) - (before_truncation ? truncation_string_length : 0));
Executed by:
  • ptx
32
1695-
1696 /* Output the 'before' field. */-
1697-
1698 if (before_truncation)
before_truncationDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
3-31
1699 fputs (truncation_string, stdout);
executed 3 times by 1 test: fputs_unlocked (truncation_string, stdout );
Executed by:
  • ptx
3
1700 print_field (before);-
1701-
1702 print_spaces (gap_size);-
1703-
1704 /* Output the 'keyafter' field. */-
1705-
1706 print_field (keyafter);-
1707 if (keyafter_truncation)
keyafter_truncationDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
3-31
1708 fputs (truncation_string, stdout);
executed 3 times by 1 test: fputs_unlocked (truncation_string, stdout );
Executed by:
  • ptx
3
1709-
1710 if (head.start < head.end)
head.start < head.endDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 32 times by 1 test
Evaluated by:
  • ptx
2-32
1711 {-
1712 /* Output the 'head' field. */-
1713-
1714 print_spaces (half_line_width-
1715 - (keyafter.end - keyafter.start)-
1716 - (keyafter_truncation ? truncation_string_length : 0)-
1717 - (head.end - head.start)-
1718 - (head_truncation ? truncation_string_length : 0));-
1719 if (head_truncation)
head_truncationDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
0-2
1720 fputs (truncation_string, stdout);
never executed: fputs_unlocked (truncation_string, stdout );
0
1721 print_field (head);-
1722 }
executed 2 times by 1 test: end of block
Executed by:
  • ptx
2
1723 else-
1724-
1725 if ((auto_reference || input_reference) && right_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
right_referenceDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-31
1726 print_spaces (half_line_width
never executed: print_spaces (half_line_width - (keyafter.end - keyafter.start) - (keyafter_truncation ? truncation_string_length : 0));
0
1727 - (keyafter.end - keyafter.start)
never executed: print_spaces (half_line_width - (keyafter.end - keyafter.start) - (keyafter_truncation ? truncation_string_length : 0));
0
1728 - (keyafter_truncation ? truncation_string_length : 0));
never executed: print_spaces (half_line_width - (keyafter.end - keyafter.start) - (keyafter_truncation ? truncation_string_length : 0));
0
1729-
1730 if ((auto_reference || input_reference) && right_reference)
auto_referenceDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • ptx
FALSEevaluated 33 times by 1 test
Evaluated by:
  • ptx
input_referenceDescription
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • ptx
right_referenceDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • ptx
0-33
1731 {-
1732 /* Output the 'reference' field. */-
1733-
1734 print_spaces (gap_size);-
1735 print_field (reference);-
1736 }
never executed: end of block
0
1737-
1738 putchar ('\n');-
1739}
executed 34 times by 1 test: end of block
Executed by:
  • ptx
34
1740-
1741/*------------------------------------------------------------------------.-
1742| Scan the whole occurs table and, for each entry, output one line in the |-
1743| appropriate format. |-
1744`------------------------------------------------------------------------*/-
1745-
1746static void-
1747generate_all_output (void)-
1748{-
1749 ptrdiff_t occurs_index; /* index of keyword entry being processed */-
1750 OCCURS *occurs_cursor; /* current keyword entry being processed */-
1751-
1752 /* The following assignments are useful to provide default values in case-
1753 line contexts or references are not used, in which case these variables-
1754 would never be computed. */-
1755-
1756 tail.start = NULL;-
1757 tail.end = NULL;-
1758 tail_truncation = false;-
1759-
1760 head.start = NULL;-
1761 head.end = NULL;-
1762 head_truncation = false;-
1763-
1764 /* Loop over all keyword occurrences. */-
1765-
1766 occurs_cursor = occurs_table[0];-
1767-
1768 for (occurs_index = 0; occurs_index < number_of_occurs[0]; occurs_index++)
occurs_index <...r_of_occurs[0]Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 26 times by 1 test
Evaluated by:
  • ptx
26-40
1769 {-
1770 /* Compute the exact size of every field and whenever truncation flags-
1771 are present or not. */-
1772-
1773 define_all_fields (occurs_cursor);-
1774-
1775 /* Produce one output line according to selected format. */-
1776-
1777 switch (output_format)-
1778 {-
1779 case UNKNOWN_FORMAT:
never executed: case UNKNOWN_FORMAT:
0
1780 /* Should never happen. */-
1781-
1782 case DUMB_FORMAT:
executed 34 times by 1 test: case DUMB_FORMAT:
Executed by:
  • ptx
34
1783 output_one_dumb_line ();-
1784 break;
executed 34 times by 1 test: break;
Executed by:
  • ptx
34
1785-
1786 case ROFF_FORMAT:
executed 3 times by 1 test: case ROFF_FORMAT:
Executed by:
  • ptx
3
1787 output_one_roff_line ();-
1788 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1789-
1790 case TEX_FORMAT:
executed 3 times by 1 test: case TEX_FORMAT:
Executed by:
  • ptx
3
1791 output_one_tex_line ();-
1792 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1793 }-
1794-
1795 /* Advance the cursor into the occurs table. */-
1796-
1797 occurs_cursor++;-
1798 }
executed 40 times by 1 test: end of block
Executed by:
  • ptx
40
1799}
executed 26 times by 1 test: end of block
Executed by:
  • ptx
26
1800-
1801/* Option decoding and main program. */-
1802-
1803/*------------------------------------------------------.-
1804| Print program identification and options, then exit. |-
1805`------------------------------------------------------*/-
1806-
1807void-
1808usage (int status)-
1809{-
1810 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 31 times by 1 test
Evaluated by:
  • ptx
5-31
1811 emit_try_help ();
executed 5 times by 1 test: end of block
Executed by:
  • ptx
5
1812 else-
1813 {-
1814 printf (_("\-
1815Usage: %s [OPTION]... [INPUT]... (without -G)\n\-
1816 or: %s -G [OPTION]... [INPUT [OUTPUT]]\n"),-
1817 program_name, program_name);-
1818 fputs (_("\-
1819Output a permuted index, including context, of the words in the input files.\n\-
1820"), stdout);-
1821-
1822 emit_stdin_note ();-
1823 emit_mandatory_arg_note ();-
1824-
1825 fputs (_("\-
1826 -A, --auto-reference output automatically generated references\n\-
1827 -G, --traditional behave more like System V 'ptx'\n\-
1828"), stdout);-
1829 fputs (_("\-
1830 -F, --flag-truncation=STRING use STRING for flagging line truncations.\n\-
1831 The default is '/'\n\-
1832"), stdout);-
1833 fputs (_("\-
1834 -M, --macro-name=STRING macro name to use instead of 'xx'\n\-
1835 -O, --format=roff generate output as roff directives\n\-
1836 -R, --right-side-refs put references at right, not counted in -w\n\-
1837 -S, --sentence-regexp=REGEXP for end of lines or end of sentences\n\-
1838 -T, --format=tex generate output as TeX directives\n\-
1839"), stdout);-
1840 fputs (_("\-
1841 -W, --word-regexp=REGEXP use REGEXP to match each keyword\n\-
1842 -b, --break-file=FILE word break characters in this FILE\n\-
1843 -f, --ignore-case fold lower case to upper case for sorting\n\-
1844 -g, --gap-size=NUMBER gap size in columns between output fields\n\-
1845 -i, --ignore-file=FILE read ignore word list from FILE\n\-
1846 -o, --only-file=FILE read only word list from this FILE\n\-
1847"), stdout);-
1848 fputs (_("\-
1849 -r, --references first field of each line is a reference\n\-
1850 -t, --typeset-mode - not implemented -\n\-
1851 -w, --width=NUMBER output width in columns, reference excluded\n\-
1852"), stdout);-
1853 fputs (HELP_OPTION_DESCRIPTION, stdout);-
1854 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
1855 emit_ancillary_info (PROGRAM_NAME);-
1856 }
executed 31 times by 1 test: end of block
Executed by:
  • ptx
31
1857 exit (status);
executed 36 times by 1 test: exit (status);
Executed by:
  • ptx
36
1858}-
1859-
1860/*----------------------------------------------------------------------.-
1861| Main program. Decode ARGC arguments passed through the ARGV array of |-
1862| strings, then launch execution. |-
1863`----------------------------------------------------------------------*/-
1864-
1865/* Long options equivalences. */-
1866static struct option const long_options[] =-
1867{-
1868 {"auto-reference", no_argument, NULL, 'A'},-
1869 {"break-file", required_argument, NULL, 'b'},-
1870 {"flag-truncation", required_argument, NULL, 'F'},-
1871 {"ignore-case", no_argument, NULL, 'f'},-
1872 {"gap-size", required_argument, NULL, 'g'},-
1873 {"ignore-file", required_argument, NULL, 'i'},-
1874 {"macro-name", required_argument, NULL, 'M'},-
1875 {"only-file", required_argument, NULL, 'o'},-
1876 {"references", no_argument, NULL, 'r'},-
1877 {"right-side-refs", no_argument, NULL, 'R'},-
1878 {"format", required_argument, NULL, 10},-
1879 {"sentence-regexp", required_argument, NULL, 'S'},-
1880 {"traditional", no_argument, NULL, 'G'},-
1881 {"typeset-mode", no_argument, NULL, 't'},-
1882 {"width", required_argument, NULL, 'w'},-
1883 {"word-regexp", required_argument, NULL, 'W'},-
1884 {GETOPT_HELP_OPTION_DECL},-
1885 {GETOPT_VERSION_OPTION_DECL},-
1886 {NULL, 0, NULL, 0},-
1887};-
1888-
1889static char const* const format_args[] =-
1890{-
1891 "roff", "tex", NULL-
1892};-
1893-
1894static enum Format const format_vals[] =-
1895{-
1896 ROFF_FORMAT, TEX_FORMAT-
1897};-
1898-
1899int-
1900main (int argc, char **argv)-
1901{-
1902 int optchar; /* argument character */-
1903 int file_index; /* index in text input file arrays */-
1904-
1905 /* Decode program options. */-
1906-
1907 initialize_main (&argc, &argv);-
1908 set_program_name (argv[0]);-
1909 setlocale (LC_ALL, "");-
1910 bindtextdomain (PACKAGE, LOCALEDIR);-
1911 textdomain (PACKAGE);-
1912-
1913 atexit (close_stdout);-
1914-
1915#if HAVE_SETCHRCLASS-
1916 setchrclass (NULL);-
1917#endif-
1918-
1919 while (optchar = getopt_long (argc, argv, "AF:GM:ORS:TW:b:i:fg:o:trw:",
optchar = geto...ptchar != (-1)Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
29-104
1920 long_options, NULL),
optchar = geto...ptchar != (-1)Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
29-104
1921 optchar != EOF)
optchar = geto...ptchar != (-1)Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
29-104
1922 {-
1923 switch (optchar)-
1924 {-
1925 default:
executed 3 times by 1 test: default:
Executed by:
  • ptx
3
1926 usage (EXIT_FAILURE);-
1927-
1928 case 'G':
code before this statement never executed: case 'G':
executed 2 times by 1 test: case 'G':
Executed by:
  • ptx
0-2
1929 gnu_extensions = false;-
1930 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1931-
1932 case 'b':
executed 2 times by 1 test: case 'b':
Executed by:
  • ptx
2
1933 break_file = optarg;-
1934 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1935-
1936 case 'f':
executed 2 times by 1 test: case 'f':
Executed by:
  • ptx
2
1937 ignore_case = true;-
1938 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1939-
1940 case 'g':
executed 6 times by 1 test: case 'g':
Executed by:
  • ptx
6
1941 {-
1942 intmax_t tmp;-
1943 if (! (xstrtoimax (optarg, NULL, 0, &tmp, NULL) == LONGINT_OK
xstrtoimax (op... == LONGINT_OKDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
2-4
1944 && 0 < tmp && tmp <= PTRDIFF_MAX))
0 < tmpDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
tmp <= (9223372036854775807L)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-4
1945 die (EXIT_FAILURE, 0, _("invalid gap width: %s"),
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid gap width: %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid gap width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid gap width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • ptx
2
1946 quote (optarg));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid gap width: %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid gap width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid gap width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • ptx
2
1947 gap_size = tmp;-
1948 break;
executed 4 times by 1 test: break;
Executed by:
  • ptx
4
1949 }-
1950-
1951 case 'i':
executed 2 times by 1 test: case 'i':
Executed by:
  • ptx
2
1952 ignore_file = optarg;-
1953 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1954-
1955 case 'o':
executed 2 times by 1 test: case 'o':
Executed by:
  • ptx
2
1956 only_file = optarg;-
1957 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1958-
1959 case 'r':
executed 2 times by 1 test: case 'r':
Executed by:
  • ptx
2
1960 input_reference = true;-
1961 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1962-
1963 case 't':
executed 2 times by 1 test: case 't':
Executed by:
  • ptx
2
1964 /* Yet to understand... */-
1965 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1966-
1967 case 'w':
executed 16 times by 1 test: case 'w':
Executed by:
  • ptx
16
1968 {-
1969 intmax_t tmp;-
1970 if (! (xstrtoimax (optarg, NULL, 0, &tmp, NULL) == LONGINT_OK
xstrtoimax (op... == LONGINT_OKDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ptx
2-14
1971 && 0 < tmp && tmp <= PTRDIFF_MAX))
0 < tmpDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
tmp <= (9223372036854775807L)Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-14
1972 die (EXIT_FAILURE, 0, _("invalid line width: %s"),
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid line width: %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid line width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid line width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • ptx
2
1973 quote (optarg));
executed 2 times by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"invalid line width: %s\", 5), quote (optarg)), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , 0, dcgettext (((void *)0), "invalid line width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "invalid line width: %s" , 5) , quote (optarg)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • ptx
2
1974 line_width = tmp;-
1975 break;
executed 14 times by 1 test: break;
Executed by:
  • ptx
14
1976 }-
1977-
1978 case 'A':
executed 3 times by 1 test: case 'A':
Executed by:
  • ptx
3
1979 auto_reference = true;-
1980 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1981-
1982 case 'F':
executed 3 times by 1 test: case 'F':
Executed by:
  • ptx
3
1983 truncation_string = copy_unescaped_string (optarg);-
1984 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
1985-
1986 case 'M':
executed 2 times by 1 test: case 'M':
Executed by:
  • ptx
2
1987 macro_name = optarg;-
1988 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1989-
1990 case 'O':
executed 1 time by 1 test: case 'O':
Executed by:
  • ptx
1
1991 output_format = ROFF_FORMAT;-
1992 break;
executed 1 time by 1 test: break;
Executed by:
  • ptx
1
1993-
1994 case 'R':
executed 2 times by 1 test: case 'R':
Executed by:
  • ptx
2
1995 right_reference = true;-
1996 break;
executed 2 times by 1 test: break;
Executed by:
  • ptx
2
1997-
1998 case 'S':
executed 6 times by 1 test: case 'S':
Executed by:
  • ptx
6
1999 context_regex.string = copy_unescaped_string (optarg);-
2000 break;
executed 6 times by 1 test: break;
Executed by:
  • ptx
6
2001-
2002 case 'T':
executed 1 time by 1 test: case 'T':
Executed by:
  • ptx
1
2003 output_format = TEX_FORMAT;-
2004 break;
executed 1 time by 1 test: break;
Executed by:
  • ptx
1
2005-
2006 case 'W':
executed 3 times by 1 test: case 'W':
Executed by:
  • ptx
3
2007 word_regex.string = copy_unescaped_string (optarg);-
2008 if (!*word_regex.string)
!*word_regex.stringDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
0-3
2009 word_regex.string = NULL;
never executed: word_regex.string = ((void *)0) ;
0
2010 break;
executed 3 times by 1 test: break;
Executed by:
  • ptx
3
2011-
2012 case 10:
executed 8 times by 1 test: case 10:
Executed by:
  • ptx
8
2013 output_format = XARGMATCH ("--format", optarg,-
2014 format_args, format_vals);-
2015 break;
executed 6 times by 1 test: break;
Executed by:
  • ptx
6
2016-
2017 case_GETOPT_HELP_CHAR;
never executed: break;
executed 31 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • ptx
0-31
2018-
2019 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 5 times by 1 test: exit ( 0 );
Executed by:
  • ptx
never executed: break;
executed 5 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • ptx
0-5
2020 }-
2021 }-
2022-
2023 /* Process remaining arguments. If GNU extensions are enabled, process-
2024 all arguments as input parameters. If disabled, accept at most two-
2025 arguments, the second of which is an output parameter. */-
2026-
2027 if (optind == argc)
optind == argcDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 13 times by 1 test
Evaluated by:
  • ptx
13-16
2028 {-
2029-
2030 /* No more argument simply means: read standard input. */-
2031-
2032 input_file_name = xmalloc (sizeof *input_file_name);-
2033 file_line_count = xmalloc (sizeof *file_line_count);-
2034 text_buffers = xmalloc (sizeof *text_buffers);-
2035 number_input_files = 1;-
2036 input_file_name[0] = NULL;-
2037 }
executed 16 times by 1 test: end of block
Executed by:
  • ptx
16
2038 else if (gnu_extensions)
gnu_extensionsDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-13
2039 {-
2040 number_input_files = argc - optind;-
2041 input_file_name = xnmalloc (number_input_files, sizeof *input_file_name);-
2042 file_line_count = xnmalloc (number_input_files, sizeof *file_line_count);-
2043 text_buffers = xnmalloc (number_input_files, sizeof *text_buffers);-
2044-
2045 for (file_index = 0; file_index < number_input_files; file_index++)
file_index < n...er_input_filesDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 13 times by 1 test
Evaluated by:
  • ptx
13-15
2046 {-
2047 if (!*argv[optind] || STREQ (argv[optind], "-"))
never executed: __result = (((const unsigned char *) (const char *) ( argv[optind] ))[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
!*argv[optind]Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
__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 15 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
__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-15
2048 input_file_name[file_index] = NULL;
never executed: input_file_name[file_index] = ((void *)0) ;
0
2049 else-
2050 input_file_name[file_index] = argv[optind];
executed 15 times by 1 test: input_file_name[file_index] = argv[optind];
Executed by:
  • ptx
15
2051 optind++;-
2052 }
executed 15 times by 1 test: end of block
Executed by:
  • ptx
15
2053 }
executed 13 times by 1 test: end of block
Executed by:
  • ptx
13
2054 else-
2055 {-
2056-
2057 /* There is one necessary input file. */-
2058-
2059 number_input_files = 1;-
2060 input_file_name = xmalloc (sizeof *input_file_name);-
2061 file_line_count = xmalloc (sizeof *file_line_count);-
2062 text_buffers = xmalloc (sizeof *text_buffers);-
2063 if (!*argv[optind] || STREQ (argv[optind], "-"))
never executed: __result = (((const unsigned char *) (const char *) ( argv[optind] ))[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
!*argv[optind]Description
TRUEnever evaluated
FALSEnever evaluated
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2064 input_file_name[0] = NULL;
never executed: input_file_name[0] = ((void *)0) ;
0
2065 else-
2066 input_file_name[0] = argv[optind];
never executed: input_file_name[0] = argv[optind];
0
2067 optind++;-
2068-
2069 /* Redirect standard output, only if requested. */-
2070-
2071 if (optind < argc)
optind < argcDescription
TRUEnever evaluated
FALSEnever evaluated
0
2072 {-
2073 if (! freopen (argv[optind], "w", stdout))
! freopen_safe... "w", stdout )Description
TRUEnever evaluated
FALSEnever evaluated
0
2074 die (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"%s\", quotearg_n_style_colon (0, shell_escape_quoting_style, argv[optind])), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_locat...l_escape_quoting_style, argv[optind])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, argv[optind])), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
2075 optind++;-
2076 }
never executed: end of block
0
2077-
2078 /* Diagnose any other argument as an error. */-
2079-
2080 if (optind < argc)
optind < argcDescription
TRUEnever evaluated
FALSEnever evaluated
0
2081 {-
2082 error (0, 0, _("extra operand %s"), quote (argv[optind]));-
2083 usage (EXIT_FAILURE);-
2084 }
never executed: end of block
0
2085 }
never executed: end of block
0
2086-
2087 /* If the output format has not been explicitly selected, choose dumb-
2088 terminal format if GNU extensions are enabled, else 'roff' format. */-
2089-
2090 if (output_format == UNKNOWN_FORMAT)
output_format ...UNKNOWN_FORMATDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 6 times by 1 test
Evaluated by:
  • ptx
6-23
2091 output_format = gnu_extensions ? DUMB_FORMAT : ROFF_FORMAT;
executed 23 times by 1 test: output_format = gnu_extensions ? DUMB_FORMAT : ROFF_FORMAT;
Executed by:
  • ptx
gnu_extensionsDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • ptx
FALSEnever evaluated
0-23
2092-
2093 /* Initialize the main tables. */-
2094-
2095 initialize_regex ();-
2096-
2097 /* Read 'Break character' file, if any. */-
2098-
2099 if (break_file)
break_fileDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
0-29
2100 digest_break_file (break_file);
never executed: digest_break_file (break_file);
0
2101-
2102 /* Read 'Ignore words' file and 'Only words' files, if any. If any of-
2103 these files is empty, reset the name of the file to NULL, to avoid-
2104 unnecessary calls to search_table. */-
2105-
2106 if (ignore_file)
ignore_fileDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
0-29
2107 {-
2108 digest_word_file (ignore_file, &ignore_table);-
2109 if (ignore_table.length == 0)
ignore_table.length == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2110 ignore_file = NULL;
never executed: ignore_file = ((void *)0) ;
0
2111 }
never executed: end of block
0
2112-
2113 if (only_file)
only_fileDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • ptx
0-29
2114 {-
2115 digest_word_file (only_file, &only_table);-
2116 if (only_table.length == 0)
only_table.length == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2117 only_file = NULL;
never executed: only_file = ((void *)0) ;
0
2118 }
never executed: end of block
0
2119-
2120 /* Prepare to study all the input files. */-
2121-
2122 number_of_occurs[0] = 0;-
2123 total_line_count = 0;-
2124 maximum_word_length = 0;-
2125 reference_max_width = 0;-
2126-
2127 for (file_index = 0; file_index < number_input_files; file_index++)
file_index < n...er_input_filesDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • ptx
FALSEevaluated 26 times by 1 test
Evaluated by:
  • ptx
26-31
2128 {-
2129 BLOCK *text_buffer = text_buffers + file_index;-
2130-
2131 /* Read the file in core, then study it. */-
2132-
2133 swallow_file_in_memory (input_file_name[file_index], text_buffer);-
2134 find_occurs_in_text (file_index);-
2135-
2136 /* Maintain for each file how many lines has been read so far when its-
2137 end is reached. Incrementing the count first is a simple kludge to-
2138 handle a possible incomplete line at end of file. */-
2139-
2140 total_line_count++;-
2141 file_line_count[file_index] = total_line_count;-
2142 }
executed 28 times by 1 test: end of block
Executed by:
  • ptx
28
2143-
2144 /* Do the output process phase. */-
2145-
2146 sort_found_occurs ();-
2147 fix_output_parameters ();-
2148 generate_all_output ();-
2149-
2150 /* All done. */-
2151-
2152 return EXIT_SUCCESS;
executed 26 times by 1 test: return 0 ;
Executed by:
  • ptx
26
2153}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2