add berkeley pr

This commit is contained in:
cgd 1994-01-06 15:57:10 +00:00
parent 107d69c359
commit c4b27fe2cd
5 changed files with 634 additions and 2 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.8.1.1 (Berkeley) 5/8/91
# $Id: Makefile,v 1.32 1993/12/21 02:54:58 cgd Exp $
# $Id: Makefile,v 1.33 1994/01/06 15:57:10 cgd Exp $
SUBDIR= apropos ar asa at biff basename cal calendar cap_mkdb \
checknr chpass cksum cmp col colcrt colrm column comm compress \
@ -9,7 +9,7 @@ SUBDIR= apropos ar asa at biff basename cal calendar cap_mkdb \
ipcrm ipcs join ktrace last lastcomm leave lex locate lock logger \
login logname look lorder m4 machine mail make man mesg mkdep mkfifo \
mkstr modstat more msgs netstat newsyslog nfsstat nice nm nohup \
pagesize passwd paste patch printenv printf quota ranlib \
pagesize passwd paste patch pr printenv printf quota ranlib \
rdist ref renice rev rlogin rpcgen rpcinfo \
rsh rup ruptime rusers rwall rwho \
sccs script sed shar showmount size soelim split strings \

7
usr.bin/pr/Makefile Normal file
View File

@ -0,0 +1,7 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
# $Id: Makefile,v 1.1 1994/01/06 15:57:17 cgd Exp $
PROG= pr
SRCS= pr.c egetopt.c
.include <bsd.prog.mk>

216
usr.bin/pr/egetopt.c Normal file
View File

@ -0,0 +1,216 @@
/*-
* Copyright (c) 1991 Keith Muller.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Keith Muller of the University of California, San Diego.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
/* from: static char sccsid[] = "@(#)egetopt.c 8.1 (Berkeley) 6/6/93"; */
static char *rcsid = "$Id: egetopt.c,v 1.1 1994/01/06 15:57:18 cgd Exp $";
#endif /* not lint */
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "extern.h"
/*
* egetopt: get option letter from argument vector (an extended
* version of getopt).
*
* Non standard additions to the ostr specs are:
* 1) '?': immediate value following arg is optional (no white space
* between the arg and the value)
* 2) '#': +/- followed by a number (with an optional sign but
* no white space between the arg and the number). The - may be
* combined with other options, but the + cannot.
*/
int eopterr = 1; /* if error message should be printed */
int eoptind = 1; /* index into parent argv vector */
int eoptopt; /* character checked for validity */
char *eoptarg; /* argument associated with option */
#define BADCH (int)'?'
#define EMSG ""
int
egetopt(nargc, nargv, ostr)
int nargc;
char * const *nargv;
const char *ostr;
{
static char *place = EMSG; /* option letter processing */
register char *oli; /* option letter list index */
static int delim; /* which option delimeter */
register char *p;
static char savec = '\0';
if (savec != '\0') {
*place = savec;
savec = '\0';
}
if (!*place) {
/*
* update scanning pointer
*/
if ((eoptind >= nargc) ||
((*(place = nargv[eoptind]) != '-') && (*place != '+'))) {
place = EMSG;
return (EOF);
}
delim = (int)*place;
if (place[1] && *++place == '-' && !place[1]) {
/*
* found "--"
*/
++eoptind;
place = EMSG;
return (EOF);
}
}
/*
* check option letter
*/
if ((eoptopt = (int)*place++) == (int)':' || (eoptopt == (int)'?') ||
!(oli = strchr(ostr, eoptopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means EOF when by itself.
*/
if ((eoptopt == (int)'-') && !*place)
return (EOF);
if (strchr(ostr, '#') && (isdigit(eoptopt) ||
(((eoptopt == (int)'-') || (eoptopt == (int)'+')) &&
isdigit(*place)))) {
/*
* # option: +/- with a number is ok
*/
for (p = place; *p != '\0'; ++p) {
if (!isdigit(*p))
break;
}
eoptarg = place-1;
if (*p == '\0') {
place = EMSG;
++eoptind;
} else {
place = p;
savec = *p;
*place = '\0';
}
return (delim);
}
if (!*place)
++eoptind;
if (eopterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void)fprintf(stderr, "%s: illegal option -- %c\n",
p, eoptopt);
}
return (BADCH);
}
if (delim == (int)'+') {
/*
* '+' is only allowed with numbers
*/
if (!*place)
++eoptind;
if (eopterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void)fprintf(stderr,
"%s: illegal '+' delimiter with option -- %c\n",
p, eoptopt);
}
return (BADCH);
}
++oli;
if ((*oli != ':') && (*oli != '?')) {
/*
* don't need argument
*/
eoptarg = NULL;
if (!*place)
++eoptind;
return (eoptopt);
}
if (*place) {
/*
* no white space
*/
eoptarg = place;
} else if (*oli == '?') {
/*
* no arg, but NOT required
*/
eoptarg = NULL;
} else if (nargc <= ++eoptind) {
/*
* no arg, but IS required
*/
place = EMSG;
if (eopterr) {
if (!(p = strrchr(*nargv, '/')))
p = *nargv;
else
++p;
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n", p,
eoptopt);
}
return (BADCH);
} else {
/*
* arg has white space
*/
eoptarg = nargv[eoptind];
}
place = EMSG;
++eoptind;
return (eoptopt);
}

