From 38575ad4621f4c73c70ce1c607d031736021f3b0 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 10 Dec 1992 19:34:55 +0000 Subject: [PATCH] Merge with pre-release 1.3.6. --- old/textutils/ChangeLog | 17 +++++++++++++---- src/csplit.c | 4 ---- src/od.c | 16 ++++++++-------- src/sort.c | 31 +++++++++++++++++++++---------- src/tail.c | 27 ++++++++++++++++++++------- src/tr.c | 6 ++++++ 6 files changed, 68 insertions(+), 33 deletions(-) diff --git a/old/textutils/ChangeLog b/old/textutils/ChangeLog index 598c090..a4fa7d7 100644 --- a/old/textutils/ChangeLog +++ b/old/textutils/ChangeLog @@ -1,4 +1,4 @@ -Tue Dec 8 10:31:14 CST 1992 +Tue Dec 8 10:31:14 1992 Jim Meyering (meyering@idefix.comco.com) * tr.c (is_char_class_member): Remove unreached return after abort. @@ -18,11 +18,16 @@ Wed Dec 2 12:28:10 1992 Jim Meyering (meyering@idefix.comco.com) struct option to use new macros from getopt.h: no_argument, required_argument, and optional_argument. -Wed Nov 25 07:51:55 1992 Jim Meyering (meyering@idefix.comco.com) +Tue Dec 01 10:57:24 1992 Jim Meyering (meyering@idefix.comco.com) - * pr.c, sort.c, od.c: Make definitions of ISPRINT etc consistent. + * od.c, pr.c, sort.c: Make uses of ctype.h macros consistent. - * tr.c (main): Close stdin and stdout. + * tr.c (main): Close stdin and stdout and check return status. + +Tue Nov 24 09:26:08 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu) + + * system.h, csplit.c: Use HAVE_FCNTL_H and HAVE_STRING_H + instead of USG. Tue Nov 24 08:42:30 1992 Jim Meyering (meyering@idefix.comco.com) @@ -48,6 +53,10 @@ Tue Nov 24 08:42:30 1992 Jim Meyering (meyering@idefix.comco.com) (write_block, dump_strings, dump): Don't test return value from functions that operate on streams. Rely on later ferror tests. +Sat Nov 21 12:41:49 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu) + + * sort.c (main, usage): Add -T option. + Thu Nov 19 14:33:40 1992 David J. MacKenzie (djm@goldman.gnu.ai.mit.edu) * tail.c (tail_forever, sigusr1, kill_kids): New functions to diff --git a/src/csplit.c b/src/csplit.c index 7b2165e..8d27ce0 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -25,10 +25,6 @@ #include "regex.h" #include "system.h" -#if !defined(USG) && !defined(STDC_HEADERS) -char *memchr (); -#endif - #ifdef STDC_HEADERS #include #else diff --git a/src/od.c b/src/od.c index ae2c3da..0e9161b 100644 --- a/src/od.c +++ b/src/od.c @@ -1,4 +1,4 @@ -/* od -- dump in octal (and other formats) the contents of files +/* od -- dump files in octal and other formats Copyright (C) 1992 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -1624,13 +1624,13 @@ main (argc, argv) specs. GNU od accepts any combination of old- and new-style options. Format specification options accumulate. */ -#define CASE_OLD_ARG(old_char,new_string) \ - case old_char: \ - { \ - int tmp; \ - tmp = decode_format_string (new_string); \ - assert (tmp == 0); \ - } \ +#define CASE_OLD_ARG(old_char,new_string) \ + case old_char: \ + { \ + int tmp; \ + tmp = decode_format_string (new_string); \ + assert (tmp == 0); \ + } \ break CASE_OLD_ARG ('a', "a"); diff --git a/src/sort.c b/src/sort.c index e514284..f4f6578 100644 --- a/src/sort.c +++ b/src/sort.c @@ -107,7 +107,7 @@ static int linelength = 30; #define LINEALLOC 262144 /* Prefix for temporary file names. */ -static char *prefix; +static char *temp_file_prefix; /* Flag to reverse the order of all comparisons. */ static int reverse; @@ -292,15 +292,15 @@ static char * tempname () { static int seq; - int len = strlen (prefix); + int len = strlen (temp_file_prefix); char *name = xmalloc (len + 16); struct tempnode *node = (struct tempnode *) xmalloc (sizeof (struct tempnode)); - if (len && prefix[len - 1] != '/') - sprintf (name, "%s/sort%5.5d%5.5d", prefix, getpid (), ++seq); + if (len && temp_file_prefix[len - 1] != '/') + sprintf (name, "%s/sort%5.5d%5.5d", temp_file_prefix, getpid (), ++seq); else - sprintf (name, "%ssort%5.5d%5.5d", prefix, getpid (), ++seq); + sprintf (name, "%ssort%5.5d%5.5d", temp_file_prefix, getpid (), ++seq); node->name = name; node->next = temphead.next; temphead.next = node; @@ -1427,9 +1427,9 @@ main (argc, argv) have_read_stdin = 0; inittables (); - prefix = getenv ("TMPDIR"); - if (prefix == NULL) - prefix = "/tmp"; + temp_file_prefix = getenv ("TMPDIR"); + if (temp_file_prefix == NULL) + temp_file_prefix = "/tmp"; #ifdef _POSIX_VERSION newact.sa_handler = sighandler; @@ -1625,6 +1625,17 @@ main (argc, argv) else error (2, 0, "option `-t' requires an argument"); break; + case 'T': + if (s[1]) + temp_file_prefix = ++s; + else if (i < argc - 1) + { + temp_file_prefix = argv[++i]; + goto outer; + } + else + error (2, 0, "option `-T' requires an argument"); + break; case 'u': unique = 1; break; @@ -1725,8 +1736,8 @@ static void usage () { fprintf (stderr, "\ -Usage: %s [-cmus] [-t separator] [-o output-file] [-bdfiMnr] [+POS1 [-POS2]]\n\ - [-k POS1[,POS2]] [file...]\n", +Usage: %s [-cmus] [-t separator] [-o output-file] [-T tempdir] [-bdfiMnr]\n\ + [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]\n", program_name); exit (2); } diff --git a/src/tail.c b/src/tail.c index a94ac9c..be0978f 100644 --- a/src/tail.c +++ b/src/tail.c @@ -43,7 +43,7 @@ Original version by Paul Rubin . Extensions by David MacKenzie . - tail -f for multiple files by Ian Lance Taylor . */ + tail -f for multiple files by Ian Lance Taylor . */ #include #include @@ -907,9 +907,22 @@ tail_forever (names, nfiles) pids = (int *) xmalloc (nfiles * sizeof (int)); - /* fork once for each file. If this is too ugly for you, don't use - tail -f on multiple files. Maybe we could use select as an - alternative, though it's less portable. Is it worth the bother? */ + /* fork once for each file. This approach uses one process and + one file descriptor for each file we tail. + More resource-efficient approaches would be: + + 1. Keep an off_t array of the last-seen sizes of the files, + and fstat them each in turn, watching for growth. + This would be more portable, but still use the same number of + file descriptors, and would probably use more CPU. + For pipes, perhaps a separate process would have to be forked to + read from the pipe and write to a temporary file. + + 2. Keep an off_t array, but only keep recently changed files open + and use stat for the others, opening them only if they change. + This would save file descriptors, to allow tail -f on a large number + of files. It's probably not worth the trouble for most uses, though, + and GNU won't have arbitrary limits on things like file descriptors. */ signal (SIGUSR1, sigusr1); @@ -929,11 +942,11 @@ tail_forever (names, nfiles) close (pipe_descs[0]); /* Each child reads continually from a file and writes to - the pipe. Each write to a pipe is the index of the file + the pipe. Each write to the pipe is the index of the file being read, followed by the number of bytes read from the - file, followed by the actual bytes. Each child is + file, followed by the actual data. Each child is careful to write no more than PIPE_BUF bytes to the pipe, - so that the data from the various children does not get + so that the data from the various children do not get intermixed. */ /* The file index for this child is always the same. */ diff --git a/src/tr.c b/src/tr.c index d0a170d..873a235 100644 --- a/src/tr.c +++ b/src/tr.c @@ -1802,5 +1802,11 @@ deleting and squeezing repeats"); } } + if (fclose (stdout) == EOF) + error (2, errno, "write error"); + + if (close (0) != 0) + error (2, errno, "standard input"); + exit (0); } -- 2.7.4