merge with 1.5.2
authorJim Meyering <jim@meyering.net>
Sat, 22 May 1993 05:06:39 +0000 (05:06 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 22 May 1993 05:06:39 +0000 (05:06 +0000)
25 files changed:
lib/regex.c
old/textutils/ChangeLog
old/textutils/NEWS
src/cat.c
src/cksum.c
src/comm.c
src/csplit.c
src/cut.c
src/expand.c
src/fold.c
src/head.c
src/join.c
src/nl.c
src/od.c
src/paste.c
src/pr.c
src/sort.c
src/split.c
src/sum.c
src/tac.c
src/tail.c
src/tr.c
src/unexpand.c
src/uniq.c
src/wc.c

index 5bd4cf6..e8b5882 100644 (file)
@@ -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
index 7a85cf2..d0f54b5 100644 (file)
@@ -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.
index c63422f..0742b70 100644 (file)
@@ -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
+\f
 Major changes in release 1.5:
 * sort is 8-bit clean
 * sort's -n and -M options no longer imply -b
index 98da7c9..724976d 100644 (file)
--- 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 ();
index e629dd8..b5e1887 100644 (file)
@@ -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 ();
index 8b4f87f..c5f4c39 100644 (file)
@@ -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 ();
index eaea8c3..6eedd39 100644 (file)
@@ -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 ();
index 2e611a9..e7997fd 100644 (file)
--- 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 ();
index f269510..99ce5c4 100644 (file)
@@ -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 ();
index ca20a28..b3cb098 100644 (file)
@@ -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 ();
index 6d7ac55..ec4d730 100644 (file)
@@ -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 ();
index 39599ef..48e791a 100644 (file)
@@ -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 ();
index 1444002..431c3e9 100644 (file)
--- 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 ();
index ea4f12b..f2f0b3c 100644 (file)
--- 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 ();
index bc9b7e5..a45b6fe 100644 (file)
@@ -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 ();
index 876387d..edf4147 100644 (file)
--- 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; i<n_files; i++)
+           print_files (1, &file_names[i]);
        }
     }
 
@@ -926,8 +975,6 @@ close_file (p)
          q->status = 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;
                }
            }
index 4acc1e5..42e0b8e 100644 (file)
@@ -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)
index addddd9..d425b52 100644 (file)
@@ -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);
index c10f0b8..1283078 100644 (file)
--- 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 ();
index 8107823..30de5ab 100644 (file)
--- 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 ();
index d3bc8cd..8feceb6 100644 (file)
@@ -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 ();
index f2a3fac..f979afb 100644 (file)
--- 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 ();
index 6fc5e78..27e8d95 100644 (file)
@@ -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 ();
index 20fa6d5..aab70db 100644 (file)
@@ -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 ();
index 22aa533..b484911 100644 (file)
--- 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 ();