61
usr.bin/pr/extern.h Normal file
View File

@ -0,0 +1,61 @@
/*-
* Copyright (c) 1991 Keith Muller.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Keith Muller of the University of California, San Diego.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)extern.h 8.1 (Berkeley) 6/6/93
* $Id: extern.h,v 1.1 1994/01/06 15:57:19 cgd Exp $
*/
extern int eoptind;
extern char *eoptarg;
void addnum __P((char *, int, int));
int egetopt __P((int, char * const *, const char *));
void flsh_errs __P((void));
int horzcol __P((int, char **));
int inln __P((FILE *, char *, int, int *, int, int *));
int inskip __P((FILE *, int, int));
void mfail __P((void));
int mulfile __P((int, char **));
FILE *nxtfile __P((int, char **, char **, char *, int));
int onecol __P((int, char **));
int otln __P((char *, int, int *, int *, int));
void pfail __P((void));
int prhead __P((char *, char *, int));
int prtail __P((int, int));
int setup __P((int, char **));
void terminate __P((int));
void usage __P((void));
int vertcol __P((int, char **));

348
usr.bin/pr/pr.1 Normal file
View File

@ -0,0 +1,348 @@
.\" Copyright (c) 1991 Keith Muller.
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Keith Muller of the University of California, San Diego.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)pr.1 8.1 (Berkeley) 6/6/93
.\" $Id: pr.1,v 1.1 1994/01/06 15:57:21 cgd Exp $
.\"
.Dd June 6, 1993
.Dt PR 1
.Os BSD 4.4
.Sh NAME
.Nm pr
.Nd print files
.Sh SYNOPSIS
.Nm pr
.Bk -words
.Op Ar \&+page
.Ek
.Bk -words
.Op Fl Ar column
.Ek
.Op Fl adFmrt
.Bk -words
.Oo
.Op Fl e
.Op Ar char
.Op Ar gap
.Oc
.Ek
.Bk -words
.Op Fl h Ar header
.Ek
.Bk -words
.Oo
.Op Fl i
.Op Ar char
.Op Ar gap
.Oc
.Ek
.Bk -words
.Op Fl l Ar lines
.Ek
.Bk -words
.Op Fl o Ar offset
.Ek
.Bk -words
.Oo
.Op Fl s
.Op Ar char
.Oc
.Ek
.Bk -words
.Oo
.Op Fl n
.Op Ar char
.Op Ar width
.Oc
.Ek
.Bk -words
.Op Fl w Ar width
.Ek
.Op -
.Op Ar file ...
.Sh DESCRIPTION
The
.Nm pr
utility is a printing and pagination filter for text files.
When multiple input files are specified, each is read, formatted,
and written to standard output.
By default, the input is separated into 66-line pages, each with
.sp
.in +2
.ti -2
\(bu A 5-line header with the page number, date, time, and
the pathname of the file.
.sp
.ti -2
\(bu A 5-line trailer consisting of blank lines.
.in -2
.Pp
If standard output is associated with a terminal,
diagnostic messages are suppressed until the
.Nm pr
utility has completed processing.
.Pp
When multiple column output is specified,
text columns are of equal width.
By default text columns are separated by at least one
.Em <blank>.
Input lines that do not fit into a text column are truncated.
Lines are not truncated under single column output.
.Sh OPTIONS
.Pp
In the following option descriptions, column, lines, offset, page, and
width are positive decimal integers and gap is a nonnegative decimal integer.
.Bl -tag -width 4n
.It Ar \&+page
Begin output at page number
.Ar page
of the formatted input.
.It Fl Ar column
Produce output that is
.Ar columns
wide (default is 1) that is written vertically
down each column in the order in which the text
is received from the input file.
The options
.Fl e
and
.Fl i
are assumed.
This option should not be used with
.Fl m .
When used with
.Fl t ,
the minimum number of lines is used to display the output.
.It Fl a
Modify the effect of the
.Fl column
option so that the columns are filled across the page in a round-robin order
(e.g., when column is 2, the first input line heads column
1, the second heads column 2, the third is the second line
in column 1, etc.).
This option requires the use of the
.Fl column
option.
.It Fl d
Produce output that is double spaced. An extra
.Em <newline>
character is output following every <newline> found in the input.
.It Fl e Ar \&[char\&]\&[gap\&]
Expand each input <tab> to the next greater column
position specified by the formula
.Ar n*gap+1 ,
where
.Em n
is an integer > 0.
If
.Ar gap
is zero or is omitted the default is 8.
All
.Em <tab>
characters in the input are expanded into the appropriate
number of
.Em <space>s .
If any nondigit character,
.Ar char ,
is specified, it is used as the input tab character.
.It Fl F
Use a
.Em <form-feed>
character for new pages,
instead of the default behavior that uses a
sequence o
.Em <newline>
characters.
.It Fl h Ar header
.Ar header
Use the string
.Ar header
to replace the
.Ar file name
in the header line.
.It Fl i Ar \&[char\&]\&[gap\&]
In output, replace multiple <space>s with <tab>s whenever two or more
adjacent <space>s reach column positions
.Ar gap+1 ,
.Ar 2*gap+1 ,
etc.
If
.Ar gap
is zero or omitted, default
.Em <tab>
settings at every eighth column position
is used.
If any nondigit character,
.Ar char ,
is specified, it is used as the output
.Em <tab>
character.
.It Fl l Ar lines
Override the 66 line default and reset the page length to
.Ar lines.
If
.Ar lines
is not greater than the sum of both the header and trailer
depths (in lines), the
.Nm pr
utility suppresses output of both the header and trailer, as if the
.Fl t
option were in effect.
.It Fl m
Merge the contents of multiple files.
One line from each file specified by a file operand is
written side by side into text columns of equal fixed widths, in
terms of the number of column positions.
The number of text columns depends on the number of
file operands successfully opened.
The maximum number of files merged depends on page width and the
per process open file limit.
The options
.Fl e
and
.Fl i
are assumed.
.It Fl n Ar \&[char\&]\&[width\&]
Provide
.Ar width
digit line numbering.
The default for
.Ar width ,
if not specified, is 5.
The number occupies the first
.Ar width
column positions of each text column or each line of
.Fl m
output.
If
.Ar char
(any nondigit character) is given, it is appended to the line number to
separate it from whatever follows. The default for
.Ar char
is a
.Em <tab> .
Line numbers longer than
.Ar width
columns are truncated.
.It Fl o Ar offset
Each line of output is preceeded by
.Ar offset
.Em <spaces>s .
If the
.FL o
option is not specified, the default is zero.
The space taken is in addition to the output line width.
.It Fl r
Write no diagnostic reports on failure to open a file.
.It Fl s Ar char
Separate text columns by the single character
.Ar char
instead of by the appropriate number of
.Em <space>s
(default for
.Ar char
is the
.Em <tab>
character).
.It Fl t
Print neither the five-line identifying
header nor the five-line trailer usually supplied for each page.
Quit printing after the last line of each file without spacing to the
end of the page.
.It Fl w Ar width
Set the width of the line to
.Ar width
column positions for multiple text-column output only.
If the
.Fl w
option is not specified and the
.Fl s
option is not specified, the default width is 72.
If the
.Fl w
option is not specified and the
.Fl s
option is specified, the default width is 512.
.It Ar file
A pathname of a file to be printed.
If no
.Ar file
operands are specified, or if a
.Ar file
operand is
.Sq Fl ,
the standard input is used.
The standard input is used only if no
.Ar file
operands are specified, or if a
.Ar file
operand is
.Sq Fl .
.El
.Pp
The
.Fl s
option does not allow the option letter to be separated from its
argument, and the options
.Fl e ,
.Fl i ,
and
.Fl n
require that both arguments, if present, not be separated from the option
letter.
.Sh ERRORS
.Pp
If
.Nm pr
receives an interrupt while printing to a terminal, it
flushes all accumulated error messages to the screen before
terminating.
.Pp
The
.Nm pr
utility exits 0 on success, and 1 if an error occurs.
.Pp
Error messages are written to standard error during the printing
process (if output is redirected) or after all successful
file printing is complete (when printing to a terminal).
.Sh SEE ALSO
.Xr cat 1 ,
.Xr more 1
.Sh STANDARDS
The
.Nm pr
utility is
.St -p1003.2
compatible.