Module Name:    src
Committed By:   joerg
Date:           Tue Sep  6 18:26:06 UTC 2011

Modified Files:
        src/usr.bin/pr: egetopt.c extern.h pr.c

Log Message:
ANSIfy, static + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/pr/egetopt.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/pr/extern.h
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/pr/pr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/pr/egetopt.c
diff -u src/usr.bin/pr/egetopt.c:1.8 src/usr.bin/pr/egetopt.c:1.9
--- src/usr.bin/pr/egetopt.c:1.8	Mon Apr 13 00:37:05 2009
+++ src/usr.bin/pr/egetopt.c	Tue Sep  6 18:26:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: egetopt.c,v 1.8 2009/04/13 00:37:05 lukem Exp $	*/
+/*	$NetBSD: egetopt.c,v 1.9 2011/09/06 18:26:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1991 Keith Muller.
@@ -38,7 +38,7 @@
 #if 0
 from: static char sccsid[] = "@(#)egetopt.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: egetopt.c,v 1.8 2009/04/13 00:37:05 lukem Exp $");
+__RCSID("$NetBSD: egetopt.c,v 1.9 2011/09/06 18:26:06 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,13 +67,10 @@
 char	*eoptarg;		/* argument associated with option */
 
 #define	BADCH	(int)'?'
-char EMSG[1] = { '\0' };
+static char EMSG[1] = { '\0' };
 
 int
