Module Name:    src
Committed By:   christos
Date:           Sat May  9 21:44:48 UTC 2015

Modified Files:
        src/usr.bin/rpcgen: rpc_main.c rpc_parse.h rpc_scan.h rpc_svcout.c
            rpc_util.c rpc_util.h

Log Message:
modernize:
        - make crash() called atexit
        - use err/errx
        - remove __P


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/rpcgen/rpc_main.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/rpcgen/rpc_parse.h
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/rpcgen/rpc_scan.h
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/rpcgen/rpc_svcout.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/rpcgen/rpc_util.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/rpcgen/rpc_util.h

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/rpcgen/rpc_main.c
diff -u src/usr.bin/rpcgen/rpc_main.c:1.39 src/usr.bin/rpcgen/rpc_main.c:1.40
--- src/usr.bin/rpcgen/rpc_main.c:1.39	Sun Dec 15 04:18:31 2013
+++ src/usr.bin/rpcgen/rpc_main.c	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_main.c,v 1.39 2013/12/15 09:18:31 wiz Exp $	*/
+/*	$NetBSD: rpc_main.c,v 1.40 2015/05/09 21:44:47 christos Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_main.c,v 1.39 2013/12/15 09:18:31 wiz Exp $");
+__RCSID("$NetBSD: rpc_main.c,v 1.40 2015/05/09 21:44:47 christos Exp $");
 #endif
 #endif
 
@@ -128,6 +128,7 @@ int     logflag;		/* Use syslog instead 
 int     tblflag;		/* Support for dispatch table file */
 int	BSDflag;		/* use BSD cplusplus macros */
 int     callerflag;		/* Generate svc_caller() function */
+int	docleanup = 1;		/* cause atexit to remove files */
 
 #define INLINE 3
 /*length at which to start doing an inline */
@@ -187,6 +188,7 @@ main(int argc, char *argv[])
 
 	(void) memset((char *) &cmd, 0, sizeof(struct commandline));
 	clear_args();
+	atexit(crash);
 	if (!parseargs(argc, argv, &cmd))
 		usage();
 
@@ -255,6 +257,7 @@ main(int argc, char *argv[])
 		(void) unlink(dos_cppfile);
 	}
 #endif
+	docleanup = 0;
 	exit(nonfatalerrors);
 	/* NOTREACHED */
 }
@@ -297,15 +300,11 @@ open_output(const char *infile, const ch
 		return;
 	}
 	if (infile != NULL && streq(outfile, infile)) {
-		f_print(stderr, "%s: output would overwrite %s\n", cmdname,
-		    infile);
-		crash();
+		errx(EXIT_FAILURE, "output would overwrite `%s'", infile);
 	}
 	fout = fopen(outfile, "w");
 	if (fout == NULL) {
-		f_print(stderr, "%s: unable to open ", cmdname);
-		perror(outfile);
-		crash();
+		err(EXIT_FAILURE, "Can't to open `%s'", outfile);
 	}
 	record_open(outfile);
 
@@ -360,22 +359,18 @@ open_input(const char *infile, const cha
 
 		retval = spawnvp(P_WAIT, arglist[0], arglist);
 		if (retval != 0) {
-			fprintf(stderr, "%s: C PreProcessor failed\n", cmdname);
-			crash();
+			err(EXIT_FAILURE, "C PreProcessor failed");
 		}
 		fnsplit(infile, drive, dir, name, ext);
 		fnmerge(cppfile, drive, dir, name, ".i");
 
 		fin = fopen(cppfile, "r");
 		if (fin == NULL) {
-			f_print(stderr, "%s: ", cmdname);
-			perror(cppfile);
-			crash();
+			err(EXIT_FAILURE, "Can't open `%s'", cppfile);
 		}
 		dos_cppfile = strdup(cppfile);
 		if (dos_cppfile == NULL) {
-			fprintf(stderr, "%s: out of memory\n", cmdname);
-			crash();
+			err(EXIT_FAILURE, "Can't copy `%s'", cppfile);
 		}
 	}
 #else
@@ -391,17 +386,15 @@ open_input(const char *infile, const cha
 		(void) dup2(pd[1], 1);
 		(void) close(pd[0]);
 		execvp(arglist[0], __UNCONST(arglist));
-		err(1, "$RPCGEN_CPP: %s", CPP);
+		err(EXIT_FAILURE, "$RPCGEN_CPP: %s", CPP);
 	case -1:
-		err(1, "fork");
+		err(EXIT_FAILURE, "fork");
 	}
 	(void) close(pd[1]);
 	fin = fdopen(pd[0], "r");
 #endif
 	if (fin == NULL) {
-		f_print(stderr, "%s: ", cmdname);
-		perror(infilename);
-		crash();
+		err(EXIT_FAILURE, "Can't open `%s'", infilename);
 	}
 }
 /* valid tirpc nettypes */
