From 6587c39b3ad22a17a2525597bc8d4712916d29fe Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 22 May 1993 05:06:39 +0000 Subject: [PATCH] merge with 1.5.2 --- lib/regex.c | 1 + old/textutils/ChangeLog | 35 +++++++++++++++ old/textutils/NEWS | 6 +++ src/cat.c | 5 ++- src/cksum.c | 5 ++- src/comm.c | 5 ++- src/csplit.c | 5 ++- src/cut.c | 5 ++- src/expand.c | 5 ++- src/fold.c | 21 ++++++++- src/head.c | 5 ++- src/join.c | 5 ++- src/nl.c | 5 ++- src/od.c | 5 ++- src/paste.c | 5 ++- src/pr.c | 116 ++++++++++++++++++++++++++++++++---------------- src/sort.c | 8 ++++ src/split.c | 5 ++- src/sum.c | 5 ++- src/tac.c | 5 ++- src/tail.c | 5 ++- src/tr.c | 5 ++- src/unexpand.c | 5 ++- src/uniq.c | 5 ++- src/wc.c | 5 ++- 25 files changed, 223 insertions(+), 59 deletions(-) diff --git a/lib/regex.c b/lib/regex.c index 5bd4cf6..e8b5882 100644 --- a/lib/regex.c +++ b/lib/regex.c @@ -4784,6 +4784,7 @@ regcomp (preg, pattern, cflags) /* regex_compile will allocate the space for the compiled pattern. */ preg->buffer = 0; preg->allocated = 0; + preg->used = 0; /* Don't bother to use a fastmap when searching. This simplifies the REG_NEWLINE case: if we used a fastmap, we'd have to put all the diff --git a/old/textutils/ChangeLog b/old/textutils/ChangeLog index 7a85cf2..d0f54b5 100644 --- a/old/textutils/ChangeLog +++ b/old/textutils/ChangeLog @@ -1,3 +1,38 @@ +Wed May 19 19:12:18 1993 Karl Berry (karl@owl.hq.ileaf.com) + + * sort.c (main): fflush before exit, so a closed stdout doesn't lose. + +Tue May 18 23:49:26 1993 Jim Meyering (meyering@comco.com) + + * mkinstalldirs: New file. + * Makefile.in (installdirs): Use it. + +Fri May 14 23:45:52 1993 Jim Meyering (meyering@comco.com) + + * all source: With --version, print version and exit immediately. + +Thu May 13 01:03:16 1993 Jim Meyering (meyering@comco.com) + + * Makefile.in (installdirs): New rules for creating installation + directories. (install): depend on it. + + * tail.c (main): Remove --compatible since `+1f' may be used + to get the BSD `-0f' behavior portably. + + * fold.c (main): Turn -N arguments, where N is a digit, into -wN. + From Ian Lance Taylor (ian@cygnus.com). + +Mon May 10 22:33:44 1993 Jim Meyering (meyering@comco.com) + + * tail.c (main): New option -C, --compatible to make `tail -0f' + work like `tail +1f' for compatibility with BSD tail. + +Thu May 6 23:28:56 1993 Jim Meyering (meyering@comco.com) + + * pr.c (print_page): Decrement cols_ready_to_print even when + lines_to_print == 0. The command `echo |pr -2ta' *still* didn't + terminate. Add parentheses for clarity. + Mon May 3 23:57:47 1993 Jim Meyering (meyering@comco.com) * Version 1.5. diff --git a/old/textutils/NEWS b/old/textutils/NEWS index c63422f..0742b70 100644 --- a/old/textutils/NEWS +++ b/old/textutils/NEWS @@ -1,3 +1,9 @@ +Major changes in release 1.6: +* with the --version option programs print the version and exit immediately +* --compatible makes `tail -0f' work like `tail +1f' for compatibility + with BSD tail. +* pr -2a really terminates + Major changes in release 1.5: * sort is 8-bit clean * sort's -n and -M options no longer imply -b diff --git a/src/cat.c b/src/cat.c index 98da7c9..724976d 100644 --- a/src/cat.c +++ b/src/cat.c @@ -225,7 +225,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/cksum.c b/src/cksum.c index e629dd8..b5e1887 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -291,7 +291,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/comm.c b/src/comm.c index 8b4f87f..c5f4c39 100644 --- a/src/comm.c +++ b/src/comm.c @@ -92,7 +92,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/csplit.c b/src/csplit.c index eaea8c3..6eedd39 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -1285,7 +1285,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/cut.c b/src/cut.c index 2e611a9..e7997fd 100644 --- a/src/cut.c +++ b/src/cut.c @@ -225,7 +225,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/expand.c b/src/expand.c index f269510..99ce5c4 100644 --- a/src/expand.c +++ b/src/expand.c @@ -154,7 +154,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/fold.c b/src/fold.c index ca20a28..b3cb098 100644 --- a/src/fold.c +++ b/src/fold.c @@ -27,6 +27,7 @@ #include "version.h" char *xrealloc (); +char *xmalloc (); void error (); /* The name this program was run with. */ @@ -83,6 +84,21 @@ main (argc, argv) program_name = argv[0]; break_spaces = count_bytes = have_read_stdin = 0; + /* Turn any numeric options into -w options. */ + for (i = 1; i < argc; i++) + { + if (argv[i][0] == '-' && ISDIGIT (argv[i][1])) + { + char *s; + + s = xmalloc (strlen (argv[i]) + 2); + s[0] = '-'; + s[1] = 'w'; + strcpy (s + 2, argv[i] + 1); + argv[i] = s; + } + } + while ((optc = getopt_long (argc, argv, "bsw:", longopts, (int *) 0)) != EOF) { @@ -111,7 +127,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/head.c b/src/head.c index 6d7ac55..ec4d730 100644 --- a/src/head.c +++ b/src/head.c @@ -194,7 +194,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/join.c b/src/join.c index 39599ef..48e791a 100644 --- a/src/join.c +++ b/src/join.c @@ -661,7 +661,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/nl.c b/src/nl.c index 1444002..431c3e9 100644 --- a/src/nl.c +++ b/src/nl.c @@ -263,7 +263,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/od.c b/src/od.c index ea4f12b..f2f0b3c 100644 --- a/src/od.c +++ b/src/od.c @@ -1790,7 +1790,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/paste.c b/src/paste.c index bc9b7e5..a45b6fe 100644 --- a/src/paste.c +++ b/src/paste.c @@ -133,7 +133,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/pr.c b/src/pr.c index 876387d..edf4147 100644 --- a/src/pr.c +++ b/src/pr.c @@ -441,6 +441,24 @@ static struct option const long_options[] = {0, 0, 0, 0} }; +/* Return the number of columns that have either an open file or + stored lines. */ + +static int +crtp () +{ + COLUMN *q; + int i; + int n; + + n = 0; + for (q = column_vector, i = 0; i < columns; ++q, ++i) + if (q->status == OPEN || + (storing_columns && q->lines_stored > 0 && q->lines_to_print > 0)) + ++n; + return n; +} + void main (argc, argv) int argc; @@ -448,28 +466,63 @@ main (argc, argv) { int c; int accum = 0; + int n_files; + char **file_names; program_name = argv[0]; - while ((c = getopt_long (argc, argv, - "0123456789abcde::fFh:i::l:mn::o:rs::tvw:", - long_options, (int *) 0)) != EOF) + n_files = 0; + file_names = (char **) xmalloc ((argc - 1) * sizeof (char *)); + + while (1) { - if (ISDIGIT (c)) + c = getopt_long (argc, argv, + "-0123456789abcde::fFh:i::l:mn::o:rs::tvw:", + long_options, (int *) 0); + if (c == 1) /* Non-option argument. */ { - accum = accum * 10 + c - '0'; - continue; + char *s; + s = optarg; + if (*s == '+') + { + ++s; + if (!ISDIGIT (*s)) + { + error (0, 0, "`+' requires a numeric argument"); + usage (); + } + /* FIXME: use strtol */ + first_page_number = atoi (s); + } + else + { + file_names[n_files++] = optarg; + } } else { - if (accum > 0) + if (ISDIGIT (c)) { - columns = accum; - explicit_columns = TRUE; + accum = accum * 10 + c - '0'; + continue; + } + else + { + if (accum > 0) + { + columns = accum; + explicit_columns = TRUE; + accum = 0; + } } - accum = 0; } + if (c == 1) + continue; + + if (c == EOF) + break; + switch (c) { case 0: /* getopt long option */ @@ -561,7 +614,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); @@ -574,20 +630,12 @@ main (argc, argv) error (1, 0, "Cannot specify both printing across and printing in parallel."); - if (optind >= 2 && strcmp (argv[optind - 1], "--") == 0) + for ( ; optind < argc; optind++) { - /* We've seen `--', so interpret all remaining arguments as - filenames. */ - } - else - { - for ( ; optind < argc && argv[optind][0] == '+'; optind++) - { - first_page_number = atoi (&argv[optind][1]); - } + file_names[n_files++] = argv[optind]; } - if (optind >= argc) + if (n_files == 0) { /* No file arguments specified; read from standard input. */ print_files (0, (char **) 0); @@ -595,11 +643,12 @@ main (argc, argv) else { if (parallel_files) - print_files (argc - optind, &argv[optind]); + print_files (n_files, file_names); else { - for ( ; optind < argc; optind++) - print_files (1, &argv[optind]); + int i; + for (i=0; istatus = CLOSED; if (q->lines_stored == 0) { - if (cols_ready_to_print > 0 && !print_across_flag) - --cols_ready_to_print; q->lines_to_print = 0; } } @@ -1078,24 +1125,18 @@ init_page () int j; COLUMN *p; - cols_ready_to_print = 0; - if (storing_columns) { store_columns (); for (j = columns - 1, p = column_vector; j; --j, ++p) { p->lines_to_print = p->lines_stored; - if (p->lines_to_print != 0) - ++cols_ready_to_print; } /* Last column. */ if (balance_columns) { p->lines_to_print = p->lines_stored; - if (p->lines_to_print != 0) - ++cols_ready_to_print; } /* Since we're not balancing columns, we don't need to store the rightmost column. Read it straight from the file. */ @@ -1104,7 +1145,6 @@ init_page () if (p->status == OPEN) { p->lines_to_print = lines_per_body; - ++cols_ready_to_print; } else p->lines_to_print = 0; @@ -1115,7 +1155,6 @@ init_page () if (p->status == OPEN) { p->lines_to_print = lines_per_body; - ++cols_ready_to_print; } else p->lines_to_print = 0; @@ -1150,7 +1189,7 @@ print_page () init_page (); - if (cols_ready_to_print == 0) + if (crtp () == 0) return FALSE; if (extremities) @@ -1164,7 +1203,7 @@ print_page () if (double_space) lines_left_on_page *= 2; - while (lines_left_on_page > 0 && cols_ready_to_print > 0) + while (lines_left_on_page > 0 && crtp () > 0) { output_position = 0; spaces_not_printed = 0; @@ -1188,8 +1227,7 @@ print_page () --p->lines_to_print; if (p->lines_to_print <= 0) { - --cols_ready_to_print; - if (cols_ready_to_print <= 0) + if (crtp () <= 0) break; } } diff --git a/src/sort.c b/src/sort.c index 4acc1e5..42e0b8e 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1747,6 +1747,14 @@ main (argc, argv) sort (files, nfiles, ofp); cleanup (); + /* If we wait for the implicit flush on exit, and the parent process + has closed stdout (e.g., exec >&- in a shell), then the output file + winds up empty. I don't understand why. This is under SunOS, + Solaris, Ultrix, and Irix. This premature fflush makes the output + reappear. --karl@cs.umb.edu */ + if (fflush (ofp) < 0) + error (1, errno, "fflush", outfile); + if (have_read_stdin && fclose (stdin) == EOF) error (1, errno, "-"); if (ferror (stdout) || fclose (stdout) == EOF) diff --git a/src/split.c b/src/split.c index addddd9..d425b52 100644 --- a/src/split.c +++ b/src/split.c @@ -185,7 +185,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage ((char *)0); diff --git a/src/sum.c b/src/sum.c index c10f0b8..1283078 100644 --- a/src/sum.c +++ b/src/sum.c @@ -95,7 +95,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/tac.c b/src/tac.c index 8107823..30de5ab 100644 --- a/src/tac.c +++ b/src/tac.c @@ -167,7 +167,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/tail.c b/src/tail.c index d3bc8cd..8feceb6 100644 --- a/src/tail.c +++ b/src/tail.c @@ -257,7 +257,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/tr.c b/src/tr.c index f2a3fac..f979afb 100644 --- a/src/tr.c +++ b/src/tr.c @@ -1666,7 +1666,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/unexpand.c b/src/unexpand.c index 6fc5e78..27e8d95 100644 --- a/src/unexpand.c +++ b/src/unexpand.c @@ -157,7 +157,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/uniq.c b/src/uniq.c index 20fa6d5..aab70db 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -154,7 +154,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); diff --git a/src/wc.c b/src/wc.c index 22aa533..b484911 100644 --- a/src/wc.c +++ b/src/wc.c @@ -111,7 +111,10 @@ main (argc, argv) } if (flag_version) - fprintf (stderr, "%s\n", version_string); + { + fprintf (stderr, "%s\n", version_string); + exit (0); + } if (flag_help) usage (); -- 2.7.4