-egetopt(nargc, nargv, ostr)
-	int nargc;
-	char * const *nargv;
-	const char *ostr;
+egetopt(int nargc, char * const *nargv, const char *ostr)
 {
 	static char *place = EMSG;	/* option letter processing */
 	char *oli;			/* option letter list index */

Index: src/usr.bin/pr/extern.h
diff -u src/usr.bin/pr/extern.h:1.5 src/usr.bin/pr/extern.h:1.6
--- src/usr.bin/pr/extern.h:1.5	Mon Apr 13 00:37:05 2009
+++ src/usr.bin/pr/extern.h	Tue Sep  6 18:26:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.5 2009/04/13 00:37:05 lukem Exp $	*/
+/*	$NetBSD: extern.h,v 1.6 2011/09/06 18:26:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1991 Keith Muller.
@@ -33,27 +33,10 @@
  * SUCH DAMAGE.
  *
  *      from: @(#)extern.h	8.1 (Berkeley) 6/6/93
- *	$NetBSD: extern.h,v 1.5 2009/04/13 00:37:05 lukem Exp $
+ *	$NetBSD: extern.h,v 1.6 2011/09/06 18:26:06 joerg 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 **, const char **, char *, int));
-int	 onecol __P((int, char **));
-int	 otln __P((char *, int, int *, int *, int));
-void	 pfail __P((void));
-int	 prhead __P((char *, const 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 **));
+int	 egetopt(int, char * const *, const char *);

Index: src/usr.bin/pr/pr.c
diff -u src/usr.bin/pr/pr.c:1.20 src/usr.bin/pr/pr.c:1.21
--- src/usr.bin/pr/pr.c:1.20	Mon Apr 13 00:37:05 2009
+++ src/usr.bin/pr/pr.c	Tue Sep  6 18:26:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $	*/
+/*	$NetBSD: pr.c,v 1.21 2011/09/06 18:26:06 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1991 Keith Muller.
@@ -43,7 +43,7 @@
 #if 0
 from: static char sccsid[] = "@(#)pr.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $");
+__RCSID("$NetBSD: pr.c,v 1.21 2011/09/06 18:26:06 joerg Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,43 +77,57 @@
 /*
  * parameter variables
  */
-int	pgnm;			/* starting page number */
-int	clcnt;			/* number of columns */
-int	colwd;			/* column data width - multiple columns */
-int	across;			/* mult col flag; write across page */
-int	dspace;			/* double space flag */
-char	inchar;			/* expand input char */
-int	ingap;			/* expand input gap */
-int	formfeed;		/* use formfeed as trailer */
-char	*header;		/* header name instead of file name */
-char	ochar;			/* contract output char */
-int	ogap;			/* contract output gap */
-int	lines;			/* number of lines per page */
-int	merge;			/* merge multiple files in output */
-char	nmchar;			/* line numbering append char */
-int	nmwd;			/* width of line number field */
-int	offst;			/* number of page offset spaces */
-int	nodiag;			/* do not report file open errors */
-char	schar;			/* text column separation character */
-int	sflag;			/* -s option for multiple columns */
-int	nohead;			/* do not write head and trailer */
-int	pgwd;			/* page width with multiple col output */
-const char *timefrmt = TIMEFMT;	/* time conversion string */
+static int	pgnm;			/* starting page number */
+static int	clcnt;			/* number of columns */
+static int	colwd;			/* column data width - multiple columns */
+static int	across;			/* mult col flag; write across page */
+static int	dspace;			/* double space flag */
+static char	inchar;			/* expand input char */
+static int	ingap;			/* expand input gap */
+static int	formfeed;		/* use formfeed as trailer */
+static char	*header;		/* header name instead of file name */
+static char	ochar;			/* contract output char */
+static int	ogap;			/* contract output gap */
+static int	lines;			/* number of lines per page */
+static int	merge;			/* merge multiple files in output */
+static char	nmchar;			/* line numbering append char */
+static int	nmwd;			/* width of line number field */
+static int	offst;			/* number of page offset spaces */
+static int	nodiag;			/* do not report file open errors */
+static char	schar;			/* text column separation character */
+static int	sflag;			/* -s option for multiple columns */
+static int	nohead;			/* do not write head and trailer */
+static int	pgwd;			/* page width with multiple col output */
+static const char *timefrmt = TIMEFMT;	/* time conversion string */
 
 /*
  * misc globals
  */
-FILE	*err;			/* error message file pointer */
-int	addone;			/* page length is odd with double space */
-int	errcnt;			/* error count on file processing */
-char	digs[] = "0123456789";	/* page number translation map */
-
-int	main __P((int, char **));
+static FILE	*errf;			/* error message file pointer */
+static int	addone;			/* page length is odd with double space */
+static int	errcnt;			/* error count on file processing */
+static const char	digs[] = "0123456789";	/* page number translation map */
+
+static void	 addnum(char *, int, int);
+static void	 flsh_errs(void);
+static int	 horzcol(int, char **);
+static int	 inln(FILE *, char *, int, int *, int, int *);
+static int	 inskip(FILE *, int, int);
+static void	 mfail(void);
+static int	 mulfile(int, char **);
+static FILE	*nxtfile(int, char **, const char **, char *, int);
+static int	 onecol(int, char **);
+static int	 otln(char *, int, int *, int *, int);
+static void	 pfail(void);
+static int	 prhead(char *, const char *, int);
+static int	 prtail(int, int);
+static int	 setup(int, char **);
+__dead static void	 terminate(int);
+static void	 usage(void);
+static int	 vertcol(int, char **);
 
 int
-main(argc, argv)
-        int argc;
-        char *argv[];
+main(int argc, char *argv[])
 {
 	int ret_val;
 
@@ -144,10 +158,8 @@
  * onecol:	print files with only one column of output.
  *		Line length is unlimited.
  */
-int
-onecol(argc, argv)
-        int argc;
-        char *argv[];
+static int
+onecol(int argc, char *argv[])
 {
 	int cnt = -1;
 	int off;
@@ -285,10 +297,8 @@
 oomem:
 	mfail();
 out:
-	if (obuf)
-		free(obuf);
-	if (hbuf)
-		free(hbuf);
+	free(obuf);
+	free(hbuf);
 	if (inf != NULL && inf != stdin)
 		(void)fclose(inf);
 	return error;
@@ -297,10 +307,8 @@
 /*
  * vertcol:	print files with more than one column of output down a page
  */
-int
-vertcol(argc, argv)
-        int argc;
-        char *argv[];
+static int
+vertcol(int argc, char *argv[])
 {
 	char *ptbf;
 	char **lstdat = NULL;
@@ -607,16 +615,11 @@
 oomem:
 	mfail();
 out:
-	if (buf)
-		free(buf);
-	if (hbuf)
-		free(hbuf);
-	if (vc)
-		free(vc);
-	if (lstdat)
-		free(lstdat);
-	if (indy)
-		free(lindy);
+	free(buf);
+	free(hbuf);
+	free(vc);
+	free(lstdat);
+	free(lindy);
 	if (inf != NULL && inf != stdin)
 		(void)fclose(inf);
 	return error;
@@ -625,10 +628,8 @@
 /*
  * horzcol:	print files with more than one column of output across a page
  */
-int
-horzcol(argc, argv)
-        int argc;
-        char *argv[];
+static int
+horzcol(int argc, char *argv[])
 {
 	char *ptbf;
 	int pln;
@@ -763,10 +764,8 @@
 oomem:
 	mfail();
 out:
-	if (buf)
-		free(buf);
-	if (hbuf)
-		free(hbuf);
+	free(buf);
+	free(hbuf);
 	if (inf != NULL && inf != stdin)
 		(void)fclose(inf);
 	return error;
@@ -776,10 +775,8 @@
  * mulfile:	print files with more than one column of output and
  *		more than one file concurrently
  */
-int
-mulfile(argc, argv)
-        int argc;
-        char *argv[];
+static int
+mulfile(int argc, char *argv[])
 {
 	char *ptbf;
 	int j;
@@ -850,7 +847,7 @@
 		pgwd = ((colwd + 1) * clcnt) - 1;
 	}
 	if (colwd < 1) {
-		(void)fprintf(err,
+		(void)fprintf(errf,
 		  "pr: page width too small for %d columns\n", clcnt);
 		goto out;
 	}
@@ -982,10 +979,8 @@
 				(void)fclose(fbuf[j]);
 		free(fbuf);
 	}
-	if (hbuf)
-		free(hbuf);
-	if (buf)
-		free(buf);
+	free(hbuf);
+	free(buf);
 	return error;
 }
 
@@ -1000,14 +995,8 @@
  *	trnc:	throw away data more than lim up to \n 
  *	mor:	set if more data in line (not truncated)
  */
-int
-inln(inf, buf, lim, cps, trnc, mor)
-	FILE *inf;
-	char *buf;
-	int lim;
-	int *cps;
-	int trnc;
-	int *mor;
+static int
+inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor)
 {
 	int col;
 	int gap = ingap;
@@ -1111,13 +1100,8 @@
  *	mor:	output line not complete in this buf; more data to come.	
  *		1 is more, 0 is complete, -1 is no \n's
  */
-int
-otln(buf, cnt, svips, svops, mor)
-	char *buf;
-	int cnt;
-	int *svops;
-	int *svips;
-	int mor;
+static int
+otln(char *buf, int cnt, int *svips, int *svops, int mor)
 {
 	int ops;		/* last col output */
 	int ips;		/* last col in buf examined */
@@ -1267,11 +1251,8 @@
  *	pgcnt	number of pages to skip
  *	lncnt	number of lines per page
  */
-int
-inskip(inf, pgcnt, lncnt)
-	FILE *inf;
-	int pgcnt;
-	int lncnt;
+static int
+inskip(FILE *inf, int pgcnt, int lncnt)
 {
 	int c;
 	int cnt;
@@ -1298,13 +1279,8 @@
  *	buf	array to store proper date for the header.
  *	dt	if set skips the date processing (used with -m)
  */
-FILE *
-nxtfile(argc, argv, fname, buf, dt)
-	int argc;
-	char **argv;
-	const char **fname;
-	char *buf;
-	int dt;
+static FILE *
+nxtfile(int argc, char **argv, const char **fname, char *buf, int dt)
 {
 	FILE *inf = NULL;
 	struct timeval tv;
@@ -1331,7 +1307,7 @@
 			return(inf);
 		if (gettimeofday(&tv, &tz) < 0) {
 			++errcnt;
-			(void)fprintf(err, "pr: cannot get time of day, %s\n",
+			(void)fprintf(errf, "pr: cannot get time of day, %s\n",
 				strerror(errno));
 			eoptind = argc - 1;
 			return(NULL);
@@ -1355,7 +1331,7 @@
 				return(inf);
 			if (gettimeofday(&tv, &tz) < 0) {
 				++errcnt;
-				(void)fprintf(err,
+				(void)fprintf(errf,
 					"pr: cannot get time of day, %s\n",
 					strerror(errno));
 				return(NULL);
@@ -1370,7 +1346,7 @@
 				++errcnt;
 				if (nodiag)
 					continue;
-				(void)fprintf(err, "pr: Cannot open %s, %s\n",
+				(void)fprintf(errf, "pr: Cannot open %s, %s\n",
 					argv[eoptind], strerror(errno));
 				continue;
 			}
@@ -1387,7 +1363,7 @@
 			if (dt) {
 				if (gettimeofday(&tv, &tz) < 0) {
 					++errcnt;
-					(void)fprintf(err,
+					(void)fprintf(errf,
 					     "pr: cannot get time of day, %s\n",
 					     strerror(errno));
 					return(NULL);
@@ -1398,7 +1374,7 @@
 				if (fstat(fileno(inf), &statbuf) < 0) {
 					++errcnt;
 					(void)fclose(inf);
-					(void)fprintf(err, 
+					(void)fprintf(errf, 
 						"pr: Cannot stat %s, %s\n",
 						argv[eoptind], strerror(errno));
 					return(NULL);
@@ -1418,7 +1394,7 @@
 		++errcnt;
 		if (inf != stdin)
 			(void)fclose(inf);
-		(void)fputs("pr: time conversion failed\n", err);
+		(void)fputs("pr: time conversion failed\n", errf);
 		return(NULL);
 	}
 	return(inf);
@@ -1440,10 +1416,7 @@
  *		numbers as part of the column so spaces may be replaced.
  */
 void
-addnum(buf, wdth, line)
-	char *buf;
-	int wdth;
-	int line;
+addnum(char *buf, int wdth, int line)
 {
 	char *pt = buf + wdth;
 
@@ -1467,11 +1440,8 @@
  *	fname	fname field for header
  *	pagcnt	page number
  */
-int
-prhead(buf, fname, pagcnt)
-	char *buf;
-	const char *fname;
-	int pagcnt;
+static int
+prhead(char *buf, const char *fname, int pagcnt)
 {
 	int ips = 0;
 	int ops = 0;
@@ -1505,10 +1475,8 @@
  *	cnt	number of lines of padding needed
  *	incomp	was a '\n' missing from last line output
  */
-int
-prtail(cnt, incomp)
-	int cnt;
-	int incomp;
+static int
+prtail(int cnt, int incomp)
 {
 	if (nohead) {
 		/*
@@ -1560,9 +1528,8 @@
 /*
  * terminate():	when a SIGINT is recvd
  */
-void
-terminate(which_sig)
-	int which_sig;
+static void
+terminate(int which_sig)
 {
 	flsh_errs();
 	(void)raise_default_signal(which_sig);
@@ -1574,51 +1541,49 @@
  * flsh_errs():	output saved up diagnostic messages after all normal
  *		processing has completed
  */
-void
-flsh_errs()
+static void
+flsh_errs(void)
 {
 	char buf[BUFSIZ];
 
 	(void)fflush(stdout);
-	(void)fflush(err);
-	if (err == stderr)
+	(void)fflush(errf);
+	if (errf == stderr)
 		return;
-	rewind(err);
-	while (fgets(buf, BUFSIZ, err) != NULL)
+	rewind(errf);
+	while (fgets(buf, BUFSIZ, errf) != NULL)
 		(void)fputs(buf, stderr);
 }
 
-void
-mfail()
+static void
+mfail(void)
 {
-	(void)fputs("pr: memory allocation failed\n", err);
+	(void)fputs("pr: memory allocation failed\n", errf);
 }
 
-void
-pfail()
+static void
+pfail(void)
 {
-	(void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
+	(void)fprintf(errf, "pr: write failure, %s\n", strerror(errno));
 }
 
-void
-usage()
+static void
+usage(void)
 {
 	(void)fputs(
-	 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",err);
+	 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",errf);
 	(void)fputs(
-	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
+	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",errf);
 	(void)fputs(
-	 "          [-s[ch]] [-w width] [-] [file ...]\n", err);
+	 "          [-s[ch]] [-w width] [-] [file ...]\n", errf);
 }
 
 /*
  * setup:	Validate command args, initialize and perform sanity 
  *		checks on options
  */
-int
-setup(argc, argv)
-	int argc;
-	char **argv;
+static int
+setup(int argc, char **argv)
 {
 	int c;
 	int eflag = 0;
@@ -1630,24 +1595,24 @@
 		/*
 		 * defer diagnostics until processing is done
 		 */
-		if ((err = tmpfile()) == NULL) {
+		if ((errf = tmpfile()) == NULL) {
 		       (void)fputs("Cannot defer diagnostic messages\n",stderr);
 		       return(1);
 		}
 	} else
-		err = stderr;
+		errf = stderr;
 	while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?T:w:")) != -1) {
 		switch (c) {
 		case '+':
 			if ((pgnm = atoi(eoptarg)) < 1) {
 			    (void)fputs("pr: +page number must be 1 or more\n",
-				err);
+				errf);
 			    return(1);
 			}
 			break;
 		case '-':
 			if ((clcnt = atoi(eoptarg)) < 1) {
-			    (void)fputs("pr: -columns must be 1 or more\n",err);
+			    (void)fputs("pr: -columns must be 1 or more\n",errf);
 			    return(1);
 			}
 			if (clcnt > 1)
@@ -1670,13 +1635,13 @@
 			    isdigit((unsigned char)*eoptarg)) {
 				if ((ingap = atoi(eoptarg)) < 0) {
 					(void)fputs(
-					"pr: -e gap must be 0 or more\n", err);
+					"pr: -e gap must be 0 or more\n", errf);
 					return(1);
 				}
 				if (ingap == 0)
 					ingap = INGAP;
 			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
-				(void)fprintf(err,
+				(void)fprintf(errf,
 				      "pr: invalid value for -e %s\n", eoptarg);
 				return(1);
 			} else
@@ -1699,13 +1664,13 @@
 			    isdigit((unsigned char)*eoptarg)) {
 				if ((ogap = atoi(eoptarg)) < 0) {
 					(void)fputs(
-					"pr: -i gap must be 0 or more\n", err);
+					"pr: -i gap must be 0 or more\n", errf);
 					return(1);
 				}
 				if (ogap == 0)
 					ogap = OGAP;
 			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
-				(void)fprintf(err,
+				(void)fprintf(errf,
 				      "pr: invalid value for -i %s\n", eoptarg);
 				return(1);
 			} else
@@ -1715,7 +1680,7 @@
 			if (!isdigit((unsigned char)*eoptarg) ||
 			    ((lines=atoi(eoptarg)) < 1)) {
 				(void)fputs(
-				 "pr: Number of lines must be 1 or more\n",err);
+				 "pr: Number of lines must be 1 or more\n",errf);
 				return(1);
 			}
 			break;
@@ -1732,11 +1697,11 @@
 			    isdigit((unsigned char)*eoptarg)) {
 				if ((nmwd = atoi(eoptarg)) < 1) {
 					(void)fputs(
-					"pr: -n width must be 1 or more\n",err);
+					"pr: -n width must be 1 or more\n",errf);
 					return(1);
 				}
 			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
-				(void)fprintf(err,
+				(void)fprintf(errf,
 				      "pr: invalid value for -n %s\n", eoptarg);
 				return(1);
 			} else
@@ -1746,7 +1711,7 @@
 			if (!isdigit((unsigned char)*eoptarg) ||
 			    ((offst = atoi(eoptarg))< 1)){
 				(void)fputs("pr: -o offset must be 1 or more\n",
-					err);
+					errf);
 				return(1);
 			}
 			break;
@@ -1760,7 +1725,7 @@
 			else
 				schar = *eoptarg++;
 			if (eoptarg && *eoptarg != '\0') {
-				(void)fprintf(err,
+				(void)fprintf(errf,
 				      "pr: invalid value for -s %s\n", eoptarg);
 				return(1);
 			}
@@ -1776,7 +1741,7 @@
 			if (!isdigit((unsigned char)*eoptarg) ||
 			    ((pgwd = atoi(eoptarg)) < 1)){
 				(void)fputs(
-				   "pr: -w width must be 1 or more \n",err);
+				   "pr: -w width must be 1 or more \n",errf);
 				return(1);
 			}
 			break;
@@ -1801,11 +1766,11 @@
 	if (across) {
 		if (clcnt == 1) {
 			(void)fputs("pr: -a flag requires multiple columns\n",
-				err);
+				errf);
 			return(1);
 		}
 		if (merge) {
-			(void)fputs("pr: -m cannot be used with -a\n", err);
+			(void)fputs("pr: -m cannot be used with -a\n", errf);
 			return(1);
 		}
 	}
@@ -1828,7 +1793,7 @@
 	if (cflag) {
 		if (merge) {
 			(void)fputs(
-			  "pr: -m cannot be used with multiple columns\n", err);
+			  "pr: -m cannot be used with multiple columns\n", errf);
 			return(1);
 		}
 		if (nmwd) {
@@ -1839,7 +1804,7 @@
 			pgwd = ((colwd + 1) * clcnt) - 1;
 		}
 		if (colwd < 1) {
-			(void)fprintf(err,
+			(void)fprintf(errf,
 			  "pr: page width is too small for %d columns\n",clcnt);
 			return(1);
 		}

Reply via email to