mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-25 16:13:17 +00:00
Modernise this code by rounding up the usual suspects: register keyword,
consts, ANSIfication of functions, proper use of __FBSDID() and so on. This commit is non-functional from a code-execution perspective, but pr(1) now compiles WARNS=6 clean.
This commit is contained in:
parent
36ffadc954
commit
e0761ab1e6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=98552
@ -35,9 +35,14 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char sccsid[] = "@(#)egetopt.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)egetopt.c 8.1 (Berkeley) 6/6/93";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -64,18 +69,16 @@ int eoptopt; /* character checked for validity */
|
|||||||
char *eoptarg; /* argument associated with option */
|
char *eoptarg; /* argument associated with option */
|
||||||
|
|
||||||
#define BADCH (int)'?'
|
#define BADCH (int)'?'
|
||||||
#define EMSG ""
|
|
||||||
|
static char emsg[] = "";
|
||||||
|
|
||||||
int
|
int
|
||||||
egetopt(nargc, nargv, ostr)
|
egetopt(int nargc, char * const *nargv, const char *ostr)
|
||||||
int nargc;
|
|
||||||
char * const *nargv;
|
|
||||||
const char *ostr;
|
|
||||||
{
|
{
|
||||||
static char *place = EMSG; /* option letter processing */
|
static char *place = emsg; /* option letter processing */
|
||||||
register char *oli; /* option letter list index */
|
char *oli; /* option letter list index */
|
||||||
static int delim; /* which option delimeter */
|
static int delim; /* which option delimeter */
|
||||||
register char *p;
|
char *p;
|
||||||
static char savec = '\0';
|
static char savec = '\0';
|
||||||
|
|
||||||
if (savec != '\0') {
|
if (savec != '\0') {
|
||||||
@ -89,7 +92,7 @@ egetopt(nargc, nargv, ostr)
|
|||||||
*/
|
*/
|
||||||
if ((eoptind >= nargc) ||
|
if ((eoptind >= nargc) ||
|
||||||
((*(place = nargv[eoptind]) != '-') && (*place != '+'))) {
|
((*(place = nargv[eoptind]) != '-') && (*place != '+'))) {
|
||||||
place = EMSG;
|
place = emsg;
|
||||||
return (EOF);
|
return (EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +102,7 @@ egetopt(nargc, nargv, ostr)
|
|||||||
* found "--"
|
* found "--"
|
||||||
*/
|
*/
|
||||||
++eoptind;
|
++eoptind;
|
||||||
place = EMSG;
|
place = emsg;
|
||||||
return (EOF);
|
return (EOF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +131,7 @@ egetopt(nargc, nargv, ostr)
|
|||||||
eoptarg = place-1;
|
eoptarg = place-1;
|
||||||
|
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
place = EMSG;
|
place = emsg;
|
||||||
++eoptind;
|
++eoptind;
|
||||||
} else {
|
} else {
|
||||||
place = p;
|
place = p;
|
||||||
@ -192,7 +195,7 @@ egetopt(nargc, nargv, ostr)
|
|||||||
/*
|
/*
|
||||||
* no arg, but IS required
|
* no arg, but IS required
|
||||||
*/
|
*/
|
||||||
place = EMSG;
|
place = emsg;
|
||||||
if (eopterr) {
|
if (eopterr) {
|
||||||
if (!(p = strrchr(*nargv, '/')))
|
if (!(p = strrchr(*nargv, '/')))
|
||||||
p = *nargv;
|
p = *nargv;
|
||||||
@ -209,7 +212,7 @@ egetopt(nargc, nargv, ostr)
|
|||||||
*/
|
*/
|
||||||
eoptarg = nargv[eoptind];
|
eoptarg = nargv[eoptind];
|
||||||
}
|
}
|
||||||
place = EMSG;
|
place = emsg;
|
||||||
++eoptind;
|
++eoptind;
|
||||||
return (eoptopt);
|
return (eoptopt);
|
||||||
}
|
}
|
||||||
|
178
usr.bin/pr/pr.c
178
usr.bin/pr/pr.c
@ -33,19 +33,22 @@
|
|||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
* 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
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
|
||||||
* $FreeBSD$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static const char copyright[] =
|
||||||
"@(#) Copyright (c) 1993\n\
|
"@(#) Copyright (c) 1993\n\
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#if 0
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94";
|
static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -110,10 +113,10 @@ int addone; /* page length is odd with double space */
|
|||||||
int errcnt; /* error count on file processing */
|
int errcnt; /* error count on file processing */
|
||||||
char digs[] = "0123456789"; /* page number translation map */
|
char digs[] = "0123456789"; /* page number translation map */
|
||||||
|
|
||||||
|
char fnamedefault[] = FNAME;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
int ret_val;
|
int ret_val;
|
||||||
|
|
||||||
@ -144,9 +147,8 @@ main(argc, argv)
|
|||||||
* Check if we should pause and write an alert character and wait for a
|
* Check if we should pause and write an alert character and wait for a
|
||||||
* carriage return on /dev/tty.
|
* carriage return on /dev/tty.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
ttypause(pagecnt)
|
ttypause(int pagecnt)
|
||||||
int pagecnt;
|
|
||||||
{
|
{
|
||||||
int pch;
|
int pch;
|
||||||
FILE *ttyfp;
|
FILE *ttyfp;
|
||||||
@ -167,15 +169,13 @@ ttypause(pagecnt)
|
|||||||
* Line length is unlimited.
|
* Line length is unlimited.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
onecol(argc, argv)
|
onecol(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register int cnt = -1;
|
int cnt = -1;
|
||||||
register int off;
|
int off;
|
||||||
register int lrgln;
|
int lrgln;
|
||||||
register int linecnt;
|
int linecnt;
|
||||||
register int num;
|
int num;
|
||||||
int lncnt;
|
int lncnt;
|
||||||
int pagecnt;
|
int pagecnt;
|
||||||
int ips;
|
int ips;
|
||||||
@ -314,17 +314,15 @@ onecol(argc, argv)
|
|||||||
* vertcol: print files with more than one column of output down a page
|
* vertcol: print files with more than one column of output down a page
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vertcol(argc, argv)
|
vertcol(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register char *ptbf;
|
char *ptbf;
|
||||||
register char **lstdat;
|
char **lstdat;
|
||||||
register int i;
|
int i;
|
||||||
register int j;
|
int j;
|
||||||
register int cnt = -1;
|
int cnt = -1;
|
||||||
register int pln;
|
int pln;
|
||||||
register int *indy;
|
int *indy;
|
||||||
int cvc;
|
int cvc;
|
||||||
int *lindy;
|
int *lindy;
|
||||||
int lncnt;
|
int lncnt;
|
||||||
@ -637,17 +635,15 @@ vertcol(argc, argv)
|
|||||||
* horzcol: print files with more than one column of output across a page
|
* horzcol: print files with more than one column of output across a page
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
horzcol(argc, argv)
|
horzcol(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register char *ptbf;
|
char *ptbf;
|
||||||
register int pln;
|
int pln;
|
||||||
register int cnt = -1;
|
int cnt = -1;
|
||||||
register char *lstdat;
|
char *lstdat;
|
||||||
register int col = colwd + 1;
|
int col = colwd + 1;
|
||||||
register int j;
|
int j;
|
||||||
register int i;
|
int i;
|
||||||
int lncnt;
|
int lncnt;
|
||||||
int pagecnt;
|
int pagecnt;
|
||||||
char *buf;
|
char *buf;
|
||||||
@ -782,16 +778,14 @@ horzcol(argc, argv)
|
|||||||
* more than one file concurrently
|
* more than one file concurrently
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
mulfile(argc, argv)
|
mulfile(int argc, char *argv[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
register char *ptbf;
|
char *ptbf;
|
||||||
register int j;
|
int j;
|
||||||
register int pln;
|
int pln;
|
||||||
register int cnt;
|
int cnt;
|
||||||
register char *lstdat;
|
char *lstdat;
|
||||||
register int i;
|
int i;
|
||||||
FILE **fbuf;
|
FILE **fbuf;
|
||||||
int actf;
|
int actf;
|
||||||
int lncnt;
|
int lncnt;
|
||||||
@ -998,19 +992,13 @@ mulfile(argc, argv)
|
|||||||
* mor: set if more data in line (not truncated)
|
* mor: set if more data in line (not truncated)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
inln(inf, buf, lim, cps, trnc, mor)
|
inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor)
|
||||||
FILE *inf;
|
|
||||||
char *buf;
|
|
||||||
register int lim;
|
|
||||||
int *cps;
|
|
||||||
int trnc;
|
|
||||||
int *mor;
|
|
||||||
{
|
{
|
||||||
register int col;
|
int col;
|
||||||
register int gap = ingap;
|
int gap = ingap;
|
||||||
register int ch = EOF;
|
int ch = EOF;
|
||||||
register char *ptbuf;
|
char *ptbuf;
|
||||||
register int chk = (int)inchar;
|
int chk = (int)inchar;
|
||||||
|
|
||||||
ptbuf = buf;
|
ptbuf = buf;
|
||||||
|
|
||||||
@ -1109,18 +1097,13 @@ inln(inf, buf, lim, cps, trnc, mor)
|
|||||||
* 1 is more, 0 is complete, -1 is no \n's
|
* 1 is more, 0 is complete, -1 is no \n's
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
otln(buf, cnt, svips, svops, mor)
|
otln(char *buf, int cnt, int *svips, int *svops, int mor)
|
||||||
register char *buf;
|
|
||||||
int cnt;
|
|
||||||
int *svops;
|
|
||||||
int *svips;
|
|
||||||
int mor;
|
|
||||||
{
|
{
|
||||||
register int ops; /* last col output */
|
int ops; /* last col output */
|
||||||
register int ips; /* last col in buf examined */
|
int ips; /* last col in buf examined */
|
||||||
register int gap = ogap;
|
int gap = ogap;
|
||||||
register int tbps;
|
int tbps;
|
||||||
register char *endbuf;
|
char *endbuf;
|
||||||
|
|
||||||
if (ogap) {
|
if (ogap) {
|
||||||
/*
|
/*
|
||||||
@ -1251,13 +1234,10 @@ otln(buf, cnt, svips, svops, mor)
|
|||||||
* lncnt number of lines per page
|
* lncnt number of lines per page
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
inskip(inf, pgcnt, lncnt)
|
inskip(FILE *inf, int pgcnt, int lncnt)
|
||||||
FILE *inf;
|
|
||||||
register int pgcnt;
|
|
||||||
register int lncnt;
|
|
||||||
{
|
{
|
||||||
register int c;
|
int c;
|
||||||
register int cnt;
|
int cnt;
|
||||||
|
|
||||||
while(--pgcnt > 0) {
|
while(--pgcnt > 0) {
|
||||||
cnt = lncnt;
|
cnt = lncnt;
|
||||||
@ -1282,12 +1262,7 @@ inskip(inf, pgcnt, lncnt)
|
|||||||
* dt if set skips the date processing (used with -m)
|
* dt if set skips the date processing (used with -m)
|
||||||
*/
|
*/
|
||||||
FILE *
|
FILE *
|
||||||
nxtfile(argc, argv, fname, buf, dt)
|
nxtfile(int argc, char *argv[], char **fname, char *buf, int dt)
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
char **fname;
|
|
||||||
char *buf;
|
|
||||||
int dt;
|
|
||||||
{
|
{
|
||||||
FILE *inf = NULL;
|
FILE *inf = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -1309,7 +1284,7 @@ nxtfile(argc, argv, fname, buf, dt)
|
|||||||
if (header != NULL)
|
if (header != NULL)
|
||||||
*fname = header;
|
*fname = header;
|
||||||
else
|
else
|
||||||
*fname = FNAME;
|
*fname = fnamedefault;
|
||||||
if (nohead)
|
if (nohead)
|
||||||
return(inf);
|
return(inf);
|
||||||
if (gettimeofday(&tv, &tz) < 0) {
|
if (gettimeofday(&tv, &tz) < 0) {
|
||||||
@ -1332,7 +1307,7 @@ nxtfile(argc, argv, fname, buf, dt)
|
|||||||
if (header != NULL)
|
if (header != NULL)
|
||||||
*fname = header;
|
*fname = header;
|
||||||
else
|
else
|
||||||
*fname = FNAME;
|
*fname = fnamedefault;
|
||||||
++eoptind;
|
++eoptind;
|
||||||
if (nohead || (dt && twice))
|
if (nohead || (dt && twice))
|
||||||
return(inf);
|
return(inf);
|
||||||
@ -1360,7 +1335,7 @@ nxtfile(argc, argv, fname, buf, dt)
|
|||||||
if (header != NULL)
|
if (header != NULL)
|
||||||
*fname = header;
|
*fname = header;
|
||||||
else if (dt)
|
else if (dt)
|
||||||
*fname = FNAME;
|
*fname = fnamedefault;
|
||||||
else
|
else
|
||||||
*fname = argv[eoptind];
|
*fname = argv[eoptind];
|
||||||
++eoptind;
|
++eoptind;
|
||||||
@ -1423,12 +1398,9 @@ nxtfile(argc, argv, fname, buf, dt)
|
|||||||
* numbers as part of the column so spaces may be replaced.
|
* numbers as part of the column so spaces may be replaced.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
addnum(buf, wdth, line)
|
addnum(char *buf, int wdth, int line)
|
||||||
register char *buf;
|
|
||||||
register int wdth;
|
|
||||||
register int line;
|
|
||||||
{
|
{
|
||||||
register char *pt = buf + wdth;
|
char *pt = buf + wdth;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
*--pt = digs[line % 10];
|
*--pt = digs[line % 10];
|
||||||
@ -1451,10 +1423,7 @@ addnum(buf, wdth, line)
|
|||||||
* pagcnt page number
|
* pagcnt page number
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
prhead(buf, fname, pagcnt)
|
prhead(char *buf, char *fname, int pagcnt)
|
||||||
char *buf;
|
|
||||||
char *fname;
|
|
||||||
int pagcnt;
|
|
||||||
{
|
{
|
||||||
int ips = 0;
|
int ips = 0;
|
||||||
int ops = 0;
|
int ops = 0;
|
||||||
@ -1489,9 +1458,7 @@ prhead(buf, fname, pagcnt)
|
|||||||
* incomp was a '\n' missing from last line output
|
* incomp was a '\n' missing from last line output
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
prtail(cnt, incomp)
|
prtail(int cnt, int incomp)
|
||||||
register int cnt;
|
|
||||||
int incomp;
|
|
||||||
{
|
{
|
||||||
if (nohead) {
|
if (nohead) {
|
||||||
/*
|
/*
|
||||||
@ -1551,8 +1518,7 @@ prtail(cnt, incomp)
|
|||||||
* terminate(): when a SIGINT is recvd
|
* terminate(): when a SIGINT is recvd
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
terminate(which_sig)
|
terminate(int which_sig __unused)
|
||||||
int which_sig;
|
|
||||||
{
|
{
|
||||||
flsh_errs();
|
flsh_errs();
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -1564,7 +1530,7 @@ terminate(which_sig)
|
|||||||
* processing has completed
|
* processing has completed
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
flsh_errs()
|
flsh_errs(void)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
@ -1578,19 +1544,19 @@ flsh_errs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mfail()
|
mfail(void)
|
||||||
{
|
{
|
||||||
(void)fputs("pr: memory allocation failed\n", err);
|
(void)fputs("pr: memory allocation failed\n", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pfail()
|
pfail(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
|
(void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fputs(
|
(void)fputs(
|
||||||
"usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
|
"usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
|
||||||
@ -1606,11 +1572,9 @@ usage()
|
|||||||
* checks on options
|
* checks on options
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
setup(argc, argv)
|
setup(int argc, char *argv[])
|
||||||
register int argc;
|
|
||||||
register char **argv;
|
|
||||||
{
|
{
|
||||||
register int c;
|
int c;
|
||||||
int d_first;
|
int d_first;
|
||||||
int eflag = 0;
|
int eflag = 0;
|
||||||
int iflag = 0;
|
int iflag = 0;
|
||||||
@ -1863,7 +1827,7 @@ setup(argc, argv)
|
|||||||
(void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : "");
|
(void) setlocale(LC_TIME, (Lflag != NULL) ? Lflag : "");
|
||||||
|
|
||||||
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
|
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
|
||||||
timefrmt = d_first ? TIMEFMTD : TIMEFMTM;
|
timefrmt = strdup(d_first ? TIMEFMTD : TIMEFMTM);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user