Updated to GNU textutils-1.9

This commit is contained in:
Nate Williams 1993-11-08 17:07:38 +00:00
parent e95e7fce8a
commit 250e001b2c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=729
9 changed files with 244 additions and 81 deletions

View File

@ -1,7 +1,11 @@
PROG= pr
SRCS= pr.c getopt.c getopt1.c error.c xmalloc.c version.c
CFLAGS+=-I${.CURDIR}
CFLAGS+=-I${.CURDIR} -DDIRENT=1 -DHAVE_LONG_DOUBLE=1 -DHAVE_LONG_DOUBLE=1 \
-DHAVE_ST_BLKSIZE=1 -DHAVE_VPRINTF=1 -DRETSIGTYPE=void \
-DSTDC_HEADERS=1 -DDHAVE_STRERROR=1 -DHAVE_FCNTL_H=1 \
-DHAVE_LIMITS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRING_H=1 \
-DHAVE_UNISTD_H=1
.include <bsd.prog.mk>

View File

@ -1,5 +1,5 @@
/* error.c -- error handler for noninteractive utilities
Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,6 +17,17 @@
/* Written by David MacKenzie. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#ifdef HAVE_VPRINTF

View File

@ -20,31 +20,24 @@
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* NOTE!!! AIX requires this to be the first thing in the file.
Do not put ANYTHING before it! */
#if !defined (__GNUC__) && defined (_AIX)
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#if defined (emacs) || defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
#include <alloca.h>
#else
#ifndef _AIX
char *alloca ();
#endif
#endif /* alloca.h */
#endif /* not __GNUC__ */
#if !__STDC__ && !defined(const) && IN_GCC
#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. */
#ifndef _NO_PROTO
@ -67,12 +60,9 @@ char *alloca ();
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#undef alloca
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#else /* Not GNU C library. */
#define __alloca alloca
#endif /* GNU C library. */
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
@ -180,7 +170,6 @@ static enum
in GCC. */
#include <string.h>
#define my_index strchr
#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
#else
/* Avoid depending on library functions or files
@ -202,16 +191,19 @@ my_index (str, chr)
return 0;
}
static void
my_bcopy (from, to, size)
const char *from;
char *to;
int size;
{
int i;
for (i = 0; i < size; i++)
to[i] = from[i];
}
/* If using GCC, we can safely declare strlen this way.
If not using GCC, it is ok not to declare it.
(Supposedly there are some machines where it might get a warning,
but changing this conditional to __STDC__ is too risky.) */
#ifdef __GNUC__
#ifdef IN_GCC
#include "gstddef.h"
#else
#include <stddef.h>
#endif
extern size_t strlen (const char *);
#endif
#endif /* GNU C library. */
/* Handle permutation of arguments. */
@ -236,17 +228,51 @@ static void
exchange (argv)
char **argv;
{
int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
char **temp = (char **) __alloca (nonopts_size);
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
/* Interchange the two blocks of data in ARGV. */
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
(optind - last_nonopt) * sizeof (char *));
my_bcopy ((char *) temp,
(char *) &argv[first_nonopt + optind - last_nonopt],
nonopts_size);
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */

View File

@ -17,14 +17,25 @@
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#if defined (emacs) || defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include "getopt.h"
#if !__STDC__ && !defined(const) && IN_GCC
#ifndef __STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#include <stdio.h>

View File

@ -97,7 +97,7 @@ blank lines or formfeeds).
Print unprintable characters in octal backslash notation.
.TP
.I "\-\-version"
Print version information on standard error then exit.
Print version information on standard output then exit.
.TP
.I "\-w page-width"
Set the page width to \fIpage-width\fP columns. The default is 72.

View File