@@ -543,7 +536,7 @@ h_output(const char *infile, const char 
 	else {
 		guard = strdup("STDIN_");
 		if (guard == NULL) {
-			err(1, "strdup");
+			err(EXIT_FAILURE, "strdup");
 		}
 	}
 
@@ -608,6 +601,7 @@ s_output(int argc, char *argv[], char *i
 	f_print(fout, "#include <sys/ioctl.h>\n");
 	f_print(fout, "#include <fcntl.h>\n");
 	f_print(fout, "#include <stdio.h>\n");
+	f_print(fout, "#include <err.h>\n");
 	f_print(fout, "#include <stdlib.h>\n");
 	f_print(fout, "#include <unistd.h>\n");
 	f_print(fout, "#include <rpc/pmap_clnt.h>\n");
@@ -780,6 +774,7 @@ clnt_output(const char *infile, const ch
 	open_output(infile, outfilename);
 	add_sample_msg();
 	f_print(fout, "#include <stdio.h>\n");
+	f_print(fout, "#include <err.h>\n");
 	if (infile && (include = extendfile(infile, ".h"))) {
 		f_print(fout, "#include \"%s\"\n", include);
 		free(include);
@@ -837,8 +832,7 @@ static void
 addarg(const char *cp)
 {
 	if (argcount >= ARGLISTLEN) {
-		f_print(stderr, "rpcgen: too many defines\n");
-		crash();
+		errx(EXIT_FAILURE, "too many defines");
 		/* NOTREACHED */
 	}
 	arglist[argcount++] = cp;
@@ -849,8 +843,7 @@ static void
 putarg(int pwhere, const char *cp)
 {
 	if (pwhere >= ARGLISTLEN) {
-		f_print(stderr, "rpcgen: arglist coding error\n");
-		crash();
+		errx(EXIT_FAILURE, "arglist coding error");
 		/* NOTREACHED */
 	}
 	arglist[pwhere] = cp;
@@ -870,17 +863,15 @@ checkfiles(const char *infile, const cha
 
 	if (infile)		/* infile ! = NULL */
 		if (stat(infile, &buf) < 0) {
-			perror(infile);
-			crash();
+			err(EXIT_FAILURE, "Can't stat `%s'", infile);
 		};
 #if 0
 	if (outfile) {
 		if (stat(outfile, &buf) < 0)
 			return;	/* file does not exist */
 		else {
-			f_print(stderr,
-			    "file '%s' already exists and may be overwritten\n", outfile);
-			crash();
+			errx("`%s' already exists and may be overwritten",
+			    outfile);
 		}
 	}
 #endif

Index: src/usr.bin/rpcgen/rpc_parse.h
diff -u src/usr.bin/rpcgen/rpc_parse.h:1.5 src/usr.bin/rpcgen/rpc_parse.h:1.6
--- src/usr.bin/rpcgen/rpc_parse.h:1.5	Sun Aug 11 04:03:10 2013
+++ src/usr.bin/rpcgen/rpc_parse.h	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_parse.h,v 1.5 2013/08/11 08:03:10 dholland Exp $	*/
+/*	$NetBSD: rpc_parse.h,v 1.6 2015/05/09 21:44:47 christos Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -156,7 +156,7 @@ struct definition {
 };
 typedef struct definition definition;
 
-definition *get_definition __P((void));
+definition *get_definition(void);
 
 struct bas_type
 {

Index: src/usr.bin/rpcgen/rpc_scan.h
diff -u src/usr.bin/rpcgen/rpc_scan.h:1.9 src/usr.bin/rpcgen/rpc_scan.h:1.10
--- src/usr.bin/rpcgen/rpc_scan.h:1.9	Sun Aug 11 04:03:10 2013
+++ src/usr.bin/rpcgen/rpc_scan.h	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_scan.h,v 1.9 2013/08/11 08:03:10 dholland Exp $	*/
+/*	$NetBSD: rpc_scan.h,v 1.10 2015/05/09 21:44:47 christos Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -99,10 +99,10 @@ typedef struct token token;
 /*
  * routine interface 
  */
-void scan __P((tok_kind, token *));
-void scan2 __P((tok_kind, tok_kind, token *));
-void scan3 __P((tok_kind, tok_kind, tok_kind, token *));
-void scan_num __P((token *));
-void peek __P((token *));
-int peekscan __P((tok_kind, token *));
-void get_token __P((token *));
+void scan(tok_kind, token *);
+void scan2(tok_kind, tok_kind, token *);
+void scan3(tok_kind, tok_kind, tok_kind, token *);
+void scan_num(token *);
+void peek(token *);
+int peekscan(tok_kind, token *);
+void get_token(token *);

Index: src/usr.bin/rpcgen/rpc_svcout.c
diff -u src/usr.bin/rpcgen/rpc_svcout.c:1.28 src/usr.bin/rpcgen/rpc_svcout.c:1.29
--- src/usr.bin/rpcgen/rpc_svcout.c:1.28	Sat May  9 14:48:14 2015
+++ src/usr.bin/rpcgen/rpc_svcout.c	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_svcout.c,v 1.28 2015/05/09 18:48:14 dholland Exp $	*/
+/*	$NetBSD: rpc_svcout.c,v 1.29 2015/05/09 21:44:47 christos Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_svcout.c 1.29 89/03/30 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_svcout.c,v 1.28 2015/05/09 18:48:14 dholland Exp $");
+__RCSID("$NetBSD: rpc_svcout.c,v 1.29 2015/05/09 21:44:47 christos Exp $");
 #endif
 #endif
 
@@ -812,19 +812,15 @@ write_rpc_svc_fg(char *infile, const cha
 		f_print(fout, "%sint pid, i;\n\n", sp);
 	f_print(fout, "%spid = fork();\n", sp);
 	f_print(fout, "%sif (pid < 0) {\n", sp);
-	f_print(fout, "%s\tperror(\"cannot fork\");\n", sp);
-	f_print(fout, "%s\texit(1);\n", sp);
+	f_print(fout, "%s\terr(EXIT_FAILURE, \"cannot fork\");\n", sp);
 	f_print(fout, "%s}\n", sp);
 	f_print(fout, "%sif (pid)\n", sp);
 	f_print(fout, "%s\texit(0);\n", sp);
 	/* get number of file descriptors */
 	if (tirpcflag) {
 		f_print(fout, "%srl.rlim_max = 0;\n", sp);
-		f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1) {\n",
-			sp);
-		f_print(fout, "%s\tperror(\"getrlimit\");\n", sp);
-		f_print(fout, "%s\texit(1);\n", sp);
-		f_print(fout, "%s}\n", sp);
+		f_print(fout, "%sif (getrlimit(RLIMIT_NOFILE, &rl) == -1)\n", sp);
+		f_print(fout, "%s\terr(EXIT_FAILURE, \"getrlimit(RLIMIT_NOFILE)\");\n", sp);
 		f_print(fout, "%sif ((size = rl.rlim_max) == 0)\n", sp);
 		f_print(fout, "%s\texit(1);\n", sp);
 	} else {

Index: src/usr.bin/rpcgen/rpc_util.c
diff -u src/usr.bin/rpcgen/rpc_util.c:1.13 src/usr.bin/rpcgen/rpc_util.c:1.14
--- src/usr.bin/rpcgen/rpc_util.c:1.13	Sat Dec 14 19:40:17 2013
+++ src/usr.bin/rpcgen/rpc_util.c	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $	*/
+/*	$NetBSD: rpc_util.c,v 1.14 2015/05/09 21:44:47 christos Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI";
 #else
-__RCSID("$NetBSD: rpc_util.c,v 1.13 2013/12/15 00:40:17 christos Exp $");
+__RCSID("$NetBSD: rpc_util.c,v 1.14 2015/05/09 21:44:47 christos Exp $");
 #endif
 #endif
 
@@ -49,6 +49,7 @@ __RCSID("$NetBSD: rpc_util.c,v 1.13 2013
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <err.h>
 #include <ctype.h>
 #include "rpc_scan.h"
 #include "rpc_parse.h"
@@ -257,9 +258,7 @@ void
 error(const char *msg)
 {
 	printwhere();
-	f_print(stderr, "%s, line %d: ", infilename, linenum);
-	f_print(stderr, "%s\n", msg);
-	crash();
+	errx(EXIT_FAILURE, "%s, line %d: %s", infilename, linenum, msg);
 }
 /*
  * Something went wrong, unlink any files that we may have created and then
@@ -270,10 +269,12 @@ crash(void)
 {
 	int     i;
 
+	if (!docleanup)
+		return;
+
 	for (i = 0; i < nfiles; i++) {
 		(void) unlink(outfiles[i]);
 	}
-	exit(1);
 }
 
 void
@@ -282,8 +283,7 @@ record_open(const char *file)
 	if (nfiles < NFILES) {
 		outfiles[nfiles++] = file;
 	} else {
-		f_print(stderr, "too many files!\n");
-		crash();
+		errx(EXIT_FAILURE, "too many files!");
 	}
 }
 

Index: src/usr.bin/rpcgen/rpc_util.h
diff -u src/usr.bin/rpcgen/rpc_util.h:1.8 src/usr.bin/rpcgen/rpc_util.h:1.9
--- src/usr.bin/rpcgen/rpc_util.h:1.8	Sat Dec 14 19:40:17 2013
+++ src/usr.bin/rpcgen/rpc_util.h	Sat May  9 17:44:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_util.h,v 1.8 2013/12/15 00:40:17 christos Exp $	*/
+/*	$NetBSD: rpc_util.h,v 1.9 2015/05/09 21:44:47 christos Exp $	*/
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -57,6 +57,7 @@ typedef struct list list;
 extern char curline[MAXLINESIZE];
 extern char *where;
 extern int linenum;
+extern int docleanup;
 
 extern const char *infilename;
 extern FILE *fout;
@@ -113,8 +114,8 @@ int isvectordef(const char *, relation);
 char *locase(const char *);
 void pvname_svc(const char *, const char *);
 void pvname(const char *, const char *);
-void error(const char *) __dead;
-void crash(void) __dead;
+void error(const char *);
+void crash(void);
 void record_open(const char *);
 void expected1(tok_kind) __dead;
 void expected2(tok_kind, tok_kind) __dead;

Reply via email to