tests: exercise tests new "==" operator
[coreutils.git] / src / cut.c
blobe2fe85170d7b741ed2913345e8db548b1e79ccea
1 /* cut - remove parts of lines of files
2 Copyright (C) 1997-2011 Free Software Foundation, Inc.
3 Copyright (C) 1984 David M. Ihnat
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Written by David Ihnat. */
20 /* POSIX changes, bug fixes, long-named options, and cleanup
21 by David MacKenzie <djm@gnu.ai.mit.edu>.
23 Rewrite cut_fields and cut_bytes -- Jim Meyering. */
25 #include <config.h>
27 #include <stdio.h>
28 #include <assert.h>
29 #include <getopt.h>
30 #include <sys/types.h>
31 #include "system.h"
33 #include "error.h"
34 #include "fadvise.h"
35 #include "getndelim2.h"
36 #include "hash.h"
37 #include "quote.h"
38 #include "xstrndup.h"
40 /* The official name of this program (e.g., no `g' prefix). */
41 #define PROGRAM_NAME "cut"
43 #define AUTHORS \
44 proper_name ("David M. Ihnat"), \
45 proper_name ("David MacKenzie"), \
46 proper_name ("Jim Meyering")
48 #define FATAL_ERROR(Message) \
49 do \
50 { \
51 error (0, 0, (Message)); \
52 usage (EXIT_FAILURE); \
53 } \
54 while (0)
56 /* Append LOW, HIGH to the list RP of range pairs, allocating additional
57 space if necessary. Update local variable N_RP. When allocating,
58 update global variable N_RP_ALLOCATED. */
60 #define ADD_RANGE_PAIR(rp, low, high) \
61 do \
62 { \
63 if (low == 0 || high == 0) \
64 FATAL_ERROR (_("fields and positions are numbered from 1")); \
65 if (n_rp >= n_rp_allocated) \
66 { \
67 (rp) = X2NREALLOC (rp, &n_rp_allocated); \
68 } \
69 rp[n_rp].lo = (low); \
70 rp[n_rp].hi = (high); \
71 ++n_rp; \
72 } \
73 while (0)
75 struct range_pair
77 size_t lo;
78 size_t hi;
81 /* This buffer is used to support the semantics of the -s option
82 (or lack of same) when the specified field list includes (does
83 not include) the first field. In both of those cases, the entire
84 first field must be read into this buffer to determine whether it
85 is followed by a delimiter or a newline before any of it may be
86 output. Otherwise, cut_fields can do the job without using this
87 buffer. */
88 static char *field_1_buffer;
90 /* The number of bytes allocated for FIELD_1_BUFFER. */
91 static size_t field_1_bufsize;
93 /* The largest field or byte index used as an endpoint of a closed
94 or degenerate range specification; this doesn't include the starting
95 index of right-open-ended ranges. For example, with either range spec
96 `2-5,9-', `2-3,5,9-' this variable would be set to 5. */
97 static size_t max_range_endpoint;
99 /* If nonzero, this is the index of the first field in a range that goes
100 to end of line. */
101 static size_t eol_range_start;
103 /* This is a bit vector.
104 In byte mode, which bytes to output.
105 In field mode, which DELIM-separated fields to output.
106 Both bytes and fields are numbered starting with 1,
107 so the zeroth bit of this array is unused.
108 A field or byte K has been selected if
109 (K <= MAX_RANGE_ENDPOINT and is_printable_field(K))
110 || (EOL_RANGE_START > 0 && K >= EOL_RANGE_START). */
111 static unsigned char *printable_field;
113 enum operating_mode
115 undefined_mode,
117 /* Output characters that are in the given bytes. */
118 byte_mode,
120 /* Output the given delimeter-separated fields. */
121 field_mode
124 static enum operating_mode operating_mode;
126 /* If true do not output lines containing no delimeter characters.
127 Otherwise, all such lines are printed. This option is valid only
128 with field mode. */
129 static bool suppress_non_delimited;
131 /* If nonzero, print all bytes, characters, or fields _except_
132 those that were specified. */
133 static bool complement;
135 /* The delimeter character for field mode. */
136 static unsigned char delim;
138 /* True if the --output-delimiter=STRING option was specified. */
139 static bool output_delimiter_specified;
141 /* The length of output_delimiter_string. */
142 static size_t output_delimiter_length;
144 /* The output field separator string. Defaults to the 1-character
145 string consisting of the input delimiter. */
146 static char *output_delimiter_string;
148 /* True if we have ever read standard input. */
149 static bool have_read_stdin;
151 #define HT_RANGE_START_INDEX_INITIAL_CAPACITY 31
153 /* The set of range-start indices. For example, given a range-spec list like
154 `-b1,3-5,4-9,15-', the following indices will be recorded here: 1, 3, 15.
155 Note that although `4' looks like a range-start index, it is in the middle
156 of the `3-5' range, so it doesn't count.
157 This table is created/used IFF output_delimiter_specified is set. */
158 static Hash_table *range_start_ht;
160 /* For long options that have no equivalent short option, use a
161 non-character as a pseudo short option, starting with CHAR_MAX + 1. */
162 enum
164 OUTPUT_DELIMITER_OPTION = CHAR_MAX + 1,
165 COMPLEMENT_OPTION
168 static struct option const longopts[] =
170 {"bytes", required_argument, NULL, 'b'},
171 {"characters", required_argument, NULL, 'c'},
172 {"fields", required_argument, NULL, 'f'},
173 {"delimiter", required_argument, NULL, 'd'},
174 {"only-delimited", no_argument, NULL, 's'},
175 {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION},
176 {"complement", no_argument, NULL, COMPLEMENT_OPTION},
177 {GETOPT_HELP_OPTION_DECL},
178 {GETOPT_VERSION_OPTION_DECL},
179 {NULL, 0, NULL, 0}
182 void
183 usage (int status)
185 if (status != EXIT_SUCCESS)
186 fprintf (stderr, _("Try `%s --help' for more information.\n"),
187 program_name);
188 else
190 printf (_("\
191 Usage: %s OPTION... [FILE]...\n\
193 program_name);
194 fputs (_("\
195 Print selected parts of lines from each FILE to standard output.\n\
197 "), stdout);
198 fputs (_("\
199 Mandatory arguments to long options are mandatory for short options too.\n\
200 "), stdout);
201 fputs (_("\
202 -b, --bytes=LIST select only these bytes\n\
203 -c, --characters=LIST select only these characters\n\
204 -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter\n\
205 "), stdout);
206 fputs (_("\
207 -f, --fields=LIST select only these fields; also print any line\n\
208 that contains no delimiter character, unless\n\
209 the -s option is specified\n\
210 -n (ignored)\n\
211 "), stdout);
212 fputs (_("\
213 --complement complement the set of selected bytes, characters\n\
214 or fields\n\
215 "), stdout);
216 fputs (_("\
217 -s, --only-delimited do not print lines not containing delimiters\n\
218 --output-delimiter=STRING use STRING as the output delimiter\n\
219 the default is to use the input delimiter\n\
220 "), stdout);
221 fputs (HELP_OPTION_DESCRIPTION, stdout);
222 fputs (VERSION_OPTION_DESCRIPTION, stdout);
223 fputs (_("\
225 Use one, and only one of -b, -c or -f. Each LIST is made up of one\n\
226 range, or many ranges separated by commas. Selected input is written\n\
227 in the same order that it is read, and is written exactly once.\n\
228 "), stdout);
229 fputs (_("\
230 Each range is one of:\n\
232 N N'th byte, character or field, counted from 1\n\
233 N- from N'th byte, character or field, to end of line\n\
234 N-M from N'th to M'th (included) byte, character or field\n\
235 -M from first to M'th (included) byte, character or field\n\
237 With no FILE, or when FILE is -, read standard input.\n\
238 "), stdout);
239 emit_ancillary_info ();
241 exit (status);
244 static inline void
245 mark_range_start (size_t i)
247 /* Record the fact that `i' is a range-start index. */
248 void *ent_from_table = hash_insert (range_start_ht, (void*) i);
249 if (ent_from_table == NULL)
251 /* Insertion failed due to lack of memory. */
252 xalloc_die ();
254 assert ((size_t) ent_from_table == i);
257 static inline void
258 mark_printable_field (size_t i)
260 size_t n = i / CHAR_BIT;
261 printable_field[n] |= (1 << (i % CHAR_BIT));
264 static inline bool
265 is_printable_field (size_t i)
267 size_t n = i / CHAR_BIT;
268 return (printable_field[n] >> (i % CHAR_BIT)) & 1;
271 static size_t
272 hash_int (const void *x, size_t tablesize)
274 #ifdef UINTPTR_MAX
275 uintptr_t y = (uintptr_t) x;
276 #else
277 size_t y = (size_t) x;
278 #endif
279 return y % tablesize;
282 static bool
283 hash_compare_ints (void const *x, void const *y)
285 return (x == y) ? true : false;
288 static bool
289 is_range_start_index (size_t i)
291 return hash_lookup (range_start_ht, (void *) i) ? true : false;
294 /* Return nonzero if the K'th field or byte is printable.
295 When returning nonzero, if RANGE_START is non-NULL,
296 set *RANGE_START to true if K is the beginning of a range, and to
297 false otherwise. */
299 static bool
300 print_kth (size_t k, bool *range_start)
302 bool k_selected
303 = ((0 < eol_range_start && eol_range_start <= k)
304 || (k <= max_range_endpoint && is_printable_field (k)));
306 bool is_selected = k_selected ^ complement;
307 if (range_start && is_selected)
308 *range_start = is_range_start_index (k);
310 return is_selected;
313 /* Comparison function for qsort to order the list of
314 struct range_pairs. */
315 static int
316 compare_ranges (const void *a, const void *b)
318 int a_start = ((const struct range_pair *) a)->lo;
319 int b_start = ((const struct range_pair *) b)->lo;
320 return a_start < b_start ? -1 : a_start > b_start;
323 /* Given the list of field or byte range specifications FIELDSTR, set
324 MAX_RANGE_ENDPOINT and allocate and initialize the PRINTABLE_FIELD
325 array. If there is a right-open-ended range, set EOL_RANGE_START
326 to its starting index. FIELDSTR should be composed of one or more
327 numbers or ranges of numbers, separated by blanks or commas.
328 Incomplete ranges may be given: `-m' means `1-m'; `n-' means `n'
329 through end of line. Return true if FIELDSTR contains at least
330 one field specification, false otherwise. */
332 /* FIXME-someday: What if the user wants to cut out the 1,000,000-th
333 field of some huge input file? This function shouldn't have to
334 allocate a table of a million bits just so we can test every
335 field < 10^6 with an array dereference. Instead, consider using
336 an adaptive approach: if the range of selected fields is too large,
337 but only a few fields/byte-offsets are actually selected, use a
338 hash table. If the range of selected fields is too large, and
339 too many are selected, then resort to using the range-pairs (the
340 `rp' array) directly. */
342 static bool
343 set_fields (const char *fieldstr)
345 size_t initial = 1; /* Value of first number in a range. */
346 size_t value = 0; /* If nonzero, a number being accumulated. */
347 bool lhs_specified = false;
348 bool rhs_specified = false;
349 bool dash_found = false; /* True if a '-' is found in this field. */
350 bool field_found = false; /* True if at least one field spec
351 has been processed. */
353 struct range_pair *rp = NULL;
354 size_t n_rp = 0;
355 size_t n_rp_allocated = 0;
356 size_t i;
357 bool in_digits = false;
359 /* Collect and store in RP the range end points.
360 It also sets EOL_RANGE_START if appropriate. */
362 while (true)
364 if (*fieldstr == '-')
366 in_digits = false;
367 /* Starting a range. */
368 if (dash_found)
369 FATAL_ERROR (_("invalid byte or field list"));
370 dash_found = true;
371 fieldstr++;
373 initial = (lhs_specified ? value : 1);
374 value = 0;
376 else if (*fieldstr == ',' ||
377 isblank (to_uchar (*fieldstr)) || *fieldstr == '\0')
379 in_digits = false;
380 /* Ending the string, or this field/byte sublist. */
381 if (dash_found)
383 dash_found = false;
385 if (!lhs_specified && !rhs_specified)
386 FATAL_ERROR (_("invalid range with no endpoint: -"));
388 /* A range. Possibilities: -n, m-n, n-.
389 In any case, `initial' contains the start of the range. */
390 if (!rhs_specified)
392 /* `n-'. From `initial' to end of line. */
393 eol_range_start = initial;
394 field_found = true;
396 else
398 /* `m-n' or `-n' (1-n). */
399 if (value < initial)
400 FATAL_ERROR (_("invalid decreasing range"));
402 /* Is there already a range going to end of line? */
403 if (eol_range_start != 0)
405 /* Yes. Is the new sequence already contained
406 in the old one? If so, no processing is
407 necessary. */
408 if (initial < eol_range_start)
410 /* No, the new sequence starts before the
411 old. Does the old range going to end of line
412 extend into the new range? */
413 if (eol_range_start <= value)
415 /* Yes. Simply move the end of line marker. */
416 eol_range_start = initial;
418 else
420 /* No. A simple range, before and disjoint from
421 the range going to end of line. Fill it. */
422 ADD_RANGE_PAIR (rp, initial, value);
425 /* In any case, some fields were selected. */
426 field_found = true;
429 else
431 /* There is no range going to end of line. */
432 ADD_RANGE_PAIR (rp, initial, value);
433 field_found = true;
435 value = 0;
438 else
440 /* A simple field number, not a range. */
441 ADD_RANGE_PAIR (rp, value, value);
442 value = 0;
443 field_found = true;
446 if (*fieldstr == '\0')
448 break;
451 fieldstr++;
452 lhs_specified = false;
453 rhs_specified = false;
455 else if (ISDIGIT (*fieldstr))
457 /* Record beginning of digit string, in case we have to
458 complain about it. */
459 static char const *num_start;
460 if (!in_digits || !num_start)
461 num_start = fieldstr;
462 in_digits = true;
464 if (dash_found)
465 rhs_specified = 1;
466 else
467 lhs_specified = 1;
469 /* Detect overflow. */
470 if (!DECIMAL_DIGIT_ACCUMULATE (value, *fieldstr - '0', size_t))
472 /* In case the user specified -c$(echo 2^64|bc),22,
473 complain only about the first number. */
474 /* Determine the length of the offending number. */
475 size_t len = strspn (num_start, "0123456789");
476 char *bad_num = xstrndup (num_start, len);
477 if (operating_mode == byte_mode)
478 error (0, 0,
479 _("byte offset %s is too large"), quote (bad_num));
480 else
481 error (0, 0,
482 _("field number %s is too large"), quote (bad_num));
483 free (bad_num);
484 exit (EXIT_FAILURE);
487 fieldstr++;
489 else
490 FATAL_ERROR (_("invalid byte or field list"));
493 max_range_endpoint = 0;
494 for (i = 0; i < n_rp; i++)
496 if (rp[i].hi > max_range_endpoint)
497 max_range_endpoint = rp[i].hi;
499 if (max_range_endpoint < eol_range_start)
500 max_range_endpoint = eol_range_start;
502 /* Allocate an array large enough so that it may be indexed by
503 the field numbers corresponding to all finite ranges
504 (i.e. `2-6' or `-4', but not `5-') in FIELDSTR. */
506 printable_field = xzalloc (max_range_endpoint / CHAR_BIT + 1);
508 qsort (rp, n_rp, sizeof (rp[0]), compare_ranges);
510 /* Set the array entries corresponding to integers in the ranges of RP. */
511 for (i = 0; i < n_rp; i++)
513 size_t j;
514 size_t rsi_candidate;
516 /* Record the range-start indices, i.e., record each start
517 index that is not part of any other (lo..hi] range. */
518 rsi_candidate = complement ? rp[i].hi + 1 : rp[i].lo;
519 if (output_delimiter_specified
520 && !is_printable_field (rsi_candidate))
521 mark_range_start (rsi_candidate);
523 for (j = rp[i].lo; j <= rp[i].hi; j++)
524 mark_printable_field (j);
527 if (output_delimiter_specified
528 && !complement
529 && eol_range_start && !is_printable_field (eol_range_start))
530 mark_range_start (eol_range_start);
532 free (rp);
534 return field_found;
537 /* Read from stream STREAM, printing to standard output any selected bytes. */
539 static void
540 cut_bytes (FILE *stream)
542 size_t byte_idx; /* Number of bytes in the line so far. */
543 /* Whether to begin printing delimiters between ranges for the current line.
544 Set after we've begun printing data corresponding to the first range. */
545 bool print_delimiter;
547 byte_idx = 0;
548 print_delimiter = false;
549 while (1)
551 int c; /* Each character from the file. */
553 c = getc (stream);
555 if (c == '\n')
557 putchar ('\n');
558 byte_idx = 0;
559 print_delimiter = false;
561 else if (c == EOF)
563 if (byte_idx > 0)
564 putchar ('\n');
565 break;
567 else
569 bool range_start;
570 bool *rs = output_delimiter_specified ? &range_start : NULL;
571 if (print_kth (++byte_idx, rs))
573 if (rs && *rs && print_delimiter)
575 fwrite (output_delimiter_string, sizeof (char),
576 output_delimiter_length, stdout);
578 print_delimiter = true;
579 putchar (c);
585 /* Read from stream STREAM, printing to standard output any selected fields. */
587 static void
588 cut_fields (FILE *stream)
590 int c;
591 size_t field_idx = 1;
592 bool found_any_selected_field = false;
593 bool buffer_first_field;
595 c = getc (stream);
596 if (c == EOF)
597 return;
599 ungetc (c, stream);
601 /* To support the semantics of the -s flag, we may have to buffer
602 all of the first field to determine whether it is `delimited.'
603 But that is unnecessary if all non-delimited lines must be printed
604 and the first field has been selected, or if non-delimited lines
605 must be suppressed and the first field has *not* been selected.
606 That is because a non-delimited line has exactly one field. */
607 buffer_first_field = (suppress_non_delimited ^ !print_kth (1, NULL));
609 while (1)
611 if (field_idx == 1 && buffer_first_field)
613 ssize_t len;
614 size_t n_bytes;
616 len = getndelim2 (&field_1_buffer, &field_1_bufsize, 0,
617 GETNLINE_NO_LIMIT, delim, '\n', stream);
618 if (len < 0)
620 free (field_1_buffer);
621 field_1_buffer = NULL;
622 if (ferror (stream) || feof (stream))
623 break;
624 xalloc_die ();
627 n_bytes = len;
628 assert (n_bytes != 0);
630 /* If the first field extends to the end of line (it is not
631 delimited) and we are printing all non-delimited lines,
632 print this one. */
633 if (to_uchar (field_1_buffer[n_bytes - 1]) != delim)
635 if (suppress_non_delimited)
637 /* Empty. */
639 else
641 fwrite (field_1_buffer, sizeof (char), n_bytes, stdout);
642 /* Make sure the output line is newline terminated. */
643 if (field_1_buffer[n_bytes - 1] != '\n')
644 putchar ('\n');
646 continue;
648 if (print_kth (1, NULL))
650 /* Print the field, but not the trailing delimiter. */
651 fwrite (field_1_buffer, sizeof (char), n_bytes - 1, stdout);
652 found_any_selected_field = true;
654 ++field_idx;
657 if (c != EOF)
659 if (print_kth (field_idx, NULL))
661 if (found_any_selected_field)
663 fwrite (output_delimiter_string, sizeof (char),
664 output_delimiter_length, stdout);
666 found_any_selected_field = true;
668 while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
670 putchar (c);
673 else
675 while ((c = getc (stream)) != delim && c != '\n' && c != EOF)
677 /* Empty. */
682 if (c == '\n')
684 c = getc (stream);
685 if (c != EOF)
687 ungetc (c, stream);
688 c = '\n';
692 if (c == delim)
693 ++field_idx;
694 else if (c == '\n' || c == EOF)
696 if (found_any_selected_field
697 || !(suppress_non_delimited && field_idx == 1))
698 putchar ('\n');
699 if (c == EOF)
700 break;
701 field_idx = 1;
702 found_any_selected_field = false;
707 static void
708 cut_stream (FILE *stream)
710 if (operating_mode == byte_mode)
711 cut_bytes (stream);
712 else
713 cut_fields (stream);
716 /* Process file FILE to standard output.
717 Return true if successful. */
719 static bool
720 cut_file (char const *file)
722 FILE *stream;
724 if (STREQ (file, "-"))
726 have_read_stdin = true;
727 stream = stdin;
729 else
731 stream = fopen (file, "r");
732 if (stream == NULL)
734 error (0, errno, "%s", file);
735 return false;
739 fadvise (stream, FADVISE_SEQUENTIAL);
741 cut_stream (stream);
743 if (ferror (stream))
745 error (0, errno, "%s", file);
746 return false;
748 if (STREQ (file, "-"))
749 clearerr (stream); /* Also clear EOF. */
750 else if (fclose (stream) == EOF)
752 error (0, errno, "%s", file);
753 return false;
755 return true;
759 main (int argc, char **argv)
761 int optc;
762 bool ok;
763 bool delim_specified = false;
764 char *spec_list_string IF_LINT ( = NULL);
766 initialize_main (&argc, &argv);
767 set_program_name (argv[0]);
768 setlocale (LC_ALL, "");
769 bindtextdomain (PACKAGE, LOCALEDIR);
770 textdomain (PACKAGE);
772 atexit (close_stdout);
774 operating_mode = undefined_mode;
776 /* By default, all non-delimited lines are printed. */
777 suppress_non_delimited = false;
779 delim = '\0';
780 have_read_stdin = false;
782 while ((optc = getopt_long (argc, argv, "b:c:d:f:ns", longopts, NULL)) != -1)
784 switch (optc)
786 case 'b':
787 case 'c':
788 /* Build the byte list. */
789 if (operating_mode != undefined_mode)
790 FATAL_ERROR (_("only one type of list may be specified"));
791 operating_mode = byte_mode;
792 spec_list_string = optarg;
793 break;
795 case 'f':
796 /* Build the field list. */
797 if (operating_mode != undefined_mode)
798 FATAL_ERROR (_("only one type of list may be specified"));
799 operating_mode = field_mode;
800 spec_list_string = optarg;
801 break;
803 case 'd':
804 /* New delimiter. */
805 /* Interpret -d '' to mean `use the NUL byte as the delimiter.' */
806 if (optarg[0] != '\0' && optarg[1] != '\0')
807 FATAL_ERROR (_("the delimiter must be a single character"));
808 delim = optarg[0];
809 delim_specified = true;
810 break;
812 case OUTPUT_DELIMITER_OPTION:
813 output_delimiter_specified = true;
814 /* Interpret --output-delimiter='' to mean
815 `use the NUL byte as the delimiter.' */
816 output_delimiter_length = (optarg[0] == '\0'
817 ? 1 : strlen (optarg));
818 output_delimiter_string = xstrdup (optarg);
819 break;
821 case 'n':
822 break;
824 case 's':
825 suppress_non_delimited = true;
826 break;
828 case COMPLEMENT_OPTION:
829 complement = true;
830 break;
832 case_GETOPT_HELP_CHAR;
834 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
836 default:
837 usage (EXIT_FAILURE);
841 if (operating_mode == undefined_mode)
842 FATAL_ERROR (_("you must specify a list of bytes, characters, or fields"));
844 if (delim != '\0' && operating_mode != field_mode)
845 FATAL_ERROR (_("an input delimiter may be specified only\
846 when operating on fields"));
848 if (suppress_non_delimited && operating_mode != field_mode)
849 FATAL_ERROR (_("suppressing non-delimited lines makes sense\n\
850 \tonly when operating on fields"));
852 if (output_delimiter_specified)
854 range_start_ht = hash_initialize (HT_RANGE_START_INDEX_INITIAL_CAPACITY,
855 NULL, hash_int,
856 hash_compare_ints, NULL);
857 if (range_start_ht == NULL)
858 xalloc_die ();
862 if (! set_fields (spec_list_string))
864 if (operating_mode == field_mode)
865 FATAL_ERROR (_("missing list of fields"));
866 else
867 FATAL_ERROR (_("missing list of positions"));
870 if (!delim_specified)
871 delim = '\t';
873 if (output_delimiter_string == NULL)
875 static char dummy[2];
876 dummy[0] = delim;
877 dummy[1] = '\0';
878 output_delimiter_string = dummy;
879 output_delimiter_length = 1;
882 if (optind == argc)
883 ok = cut_file ("-");
884 else
885 for (ok = true; optind < argc; optind++)
886 ok &= cut_file (argv[optind]);
888 if (range_start_ht)
889 hash_free (range_start_ht);
891 if (have_read_stdin && fclose (stdin) == EOF)
893 error (0, errno, "-");
894 ok = false;
897 exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);