Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/rpcgen modernize:
details: https://anonhg.NetBSD.org/src/rev/a7786de8c601
branches: trunk
changeset: 338083:a7786de8c601
user: christos <christos%NetBSD.org@localhost>
date: Sat May 09 21:44:47 2015 +0000
description:
modernize:
- make crash() called atexit
- use err/errx
- remove __P
diffstat:
usr.bin/rpcgen/rpc_main.c | 51 ++++++++++++++++++--------------------------
usr.bin/rpcgen/rpc_parse.h | 4 +-
usr.bin/rpcgen/rpc_scan.h | 16 +++++++-------
usr.bin/rpcgen/rpc_svcout.c | 14 ++++-------
usr.bin/rpcgen/rpc_util.c | 16 +++++++-------
usr.bin/rpcgen/rpc_util.h | 7 +++--
6 files changed, 48 insertions(+), 60 deletions(-)
diffs (truncated from 348 to 300 lines):
diff -r 00517c3f9cd4 -r a7786de8c601 usr.bin/rpcgen/rpc_main.c
--- a/usr.bin/rpcgen/rpc_main.c Sat May 09 21:31:05 2015 +0000
+++ b/usr.bin/rpcgen/rpc_main.c Sat May 09 21:44:47 2015 +0000
@@ -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 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 @@
(void) memset((char *) &cmd, 0, sizeof(struct commandline));
clear_args();
+ atexit(crash);
if (!parseargs(argc, argv, &cmd))
usage();
@@ -255,6 +257,7 @@
(void) unlink(dos_cppfile);
}
#endif
+ docleanup = 0;
exit(nonfatalerrors);
/* NOTREACHED */
}
@@ -297,15 +300,11 @@
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 @@
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 @@
(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 @@
else {
guard = strdup("STDIN_");
if (guard == NULL) {
- err(1, "strdup");
+ err(EXIT_FAILURE, "strdup");
}
}
@@ -608,6 +601,7 @@
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 @@
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 @@
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 @@
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 @@
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
diff -r 00517c3f9cd4 -r a7786de8c601 usr.bin/rpcgen/rpc_parse.h
--- a/usr.bin/rpcgen/rpc_parse.h Sat May 09 21:31:05 2015 +0000
+++ b/usr.bin/rpcgen/rpc_parse.h Sat May 09 21:44:47 2015 +0000
@@ -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 @@
};
typedef struct definition definition;
-definition *get_definition __P((void));
+definition *get_definition(void);
struct bas_type
{
diff -r 00517c3f9cd4 -r a7786de8c601 usr.bin/rpcgen/rpc_scan.h
--- a/usr.bin/rpcgen/rpc_scan.h Sat May 09 21:31:05 2015 +0000
+++ b/usr.bin/rpcgen/rpc_scan.h Sat May 09 21:44:47 2015 +0000
@@ -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 @@
/*
* 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 *);
diff -r 00517c3f9cd4 -r a7786de8c601 usr.bin/rpcgen/rpc_svcout.c
--- a/usr.bin/rpcgen/rpc_svcout.c Sat May 09 21:31:05 2015 +0000
+++ b/usr.bin/rpcgen/rpc_svcout.c Sat May 09 21:44:47 2015 +0000
@@ -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 @@
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 {
diff -r 00517c3f9cd4 -r a7786de8c601 usr.bin/rpcgen/rpc_util.c
--- a/usr.bin/rpcgen/rpc_util.c Sat May 09 21:31:05 2015 +0000
+++ b/usr.bin/rpcgen/rpc_util.c Sat May 09 21:44:47 2015 +0000
@@ -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 @@
#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 @@
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 @@
{
int i;
Home |
Main Index |
Thread Index |
Old Index