@ -94,6 +94,17 @@
-w width Set the page width to WIDTH characters. */
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
@ -426,15 +437,15 @@ static int *clump_buff;
static int truncate_lines = FALSE;
/* If non-zero, display usage information and exit. */
static int flag_help;
static int show_help;
/* If non-zero, print the version on standard error. */
static int flag_version;
/* If non-zero, print the version on standard output then exit. */
static int show_version;
static struct option const long_options[] =
{
{"help", no_argument, &flag_help, 1},
{"version", no_argument, &flag_version, 1},
{"help", no_argument, &show_help, 1},
{"version", no_argument, &show_version, 1},
{0, 0, 0, 0}
};
@ -469,7 +480,9 @@ main (argc, argv)
program_name = argv[0];
n_files = 0;
file_names = (char **) xmalloc ((argc - 1) * sizeof (char *));
file_names = (argc > 1
? (char **) xmalloc ((argc - 1) * sizeof (char *))
: NULL);
while (1)
{
@ -486,7 +499,7 @@ main (argc, argv)
if (!ISDIGIT (*s))
{
error (0, 0, "`+' requires a numeric argument");
usage ();
usage (2);
}
/* FIXME: use strtol */
first_page_number = atoi (s);
@ -591,7 +604,7 @@ main (argc, argv)
fprintf (stderr, "\
%s: extra characters in the argument to the `-s' option: `%s'\n",
program_name, s);
usage ();
usage (2);
}
}
break;
@ -605,19 +618,19 @@ main (argc, argv)
chars_per_line = atoi (optarg);
break;
default:
usage ();
usage (2);
break;
}
}
if (flag_version)
if (show_version)
{
fprintf (stderr, "%s\n", version_string);
printf ("%s\n", version_string);
exit (0);
}
if (flag_help)
usage ();
if (show_help)
usage (0);
if (parallel_files && explicit_columns)
error (1, 0,
@ -682,7 +695,7 @@ getoptarg (arg, switch_char, character, number)
fprintf (stderr, "\
%s: extra characters in the argument to the `-%c' option: `%s'\n",
program_name, switch_char, arg);
usage ();
usage (2);
}
}
}
@ -1863,13 +1876,45 @@ cleanup ()
/* Complain, print a usage message, and die. */
static void
usage ()
usage (status)
int status;
{
fprintf (stderr, "\
Usage: %s [+PAGE] [-COLUMN] [-abcdfFmrtv] [-e[in-tab-char[in-tab-width]]]\n\
[-h header] [-i[out-tab-char[out-tab-width]]] [-l page-length]\n\
[-n[number-separator[digits]]] [-o left-margin]\n\
[-s[column-separator]] [-w page-width] [--help] [--version] [file...]\n",
program_name);
exit (2);
if (status != 0)
fprintf (stderr, "Try `%s --help' for more information.\n",
program_name);
else
{
printf ("\
Usage: %s [OPTION]... [FILE]...\n\
",
program_name);
printf ("\
\n\
+PAGE begin printing with page PAGE\n\
-COLUMN produce COLUMN-column output and print columns down\n\
-F, -f simulate formfeed with newlines on output\n\
-a print columns across rather than down\n\
-b balance columns on the last page\n\
-c use hat notation (^G) and octal backslash notation\n\
-d double space the output\n\
-e[CHAR[WIDTH]] expand input CHARs (TABs) to tab WIDTH (8)\n\
-h HEADER use HEADER instead of filename in page headers\n\
-i[CHAR[WIDTH]] replace spaces with CHARs (TABs) to tab WIDTH (8)\n\
-l PAGE_LENGTH set the page length to PAGE_LENGTH (66) lines\n\
-m print all files in parallel, one in each column\n\
-n[SEP[DIGITS]] number lines, use DIGITS (5) digits, then SEP (TAB)\n\
-o MARGIN offset each line with MARGIN spaces (do not affect -w)\n\
-r inhibit warning when a file cannot be opened\n\
-s[SEP] separate columns by character SEP (TAB)\n\
-t inhibit 5-line page headers and trailers\n\
-v use octal backslash notation\n\
-w PAGE_WIDTH set page width to PAGE_WIDTH (72) columns\n\
--help display this help and exit\n\
--version output version information and exit\n\
\n\
-t implied by -l N when N < 10. Without -s, columns are separated by\n\
spaces. With no FILE, or when FILE is -, read standard input.\n\
");
}
exit (status);
}

View File

@ -18,6 +18,40 @@
/* Include sys/types.h before this file. */
#include <sys/stat.h>
#ifdef STAT_MACROS_BROKEN
#ifdef S_ISBLK
#undef S_ISBLK
#endif
#ifdef S_ISCHR
#undef S_ISCHR
#endif
#ifdef S_ISDIR
#undef S_ISDIR
#endif
#ifdef S_ISFIFO
#undef S_ISFIFO
#endif
#ifdef S_ISLNK
#undef S_ISLNK
#endif
#ifdef S_ISMPB
#undef S_ISMPB
#endif
#ifdef S_ISMPC
#undef S_ISMPC
#endif
#ifdef S_ISNWK
#undef S_ISNWK
#endif
#ifdef S_ISREG
#undef S_ISREG
#endif
#ifdef S_ISSOCK
#undef S_ISSOCK
#endif
#endif /* STAT_MACROS_BROKEN. */
#ifndef S_ISREG /* Doesn't have POSIX.1 stat stuff. */
#define mode_t unsigned short
#endif
@ -80,10 +114,8 @@ off_t lseek ();
#endif
#else
#include <strings.h>
#ifndef __386BSD__
char *memchr ();
#endif
#endif
#include <errno.h>
#ifdef STDC_HEADERS

View File

@ -1,2 +1,13 @@
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#include "version.h"
const char *version_string = "GNU textutils 1.6";
const char *version_string = "GNU textutils 1.9";

View File

@ -1,5 +1,5 @@
/* xmalloc.c -- malloc with out of memory checking
Copyright (C) 1990, 1991 Free Software Foundation, Inc.
Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,23 +15,46 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef STDC_HEADERS
#ifdef HAVE_CONFIG_H
#if defined (CONFIG_BROKETS)
/* We use <config.h> instead of "config.h" so that a compilation
using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
(which it would do because it found this file in $srcdir). */
#include <config.h>
#else
#include "config.h"
#endif
#endif
#if __STDC__
#define VOID void
#else
#define VOID char
#endif
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#else
char *malloc ();
char *realloc ();
VOID *malloc ();
VOID *realloc ();
void free ();
#endif
#if __STDC__ && defined (HAVE_VPRINTF)
void error (int, int, char const *, ...);
#else
void error ();
#endif
/* Allocate N bytes of memory dynamically, with error checking. */
char *
VOID *
xmalloc (n)
unsigned n;
size_t n;
{
char *p;
VOID *p;
p = malloc (n);
if (p == 0)
@ -45,10 +68,10 @@ xmalloc (n)
If P is NULL, run xmalloc.
If N is 0, run free and return NULL. */
char *
VOID *
xrealloc (p, n)
char *p;
unsigned n;
VOID *p;
size_t n;
{
if (p == 0)
return xmalloc (n);