aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/pr
diff options
context:
space:
mode:
authorNate Williams <nate@FreeBSD.org>1993-11-08 17:07:38 +0000
committerNate Williams <nate@FreeBSD.org>1993-11-08 17:07:38 +0000
commit250e001b2c62455cba410c74f485f1906e99359c (patch)
treed21c9226ea4e4473b5a4db104749bd389e4f33d9 /gnu/usr.bin/pr
parente95e7fce8af340d8fc0a30356c6b2aa16112f0f3 (diff)
Notes
Diffstat (limited to 'gnu/usr.bin/pr')
-rw-r--r--gnu/usr.bin/pr/Makefile8
-rw-r--r--gnu/usr.bin/pr/error.c13
-rw-r--r--gnu/usr.bin/pr/getopt.c108
-rw-r--r--gnu/usr.bin/pr/getopt1.c13
-rw-r--r--gnu/usr.bin/pr/pr.12
-rw-r--r--gnu/usr.bin/pr/pr.c89
-rw-r--r--gnu/usr.bin/pr/system.h36
-rw-r--r--gnu/usr.bin/pr/version.c13
-rw-r--r--gnu/usr.bin/pr/xmalloc.c43
9 files changed, 244 insertions, 81 deletions
diff --git a/gnu/usr.bin/pr/Makefile b/gnu/usr.bin/pr/Makefile
index 6c8d431ebc60..d651c20149fd 100644
--- a/gnu/usr.bin/pr/Makefile
+++ b/gnu/usr.bin/pr/Makefile
@@ -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>
diff --git a/gnu/usr.bin/pr/error.c b/gnu/usr.bin/pr/error.c
index e849c5b2fb1a..41d66fb4f4f7 100644
--- a/gnu/usr.bin/pr/error.c
+++ b/gnu/usr.bin/pr/error.c
@@ -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
diff --git a/gnu/usr.bin/pr/getopt.c b/gnu/usr.bin/pr/getopt.c
index a59a01339835..7a4673b8d8db 100644
--- a/gnu/usr.bin/pr/getopt.c
+++ b/gnu/usr.bin/pr/getopt.c
@@ -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;
+
+ /* 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. */
- /* Interchange the two blocks of data in ARGV. */
+ 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;
- 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);
+ /* 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. */
diff --git a/gnu/usr.bin/pr/getopt1.c b/gnu/usr.bin/pr/getopt1.c
index a32615ce36e7..f784b5757c59 100644
--- a/gnu/usr.bin/pr/getopt1.c
+++ b/gnu/usr.bin/pr/getopt1.c
@@ -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>
diff --git a/gnu/usr.bin/pr/pr.1 b/gnu/usr.bin/pr/pr.1
index 10cdd8c133d6..814f4e15150b 100644
--- a/gnu/usr.bin/pr/pr.1
+++ b/gnu/usr.bin/pr/pr.1
@@ -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.
diff --git a/gnu/usr.bin/pr/pr.c b/gnu/usr.bin/pr/pr.c
index 250f532b7326..8ecc2c6f021c 100644
--- a/gnu/usr.bin/pr/pr.c
+++ b/gnu/usr.bin/pr/pr.c
@@ -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);
}
diff --git a/gnu/usr.bin/pr/system.h b/gnu/usr.bin/pr/system.h
index d26022dde740..4aeaaea188b6 100644
--- a/gnu/usr.bin/pr/system.h
+++ b/gnu/usr.bin/pr/system.h
@@ -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
diff --git a/gnu/usr.bin/pr/version.c b/gnu/usr.bin/pr/version.c
index a6294189cc79..64c62b1953ab 100644
--- a/gnu/usr.bin/pr/version.c
+++ b/gnu/usr.bin/pr/version.c
@@ -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";
diff --git a/gnu/usr.bin/pr/xmalloc.c b/gnu/usr.bin/pr/xmalloc.c
index f989004bebcd..58a81b5abbce 100644
--- a/gnu/usr.bin/pr/xmalloc.c
+++ b/gnu/usr.bin/pr/xmalloc.c
@@ -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);