summaryrefslogtreecommitdiff
path: root/usr/src/cmd/rpcgen
diff options
context:
space:
mode:
authorrobinson <none@none>2005-07-01 13:10:39 -0700
committerrobinson <none@none>2005-07-01 13:10:39 -0700
commit61961e0f20c7637a3846bb39786bb9dffa91dfb9 (patch)
treea205cd61b8055bd820ff84bd5412bcea48fc08ee /usr/src/cmd/rpcgen
parent6550f384c4c0d912ed90ff04d9da05ce4b4501e6 (diff)
downloadillumos-joyent-61961e0f20c7637a3846bb39786bb9dffa91dfb9.tar.gz
PSARC/2005/362 Removal of <rpc/trace.h>
4426428 libnsl needs some tidying up 6256192 Remaining ulonglong_t needs to be exorcised 6267468 rpcgen generates code gcc doesn't like 6271220 rpc/trace.h is obsolete and dead code 6271232 rpcgen fails to cast memset correctly --HG-- rename : usr/src/lib/libnsl/dial/dk.h => deleted_files/usr/src/lib/libnsl/dial/dk.h rename : usr/src/lib/libnsl/dial/dkbreak.c => deleted_files/usr/src/lib/libnsl/dial/dkbreak.c rename : usr/src/lib/libnsl/dial/dkdial.c => deleted_files/usr/src/lib/libnsl/dial/dkdial.c rename : usr/src/lib/libnsl/dial/dkerr.c => deleted_files/usr/src/lib/libnsl/dial/dkerr.c rename : usr/src/lib/libnsl/dial/dkminor.c => deleted_files/usr/src/lib/libnsl/dial/dkminor.c rename : usr/src/lib/libnsl/dial/dtnamer.c => deleted_files/usr/src/lib/libnsl/dial/dtnamer.c rename : usr/src/lib/libnsl/rpc/rpc_trace.c => deleted_files/usr/src/lib/libnsl/rpc/rpc_trace.c rename : usr/src/uts/common/rpc/trace.h => deleted_files/usr/src/uts/common/rpc/trace.h
Diffstat (limited to 'usr/src/cmd/rpcgen')
-rw-r--r--usr/src/cmd/rpcgen/Makefile7
-rw-r--r--usr/src/cmd/rpcgen/rpc_clntout.c104
-rw-r--r--usr/src/cmd/rpcgen/rpc_cout.c382
-rw-r--r--usr/src/cmd/rpcgen/rpc_hout.c210
-rw-r--r--usr/src/cmd/rpcgen/rpc_main.c379
-rw-r--r--usr/src/cmd/rpcgen/rpc_parse.c164
-rw-r--r--usr/src/cmd/rpcgen/rpc_parse.h3
-rw-r--r--usr/src/cmd/rpcgen/rpc_sample.c68
-rw-r--r--usr/src/cmd/rpcgen/rpc_scan.c250
-rw-r--r--usr/src/cmd/rpcgen/rpc_scan.h38
-rw-r--r--usr/src/cmd/rpcgen/rpc_svcout.c253
-rw-r--r--usr/src/cmd/rpcgen/rpc_tblout.c47
-rw-r--r--usr/src/cmd/rpcgen/rpc_util.c227
-rw-r--r--usr/src/cmd/rpcgen/rpc_util.h69
14 files changed, 972 insertions, 1229 deletions
diff --git a/usr/src/cmd/rpcgen/Makefile b/usr/src/cmd/rpcgen/Makefile
index b3ea1b241c..422beabda0 100644
--- a/usr/src/cmd/rpcgen/Makefile
+++ b/usr/src/cmd/rpcgen/Makefile
@@ -19,10 +19,12 @@
#
# CDDL HEADER END
#
+
#
-#ident "%Z%%M% %I% %E% SMI"
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
#
-# Copyright (c) 1989 by Sun Microsystems, Inc.
+# ident "%Z%%M% %I% %E% SMI"
#
# cmd/rpcgen/Makefile
@@ -36,6 +38,7 @@ SRCS= $(OBJS:%.o=%.c)
include ../Makefile.cmd
LDLIBS +=
+CFLAGS += -v
.KEEP_STATE:
diff --git a/usr/src/cmd/rpcgen/rpc_clntout.c b/usr/src/cmd/rpcgen/rpc_clntout.c
index 875d60f028..465cd3c2b1 100644
--- a/usr/src/cmd/rpcgen/rpc_clntout.c
+++ b/usr/src/cmd/rpcgen/rpc_clntout.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -45,24 +47,24 @@
#include "rpc_parse.h"
#include "rpc_util.h"
-extern pdeclaration();
-void printarglist();
+extern void pdeclaration(char *, declaration *, int, char *);
+extern void printarglist(proc_list *, char *, char *, char *);
+static void write_program(definition *);
+static void printbody(proc_list *);
static char RESULT[] = "clnt_res";
-
-#define DEFAULT_TIMEOUT 25 /* in seconds */
-
+#define DEFAULT_TIMEOUT 25 /* in seconds */
void
-write_stubs()
+write_stubs(void)
{
list *l;
definition *def;
f_print(fout,
- "\n/* Default timeout can be changed using clnt_control() */\n");
+ "\n/* Default timeout can be changed using clnt_control() */\n");
f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
DEFAULT_TIMEOUT);
for (l = defined; l != NULL; l = l->next) {
@@ -73,9 +75,8 @@ write_stubs()
}
}
-static
-write_program(def)
- definition *def;
+static void
+write_program(definition *def)
{
version_list *vp;
proc_list *proc;
@@ -110,10 +111,8 @@ write_program(def)
/* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
-void printarglist(proc, result, addargname, addargtype)
- proc_list *proc;
- char *result;
- char* addargname, * addargtype;
+void
+printarglist(proc_list *proc, char *result, char *addargname, char *addargtype)
{
bool_t oneway = streq(proc->res_type, "oneway");
decl_list *l;
@@ -123,9 +122,9 @@ void printarglist(proc, result, addargname, addargtype)
if (Cflag) { /* C++ style heading */
f_print(fout, "(");
ptype(proc->args.decls->decl.prefix,
- proc->args.decls->decl.type, 1);
+ proc->args.decls->decl.type, 1);
- if (mtflag) {/* Generate result field */
+ if (mtflag) { /* Generate result field */
f_print(fout, "*argp, ");
if (!oneway) {
ptype(proc->res_prefix,
@@ -135,7 +134,8 @@ void printarglist(proc, result, addargname, addargtype)
f_print(fout, "%s%s)\n",
addargtype, addargname);
} else
- f_print(fout, "*argp, %s%s)\n", addargtype, addargname);
+ f_print(fout, "*argp, %s%s)\n",
+ addargtype, addargname);
} else {
if (!mtflag)
f_print(fout, "(argp, %s)\n", addargname);
@@ -162,7 +162,7 @@ void printarglist(proc, result, addargname, addargtype)
/* newstyle, 0 argument */
if (mtflag) {
f_print(fout, "(");
-
+
if (Cflag) {
if (!oneway) {
ptype(proc->res_prefix,
@@ -172,7 +172,7 @@ void printarglist(proc, result, addargname, addargtype)
f_print(fout, "%s%s)\n",
addargtype, addargname);
} else
- f_print(fout, "(%s)\n", addargname);
+ f_print(fout, "(%s)\n", addargname);
} else
if (Cflag)
@@ -186,12 +186,12 @@ void printarglist(proc, result, addargname, addargtype)
for (l = proc->args.decls; l != NULL; l = l->next)
f_print(fout, "%s, ", l->decl.name);
if (mtflag && !oneway)
- f_print(fout, "%s, ", result);
+ f_print(fout, "%s, ", result);
f_print(fout, "%s)\n", addargname);
for (l = proc->args.decls; l != NULL; l = l->next) {
pdeclaration(proc->args.argname,
- &l->decl, 1, ";\n");
+ &l->decl, 1, ";\n");
}
if (mtflag && !oneway) {
f_print(fout, "\t");
@@ -203,7 +203,7 @@ void printarglist(proc, result, addargname, addargtype)
f_print(fout, "(");
for (l = proc->args.decls; l != NULL; l = l->next) {
pdeclaration(proc->args.argname, &l->decl, 0,
- ", ");
+ ", ");
}
if (mtflag && !oneway) {
ptype(proc->res_prefix, proc->res_type, 1);
@@ -221,8 +221,7 @@ void printarglist(proc, result, addargname, addargtype)
static char *
-ampr(type)
- char *type;
+ampr(char *type)
{
if (isvectordef(type, REL_ALIAS)) {
return ("");
@@ -231,21 +230,17 @@ ampr(type)
}
}
-static
-printbody(proc)
- proc_list *proc;
+static void
+printbody(proc_list *proc)
{
decl_list *l;
bool_t args2 = (proc->arg_num > 1);
- int i;
bool_t oneway = streq(proc->res_type, "oneway");
/*
* For new style with multiple arguments, need a structure in which
* to stuff the arguments.
*/
-
-
if (newstyle && args2) {
f_print(fout, "\t%s", proc->args.argname);
f_print(fout, " arg;\n");
@@ -261,7 +256,7 @@ printbody(proc)
f_print(fout, "%s;\n", RESULT);
f_print(fout, "\n");
f_print(fout,
- "\tmemset((char *)%s%s, 0, sizeof (%s));\n",
+ "\t(void) memset(%s%s, 0, sizeof (%s));\n",
ampr(proc->res_type), RESULT, RESULT);
}
@@ -275,11 +270,11 @@ printbody(proc)
f_print(fout, "\t if ");
f_print(fout,
- "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ",
+ "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
proc->proc_name);
f_print(fout,
- "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,",
+ "NULL,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,",
stringfix(proc->res_type),
(mtflag)?"":ampr(proc->res_type),
RESULT);
@@ -304,11 +299,11 @@ printbody(proc)
else
f_print(fout, "\tif ");
f_print(fout,
- "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_%s",
+ "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
proc->proc_name, proc->args.argname);
f_print(fout,
- ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,",
+ ", (caddr_t)&arg,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,",
stringfix(proc->res_type),
(mtflag)?"":ampr(proc->res_type),
RESULT);
@@ -321,9 +316,9 @@ printbody(proc)
if (!mtflag)
f_print(fout,
"\tif (clnt_call(clnt, "
- "%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,\n\t\tTIMEOUT) != "
+ "%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,\n\t\tTIMEOUT) != "
"RPC_SUCCESS) {\n",
proc->proc_name,
stringfix(proc->args.decls->decl.type),
@@ -337,9 +332,9 @@ printbody(proc)
else
f_print(fout,
"\treturn (clnt_call(clnt, "
- "%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s,\n\t\tTIMEOUT));\n",
+ "%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s,\n\t\tTIMEOUT));\n",
proc->proc_name,
stringfix(proc->args.decls->decl.type),
(newstyle ? "&" : ""),
@@ -368,7 +363,7 @@ printbody(proc)
f_print(fout, "%s;\n", RESULT);
f_print(fout, "\n");
f_print(fout,
- "\tmemset((char *)&%s, 0, sizeof (%s));\n",
+ "\t(void) memset(&%s, 0, sizeof (%s));\n",
RESULT, RESULT);
}
@@ -382,10 +377,9 @@ printbody(proc)
f_print(fout, "\t if ((%s = ", RESULT);
f_print(fout,
- "clnt_send(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ",
+ "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
proc->proc_name);
- f_print(fout,
- "(caddr_t) NULL)");
+ f_print(fout, "NULL)");
if (mtflag)
f_print(fout, ");\n");
@@ -406,10 +400,10 @@ printbody(proc)
else
f_print(fout, "\tif ((%s =", RESULT);
f_print(fout,
- "clnt_send(clnt, %s,\n\t\t(xdrproc_t) xdr_%s",
+ "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
proc->proc_name, proc->args.argname);
f_print(fout,
- ", (caddr_t) &arg)");
+ ", (caddr_t)&arg)");
if (mtflag)
f_print(fout, ");\n");
else
@@ -418,8 +412,8 @@ printbody(proc)
if (!mtflag)
f_print(fout,
"\tif ((%s = clnt_send(clnt, "
- "%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s)) != RPC_SUCCESS) {\n",
+ "%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s)) != RPC_SUCCESS) {\n",
RESULT,
proc->proc_name,
stringfix(proc->args.decls->decl.type),
@@ -431,8 +425,8 @@ printbody(proc)
f_print(fout,
"\treturn (clnt_send(clnt, "
- "%s,\n\t\t(xdrproc_t) xdr_%s, "
- "(caddr_t) %s%s));\n",
+ "%s,\n\t\t(xdrproc_t)xdr_%s, "
+ "(caddr_t)%s%s));\n",
proc->proc_name,
stringfix(proc->args.decls->decl.type),
(newstyle ? "&" : ""),
diff --git a/usr/src/cmd/rpcgen/rpc_cout.c b/usr/src/cmd/rpcgen/rpc_cout.c
index e5e1364327..cd05e56f9d 100644
--- a/usr/src/cmd/rpcgen/rpc_cout.c
+++ b/usr/src/cmd/rpcgen/rpc_cout.c
@@ -19,6 +19,7 @@
*
* CDDL HEADER END
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -41,20 +42,36 @@
* rpc_cout.c, XDR routine outputter for the RPC protocol compiler
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "rpc_parse.h"
#include "rpc_util.h"
+extern void crash(void);
+
+static void print_header(definition *);
+static void print_trailer(void);
+static void emit_enum(definition *);
+static void emit_program(definition *);
+static void emit_union(definition *);
+static void emit_struct(definition *);
+static void emit_typedef(definition *);
+static void print_stat(int, declaration *);
+static void emit_inline(int, declaration *, int);
+static void emit_inline64(int, declaration *, int);
+static void emit_single_in_line(int, declaration *, int, relation);
+static void emit_single_in_line64(int, declaration *, int, relation);
+static char *upcase(char *);
+
/*
* Emit the C-routine for the given definition
*/
void
-emit(def)
- definition *def;
+emit(definition *def)
{
- if (def->def_kind == DEF_CONST) {
+ if (def->def_kind == DEF_CONST)
return;
- }
if (def->def_kind == DEF_PROGRAM) {
emit_program(def);
return;
@@ -88,63 +105,50 @@ emit(def)
print_trailer();
}
-static
-findtype(def, type)
- definition *def;
- char *type;
+static int
+findtype(definition *def, char *type)
{
- if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
+ if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST)
return (0);
- } else {
- return (streq(def->def_name, type));
- }
+ return (streq(def->def_name, type));
}
-static
-undefined(type)
- char *type;
+static int
+undefined(char *type)
{
definition *def;
- def = (definition *) FINDVAL(defined, type, findtype);
+ def = (definition *)FINDVAL(defined, type, findtype);
return (def == NULL);
}
-static
-print_generic_header(procname, pointerp)
- char *procname;
- int pointerp;
+static void
+print_generic_header(char *procname, int pointerp)
{
f_print(fout, "\n");
f_print(fout, "bool_t\n");
if (Cflag) {
- f_print(fout, "xdr_%s(", procname);
- f_print(fout, "register XDR *xdrs, ");
- f_print(fout, "%s ", procname);
- if (pointerp)
- f_print(fout, "*");
- f_print(fout, "objp)\n{\n\n");
+ f_print(fout, "xdr_%s(", procname);
+ f_print(fout, "XDR *xdrs, ");
+ f_print(fout, "%s ", procname);
+ if (pointerp)
+ f_print(fout, "*");
+ f_print(fout, "objp)\n{\n\n");
} else {
- f_print(fout, "xdr_%s(xdrs, objp)\n", procname);
- f_print(fout, "\tregister XDR *xdrs;\n");
- f_print(fout, "\t%s ", procname);
- if (pointerp)
- f_print(fout, "*");
- f_print(fout, "objp;\n{\n\n");
+ f_print(fout, "xdr_%s(xdrs, objp)\n", procname);
+ f_print(fout, "\tXDR *xdrs;\n");
+ f_print(fout, "\t%s ", procname);
+ if (pointerp)
+ f_print(fout, "*");
+ f_print(fout, "objp;\n{\n\n");
}
}
-static
-print_header(def)
- definition *def;
+static void
+print_header(definition *def)
{
-
- decl_list *dl;
- bas_type *ptr;
- int i;
-
print_generic_header(def->def_name,
def->def_kind != DEF_TYPEDEF ||
!isvectordef(def->def.ty.old_type,
@@ -154,91 +158,73 @@ print_header(def)
if (inlinelen == 0)
return;
/* May cause lint to complain. but ... */
- f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n");
- f_print(fout, "\tregister int *buf;\n");
- f_print(fout, "#else\n");
- f_print(fout, "\tregister long *buf;\n");
- f_print(fout, "#endif\n\n");
+ f_print(fout, "\trpc_inline_t *buf;\n\n");
}
-static
-print_prog_header(plist)
- proc_list *plist;
+static void
+print_prog_header(proc_list *plist)
{
print_generic_header(plist->args.argname, 1);
}
-static
-print_trailer()
+static void
+print_trailer(void)
{
f_print(fout, "\treturn (TRUE);\n");
f_print(fout, "}\n");
}
-static
-print_ifopen(indent, name)
- int indent;
- char *name;
+static void
+print_ifopen(int indent, char *name)
{
tabify(fout, indent);
if (streq(name, "rpcprog_t") ||
- streq(name, "rpcvers_t") ||
- streq(name, "rpcproc_t") ||
- streq(name, "rpcprot_t") ||
- streq(name, "rpcport_t"))
- strtok(name, "_");
+ streq(name, "rpcvers_t") ||
+ streq(name, "rpcproc_t") ||
+ streq(name, "rpcprot_t") ||
+ streq(name, "rpcport_t"))
+ (void) strtok(name, "_");
f_print(fout, "if (!xdr_%s(xdrs", name);
}
-static
-print_ifarg(arg)
- char *arg;
+static void
+print_ifarg(char *arg)
{
f_print(fout, ", %s", arg);
}
-static
-print_ifsizeof(indent, prefix, type)
- int indent;
- char *prefix;
- char *type;
+static void
+print_ifsizeof(int indent, char *prefix, char *type)
{
if (indent) {
f_print(fout, ",\n");
tabify(fout, indent);
- } else {
+ } else {
f_print(fout, ", ");
}
if (streq(type, "bool")) {
- f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool");
+ f_print(fout, "sizeof (bool_t), (xdrproc_t)xdr_bool");
} else {
f_print(fout, "sizeof (");
if (undefined(type) && prefix) {
f_print(fout, "%s ", prefix);
}
- f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
+ f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type);
}
}
-static
-print_ifclose(indent)
- int indent;
+static void
+print_ifclose(int indent)
{
f_print(fout, "))\n");
tabify(fout, indent);
f_print(fout, "\treturn (FALSE);\n");
}
-static
-print_ifstat(indent, prefix, type, rel, amax, objname, name)
- int indent;
- char *prefix;
- char *type;
- relation rel;
- char *amax;
- char *objname;
- char *name;
+static void
+print_ifstat(int indent, char *prefix, char *type, relation rel,
+ char *amax, char *objname, char *name)
{
char *alt = NULL;
@@ -250,11 +236,10 @@ print_ifstat(indent, prefix, type, rel, amax, objname, name)
print_ifsizeof(0, prefix, type);
break;
case REL_VECTOR:
- if (streq(type, "string")) {
+ if (streq(type, "string"))
alt = "string";
- } else if (streq(type, "opaque")) {
+ else if (streq(type, "opaque"))
alt = "opaque";
- }
if (alt) {
print_ifopen(indent, alt);
print_ifarg(objname);
@@ -264,39 +249,34 @@ print_ifstat(indent, prefix, type, rel, amax, objname, name)
f_print(fout, "%s", objname);
}
print_ifarg(amax);
- if (!alt) {
+ if (!alt)
print_ifsizeof(indent + 1, prefix, type);
- }
break;
case REL_ARRAY:
- if (streq(type, "string")) {
+ if (streq(type, "string"))
alt = "string";
- } else if (streq(type, "opaque")) {
+ else if (streq(type, "opaque"))
alt = "bytes";
- }
if (streq(type, "string")) {
print_ifopen(indent, alt);
print_ifarg(objname);
} else {
- if (alt) {
+ if (alt)
print_ifopen(indent, alt);
- } else {
+ else
print_ifopen(indent, "array");
- }
print_ifarg("(char **)");
- if (*objname == '&') {
+ if (*objname == '&')
f_print(fout, "%s.%s_val, (u_int *) %s.%s_len",
objname, name, objname, name);
- } else {
+ else
f_print(fout,
"&%s->%s_val, (u_int *) &%s->%s_len",
objname, name, objname, name);
- }
}
print_ifarg(amax);
- if (!alt) {
+ if (!alt)
print_ifsizeof(indent + 1, prefix, type);
- }
break;
case REL_ALIAS:
print_ifopen(indent, type);
@@ -307,18 +287,16 @@ print_ifstat(indent, prefix, type, rel, amax, objname, name)
}
/* ARGSUSED */
-static
-emit_enum(def)
- definition *def;
+static void
+emit_enum(definition *def)
{
print_ifopen(1, "enum");
print_ifarg("(enum_t *)objp");
print_ifclose(1);
}
-static
-emit_program(def)
- definition *def;
+static void
+emit_program(definition *def)
{
decl_list *dl;
version_list *vlist;
@@ -337,16 +315,13 @@ emit_program(def)
}
-static
-emit_union(def)
- definition *def;
+static void
+emit_union(definition *def)
{
declaration *dflt;
case_list *cl;
declaration *cs;
char *object;
- char *vecformat = "objp->%s_u.%s";
- char *format = "&objp->%s_u.%s";
print_stat(1, &def->def.un.enum_decl);
f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
@@ -357,15 +332,16 @@ emit_union(def)
continue;
cs = &cl->case_decl;
if (!streq(cs->type, "void")) {
- object = alloc(strlen(def->def_name) + strlen(format) +
- strlen(cs->name) + 1);
- if (isvectordef(cs->type, cs->rel)) {
- s_print(object, vecformat, def->def_name,
- cs->name);
- } else {
- s_print(object, format, def->def_name,
- cs->name);
- }
+ size_t len = strlen(def->def_name) +
+ strlen("&objp->%s_u.%s") +
+ strlen(cs->name) + 1;
+ object = malloc(len);
+ if (isvectordef(cs->type, cs->rel))
+ (void) snprintf(object, len, "objp->%s_u.%s",
+ def->def_name, cs->name);
+ else
+ (void) snprintf(object, len, "&objp->%s_u.%s",
+ def->def_name, cs->name);
print_ifstat(2, cs->prefix, cs->type, cs->rel,
cs->array_max, object, cs->name);
free(object);
@@ -375,16 +351,17 @@ emit_union(def)
dflt = def->def.un.default_decl;
if (dflt != NULL) {
if (!streq(dflt->type, "void")) {
+ size_t len = strlen(def->def_name) +
+ strlen("&objp->%s_u.%s") +
+ strlen(dflt->name) + 1;
f_print(fout, "\tdefault:\n");
- object = alloc(strlen(def->def_name) + strlen(format) +
-strlen(dflt->name) + 1);
- if (isvectordef(dflt->type, dflt->rel)) {
- s_print(object, vecformat, def->def_name,
- dflt->name);
- } else {
- s_print(object, format, def->def_name,
- dflt->name);
- }
+ object = malloc(len);
+ if (isvectordef(dflt->type, dflt->rel))
+ (void) snprintf(object, len, "objp->%s_u.%s",
+ def->def_name, dflt->name);
+ else
+ (void) snprintf(object, len, "&objp->%s_u.%s",
+ def->def_name, dflt->name);
print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
dflt->array_max, object, dflt->name);
@@ -485,6 +462,7 @@ arraysize(char *sz, declaration *dc, int elsize)
int slen = 0;
char *plus = "";
char *tmp;
+ size_t tlen;
/*
* Calculate the size of a string to hold the size of all arrays
@@ -511,16 +489,19 @@ arraysize(char *sz, declaration *dc, int elsize)
* for the trailing NULL
*/
len = strlen(dc->array_max) + (elsize == 1 ? 0 : digits + 5) + 1;
- tmp = realloc(sz, slen + len + strlen(plus));
+ tlen = slen + len + strlen(plus);
+ tmp = realloc(sz, tlen);
if (tmp == NULL) {
f_print(stderr, "Fatal error : no memory\n");
crash();
}
if (elsize == 1)
- s_print(tmp + slen, "%s%s", plus, dc->array_max);
+ (void) snprintf(tmp + slen, tlen - slen, "%s%s",
+ plus, dc->array_max);
else
- s_print(tmp + slen, "%s(%s) * %d", plus, dc->array_max, elsize);
+ (void) snprintf(tmp + slen, tlen - slen, "%s(%s) * %d",
+ plus, dc->array_max, elsize);
return (tmp);
}
@@ -529,9 +510,8 @@ static void
inline_struct(decl_list *dl, decl_list *last, int flag, int indent)
{
int size, tsize;
- decl_list *cur, *psav;
- char *sizestr, *plus;
- char ptemp[256];
+ decl_list *cur;
+ char *sizestr;
cur = NULL;
tsize = 0;
@@ -570,16 +550,17 @@ inline_struct(decl_list *dl, decl_list *last, int flag, int indent)
}
}
- if (cur != NULL)
- if (sizestr == NULL && tsize < inlinelen) {
- /* don't expand into inline code if tsize < inlinelen */
- while (cur != dl) {
- print_stat(indent + 1, &cur->decl);
- cur = cur->next;
- }
- } else {
- expand_inline(indent, sizestr, tsize, flag, dl, cur);
+ if (cur == NULL)
+ return;
+ if (sizestr == NULL && tsize < inlinelen) {
+ /* don't expand into inline code if tsize < inlinelen */
+ while (cur != dl) {
+ print_stat(indent + 1, &cur->decl);
+ cur = cur->next;
}
+ } else {
+ expand_inline(indent, sizestr, tsize, flag, dl, cur);
+ }
}
/*
@@ -598,19 +579,17 @@ check_inline(decl_list *dl, int inlinelen, int *have_vector)
return (0);
for (; dl != NULL; dl = dl->next) {
- if (inline_type(&dl->decl, &size)) {
- if (dl->decl.rel == REL_VECTOR) {
- *have_vector = 1;
- doinline = 1;
- break;
- } else {
- tsize += size;
- if (tsize >= inlinelen)
- doinline = 1;
- }
- } else {
+ if (!inline_type(&dl->decl, &size)) {
tsize = 0;
+ continue;
+ }
+ if (dl->decl.rel == REL_VECTOR) {
+ *have_vector = 1;
+ return (1);
}
+ tsize += size;
+ if (tsize >= inlinelen)
+ doinline = 1;
}
return (doinline);
@@ -703,9 +682,8 @@ emit_struct_tail_recursion(definition *defp, int can_inline)
f_print(fout, "\n\t}\n");
}
-static
-emit_struct(def)
- definition *def;
+static void
+emit_struct(definition *def)
{
decl_list *dl = def->def.st.decls;
int can_inline, have_vector;
@@ -741,9 +719,8 @@ emit_struct(def)
}
-static
-emit_typedef(def)
- definition *def;
+static void
+emit_typedef(definition *def)
{
char *prefix = def->def.ty.old_prefix;
char *type = def->def.ty.old_type;
@@ -753,10 +730,8 @@ emit_typedef(def)
print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
}
-static
-print_stat(indent, dec)
- int indent;
- declaration *dec;
+static void
+print_stat(int indent, declaration *dec)
{
char *prefix = dec->prefix;
char *type = dec->type;
@@ -764,21 +739,16 @@ print_stat(indent, dec)
relation rel = dec->rel;
char name[256];
- if (isvectordef(type, rel)) {
- s_print(name, "objp->%s", dec->name);
- } else {
- s_print(name, "&objp->%s", dec->name);
- }
+ if (isvectordef(type, rel))
+ (void) snprintf(name, sizeof (name), "objp->%s", dec->name);
+ else
+ (void) snprintf(name, sizeof (name), "&objp->%s", dec->name);
print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
}
-char *upcase();
-
-emit_inline(indent, decl, flag)
-int indent;
-declaration *decl;
-int flag;
+static void
+emit_inline(int indent, declaration *decl, int flag)
{
switch (decl->rel) {
case REL_ALIAS :
@@ -788,7 +758,7 @@ int flag;
tabify(fout, indent);
f_print(fout, "{\n");
tabify(fout, indent + 1);
- f_print(fout, "register %s *genp;\n\n", decl->type);
+ f_print(fout, "%s *genp;\n\n", decl->type);
tabify(fout, indent + 1);
f_print(fout,
"for (i = 0, genp = objp->%s;\n", decl->name);
@@ -802,10 +772,8 @@ int flag;
}
}
-emit_inline64(indent, decl, flag)
-int indent;
-declaration *decl;
-int flag;
+static void
+emit_inline64(int indent, declaration *decl, int flag)
{
switch (decl->rel) {
case REL_ALIAS :
@@ -815,7 +783,7 @@ int flag;
tabify(fout, indent);
f_print(fout, "{\n");
tabify(fout, indent + 1);
- f_print(fout, "register %s *genp;\n\n", decl->type);
+ f_print(fout, "%s *genp;\n\n", decl->type);
tabify(fout, indent + 1);
f_print(fout,
"for (i = 0, genp = objp->%s;\n", decl->name);
@@ -829,11 +797,8 @@ int flag;
}
}
-emit_single_in_line(indent, decl, flag, rel)
-int indent;
-declaration *decl;
-int flag;
-relation rel;
+static void
+emit_single_in_line(int indent, declaration *decl, int flag, relation rel)
{
char *upp_case;
int freed = 0;
@@ -850,19 +815,17 @@ relation rel;
upp_case = upcase(decl->type);
/* hack - XX */
- if (strcmp(upp_case, "INT") == 0)
- {
+ if (strcmp(upp_case, "INT") == 0) {
free(upp_case);
freed = 1;
upp_case = "LONG";
}
if ((strcmp(upp_case, "U_INT") == 0) ||
- (strcmp(upp_case, "RPCPROG") == 0) ||
- (strcmp(upp_case, "RPCVERS") == 0) ||
- (strcmp(upp_case, "RPCPROC") == 0) ||
- (strcmp(upp_case, "RPCPROT") == 0) ||
- (strcmp(upp_case, "RPCPORT") == 0))
- {
+ (strcmp(upp_case, "RPCPROG") == 0) ||
+ (strcmp(upp_case, "RPCVERS") == 0) ||
+ (strcmp(upp_case, "RPCPROC") == 0) ||
+ (strcmp(upp_case, "RPCPROT") == 0) ||
+ (strcmp(upp_case, "RPCPORT") == 0)) {
free(upp_case);
freed = 1;
upp_case = "U_LONG";
@@ -881,11 +844,8 @@ relation rel;
free(upp_case);
}
-emit_single_in_line64(indent, decl, flag, rel)
-int indent;
-declaration *decl;
-int flag;
-relation rel;
+static void
+emit_single_in_line64(int indent, declaration *decl, int flag, relation rel)
{
char *upp_case;
int freed = 0;
@@ -902,20 +862,18 @@ relation rel;
upp_case = upcase(decl->type);
/* hack - XX */
- if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0))
- {
+ if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0)) {
free(upp_case);
freed = 1;
upp_case = "INT32";
}
if ((strcmp(upp_case, "U_INT") == 0) ||
- (strcmp(upp_case, "U_LONG") == 0) ||
- (strcmp(upp_case, "RPCPROG") == 0) ||
- (strcmp(upp_case, "RPCVERS") == 0) ||
- (strcmp(upp_case, "RPCPROC") == 0) ||
- (strcmp(upp_case, "RPCPROT") == 0) ||
- (strcmp(upp_case, "RPCPORT") == 0))
- {
+ (strcmp(upp_case, "U_LONG") == 0) ||
+ (strcmp(upp_case, "RPCPROG") == 0) ||
+ (strcmp(upp_case, "RPCVERS") == 0) ||
+ (strcmp(upp_case, "RPCPROC") == 0) ||
+ (strcmp(upp_case, "RPCPROT") == 0) ||
+ (strcmp(upp_case, "RPCPORT") == 0)) {
free(upp_case);
freed = 1;
upp_case = "U_INT32";
@@ -934,15 +892,13 @@ relation rel;
free(upp_case);
}
-char *
-upcase(str)
-char *str;
+static char *
+upcase(char *str)
{
char *ptr, *hptr;
- ptr = (char *)malloc(strlen(str)+1);
- if (ptr == (char *)NULL)
- {
+ ptr = malloc(strlen(str)+1);
+ if (ptr == NULL) {
f_print(stderr, "malloc failed\n");
exit(1);
};
diff --git a/usr/src/cmd/rpcgen/rpc_hout.c b/usr/src/cmd/rpcgen/rpc_hout.c
index 5a3447fe83..36de8adf9c 100644
--- a/usr/src/cmd/rpcgen/rpc_hout.c
+++ b/usr/src/cmd/rpcgen/rpc_hout.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -40,15 +42,26 @@
* rpc_hout.c, Header file outputter for the RPC protocol compiler
*/
#include <stdio.h>
+#include <stdlib.h>
#include <ctype.h>
#include "rpc_parse.h"
#include "rpc_util.h"
-void storexdrfuncdecl();
-
-static char RESULT[] = "clnt_res";
-
-static enum rpc_gvc {
+extern void pprocdef(proc_list *, version_list *, char *, int, int);
+extern void pdeclaration(char *, declaration *, int, char *);
+
+static void storexdrfuncdecl(char *, int);
+static void pconstdef(definition *);
+static void pstructdef(definition *);
+static void puniondef(definition *);
+static void pdefine(char *, char *);
+static void pprogramdef(definition *);
+static void parglist(proc_list *, char *);
+static void penumdef(definition *);
+static void ptypedef(definition *);
+static uint_t undefined2(char *, char *);
+
+enum rpc_gvc {
PROGRAM,
VERSION,
PROCEDURE
@@ -58,16 +71,13 @@ static enum rpc_gvc {
* Print the C-version of an xdr definition
*/
void
-print_datadef(def)
- definition *def;
+print_datadef(definition *def)
{
-
if (def->def_kind == DEF_PROGRAM) /* handle data only */
return;
- if (def->def_kind != DEF_CONST) {
+ if (def->def_kind != DEF_CONST)
f_print(fout, "\n");
- }
switch (def->def_kind) {
case DEF_STRUCT:
pstructdef(def);
@@ -88,10 +98,9 @@ print_datadef(def)
pconstdef(def);
break;
}
- if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
+ if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST)
storexdrfuncdecl(def->def_name, def->def_kind != DEF_TYPEDEF ||
!isvectordef(def->def.ty.old_type, def->def.ty.rel));
- }
}
@@ -110,12 +119,12 @@ print_funcdef(definition *def)
* store away enough information to allow the XDR functions to be spat
* out at the end of the file
*/
-void
+static void
storexdrfuncdecl(char *name, int pointerp)
{
xdrfunc *xdrptr;
- xdrptr = (xdrfunc *) malloc(sizeof (struct xdrfunc));
+ xdrptr = malloc(sizeof (struct xdrfunc));
xdrptr->name = name;
xdrptr->pointerp = pointerp;
@@ -143,7 +152,7 @@ print_xdr_func_def(char *name, int pointerp, int i)
}
-static
+static void
pconstdef(definition *def)
{
pdefine(def->def_name, def->def.co);
@@ -153,7 +162,7 @@ pconstdef(definition *def)
* print out the definitions for the arguments of functions in the
* header file
*/
-static
+static void
pargdef(definition *def)
{
decl_list *l;
@@ -162,46 +171,37 @@ pargdef(definition *def)
proc_list *plist;
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
- for (plist = vers->procs; plist != NULL;
- plist = plist->next) {
-
- if (!newstyle || plist->arg_num < 2) {
- continue; /* old style or single args */
- }
- name = plist->args.argname;
- f_print(fout, "struct %s {\n", name);
- for (l = plist->args.decls;
- l != NULL; l = l->next) {
- pdeclaration(name, &l->decl, 1, ";\n");
- }
- f_print(fout, "};\n");
- f_print(fout, "typedef struct %s %s;\n",
- name, name);
- storexdrfuncdecl(name, 1);
- f_print(fout, "\n");
- }
+ for (plist = vers->procs; plist != NULL; plist = plist->next) {
+ if (!newstyle || plist->arg_num < 2)
+ continue; /* old style or single args */
+ name = plist->args.argname;
+ f_print(fout, "struct %s {\n", name);
+ for (l = plist->args.decls; l != NULL; l = l->next)
+ pdeclaration(name, &l->decl, 1, ";\n");
+ f_print(fout, "};\n");
+ f_print(fout, "typedef struct %s %s;\n", name, name);
+ storexdrfuncdecl(name, 1);
+ f_print(fout, "\n");
}
+ }
}
-static
-pstructdef(def)
- definition *def;
+static void
+pstructdef(definition *def)
{
decl_list *l;
char *name = def->def_name;
f_print(fout, "struct %s {\n", name);
- for (l = def->def.st.decls; l != NULL; l = l->next) {
+ for (l = def->def.st.decls; l != NULL; l = l->next)
pdeclaration(name, &l->decl, 1, ";\n");
- }
f_print(fout, "};\n");
f_print(fout, "typedef struct %s %s;\n", name, name);
}
-static
-puniondef(def)
- definition *def;
+static void
+puniondef(definition *def)
{
case_list *l;
char *name = def->def_name;
@@ -209,34 +209,30 @@ puniondef(def)
f_print(fout, "struct %s {\n", name);
decl = &def->def.un.enum_decl;
- if (streq(decl->type, "bool")) {
+ if (streq(decl->type, "bool"))
f_print(fout, "\tbool_t %s;\n", decl->name);
- } else {
+ else
f_print(fout, "\t%s %s;\n", decl->type, decl->name);
- }
f_print(fout, "\tunion {\n");
for (l = def->def.un.cases; l != NULL; l = l->next) {
if (l->contflag == 0)
pdeclaration(name, &l->case_decl, 2, ";\n");
}
decl = def->def.un.default_decl;
- if (decl && !streq(decl->type, "void")) {
+ if (decl && !streq(decl->type, "void"))
pdeclaration(name, decl, 2, ";\n");
- }
f_print(fout, "\t} %s_u;\n", name);
f_print(fout, "};\n");
f_print(fout, "typedef struct %s %s;\n", name, name);
}
-static
-pdefine(name, num)
- char *name;
- char *num;
+static void
+pdefine(char *name, char *num)
{
f_print(fout, "#define\t%s %s\n", name, num);
}
-static
+static void
puldefine(char *name, char *num, enum rpc_gvc which)
{
switch (which) {
@@ -250,7 +246,7 @@ puldefine(char *name, char *num, enum rpc_gvc which)
}
}
-static
+static uint_t
define_printed(proc_list *stop, version_list *start)
{
version_list *vers;
@@ -258,19 +254,18 @@ define_printed(proc_list *stop, version_list *start)
for (vers = start; vers != NULL; vers = vers->next) {
for (proc = vers->procs; proc != NULL; proc = proc->next) {
- if (proc == stop) {
+ if (proc == stop)
return (0);
- } else if (streq(proc->proc_name, stop->proc_name)) {
+ if (streq(proc->proc_name, stop->proc_name))
return (1);
- }
}
}
abort();
/* NOTREACHED */
}
-static
-pfreeprocdef(char * name, char *vers, int mode)
+static void
+pfreeprocdef(char *name, char *vers, int mode)
{
f_print(fout, "extern int ");
pvname(name, vers);
@@ -278,13 +273,10 @@ pfreeprocdef(char * name, char *vers, int mode)
f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
else
f_print(fout, "_freeresult();\n");
-
-
}
-static
-pprogramdef(def)
- definition *def;
+static void
+pprogramdef(definition *def)
{
version_list *vers;
proc_list *proc;
@@ -300,7 +292,7 @@ pprogramdef(def)
"extern struct rpcgen_table %s_%s_table[];\n",
locase(def->def_name), vers->vers_num);
f_print(fout,
- "extern %s_%s_nproc;\n",
+ "extern int %s_%s_nproc;\n",
locase(def->def_name), vers->vers_num);
}
puldefine(vers->vers_name, vers->vers_num, VERSION);
@@ -313,12 +305,10 @@ pprogramdef(def)
if (!Cflag) {
ext = "extern ";
for (proc = vers->procs; proc != NULL;
- proc = proc->next) {
- if (!define_printed(proc,
- def->def.pr.versions)) {
+ proc = proc->next) {
+ if (!define_printed(proc, def->def.pr.versions))
puldefine(proc->proc_name,
- proc->proc_num, PROCEDURE);
- }
+ proc->proc_num, PROCEDURE);
f_print(fout, "%s", ext);
pprocdef(proc, vers, NULL, 0, 2);
@@ -352,19 +342,16 @@ pprogramdef(def)
pprocdef(proc, vers,
"struct svc_req *", 1, i);
}
- pfreeprocdef(def->def_name, vers->vers_num, i);
+ pfreeprocdef(def->def_name, vers->vers_num, i);
}
f_print(fout, "#endif /* K&R C */\n");
}
}
}
-pprocdef(proc, vp, addargtype, server_p, mode)
- proc_list *proc;
- version_list *vp;
- char *addargtype;
- int server_p;
- int mode;
+void
+pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p,
+ int mode)
{
if (mtflag) {
/* Print MT style stubs */
@@ -385,22 +372,14 @@ pprocdef(proc, vp, addargtype, server_p, mode)
* mode 1 = ANSI-C, mode 2 = K&R C
*/
if (mode == 1)
- parglist(proc, addargtype, server_p);
+ parglist(proc, addargtype);
else
f_print(fout, "();\n");
-
-
-
}
-
-
/* print out argument list of procedure */
-static
-parglist(proc, addargtype, server_p)
- proc_list *proc;
- char *addargtype;
- int server_p;
+static void
+parglist(proc_list *proc, char *addargtype)
{
decl_list *dl;
int oneway = streq(proc->res_type, "oneway");
@@ -409,6 +388,7 @@ parglist(proc, addargtype, server_p)
if (proc->arg_num < 2 && newstyle &&
streq(proc->args.decls->decl.type, "void")) {
/* 0 argument in new style: do nothing */
+ /* EMPTY */
} else {
for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
ptype(dl->decl.prefix, dl->decl.type, 1);
@@ -425,12 +405,10 @@ parglist(proc, addargtype, server_p)
}
f_print(fout, "%s);\n", addargtype);
-
}
-static
-penumdef(def)
- definition *def;
+static void
+penumdef(definition *def)
{
char *name = def->def_name;
enumval_list *l;
@@ -445,11 +423,10 @@ penumdef(def)
last = l->assignment;
count = 1;
} else {
- if (last == NULL) {
+ if (last == NULL)
f_print(fout, " = %d", count++);
- } else {
+ else
f_print(fout, " = %s + %d", last, count++);
- }
}
if (l->next)
f_print(fout, ",\n");
@@ -460,9 +437,8 @@ penumdef(def)
f_print(fout, "typedef enum %s %s;\n", name, name);
}
-static
-ptypedef(def)
- definition *def;
+static void
+ptypedef(definition *def)
{
char *name = def->def_name;
char *old = def->def.ty.old_type;
@@ -479,11 +455,11 @@ ptypedef(def)
} else if (streq(old, "bool")) {
old = "bool_t";
}
- if (undefined2(old, name) && def->def.ty.old_prefix) {
- s_print(prefix, "%s ", def->def.ty.old_prefix);
- } else {
+ if (undefined2(old, name) && def->def.ty.old_prefix)
+ (void) snprintf(prefix, sizeof (prefix), "%s ",
+ def->def.ty.old_prefix);
+ else
prefix[0] = 0;
- }
f_print(fout, "typedef ");
switch (rel) {
case REL_ARRAY:
@@ -507,23 +483,18 @@ ptypedef(def)
}
}
-pdeclaration(name, dec, tab, separator)
- char *name;
- declaration *dec;
- int tab;
- char *separator;
+void
+pdeclaration(char *name, declaration *dec, int tab, char *separator)
{
char buf[8]; /* enough to hold "struct ", include NUL */
char *prefix;
char *type;
- if (streq(dec->type, "void")) {
+ if (streq(dec->type, "void"))
return;
- }
tabify(fout, tab);
- if (streq(dec->type, name) && !dec->prefix) {
+ if (streq(dec->type, name) && !dec->prefix)
f_print(fout, "struct ");
- }
if (streq(dec->type, "string")) {
f_print(fout, "char *%s", dec->name);
} else {
@@ -534,7 +505,8 @@ pdeclaration(name, dec, tab, separator)
type = "char";
} else {
if (dec->prefix) {
- s_print(buf, "%s ", dec->prefix);
+ (void) snprintf(buf, sizeof (buf),
+ "%s ", dec->prefix);
prefix = buf;
}
type = dec->type;
@@ -562,13 +534,12 @@ pdeclaration(name, dec, tab, separator)
break;
}
}
+ /* LINTED variable format */
f_print(fout, separator);
}
-static
-undefined2(type, stop)
- char *type;
- char *stop;
+static uint_t
+undefined2(char *type, char *stop)
{
list *l;
definition *def;
@@ -576,11 +547,10 @@ undefined2(type, stop)
for (l = defined; l != NULL; l = l->next) {
def = (definition *) l->val;
if (def->def_kind != DEF_PROGRAM) {
- if (streq(def->def_name, stop)) {
+ if (streq(def->def_name, stop))
return (1);
- } else if (streq(def->def_name, type)) {
+ if (streq(def->def_name, type))
return (0);
- }
}
}
return (1);
diff --git a/usr/src/cmd/rpcgen/rpc_main.c b/usr/src/cmd/rpcgen/rpc_main.c
index 25dc0a300f..de677886a0 100644
--- a/usr/src/cmd/rpcgen/rpc_main.c
+++ b/usr/src/cmd/rpcgen/rpc_main.c
@@ -19,6 +19,7 @@
*
* CDDL HEADER END
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -42,8 +43,11 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/file.h>
@@ -53,15 +57,30 @@
#include "rpc_scan.h"
-extern void write_sample_svc();
-int write_sample_clnt();
-void write_sample_clnt_main();
-char *rindex();
-
-static int svc_output();
-static void mkfile_output();
-
-#define EXTEND 1 /* alias for TRUE */
+extern void write_sample_svc(definition *);
+extern int write_sample_clnt(definition *);
+extern void write_sample_clnt_main(void);
+extern void reinitialize(void);
+extern void crash(void);
+extern void add_type(int, char *);
+extern void add_sample_msg(void);
+
+static void svc_output(char *, char *, int, char *);
+static void clnt_output(char *, char *, int, char *);
+static void c_output(char *, char *, int, char *);
+static void mkfile_output(struct commandline *);
+static void c_initialize(void);
+static void h_output(char *, char *, int, char *);
+static void s_output(int, char *[], char *, char *, int, char *, int, int);
+static void l_output(char *, char *, int, char *);
+static void t_output(char *, char *, int, char *);
+static int do_registers(int, char *[]);
+static uint_t parseargs(int, char *[], struct commandline *);
+static void usage(void);
+static void version_info(void);
+static void options_usage(void);
+
+#define EXTEND 1 /* alias for TRUE */
#define DONT_EXTEND 0 /* alias for FALSE */
#define SUNOS_CPP "/usr/lib/cpp"
@@ -86,11 +105,10 @@ static int allnc = sizeof (allnv)/sizeof (allnv[0]);
/*
* machinations for handling expanding argument list
*/
-static void addarg(); /* add another argument to the list */
-static void putarg(); /* put argument at specified location */
-static void clear_args(); /* clear argument list */
-static void checkfiles(); /* check if out file already exists */
-
+static void addarg(char *); /* add another argument to the list */
+static void putarg(int, char *); /* put argument at specified location */
+static void clear_args(void); /* clear argument list */
+static void checkfiles(char *, char *); /* check if out file already exists */
#define ARGLISTLEN 20
@@ -130,13 +148,12 @@ xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
pid_t childpid;
-main(argc, argv)
- int argc;
- char *argv[];
+int
+main(int argc, char *argv[])
{
struct commandline cmd;
- (void) memset((char *)&cmd, 0, sizeof (struct commandline));
+ (void) memset(&cmd, 0, sizeof (struct commandline));
clear_args();
if (!parseargs(argc, argv, &cmd))
usage();
@@ -145,9 +162,8 @@ main(argc, argv)
* so in that case only, check if the outfile exists, and if so,
* print an error message and exit.
*/
- if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
+ if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag)
checkfiles(cmd.infile, cmd.outfile);
- }
else
checkfiles(cmd.infile, NULL);
@@ -186,7 +202,7 @@ main(argc, argv)
EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
if (tblflag) {
reinitialize();
- t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
+ t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
}
if (allfiles) {
@@ -204,8 +220,7 @@ main(argc, argv)
}
}
- exit(nonfatalerrors);
- /* NOTREACHED */
+ return (nonfatalerrors);
}
@@ -213,21 +228,17 @@ main(argc, argv)
* add extension to filename
*/
static char *
-extendfile(file, ext)
- char *file;
- char *ext;
+extendfile(char *file, char *ext)
{
char *res;
char *p;
- res = alloc(strlen(file) + strlen(ext) + 1);
- if (res == NULL) {
+ res = malloc(strlen(file) + strlen(ext) + 1);
+ if (res == NULL)
abort();
- }
p = strrchr(file, '.');
- if (p == NULL) {
+ if (p == NULL)
p = file + strlen(file);
- }
(void) strcpy(res, file);
(void) strcpy(res + (p - file), ext);
return (res);
@@ -236,10 +247,8 @@ extendfile(file, ext)
/*
* Open output file with given extension
*/
-static
-open_output(infile, outfile)
- char *infile;
- char *outfile;
+static void
+open_output(char *infile, char *outfile)
{
if (outfile == NULL) {
@@ -262,8 +271,8 @@ open_output(infile, outfile)
}
-static
-add_warning()
+static void
+add_warning(void)
{
f_print(fout, "/*\n");
f_print(fout, " * Please do not edit this file.\n");
@@ -272,28 +281,31 @@ add_warning()
}
/* clear list of arguments */
-static void clear_args()
+static void
+clear_args(void)
{
int i;
+
for (i = FIXEDARGS; i < ARGLISTLEN; i++)
arglist[i] = NULL;
argcount = FIXEDARGS;
}
/* make sure that a CPP exists */
-static void find_cpp()
+static void
+find_cpp(void)
{
struct stat buf;
if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
if (cppDefined) {
- fprintf(stderr,
+ (void) fprintf(stderr,
"cannot find C preprocessor: %s \n", CPP);
crash();
} else { /* try the other one */
CPP = SUNOS_CPP;
if (stat(CPP, &buf) < 0) { /* can't find any cpp */
- fprintf(stderr,
+ (void) fprintf(stderr,
"cannot find any C preprocessor (cpp)\n");
crash();
}
@@ -304,10 +316,8 @@ static void find_cpp()
/*
* Open input file with given define for C-preprocessor
*/
-static
-open_input(infile, define)
- char *infile;
- char *define;
+static void
+open_input(char *infile, char *define)
{
int pd[2];
@@ -325,9 +335,10 @@ open_input(infile, define)
(void) close(1);
(void) dup2(pd[1], 1);
(void) close(pd[0]);
- execv(arglist[0], arglist);
+ (void) execv(arglist[0], arglist);
perror("execv");
exit(1);
+ /* NOTREACHED */
case -1:
perror("fork");
exit(1);
@@ -342,8 +353,7 @@ open_input(infile, define)
}
/* valid tirpc nettypes */
-static char *valid_ti_nettypes[] =
-{
+static char *valid_ti_nettypes[] = {
"netpath",
"visible",
"circuit_v",
@@ -354,19 +364,17 @@ static char *valid_ti_nettypes[] =
"tcp",
"raw",
NULL
- };
+};
/* valid inetd nettypes */
-static char *valid_i_nettypes[] =
-{
+static char *valid_i_nettypes[] = {
"udp",
"tcp",
NULL
- };
+};
-static int check_nettype(name, list_to_check)
-char *name;
-char *list_to_check[];
+static int
+check_nettype(char *name, char *list_to_check[])
{
int i;
for (i = 0; list_to_check[i] != NULL; i++) {
@@ -379,9 +387,7 @@ char *list_to_check[];
}
static char *
-file_name(file, ext)
-char *file;
-char *ext;
+file_name(char *file, char *ext)
{
char *temp;
temp = extendfile(file, ext);
@@ -390,16 +396,11 @@ char *ext;
return (temp);
else
return ((char *)" ");
-
}
-static
-c_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+c_output(char *infile, char *define, int extend, char *outfile)
{
definition *def;
char *include;
@@ -418,10 +419,10 @@ c_output(infile, define, extend, outfile)
} else
f_print(fout, "#include <rpc/rpc.h>\n");
/*
- * Include malloc.h to support mem_alloc calls.
+ * Include stdlib.h to support mem_alloc calls.
*/
f_print(fout, "\n#ifndef _KERNEL\n");
- f_print(fout, "#include <malloc.h>\n");
+ f_print(fout, "#include <stdlib.h>\n");
f_print(fout, "#endif /* !_KERNEL */\n\n");
tell = ftell(fout);
while (def = get_definition()) {
@@ -433,9 +434,9 @@ c_output(infile, define, extend, outfile)
}
-c_initialize()
+static void
+c_initialize(void)
{
-
/*
* add all the starting basic types.
* We may need to add some derived types
@@ -454,7 +455,6 @@ c_initialize()
add_type(1, "rpcproc_t");
add_type(1, "rpcprot_t");
add_type(1, "rpcport_t");
-
}
char rpcgen_table_dcl1[] = "struct rpcgen_table {\n";
@@ -471,8 +471,7 @@ char rpcgen_table_proc_b[] = "\tchar\t*(*proc)();\n";
char *
-generate_guard(pathname)
- char *pathname;
+generate_guard(char *pathname)
{
char *filename, *guard, *tmp;
@@ -509,12 +508,8 @@ generate_guard(pathname)
*/
-static
-h_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+h_output(char *infile, char *define, int extend, char *outfile)
{
definition *def;
char *outfilename;
@@ -528,13 +523,12 @@ h_output(infile, define, extend, outfile)
outfilename = extend ? extendfile(infile, outfile) : outfile;
open_output(infile, outfilename);
add_warning();
- if (outfilename || infile) {
+ if (outfilename || infile)
guard = generate_guard(outfilename ? outfilename: infile);
- } else
+ else
guard = "STDIN_";
- f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
- guard);
+ f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, guard);
f_print(fout, "#include <rpc/rpc.h>\n");
@@ -557,54 +551,49 @@ h_output(infile, define, extend, outfile)
tell = ftell(fout);
/* print data definitions */
- while (def = get_definition()) {
+ while (def = get_definition())
print_datadef(def);
- }
/*
* print function declarations.
* Do this after data definitions because they might be used as
* arguments for functions
*/
- for (l = defined; l != NULL; l = l->next) {
+ for (l = defined; l != NULL; l = l->next)
print_funcdef(l->val);
- }
/* Now print all xdr func declarations */
if (xdrfunc_head != NULL) {
-
- f_print(fout,
- "\n/* the xdr functions */\n");
+ f_print(fout, "\n/* the xdr functions */\n");
if (CCflag) {
- f_print(fout, "\n#ifdef __cplusplus\n");
- f_print(fout, "extern \"C\" {\n");
- f_print(fout, "#endif\n");
- }
+ f_print(fout, "\n#ifdef __cplusplus\n");
+ f_print(fout, "extern \"C\" {\n");
+ f_print(fout, "#endif\n");
+ }
if (!Cflag) {
xdrfuncp = xdrfunc_head;
while (xdrfuncp != NULL) {
print_xdr_func_def(xdrfuncp->name,
- xdrfuncp->pointerp, 2);
+ xdrfuncp->pointerp, 2);
xdrfuncp = xdrfuncp->next;
}
} else {
-
for (i = 1; i < 3; i++) {
if (i == 1)
- f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
-
+ f_print(fout,
+"\n#if defined(__STDC__) || defined(__cplusplus)\n");
else
f_print(fout, "\n#else /* K&R C */\n");
xdrfuncp = xdrfunc_head;
while (xdrfuncp != NULL) {
print_xdr_func_def(xdrfuncp->name,
- xdrfuncp->pointerp, i);
+ xdrfuncp->pointerp, i);
xdrfuncp = xdrfuncp->next;
}
}
- f_print(fout, "\n#endif /* K&R C */\n");
+ f_print(fout, "\n#endif /* K&R C */\n");
}
}
@@ -631,16 +620,9 @@ h_output(infile, define, extend, outfile)
/*
* Compile into an RPC service
*/
-static
-s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
- int argc;
- char *argv[];
- char *infile;
- char *define;
- int extend;
- char *outfile;
- int nomain;
- int netflag;
+static void
+s_output(int argc, char *argv[], char *infile, char *define, int extend,
+ char *outfile, int nomain, int netflag)
{
char *include;
definition *def;
@@ -670,16 +652,14 @@ s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
indefinitewait = 1;
else if (strcmp(svcclosetime, "0") == 0)
exitnow = 1;
- else if (inetdflag || pmflag) {
+ else if (inetdflag || pmflag)
timerflag = 1;
- }
if (!tirpcflag && inetdflag)
f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n");
- if (Cflag && (inetdflag || pmflag)) {
+ if (Cflag && (inetdflag || pmflag))
if (tirpcflag)
f_print(fout, "#include <unistd.h> /* setsid */\n");
- }
if (tirpcflag)
f_print(fout, "#include <sys/types.h>\n");
@@ -691,9 +671,8 @@ s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
f_print(fout, "#include <rpc/svc_soc.h>\n");
}
- if ((netflag || pmflag) && tirpcflag && !nomain) {
+ if ((netflag || pmflag) && tirpcflag && !nomain)
f_print(fout, "#include <netconfig.h>\n");
- }
if (tirpcflag)
f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
if (logflag || inetdflag || pmflag)
@@ -709,9 +688,8 @@ s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
if (timerflag)
f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
svcclosetime);
- while (def = get_definition()) {
+ while (def = get_definition())
foundprogram |= (def->def_kind == DEF_PROGRAM);
- }
if (extend && !foundprogram) {
(void) unlink(outfilename);
return;
@@ -730,12 +708,8 @@ s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
/*
* generate client side stubs
*/
-static
-l_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+l_output(char *infile, char *define, int extend, char *outfile)
{
char *include;
definition *def;
@@ -759,9 +733,8 @@ l_output(infile, define, extend, outfile)
f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
f_print(fout, "#endif /* !_KERNEL */\n");
- while (def = get_definition()) {
+ while (def = get_definition())
foundprogram |= (def->def_kind == DEF_PROGRAM);
- }
if (extend && !foundprogram) {
(void) unlink(outfilename);
return;
@@ -772,12 +745,8 @@ l_output(infile, define, extend, outfile)
/*
* generate the dispatch table
*/
-static
-t_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+t_output(char *infile, char *define, int extend, char *outfile)
{
definition *def;
int foundprogram = 0;
@@ -798,12 +767,8 @@ t_output(infile, define, extend, outfile)
}
/* sample routine for the server template */
-static
-svc_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+svc_output(char *infile, char *define, int extend, char *outfile)
{
definition *def;
char *include;
@@ -831,21 +796,15 @@ svc_output(infile, define, extend, outfile)
f_print(fout, "#include <signal.h>\n");
tell = ftell(fout);
- while (def = get_definition()) {
+ while (def = get_definition())
write_sample_svc(def);
- }
- if (extend && tell == ftell(fout)) {
+ if (extend && tell == ftell(fout))
(void) unlink(outfilename);
- }
}
/* sample main routine for client */
-static
-clnt_output(infile, define, extend, outfile)
- char *infile;
- char *define;
- int extend;
- char *outfile;
+static void
+clnt_output(char *infile, char *define, int extend, char *outfile)
{
definition *def;
char *include;
@@ -873,21 +832,19 @@ clnt_output(infile, define, extend, outfile)
f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
tell = ftell(fout);
- while (def = get_definition()) {
+ while (def = get_definition())
has_program += write_sample_clnt(def);
- }
if (has_program)
write_sample_clnt_main();
- if (extend && tell == ftell(fout)) {
+ if (extend && tell == ftell(fout))
(void) unlink(outfilename);
- }
}
-static void mkfile_output(cmd)
-struct commandline *cmd;
+static void
+mkfile_output(struct commandline *cmd)
{
char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
char *servername, *svcname, *servprogname, *clntprogname;
@@ -910,14 +867,14 @@ struct commandline *cmd;
clntprogname = extendfile(cmd->infile, "_client");
if (allfiles) {
- mkfilename = alloc(strlen("makefile.") +
+ mkfilename = malloc(strlen("makefile.") +
strlen(cmd->infile) + 1);
if (mkfilename == NULL) {
f_print(stderr, "Out of memory!\n");
return;
}
temp = (char *)rindex(cmd->infile, '.');
- strcpy(mkfilename, "makefile.");
+ (void) strcpy(mkfilename, "makefile.");
(void) strncat(mkfilename, cmd->infile,
(temp - cmd->infile));
} else
@@ -980,15 +937,12 @@ $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
}
-
/*
* Perform registrations for service output
* Return 0 if failed; 1 otherwise.
*/
static int
-do_registers(argc, argv)
- int argc;
- char *argv[];
+do_registers(int argc, char *argv[])
{
int i;
@@ -1022,8 +976,7 @@ do_registers(argc, argv)
* Add another argument to the arg list
*/
static void
-addarg(cp)
- char *cp;
+addarg(char *cp)
{
if (argcount >= ARGLISTLEN) {
f_print(stderr, "rpcgen: too many defines\n");
@@ -1031,13 +984,10 @@ addarg(cp)
/*NOTREACHED*/
}
arglist[argcount++] = cp;
-
}
static void
-putarg(where, cp)
- char *cp;
- int where;
+putarg(int where, char *cp)
{
if (where >= ARGLISTLEN) {
f_print(stderr, "rpcgen: arglist coding error\n");
@@ -1052,41 +1002,32 @@ putarg(where, cp)
* if the file already exists. Otherwise the file may get overwritten
* If input file does not exist, exit with an error
*/
-
static void
-checkfiles(infile, outfile)
-char *infile;
-char *outfile;
+checkfiles(char *infile, char *outfile)
{
-
struct stat buf;
- if (infile) /* infile ! = NULL */
- if (stat(infile, &buf) < 0)
- {
+ if (infile) { /* infile ! = NULL */
+ if (stat(infile, &buf) < 0) {
perror(infile);
crash();
- };
+ }
+ }
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();
- }
+ f_print(stderr,
+ "file '%s' already exists and may be overwritten\n",
+ outfile);
+ crash();
}
}
/*
* Parse command line arguments
*/
-static
-parseargs(argc, argv, cmd)
- int argc;
- char *argv[];
- struct commandline *cmd;
+static uint_t
+parseargs(int argc, char *argv[], struct commandline *cmd)
{
int i;
int j;
@@ -1096,9 +1037,8 @@ parseargs(argc, argv, cmd)
cmdname = argv[0];
cmd->infile = cmd->outfile = NULL;
- if (argc < 2) {
+ if (argc < 2)
return (0);
- }
allfiles = 0;
flag['c'] = 0;
flag['h'] = 0;
@@ -1133,9 +1073,8 @@ parseargs(argc, argv, cmd)
case 'l':
case 'm':
case 't':
- if (flag[c]) {
+ if (flag[c])
return (0);
- }
flag[c] = 1;
break;
case 'S':
@@ -1155,9 +1094,8 @@ parseargs(argc, argv, cmd)
else
return (0);
- if (flag[ch]) {
+ if (flag[ch])
return (0);
- }
flag[ch] = 1;
break;
case 'C': /* ANSI C syntax */
@@ -1187,9 +1125,8 @@ parseargs(argc, argv, cmd)
logflag = 1;
break;
case 'K':
- if (++i == argc) {
+ if (++i == argc)
return (0);
- }
svcclosetime = argv[i];
goto nextarg;
case 'T':
@@ -1197,47 +1134,41 @@ parseargs(argc, argv, cmd)
break;
case 'A':
mtauto = 1;
- /* fall through */
+ /* FALLTHRU */
case 'M':
mtflag = 1;
break;
case 'i' :
- if (++i == argc) {
+ if (++i == argc)
return (0);
- }
inlinelen = atoi(argv[i]);
goto nextarg;
case 'n':
case 'o':
case 's':
if (argv[i][j - 1] != '-' ||
- argv[i][j + 1] != 0) {
+ argv[i][j + 1] != 0)
return (0);
- }
flag[c] = 1;
- if (++i == argc) {
+ if (++i == argc)
return (0);
- }
if (c == 'o') {
- if (cmd->outfile) {
+ if (cmd->outfile)
return (0);
- }
cmd->outfile = argv[i];
}
goto nextarg;
case 'D':
- if (argv[i][j - 1] != '-') {
+ if (argv[i][j - 1] != '-')
return (0);
- }
(void) addarg(argv[i]);
goto nextarg;
case 'v':
version_info();
return (0);
case 'Y':
- if (++i == argc) {
+ if (++i == argc)
return (0);
- }
(void) strcpy(pathbuf, argv[i]);
(void) strcat(pathbuf, "/cpp");
CPP = pathbuf;
@@ -1277,7 +1208,8 @@ parseargs(argc, argv, cmd)
pmflag = 0; /* set pmflag only in tirpcmode */
inetdflag = 1; /* inetdflag is TRUE by default */
if (cmd->nflag) { /* netid needs TIRPC */
- f_print(stderr, "Cannot use netid flag without TIRPC.\n");
+ f_print(stderr,
+ "Cannot use netid flag without TIRPC.\n");
return (0);
}
}
@@ -1293,15 +1225,15 @@ parseargs(argc, argv, cmd)
cmd->Scflag + cmd->makefileflag;
if (nflags == 0) {
- if (cmd->outfile != NULL || cmd->infile == NULL) {
+ if (cmd->outfile != NULL || cmd->infile == NULL)
return (0);
- }
} else if (cmd->infile == NULL &&
(cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
f_print(stderr, "\"infile\" is required for template"
" generation flags.\n");
return (0);
- } if (nflags > 1) {
+ }
+ if (nflags > 1) {
f_print(stderr,
"Cannot have more than one file generation flag.\n");
return (0);
@@ -1309,8 +1241,8 @@ parseargs(argc, argv, cmd)
return (1);
}
-static
-usage()
+static void
+usage(void)
{
f_print(stderr, "%s (%d.%d)\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR);
f_print(stderr, "usage: %s infile\n", cmdname);
@@ -1324,15 +1256,15 @@ usage()
exit(1);
}
-static
-version_info()
+static void
+version_info(void)
{
f_print(stderr, "%s %d.%d\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR);
exit(1);
}
-static
-options_usage()
+static void
+options_usage(void)
{
f_print(stderr, "options:\n");
f_print(stderr, "-a\t\tgenerate all files, including samples\n");
@@ -1372,18 +1304,3 @@ options_usage()
f_print(stderr, "-Y path\t\tpath where cpp is found\n");
exit(1);
}
-
-
-char *
-rindex(sp, c)
- register char *sp, c;
-{
- register char *r;
-
- r = NULL;
- do {
- if (*sp == c)
- r = sp;
- } while (*sp++);
- return (r);
-}
diff --git a/usr/src/cmd/rpcgen/rpc_parse.c b/usr/src/cmd/rpcgen/rpc_parse.c
index bf7af51813..40d92b6e2c 100644
--- a/usr/src/cmd/rpcgen/rpc_parse.c
+++ b/usr/src/cmd/rpcgen/rpc_parse.c
@@ -19,6 +19,7 @@
*
* CDDL HEADER END
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -41,6 +42,7 @@
* rpc_parse.c, Parser for the RPC protocol compiler
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "rpc/types.h"
#include "rpc_scan.h"
@@ -49,19 +51,30 @@
#define ARGNAME "arg"
-extern char *make_argname();
-extern char *strdup();
+extern char *make_argname(char *, char *);
+
+static void isdefined(definition *);
+static void def_struct(definition *);
+static void def_program(definition *);
+static void def_enum(definition *);
+static void def_const(definition *);
+static void def_union(definition *);
+static void def_typedef(definition *);
+static void get_declaration(declaration *, defkind);
+static void get_prog_declaration(declaration *, defkind, int);
+static void get_type(char **, char **, defkind);
+static void unsigned_dec(char **);
/*
* return the next definition you see
*/
definition *
-get_definition()
+get_definition(void)
{
definition *defp;
token tok;
- defp = ALLOC(definition);
+ defp = calloc(1, sizeof (definition));
get_token(&tok);
switch (tok.kind) {
case TOK_STRUCT:
@@ -92,9 +105,8 @@ get_definition()
return (defp);
}
-static
-isdefined(defp)
- definition *defp;
+static void
+isdefined(definition *defp)
{
STOREVAL(&defined, defp);
}
@@ -102,6 +114,7 @@ isdefined(defp)
/*
* We treat s == NULL the same as *s == '\0'
*/
+static int
streqn(const char *s1, const char *s2)
{
if (s1 == NULL)
@@ -120,7 +133,6 @@ cmptype(definition *defp, char *type)
/* We only want typedef definitions */
if (streq(defp->def_name, type) && defp->def_kind == DEF_TYPEDEF)
return (1);
-
return (0);
}
@@ -212,11 +224,11 @@ is_self_reference(definition *defp, declaration *decp)
*/
if (decp->rel == REL_POINTER && dp->def.ty.rel != REL_ALIAS)
return (0);
- else if (decp->rel == REL_ALIAS &&
+ if (decp->rel == REL_ALIAS &&
(dp->def.ty.rel != REL_ALIAS &&
dp->def.ty.rel != REL_POINTER))
return (0);
- else if (decp->rel != REL_ALIAS && decp->rel != REL_POINTER)
+ if (decp->rel != REL_ALIAS && decp->rel != REL_POINTER)
/* Should never get here */
return (0);
@@ -232,9 +244,8 @@ is_self_reference(definition *defp, declaration *decp)
return (1);
}
-static
-def_struct(defp)
- definition *defp;
+static void
+def_struct(definition *defp)
{
token tok;
declaration dec;
@@ -250,7 +261,7 @@ def_struct(defp)
defp->def.st.tail = NULL;
do {
get_declaration(&dec, DEF_STRUCT);
- decls = ALLOC(decl_list);
+ decls = calloc(1, sizeof (decl_list));
decls->decl = dec;
/*
* Keep a referenct to the last declaration to check for
@@ -272,9 +283,8 @@ def_struct(defp)
defp->def.st.tail = endp;
}
-static
-def_program(defp)
- definition *defp;
+static void
+def_program(definition *defp)
{
token tok;
declaration dec;
@@ -295,13 +305,13 @@ def_program(defp)
scan(TOK_VERSION, &tok);
do {
scan(TOK_IDENT, &tok);
- vlist = ALLOC(version_list);
+ vlist = calloc(1, sizeof (version_list));
vlist->vers_name = tok.str;
scan(TOK_LBRACE, &tok);
ptailp = &vlist->procs;
do {
/* get result type */
- plist = ALLOC(proc_list);
+ plist = calloc(1, sizeof (proc_list));
get_type(&plist->res_prefix, &plist->res_type,
DEF_RESULT);
if (streq(plist->res_type, "opaque")) {
@@ -321,7 +331,7 @@ def_program(defp)
get_prog_declaration(&dec, DEF_PROGRAM, num_args);
if (streq(dec.type, "void"))
isvoid = TRUE;
- decls = ALLOC(decl_list);
+ decls = calloc(1, sizeof (decl_list));
plist->args.decls = decls;
decls->decl = dec;
tailp = &decls->next;
@@ -330,7 +340,7 @@ def_program(defp)
num_args++;
get_prog_declaration(&dec, DEF_STRUCT,
num_args);
- decls = ALLOC(decl_list);
+ decls = calloc(1, sizeof (decl_list));
decls->decl = dec;
*tailp = decls;
if (streq(dec.type, "void"))
@@ -364,8 +374,7 @@ def_program(defp)
scan_num(&tok);
vlist->vers_num = tok.str;
/* make the argument structure name for each arg */
- for (plist = vlist->procs; plist != NULL;
- plist = plist->next) {
+ for (plist = vlist->procs; plist != NULL; plist = plist->next) {
plist->args.argname = make_argname(plist->proc_name,
vlist->vers_num);
/* free the memory ?? */
@@ -379,10 +388,8 @@ def_program(defp)
*vtailp = NULL;
}
-
-static
-def_enum(defp)
- definition *defp;
+static void
+def_enum(definition *defp)
{
token tok;
enumval_list *elist;
@@ -395,7 +402,7 @@ def_enum(defp)
tailp = &defp->def.en.vals;
do {
scan(TOK_IDENT, &tok);
- elist = ALLOC(enumval_list);
+ elist = calloc(1, sizeof (enumval_list));
elist->name = tok.str;
elist->assignment = NULL;
scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
@@ -410,9 +417,8 @@ def_enum(defp)
*tailp = NULL;
}
-static
-def_const(defp)
- definition *defp;
+static void
+def_const(definition *defp)
{
token tok;
@@ -424,13 +430,12 @@ def_const(defp)
defp->def.co = tok.str;
}
-static
-def_union(defp)
- definition *defp;
+static void
+def_union(definition *defp)
{
token tok;
declaration dec;
- case_list *cases, *tcase;
+ case_list *cases;
case_list **tailp;
int flag;
@@ -447,7 +452,7 @@ def_union(defp)
scan(TOK_CASE, &tok);
while (tok.kind == TOK_CASE) {
scan2(TOK_IDENT, TOK_CHARCONST, &tok);
- cases = ALLOC(case_list);
+ cases = calloc(1, sizeof (case_list));
cases->case_name = tok.str;
scan(TOK_COLON, &tok);
/* now peek at next token */
@@ -459,19 +464,15 @@ def_union(defp)
/* continued case statement */
*tailp = cases;
tailp = &cases->next;
- cases = ALLOC(case_list);
+ cases = calloc(1, sizeof (case_list));
cases->case_name = tok.str;
scan(TOK_COLON, &tok);
} while (peekscan(TOK_CASE, &tok));
+ } else if (flag) {
+ *tailp = cases;
+ tailp = &cases->next;
+ cases = calloc(1, sizeof (case_list));
}
- else
- if (flag)
- {
-
- *tailp = cases;
- tailp = &cases->next;
- cases = ALLOC(case_list);
- };
get_declaration(&dec, DEF_UNION);
cases->case_decl = dec;
@@ -486,7 +487,7 @@ def_union(defp)
if (tok.kind == TOK_DEFAULT) {
scan(TOK_COLON, &tok);
get_declaration(&dec, DEF_UNION);
- defp->def.un.default_decl = ALLOC(declaration);
+ defp->def.un.default_decl = calloc(1, sizeof (declaration));
*defp->def.un.default_decl = dec;
scan(TOK_SEMICOLON, &tok);
scan(TOK_RBRACE, &tok);
@@ -495,8 +496,7 @@ def_union(defp)
}
}
-static char *reserved_words[] =
-{
+static char *reserved_words[] = {
"array",
"bytes",
"destroy",
@@ -510,29 +510,27 @@ static char *reserved_words[] =
"union",
"vector",
NULL
- };
+};
-static char *reserved_types[] =
-{
+static char *reserved_types[] = {
"opaque",
"string",
NULL
- };
+};
/*
* check that the given name is not one that would eventually result in
* xdr routines that would conflict with internal XDR routines.
*/
-static check_type_name(name, new_type)
-int new_type;
-char *name;
+static void
+check_type_name(char *name, int new_type)
{
int i;
char tmp[100];
for (i = 0; reserved_words[i] != NULL; i++) {
if (strcmp(name, reserved_words[i]) == 0) {
- snprintf(tmp, sizeof (tmp),
+ (void) snprintf(tmp, sizeof (tmp),
"illegal (reserved) name :\'%s\' "
"in type definition",
name);
@@ -542,7 +540,7 @@ char *name;
if (new_type) {
for (i = 0; reserved_types[i] != NULL; i++) {
if (strcmp(name, reserved_types[i]) == 0) {
- snprintf(tmp, sizeof (tmp),
+ (void) snprintf(tmp, sizeof (tmp),
"illegal (reserved) name :\'%s\' "
"in type definition",
name);
@@ -552,11 +550,8 @@ char *name;
}
}
-
-
-static
-def_typedef(defp)
- definition *defp;
+static void
+def_typedef(definition *defp)
{
declaration dec;
@@ -570,18 +565,15 @@ def_typedef(defp)
defp->def.ty.array_max = dec.array_max;
}
-static
-get_declaration(dec, dkind)
- declaration *dec;
- defkind dkind;
+static void
+get_declaration(declaration *dec, defkind dkind)
{
token tok;
get_type(&dec->prefix, &dec->type, dkind);
dec->rel = REL_ALIAS;
- if (streq(dec->type, "void")) {
+ if (streq(dec->type, "void"))
return;
- }
check_type_name(dec->type, 0);
scan2(TOK_STAR, TOK_IDENT, &tok);
@@ -591,19 +583,17 @@ get_declaration(dec, dkind)
}
dec->name = tok.str;
if (peekscan(TOK_LBRACKET, &tok)) {
- if (dec->rel == REL_POINTER) {
+ if (dec->rel == REL_POINTER)
error("no array-of-pointer declarations "
"-- use typedef");
- }
dec->rel = REL_VECTOR;
scan_num(&tok);
dec->array_max = tok.str;
scan(TOK_RBRACKET, &tok);
} else if (peekscan(TOK_LANGLE, &tok)) {
- if (dec->rel == REL_POINTER) {
+ if (dec->rel == REL_POINTER)
error("no array-of-pointer declarations "
"-- use typedef");
- }
dec->rel = REL_ARRAY;
if (peekscan(TOK_RANGLE, &tok)) {
dec->array_max = "~0"; /* unspecified size, use max */
@@ -624,12 +614,8 @@ get_declaration(dec, dkind)
}
}
-
-static
-get_prog_declaration(dec, dkind, num)
- declaration *dec;
- defkind dkind;
- int num; /* arg number */
+static void
+get_prog_declaration(declaration *dec, defkind dkind, int num)
{
token tok;
char name[sizeof (ARGNAME) + 10];
@@ -650,19 +636,17 @@ get_prog_declaration(dec, dkind, num)
dec->name = strdup(tok.str);
else {
/* default name of argument */
- snprintf(name, sizeof (name), "%s%d", ARGNAME, num);
+ (void) snprintf(name, sizeof (name), "%s%d", ARGNAME, num);
dec->name = strdup(name);
}
if (dec->name == NULL)
error("internal error -- out of memory");
- if (streq(dec->type, "void")) {
+ if (streq(dec->type, "void"))
return;
- }
- if (streq(dec->type, "opaque")) {
+ if (streq(dec->type, "opaque"))
error("opaque -- illegal argument type");
- }
if (peekscan(TOK_STAR, &tok)) {
if (streq(dec->type, "string")) {
error("pointer to string not allowed "
@@ -701,13 +685,8 @@ get_prog_declaration(dec, dkind, num)
}
}
-
-
-static
-get_type(prefixp, typep, dkind)
- char **prefixp;
- char **typep;
- defkind dkind;
+static void
+get_type(char **prefixp, char **typep, defkind dkind)
{
token tok;
@@ -769,9 +748,8 @@ get_type(prefixp, typep, dkind)
}
}
-static
-unsigned_dec(typep)
- char **typep;
+static void
+unsigned_dec(char **typep)
{
token tok;
diff --git a/usr/src/cmd/rpcgen/rpc_parse.h b/usr/src/cmd/rpcgen/rpc_parse.h
index 1f74251055..0bb4170824 100644
--- a/usr/src/cmd/rpcgen/rpc_parse.h
+++ b/usr/src/cmd/rpcgen/rpc_parse.h
@@ -19,6 +19,7 @@
*
* CDDL HEADER END
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -65,7 +66,7 @@ enum relation {
REL_VECTOR, /* fixed length array */
REL_ARRAY, /* variable length array */
REL_POINTER, /* pointer */
- REL_ALIAS, /* simple */
+ REL_ALIAS /* simple */
};
typedef enum relation relation;
diff --git a/usr/src/cmd/rpcgen/rpc_sample.c b/usr/src/cmd/rpcgen/rpc_sample.c
index 92cc3d6aa9..846e3d8e7d 100644
--- a/usr/src/cmd/rpcgen/rpc_sample.c
+++ b/usr/src/cmd/rpcgen/rpc_sample.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -49,22 +51,22 @@
static char RQSTP[] = "rqstp";
-void printarglist();
+extern void printarglist(proc_list *, char *, char *, char *);
+
+static void write_sample_client(char *, version_list *);
+static void write_sample_server(definition *);
+static void return_type(proc_list *);
void
-write_sample_svc(def)
- definition *def;
+write_sample_svc(definition *def)
{
-
if (def->def_kind != DEF_PROGRAM)
return;
write_sample_server(def);
}
-
int
-write_sample_clnt(def)
- definition *def;
+write_sample_clnt(definition *def)
{
version_list *vp;
int count = 0;
@@ -79,11 +81,8 @@ write_sample_clnt(def)
return (count);
}
-
-static
-write_sample_client(program_name, vp)
- char *program_name;
- version_list *vp;
+static void
+write_sample_client(char *program_name, version_list *vp)
{
proc_list *proc;
int i;
@@ -164,23 +163,21 @@ write_sample_client(program_name, vp)
f_print(fout, "&");
pvname(proc->proc_name, vp->vers_num);
if (mtflag) {
- if (streq(proc->res_type, "oneway")) {
+ if (streq(proc->res_type, "oneway"))
f_print(fout, "_arg, clnt);\n");
- } else {
+ else
f_print(fout,
"_arg, &result_%d, clnt);\n", i);
- }
} else
f_print(fout, "_arg, clnt);\n");
} else if (streq(proc->args.decls->decl.type, "void")) {
if (mtflag) {
- if (streq(proc->res_type, "oneway")) {
+ if (streq(proc->res_type, "oneway"))
f_print(fout, "(clnt);\n");
- } else {
+ else
f_print(fout,
"(&result_%d, clnt);\n", i);
- }
} else
f_print(fout, "(clnt);\n");
} else {
@@ -190,16 +187,14 @@ write_sample_client(program_name, vp)
f_print(fout, "_%s, ", l->decl.name);
}
if (mtflag) {
- if (!streq(proc->res_type, "oneway")) {
+ if (!streq(proc->res_type, "oneway"))
f_print(fout, "&result_%d, ", i);
- }
}
f_print(fout, "clnt);\n");
}
if (mtflag) {
f_print(fout, "\tif (retval_%d != RPC_SUCCESS) {\n", i);
-
} else {
f_print(fout, "\tif (result_%d == (", i);
ptype(proc->res_prefix, proc->res_type, 1);
@@ -215,9 +210,8 @@ write_sample_client(program_name, vp)
f_print(fout, "}\n");
}
-static
-write_sample_server(def)
- definition *def;
+static void
+write_sample_server(definition *def)
{
version_list *vp;
proc_list *proc;
@@ -247,8 +241,7 @@ write_sample_server(def)
else
f_print(fout, "char *");
/* cannot have void type */
- f_print(fout, " result;\n",
- proc->res_type);
+ f_print(fout, " result;\n");
}
f_print(fout, "\n\t/*\n\t * insert server code "
@@ -288,16 +281,14 @@ write_sample_server(def)
}
}
-
-
-static
-return_type(plist)
- proc_list *plist;
+static void
+return_type(proc_list *plist)
{
ptype(plist->res_prefix, plist->res_type, 1);
}
-add_sample_msg()
+void
+add_sample_msg(void)
{
f_print(fout, "/*\n");
f_print(fout, " * This is sample code generated by rpcgen.\n");
@@ -307,7 +298,7 @@ add_sample_msg()
}
void
-write_sample_clnt_main()
+write_sample_clnt_main(void)
{
list *l;
definition *def;
@@ -315,9 +306,9 @@ write_sample_clnt_main()
f_print(fout, "\n\n");
if (Cflag)
- f_print(fout, "main(int argc, char *argv[])\n{\n");
+ f_print(fout, "int\nmain(int argc, char *argv[])\n{\n");
else
- f_print(fout, "main(argc, argv)\n\tint argc;\n"
+ f_print(fout, "int\nmain(argc, argv)\n\tint argc;\n"
"\tchar *argv[];\n{\n");
f_print(fout, "\tchar *host;");
@@ -329,9 +320,8 @@ write_sample_clnt_main()
for (l = defined; l != NULL; l = l->next) {
def = l->val;
- if (def->def_kind != DEF_PROGRAM) {
+ if (def->def_kind != DEF_PROGRAM)
continue;
- }
for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
f_print(fout, "\t");
pvname(def->def_name, vp->vers_num);
diff --git a/usr/src/cmd/rpcgen/rpc_scan.c b/usr/src/cmd/rpcgen/rpc_scan.c
index 88b68f978c..bba380eff8 100644
--- a/usr/src/cmd/rpcgen/rpc_scan.c
+++ b/usr/src/cmd/rpcgen/rpc_scan.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -37,75 +39,73 @@
#pragma ident "%Z%%M% %I% %E% SMI"
/*
- * rpc_scan.c, Scanner for the RPC protocol compiler
+ * rpc_scan.c, Scanner for the RPC protocol compiler
*/
#include <sys/wait.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <strings.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
-#define startcomment(where) (where[0] == '/' && where[1] == '*')
-#define endcomment(where) (where[-1] == '*' && where[0] == '/')
+#define startcomment(where) (where[0] == '/' && where[1] == '*')
+#define endcomment(where) (where[-1] == '*' && where[0] == '/')
static int pushed = 0; /* is a token pushed */
static token lasttok; /* last token, if pushed */
+static void unget_token(token *);
+static void findstrconst(char **, char **);
+static void findchrconst(char **, char **);
+static void findconst(char **, char **);
+static void findkind(char **, token *);
+static int cppline(char *);
+static int directive(char *);
+static void printdirective(char *);
+static void docppline(char *, int *, char **);
+
/*
- * scan expecting 1 given token
+ * scan expecting 1 given token
*/
void
-scan(expect, tokp)
- tok_kind expect;
- token *tokp;
+scan(tok_kind expect, token *tokp)
{
get_token(tokp);
- if (tokp->kind != expect) {
+ if (tokp->kind != expect)
expected1(expect);
- }
}
/*
- * scan expecting any of the 2 given tokens
+ * scan expecting any of the 2 given tokens
*/
void
-scan2(expect1, expect2, tokp)
- tok_kind expect1;
- tok_kind expect2;
- token *tokp;
+scan2(tok_kind expect1, tok_kind expect2, token *tokp)
{
get_token(tokp);
- if (tokp->kind != expect1 && tokp->kind != expect2) {
+ if (tokp->kind != expect1 && tokp->kind != expect2)
expected2(expect1, expect2);
- }
}
/*
- * scan expecting any of the 3 given token
+ * scan expecting any of the 3 given token
*/
void
-scan3(expect1, expect2, expect3, tokp)
- tok_kind expect1;
- tok_kind expect2;
- tok_kind expect3;
- token *tokp;
+scan3(tok_kind expect1, tok_kind expect2, tok_kind expect3, token *tokp)
{
get_token(tokp);
- if (tokp->kind != expect1 && tokp->kind != expect2
- && tokp->kind != expect3) {
+ if (tokp->kind != expect1 && tokp->kind != expect2 &&
+ tokp->kind != expect3)
expected3(expect1, expect2, expect3);
- }
}
/*
- * scan expecting a constant, possibly symbolic
+ * scan expecting a constant, possibly symbolic
*/
void
-scan_num(tokp)
- token *tokp;
+scan_num(token *tokp)
{
get_token(tokp);
switch (tokp->kind) {
@@ -117,23 +117,20 @@ scan_num(tokp)
}
/*
- * Peek at the next token
+ * Peek at the next token
*/
void
-peek(tokp)
- token *tokp;
+peek(token *tokp)
{
get_token(tokp);
unget_token(tokp);
}
/*
- * Peek at the next token and scan it if it matches what you expect
+ * Peek at the next token and scan it if it matches what you expect
*/
int
-peekscan(expect, tokp)
- tok_kind expect;
- token *tokp;
+peekscan(tok_kind expect, token *tokp)
{
peek(tokp);
if (tokp->kind == expect) {
@@ -144,16 +141,14 @@ peekscan(expect, tokp)
}
/*
- * Get the next token, printing out any directive that are encountered.
+ * Get the next token, printing out any directive that are encountered.
*/
void
-get_token(tokp)
- token *tokp;
+get_token(token *tokp)
{
int commenting;
int stat = 0;
-
-
+
if (pushed) {
pushed = 0;
*tokp = lasttok;
@@ -165,8 +160,12 @@ get_token(tokp)
for (;;) {
if (!fgets(curline, MAXLINESIZE, fin)) {
tokp->kind = TOK_EOF;
- /* now check if cpp returned non NULL value */
- waitpid(childpid, &stat, WUNTRACED);
+ /*
+ * now check if cpp returned
+ * non NULL value
+ */
+ (void) waitpid(childpid, &stat,
+ WUNTRACED);
if (stat > 0) {
/* Set return value from rpcgen */
nonfatalerrors = stat >> 8;
@@ -178,8 +177,8 @@ get_token(tokp)
if (commenting) {
break;
} else if (cppline(curline)) {
- docppline(curline, &linenum,
- &infilename);
+ docppline(curline, &linenum,
+ &infilename);
} else if (directive(curline)) {
printdirective(curline);
} else {
@@ -208,7 +207,7 @@ get_token(tokp)
}
/*
- * 'where' is not whitespace, comment or directive Must be a token!
+ * 'where' is not whitespace, comment or directive Must be a token!
*/
switch (*where) {
case ':':
@@ -292,13 +291,18 @@ get_token(tokp)
if (!(isalpha(*where) || *where == '_')) {
char buf[100];
char *p;
+ size_t blen;
- s_print(buf, "illegal character in file: ");
- p = buf + strlen(buf);
+ (void) snprintf(buf, sizeof (buf),
+ "illegal character in file: ");
+ blen = strlen(buf);
+ p = buf + blen;
if (isprint(*where)) {
- s_print(p, "%c", *where);
+ (void) snprintf(p, sizeof (buf) - blen,
+ "%c", *where);
} else {
- s_print(p, "%d", *where);
+ (void) snprintf(p, sizeof (buf) - blen,
+ "%d", *where);
}
error(buf);
}
@@ -307,67 +311,58 @@ get_token(tokp)
}
}
-static
-unget_token(tokp)
- token *tokp;
+static void
+unget_token(token *tokp)
{
lasttok = *tokp;
pushed = 1;
}
-static
-findstrconst(str, val)
- char **str;
- char **val;
+static void
+findstrconst(char **str, char **val)
{
char *p;
int size;
p = *str;
do {
- *p++;
+ p++;
} while (*p && *p != '"');
if (*p == 0) {
error("unterminated string constant");
}
p++;
size = p - *str;
- *val = alloc(size + 1);
+ *val = malloc(size + 1);
(void) strncpy(*val, *str, size);
(*val)[size] = 0;
*str = p;
}
-static
-findchrconst(str, val)
- char **str;
- char **val;
+static void
+findchrconst(char **str, char **val)
{
char *p;
int size;
p = *str;
do {
- *p++;
+ p++;
} while (*p && *p != '\'');
- if (*p == 0) {
+ if (*p == 0)
error("unterminated string constant");
- }
p++;
size = p - *str;
- if (size != 3) {
+ if (size != 3)
error("empty char string");
- }
- *val = alloc(size + 1);
+ *val = malloc(size + 1);
(void) strncpy(*val, *str, size);
(*val)[size] = 0;
*str = p;
}
-static
-findconst(str, val)
- char **str;
- char **val;
+static void
+findconst(char **str, char **val)
{
char *p;
int size;
@@ -384,44 +379,42 @@ findconst(str, val)
} while (isdigit(*p));
}
size = p - *str;
- *val = alloc(size + 1);
+ *val = malloc(size + 1);
(void) strncpy(*val, *str, size);
(*val)[size] = 0;
*str = p;
}
static token symbols[] = {
- {TOK_CONST, "const"},
- {TOK_UNION, "union"},
- {TOK_SWITCH, "switch"},
- {TOK_CASE, "case"},
- {TOK_DEFAULT, "default"},
- {TOK_STRUCT, "struct"},
- {TOK_TYPEDEF, "typedef"},
- {TOK_ENUM, "enum"},
- {TOK_OPAQUE, "opaque"},
- {TOK_BOOL, "bool"},
- {TOK_VOID, "void"},
- {TOK_ONEWAY, "oneway"},
- {TOK_CHAR, "char"},
- {TOK_INT, "int"},
- {TOK_UNSIGNED, "unsigned"},
- {TOK_SHORT, "short"},
- {TOK_LONG, "long"},
- {TOK_HYPER, "hyper"},
- {TOK_FLOAT, "float"},
- {TOK_DOUBLE, "double"},
- {TOK_QUAD, "quadruple"},
- {TOK_STRING, "string"},
- {TOK_PROGRAM, "program"},
- {TOK_VERSION, "version"},
- {TOK_EOF, "??????"},
+ {TOK_CONST, "const"},
+ {TOK_UNION, "union"},
+ {TOK_SWITCH, "switch"},
+ {TOK_CASE, "case"},
+ {TOK_DEFAULT, "default"},
+ {TOK_STRUCT, "struct"},
+ {TOK_TYPEDEF, "typedef"},
+ {TOK_ENUM, "enum"},
+ {TOK_OPAQUE, "opaque"},
+ {TOK_BOOL, "bool"},
+ {TOK_VOID, "void"},
+ {TOK_ONEWAY, "oneway"},
+ {TOK_CHAR, "char"},
+ {TOK_INT, "int"},
+ {TOK_UNSIGNED, "unsigned"},
+ {TOK_SHORT, "short"},
+ {TOK_LONG, "long"},
+ {TOK_HYPER, "hyper"},
+ {TOK_FLOAT, "float"},
+ {TOK_DOUBLE, "double"},
+ {TOK_QUAD, "quadruple"},
+ {TOK_STRING, "string"},
+ {TOK_PROGRAM, "program"},
+ {TOK_VERSION, "version"},
+ {TOK_EOF, "??????"},
};
-static
-findkind(mark, tokp)
- char **mark;
- token *tokp;
+static void
+findkind(char **mark, token *tokp)
{
int len;
token *s;
@@ -441,70 +434,57 @@ findkind(mark, tokp)
}
tokp->kind = TOK_IDENT;
for (len = 0; isalnum(str[len]) || str[len] == '_'; len++);
- tokp->str = alloc(len + 1);
+ tokp->str = malloc(len + 1);
(void) strncpy(tokp->str, str, len);
tokp->str[len] = 0;
*mark = str + len;
}
-static
-cppline(line)
- char *line;
+static int
+cppline(char *line)
{
return (line == curline && *line == '#');
}
-static
-directive(line)
- char *line;
+static int
+directive(char *line)
{
return (line == curline && *line == '%');
}
-static
-printdirective(line)
- char *line;
+static void
+printdirective(char *line)
{
f_print(fout, "%s", line + 1);
}
-static
-docppline(line, lineno, fname)
- char *line;
- int *lineno;
- char **fname;
+static void
+docppline(char *line, int *lineno, char **fname)
{
char *file;
int num;
char *p;
line++;
- while (isspace(*line)) {
+ while (isspace(*line))
line++;
- }
num = atoi(line);
- while (isdigit(*line)) {
+ while (isdigit(*line))
line++;
- }
- while (isspace(*line)) {
+ while (isspace(*line))
line++;
- }
- if (*line != '"') {
+ if (*line != '"')
error("preprocessor error");
- }
line++;
- p = file = alloc(strlen(line) + 1);
- while (*line && *line != '"') {
+ p = file = malloc(strlen(line) + 1);
+ while (*line && *line != '"')
*p++ = *line++;
- }
- if (*line == 0) {
+ if (*line == 0)
error("preprocessor error");
- }
*p = 0;
- if (*file == 0) {
+ if (*file == 0)
*fname = NULL;
- } else {
+ else
*fname = file;
- }
*lineno = num - 1;
}
diff --git a/usr/src/cmd/rpcgen/rpc_scan.h b/usr/src/cmd/rpcgen/rpc_scan.h
index 2a712dd755..84630b2b26 100644
--- a/usr/src/cmd/rpcgen/rpc_scan.h
+++ b/usr/src/cmd/rpcgen/rpc_scan.h
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -34,12 +36,19 @@
* contributors.
*/
+#ifndef _RPC_SCAN_H
+#define _RPC_SCAN_H
+
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* rpc_scan.h, Definitions for the RPCL scanner
*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* kinds of tokens
*/
@@ -89,7 +98,7 @@ enum tok_kind {
typedef enum tok_kind tok_kind;
/*
- * a token
+ * a token
*/
struct token {
tok_kind kind;
@@ -97,14 +106,19 @@ struct token {
};
typedef struct token token;
-
/*
- * routine interface
+ * routine interface
*/
-void scan();
-void scan2();
-void scan3();
-void scan_num();
-void peek();
-int peekscan();
-void get_token();
+extern void scan(tok_kind, token *);
+extern void scan2(tok_kind, tok_kind, token *);
+extern void scan3(tok_kind, tok_kind, tok_kind, token *);
+extern void scan_num(token *);
+extern void peek(token *);
+extern int peekscan(tok_kind, token *);
+extern void get_token(token *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RPC_SCAN_H */
diff --git a/usr/src/cmd/rpcgen/rpc_svcout.c b/usr/src/cmd/rpcgen/rpc_svcout.c
index 26dd9a6793..490a8f25c5 100644
--- a/usr/src/cmd/rpcgen/rpc_svcout.c
+++ b/usr/src/cmd/rpcgen/rpc_svcout.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -44,34 +46,48 @@
#include "rpc_parse.h"
#include "rpc_util.h"
+extern int nullproc(proc_list *);
+
static char RQSTP[] = "rqstp";
static char TRANSP[] = "transp";
static char ARG[] = "argument";
static char RESULT[] = "result";
static char ROUTINE[] = "local";
-static char ONEWAY_ROUTINE[] = "oneway_local";
static char RETVAL[] = "retval";
-char _errbuf[256]; /* For all messages */
-
-void internal_proctype();
+#define ERRBUFLEN 256
+char _errbuf[ERRBUFLEN]; /* For all messages */
+
+static void internal_proctype(proc_list *);
+static void write_real_program(definition *);
+static void write_programs(char *);
+static void write_program(definition *, char *);
+static void printerr(char *, char *);
+static void write_svc_aux(int);
+static void printif(char *, char *, char *, char *);
+static void write_inetmost(char *);
+static void print_return(char *);
+static void print_pmapunset(char *);
+static void print_err_message(char *);
+static void write_msg_out(void);
+static void write_timeout_func(void);
+static void write_pm_most(char *, int);
+static void write_rpc_svc_fg(char *, char *);
+static void open_log_file(char *, char *);
-static
-p_xdrfunc(rname, typename)
-char *rname;
-char *typename;
+static void
+p_xdrfunc(char *rname, char *typename)
{
if (Cflag)
- f_print(fout, "\t\t_xdr_%s = (xdrproc_t) xdr_%s;\n",
+ f_print(fout, "\t\t_xdr_%s = (xdrproc_t)xdr_%s;\n",
rname, stringfix(typename));
else
f_print(fout, "\t\t_xdr_%s = xdr_%s;\n",
rname, stringfix(typename));
}
-void
-internal_proctype(plist)
- proc_list *plist;
+static void
+internal_proctype(proc_list *plist)
{
f_print(fout, "static ");
ptype(plist->res_prefix, plist->res_type, 1);
@@ -80,7 +96,7 @@ internal_proctype(plist)
static void
-write_mtauto()
+write_mtauto(void)
{
f_print(fout, "\tif (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) {\n");
f_print(fout, "\t\t_msgout(\"%s\");\n",
@@ -92,10 +108,7 @@ write_mtauto()
* write most of the service, that is, everything but the registrations.
*/
void
-write_most(infile, netflag, nomain)
- char *infile; /* our name */
- int netflag;
- int nomain;
+write_most(char *infile, int netflag, int nomain)
{
if (inetdflag || pmflag) {
char *var_type;
@@ -131,12 +144,12 @@ write_most(infile, netflag, nomain)
write_svc_aux(nomain);
}
/* write out dispatcher and stubs */
- write_programs(nomain? (char *)NULL : "static");
+ write_programs(nomain ? NULL : "static");
if (nomain)
return;
- f_print(fout, "\nmain()\n");
+ f_print(fout, "\nint\nmain()\n");
f_print(fout, "{\n");
if (inetdflag) {
write_inetmost(infile);
@@ -182,8 +195,7 @@ write_most(infile, netflag, nomain)
* write a registration for the given transport
*/
void
-write_netid_register(transp)
- char *transp;
+write_netid_register(char *transp)
{
list *l;
definition *def;
@@ -195,15 +207,16 @@ write_netid_register(transp)
f_print(fout, "\n");
f_print(fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp);
f_print(fout, "%s\tif (nconf == NULL) {\n", sp);
- (void) sprintf(_errbuf, "cannot find %s netid.", transp);
- sprintf(tmpbuf, "%s\t\t", sp);
+ (void) snprintf(_errbuf, ERRBUFLEN, "cannot find %s netid.", transp);
+ (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s\t\t", sp);
print_err_message(tmpbuf);
f_print(fout, "%s\t\texit(1);\n", sp);
f_print(fout, "%s\t}\n", sp);
f_print(fout, "%s\t%s = svc_tli_create(RPC_ANYFD, nconf, 0, 0, 0);\n",
- sp, TRANSP, transp);
+ sp, TRANSP);
f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
- (void) sprintf(_errbuf, "cannot create %s service.", transp);
+ (void) snprintf(_errbuf, ERRBUFLEN, "cannot create %s service.",
+ transp);
print_err_message(tmpbuf);
f_print(fout, "%s\t\texit(1);\n", sp);
f_print(fout, "%s\t}\n", sp);
@@ -222,7 +235,7 @@ write_netid_register(transp)
sp, TRANSP, def->def_name, vp->vers_name);
pvname(def->def_name, vp->vers_num);
f_print(fout, ", nconf)) {\n");
- (void) sprintf(_errbuf,
+ (void) snprintf(_errbuf, ERRBUFLEN,
"unable to register (%s, %s, %s).",
def->def_name, vp->vers_name, transp);
print_err_message(tmpbuf);
@@ -237,8 +250,7 @@ write_netid_register(transp)
* write a registration for the given transport for TLI
*/
void
-write_nettype_register(transp)
- char *transp;
+write_nettype_register(char *transp)
{
list *l;
definition *def;
@@ -254,7 +266,7 @@ write_nettype_register(transp)
pvname(def->def_name, vp->vers_num);
f_print(fout, ", %s, %s, \"%s\")) {\n",
def->def_name, vp->vers_name, transp);
- (void) sprintf(_errbuf,
+ (void) snprintf(_errbuf, ERRBUFLEN,
"unable to create (%s, %s) for %s.",
def->def_name, vp->vers_name, transp);
print_err_message("\t\t");
@@ -268,12 +280,13 @@ write_nettype_register(transp)
* write the rest of the service
*/
void
-write_rest()
+write_rest(void)
{
f_print(fout, "\n");
if (inetdflag) {
f_print(fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
- (void) sprintf(_errbuf, "could not create a handle");
+ (void) snprintf(_errbuf, ERRBUFLEN,
+ "could not create a handle");
print_err_message("\t\t");
f_print(fout, "\t\texit(1);\n");
f_print(fout, "\t}\n");
@@ -298,16 +311,15 @@ write_rest()
}
}
f_print(fout, "\tsvc_run();\n");
- (void) sprintf(_errbuf, "svc_run returned");
+ (void) snprintf(_errbuf, ERRBUFLEN, "svc_run returned");
print_err_message("\t");
f_print(fout, "\texit(1);\n");
f_print(fout, "\t/* NOTREACHED */\n");
f_print(fout, "}\n");
}
-void
-write_programs(storage)
- char *storage;
+static void
+write_programs(char *storage)
{
list *l;
definition *def;
@@ -315,17 +327,15 @@ write_programs(storage)
/* write out stubs for procedure definitions */
for (l = defined; l != NULL; l = l->next) {
def = (definition *) l->val;
- if (def->def_kind == DEF_PROGRAM) {
+ if (def->def_kind == DEF_PROGRAM)
write_real_program(def);
- }
}
/* write out dispatcher for each program */
for (l = defined; l != NULL; l = l->next) {
def = (definition *) l->val;
- if (def->def_kind == DEF_PROGRAM) {
+ if (def->def_kind == DEF_PROGRAM)
write_program(def, storage);
- }
}
@@ -337,9 +347,8 @@ write_programs(storage)
* Unpacks single user argument of printmsg_1 to call-by-value format
* expected by printmsg_1.
*/
-static
-write_real_program(def)
- definition *def;
+static void
+write_real_program(definition *def)
{
version_list *vp;
proc_list *proc;
@@ -362,6 +371,7 @@ write_real_program(def)
f_print(fout, "(");
/* arg name */
if (proc->arg_num > 1)
+ /* LINTED variable format */
f_print(fout, proc->args.argname);
else
ptype(proc->args.decls->decl.prefix,
@@ -424,10 +434,8 @@ write_real_program(def)
}
}
-static
-write_program(def, storage)
- definition *def;
- char *storage;
+static void
+write_program(definition *def, char *storage)
{
version_list *vp;
proc_list *proc;
@@ -540,8 +548,8 @@ write_program(def, storage)
f_print(fout, "\tcase NULLPROC:\n");
f_print(fout,
Cflag ?
-"\t\t(void) svc_sendreply(%s,\n\t\t\t(xdrproc_t) xdr_void, (char *)NULL);\n" :
-"\t\t(void) svc_sendreply(%s, xdr_void,\n\t\t\t(char *)NULL);\n",
+"\t\t(void) svc_sendreply(%s,\n\t\t\t(xdrproc_t)xdr_void, NULL);\n" :
+"\t\t(void) svc_sendreply(%s, xdr_void,\n\t\t\tNULL);\n",
TRANSP);
print_return("\t\t");
f_print(fout, "\n");
@@ -601,7 +609,7 @@ write_program(def, storage)
f_print(fout,
"\t(void) memset((char *)&%s, 0, sizeof (%s));\n",
ARG, ARG);
- printif("getargs", TRANSP, "(caddr_t) &", ARG);
+ printif("getargs", TRANSP, "(caddr_t)&", ARG);
printerr("decode", TRANSP);
print_return("\t\t");
f_print(fout, "\t}\n");
@@ -617,11 +625,11 @@ write_program(def, storage)
else
if (Cflag)
f_print(fout,
-"\t%s = (bool_t) (*%s)((char *)&%s, (void *)&%s, %s);\n",
+"\t%s = (bool_t)(*%s)((char *)&%s, (void *)&%s, %s);\n",
RETVAL, ROUTINE, ARG, RESULT, RQSTP);
else
f_print(fout,
-"\t%s = (bool_t) (*%s)(&%s, &%s, %s);\n",
+"\t%s = (bool_t)(*%s)(&%s, &%s, %s);\n",
RETVAL, ROUTINE, ARG, RESULT, RQSTP);
@@ -639,8 +647,8 @@ write_program(def, storage)
printerr("systemerr", TRANSP);
f_print(fout, "\t}\n");
- printif("freeargs", TRANSP, "(caddr_t) &", ARG);
- (void) sprintf(_errbuf, "unable to free arguments");
+ printif("freeargs", TRANSP, "(caddr_t)&", ARG);
+ (void) snprintf(_errbuf, ERRBUFLEN, "unable to free arguments");
print_err_message("\t\t");
f_print(fout, "\t\texit(1);\n");
f_print(fout, "\t}\n");
@@ -651,9 +659,10 @@ write_program(def, storage)
pvname(def->def_name, vp->vers_num);
f_print(fout,
-"_freeresult(%s, _xdr_%s, (caddr_t) &%s))\n",
+"_freeresult(%s, _xdr_%s, (caddr_t)&%s))\n",
TRANSP, RESULT, RESULT);
- (void) sprintf(_errbuf, "unable to free results");
+ (void) snprintf(_errbuf, ERRBUFLEN,
+ "unable to free results");
print_err_message("\t\t\t");
f_print(fout, "\n");
f_print(fout, "\t}\n");
@@ -663,39 +672,31 @@ write_program(def, storage)
}
}
-static
-printerr(err, transp)
- char *err;
- char *transp;
+static void
+printerr(char *err, char *transp)
{
f_print(fout, "\t\tsvcerr_%s(%s);\n", err, transp);
}
-static
-printif(proc, transp, prefix, arg)
- char *proc;
- char *transp;
- char *prefix;
- char *arg;
+static void
+printif(char *proc, char *transp, char *prefix, char *arg)
{
f_print(fout, "\tif (!svc_%s(%s, _xdr_%s, %s%s)) {\n",
proc, transp, arg, prefix, arg);
}
-nullproc(proc)
- proc_list *proc;
+int
+nullproc(proc_list *proc)
{
for (; proc != NULL; proc = proc->next) {
- if (streq(proc->proc_num, "0")) {
+ if (streq(proc->proc_num, "0"))
return (1);
- }
}
return (0);
}
-static
-write_inetmost(infile)
- char *infile;
+static void
+write_inetmost(char *infile)
{
f_print(fout, "\tregister SVCXPRT *%s;\n", TRANSP);
f_print(fout, "\tint sock;\n");
@@ -722,39 +723,35 @@ write_inetmost(infile)
f_print(fout, "\t}\n");
}
-static
-print_return(space)
- char *space;
+static void
+print_return(char *space)
{
- if (exitnow)
+ if (exitnow) {
f_print(fout, "%sexit(0);\n", space);
- else {
- if (timerflag) {
- if (mtflag)
- f_print(fout,
- "%smutex_lock(&_svcstate_lock);\n",
+ return;
+ }
+ if (timerflag) {
+ if (mtflag)
+ f_print(fout, "%smutex_lock(&_svcstate_lock);\n",
space);
- f_print(fout, "%s_rpcsvccount--;\n", space);
- f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space);
- if (mtflag)
- f_print(fout,
- "%smutex_unlock(&_svcstate_lock);\n",
+ f_print(fout, "%s_rpcsvccount--;\n", space);
+ f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space);
+ if (mtflag)
+ f_print(fout, "%smutex_unlock(&_svcstate_lock);\n",
space);
- }
- f_print(fout, "%sreturn;\n", space);
}
+ f_print(fout, "%sreturn;\n", space);
}
-static
-print_pmapunset(space)
- char *space;
+static void
+print_pmapunset(char *space)
{
list *l;
definition *def;
version_list *vp;
for (l = defined; l != NULL; l = l->next) {
- def = (definition *) l->val;
+ def = (definition *)l->val;
if (def->def_kind == DEF_PROGRAM) {
for (vp = def->def.pr.versions; vp != NULL;
vp = vp->next) {
@@ -765,9 +762,8 @@ print_pmapunset(space)
}
}
-static
-print_err_message(space)
- char *space;
+static void
+print_err_message(char *space)
{
if (logflag)
f_print(fout, "%ssyslog(LOG_ERR, \"%%s\", \"%s\");\n", space,
@@ -782,9 +778,8 @@ print_err_message(space)
/*
* Write the server auxiliary function (_msgout, timeout)
*/
-void
-write_svc_aux(nomain)
- int nomain;
+static void
+write_svc_aux(int nomain)
{
if (!logflag)
write_msg_out();
@@ -795,16 +790,16 @@ write_svc_aux(nomain)
/*
* Write the _msgout function
*/
-
-write_msg_out()
+static void
+write_msg_out(void)
{
f_print(fout, "\n");
- f_print(fout, "static\n");
+ f_print(fout, "static ");
if (!Cflag) {
- f_print(fout, "void _msgout(msg)\n");
+ f_print(fout, "void\n_msgout(msg)\n");
f_print(fout, "\tchar *msg;\n");
} else {
- f_print(fout, "void _msgout(char* msg)\n");
+ f_print(fout, "void\n_msgout(char *msg)\n");
}
f_print(fout, "{\n");
f_print(fout, "#ifdef RPC_SVC_FG\n");
@@ -823,8 +818,8 @@ write_msg_out()
/*
* Write the timeout function
*/
-static
-write_timeout_func()
+static void
+write_timeout_func(void)
{
if (!timerflag)
return;
@@ -923,10 +918,8 @@ write_timeout_func()
/*
* Write the most of port monitor support
*/
-static
-write_pm_most(infile, netflag)
- char *infile;
- int netflag;
+static void
+write_pm_most(char *infile, int netflag)
{
list *l;
definition *def;
@@ -961,10 +954,9 @@ write_pm_most(infile, netflag)
f_print(fout, "\t\t/* started from inetd */\n");
f_print(fout, "\t\t\tpmclose = 1;\n");
}
- f_print(fout,
- "\t\t} else {\n");
+ f_print(fout, "\t\t} else {\n");
f_print(fout, "\t\t\tif ((nconf = getnetconfigent(netid)) == NULL)\n");
- sprintf(_errbuf, "cannot get transport info");
+ (void) snprintf(_errbuf, ERRBUFLEN, "cannot get transport info");
print_err_message("\t\t\t\t");
if (timerflag)
f_print(fout,
@@ -973,7 +965,7 @@ write_pm_most(infile, netflag)
f_print(fout,
"\t\tif ((%s = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {\n",
TRANSP);
- sprintf(_errbuf, "cannot create server handle");
+ (void) snprintf(_errbuf, ERRBUFLEN, "cannot create server handle");
print_err_message("\t\t\t");
f_print(fout, "\t\t\texit(1);\n");
f_print(fout, "\t\t}\n");
@@ -990,7 +982,8 @@ write_pm_most(infile, netflag)
TRANSP, def->def_name, vp->vers_name);
pvname(def->def_name, vp->vers_num);
f_print(fout, ", 0)) {\n");
- (void) sprintf(_errbuf, "unable to register (%s, %s).",
+ (void) snprintf(_errbuf, ERRBUFLEN,
+ "unable to register (%s, %s).",
def->def_name, vp->vers_name);
print_err_message("\t\t\t");
f_print(fout, "\t\t\texit(1);\n");
@@ -1024,10 +1017,8 @@ write_pm_most(infile, netflag)
/*
* Support for backgrounding the server if self started.
*/
-static
-write_rpc_svc_fg(infile, sp)
- char *infile;
- char *sp;
+static void
+write_rpc_svc_fg(char *infile, char *sp)
{
f_print(fout, "#ifndef RPC_SVC_FG\n");
f_print(fout, "#pragma weak closefrom\n");
@@ -1083,10 +1074,8 @@ write_rpc_svc_fg(infile, sp)
open_log_file(infile, sp);
}
-static
-open_log_file(infile, sp)
- char *infile;
- char *sp;
+static void
+open_log_file(char *infile, char *sp)
{
char *s;
@@ -1098,15 +1087,11 @@ open_log_file(infile, sp)
*s = '.';
}
-
-
-
/*
* write a registration for the given transport for Inetd
*/
void
-write_inetd_register(transp)
- char *transp;
+write_inetd_register(char *transp)
{
list *l;
definition *def;
@@ -1135,8 +1120,9 @@ write_inetd_register(transp)
f_print(fout, ", 0, 0");
f_print(fout, ");\n");
f_print(fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
- (void) sprintf(_errbuf, "cannot create %s service.", transp);
- (void) sprintf(tmpbuf, "%s\t\t", sp);
+ (void) snprintf(_errbuf, ERRBUFLEN, "cannot create %s service.",
+ transp);
+ (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s\t\t", sp);
print_err_message(tmpbuf);
f_print(fout, "%s\t\texit(1);\n", sp);
f_print(fout, "%s\t}\n", sp);
@@ -1148,9 +1134,8 @@ write_inetd_register(transp)
}
for (l = defined; l != NULL; l = l->next) {
def = (definition *) l->val;
- if (def->def_kind != DEF_PROGRAM) {
+ if (def->def_kind != DEF_PROGRAM)
continue;
- }
for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
f_print(fout, "%s\tif (!svc_register(%s, %s, %s, ",
sp, TRANSP, def->def_name, vp->vers_name);
@@ -1160,7 +1145,7 @@ write_inetd_register(transp)
else
f_print(fout, ", IPPROTO_%s)) {\n",
isudp ? "UDP": "TCP");
- (void) sprintf(_errbuf,
+ (void) snprintf(_errbuf, ERRBUFLEN,
"unable to register (%s, %s, %s).",
def->def_name, vp->vers_name, transp);
print_err_message(tmpbuf);
diff --git a/usr/src/cmd/rpcgen/rpc_tblout.c b/usr/src/cmd/rpcgen/rpc_tblout.c
index b9ab843722..66c7ce8840 100644
--- a/usr/src/cmd/rpcgen/rpc_tblout.c
+++ b/usr/src/cmd/rpcgen/rpc_tblout.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -44,6 +46,11 @@
#include "rpc_parse.h"
#include "rpc_util.h"
+extern int nullproc(proc_list *);
+
+static void write_table(definition *);
+static void printit(char *, char *);
+
#define TABSIZE 8
#define TABCOUNT 5
#define TABSTOP (TABSIZE*TABCOUNT)
@@ -54,35 +61,34 @@ static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
static char tbl_end[] = "};\n";
static char null_entry_b[] = "\n\t(char *(*)())0,\n"
- " \t(xdrproc_t) xdr_void,\t\t\t0,\n"
- " \t(xdrproc_t) xdr_void,\t\t\t0,\n";
+ " \t(xdrproc_t)xdr_void,\t\t\t0,\n"
+ " \t(xdrproc_t)xdr_void,\t\t\t0,\n";
static char null_entry[] = "\n\t(void *(*)())0,\n"
- " \t(xdrproc_t) xdr_void,\t\t\t0,\n"
- " \t(xdrproc_t) xdr_void,\t\t\t0,\n";
+ " \t(xdrproc_t)xdr_void,\t\t\t0,\n"
+ " \t(xdrproc_t)xdr_void,\t\t\t0,\n";
static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)"
"/sizeof(%s_table[0]);\n\n";
void
-write_tables()
+write_tables(void)
{
list *l;
definition *def;
f_print(fout, "\n");
for (l = defined; l != NULL; l = l->next) {
- def = (definition *) l->val;
+ def = (definition *)l->val;
if (def->def_kind == DEF_PROGRAM) {
write_table(def);
}
}
}
-static
-write_table(def)
- definition *def;
+static void
+write_table(definition *def)
{
version_list *vp;
proc_list *proc;
@@ -93,7 +99,7 @@ write_table(def)
for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
warning = 0;
- s_print(progvers, "%s_%s",
+ (void) snprintf(progvers, sizeof (progvers), "%s_%s",
locase(def->def_name), vp->vers_num);
/* print the table header */
f_print(fout, tbl_hdr, progvers);
@@ -140,7 +146,7 @@ write_table(def)
/* argument info */
if (proc->arg_num > 1)
- printit((char *) NULL, proc->args.argname);
+ printit(NULL, proc->args.argname);
else
/* do we have to do something special for newstyle */
printit(proc->args.decls->decl.prefix,
@@ -155,20 +161,17 @@ write_table(def)
}
}
-static
-printit(prefix, type)
- char *prefix;
- char *type;
+static void
+printit(char *prefix, char *type)
{
int len;
int tabs;
- if (streq(type, "oneway")) {
- len = fprintf(fout, "\t(xdrproc_t) xdr_void,");
- } else {
- len = fprintf(fout, "\t(xdrproc_t) xdr_%s,", stringfix(type));
- }
+ if (streq(type, "oneway"))
+ len = fprintf(fout, "\t(xdrproc_t)xdr_void,");
+ else
+ len = fprintf(fout, "\t(xdrproc_t)xdr_%s,", stringfix(type));
/* account for leading tab expansion */
len += TABSIZE - 1;
if (len >= TABSTOP) {
diff --git a/usr/src/cmd/rpcgen/rpc_util.c b/usr/src/cmd/rpcgen/rpc_util.c
index 8e37e89dc0..0b4f368909 100644
--- a/usr/src/cmd/rpcgen/rpc_util.c
+++ b/usr/src/cmd/rpcgen/rpc_util.c
@@ -18,8 +18,10 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
- *
- * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -40,11 +42,18 @@
* rpc_util.c, Utility routines for the RPC protocol compiler
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <ctype.h>
+#include <string.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
+extern void crash(void);
+
+static void printwhere(void);
+
#define ARGEXT "argument"
char curline[MAXLINESIZE]; /* current read line */
@@ -65,9 +74,10 @@ list *defined; /* list of defined things */
/*
* Reinitialize the world
*/
-reinitialize()
+void
+reinitialize(void)
{
- memset(curline, 0, MAXLINESIZE);
+ (void) memset(curline, 0, MAXLINESIZE);
where = curline;
linenum = 0;
defined = NULL;
@@ -76,9 +86,8 @@ reinitialize()
/*
* string equality
*/
-streq(a, b)
- char *a;
- char *b;
+int
+streq(char *a, char *b)
{
return (strcmp(a, b) == 0);
}
@@ -87,16 +96,11 @@ streq(a, b)
* find a value in a list
*/
definition *
-findval(lst, val, cmp)
- list *lst;
- char *val;
- int (*cmp) ();
-
+findval(list *lst, char *val, int (*cmp)())
{
for (; lst != NULL; lst = lst->next) {
- if ((*cmp) (lst->val, val)) {
+ if ((*cmp) (lst->val, val))
return (lst->val);
- }
}
return (NULL);
}
@@ -105,45 +109,37 @@ findval(lst, val, cmp)
* store a value in a list
*/
void
-storeval(lstp, val)
- list **lstp;
- definition *val;
+storeval(list **lstp, definition *val)
{
list **l;
list *lst;
- for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
- lst = ALLOC(list);
+ for (l = lstp; *l != NULL; l = (list **)&(*l)->next);
+ lst = calloc(1, sizeof (list));
lst->val = val;
lst->next = NULL;
*l = lst;
}
-static
-findit(def, type)
- definition *def;
- char *type;
+static int
+findit(definition *def, char *type)
{
return (streq(def->def_name, type));
}
static char *
-fixit(type, orig)
- char *type;
- char *orig;
+fixit(char *type, char *orig)
{
definition *def;
- def = (definition *) FINDVAL(defined, type, findit);
- if (def == NULL || def->def_kind != DEF_TYPEDEF) {
+ def = (definition *)FINDVAL(defined, type, findit);
+ if (def == NULL || def->def_kind != DEF_TYPEDEF)
return (orig);
- }
switch (def->def.ty.rel) {
case REL_VECTOR:
if (streq(def->def.ty.old_type, "opaque"))
return ("char");
- else
- return (def->def.ty.old_type);
+ return (def->def.ty.old_type);
case REL_ALIAS:
return (fixit(def->def.ty.old_type, orig));
@@ -153,28 +149,21 @@ fixit(type, orig)
}
char *
-fixtype(type)
- char *type;
+fixtype(char *type)
{
return (fixit(type, type));
}
char *
-stringfix(type)
- char *type;
+stringfix(char *type)
{
- if (streq(type, "string")) {
+ if (streq(type, "string"))
return ("wrapstring");
- } else {
- return (type);
- }
+ return (type);
}
void
-ptype(prefix, type, follow)
- char *prefix;
- char *type;
- int follow;
+ptype(char *prefix, char *type, int follow)
{
if (prefix != NULL) {
if (streq(prefix, "enum")) {
@@ -194,21 +183,16 @@ ptype(prefix, type, follow)
}
}
-static
-typedefed(def, type)
- definition *def;
- char *type;
+static int
+typedefed(definition *def, char *type)
{
- if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
+ if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL)
return (0);
- } else {
- return (streq(def->def_name, type));
- }
+ return (streq(def->def_name, type));
}
-isvectordef(type, rel)
- char *type;
- relation rel;
+int
+isvectordef(char *type, relation rel)
{
definition *def;
@@ -221,7 +205,7 @@ isvectordef(type, rel)
case REL_POINTER:
return (0);
case REL_ALIAS:
- def = (definition *) FINDVAL(defined, type, typedefed);
+ def = (definition *)FINDVAL(defined, type, typedefed);
if (def == NULL)
return (0);
type = def->def.ty.old_type;
@@ -231,32 +215,26 @@ isvectordef(type, rel)
}
char *
-locase(str)
- char *str;
+locase(char *str)
{
char c;
static char buf[100];
char *p = buf;
- while (c = *str++) {
+ while (c = *str++)
*p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
- }
*p = 0;
return (buf);
}
void
-pvname_svc(pname, vnum)
- char *pname;
- char *vnum;
+pvname_svc(char *pname, char *vnum)
{
f_print(fout, "%s_%s_svc", locase(pname), vnum);
}
void
-pvname(pname, vnum)
- char *pname;
- char *vnum;
+pvname(char *pname, char *vnum)
{
f_print(fout, "%s_%s", locase(pname), vnum);
}
@@ -265,8 +243,7 @@ pvname(pname, vnum)
* print a useful (?) error message, and then die
*/
void
-error(msg)
- char *msg;
+error(char *msg)
{
printwhere();
f_print(stderr, "%s, line %d: ", infilename, linenum);
@@ -278,26 +255,25 @@ error(msg)
* Something went wrong, unlink any files that we may have created and then
* die.
*/
-crash()
+void
+crash(void)
{
int i;
- for (i = 0; i < nfiles; i++) {
+ for (i = 0; i < nfiles; i++)
(void) unlink(outfiles[i]);
- }
exit(1);
}
void
-record_open(file)
- char *file;
+record_open(char *file)
{
if (nfiles < NFILES) {
outfiles[nfiles++] = file;
- } else {
- f_print(stderr, "too many files!\n");
- crash();
+ return;
}
+ f_print(stderr, "too many files!\n");
+ crash();
}
static char expectbuf[100];
@@ -307,11 +283,10 @@ static char *toktostr();
* error, token encountered was not the expected one
*/
void
-expected1(exp1)
- tok_kind exp1;
+expected1(tok_kind exp1)
{
- s_print(expectbuf, "expected '%s'",
- toktostr(exp1));
+ (void) snprintf(expectbuf,
+ sizeof (expectbuf), "expected '%s'", toktostr(exp1));
error(expectbuf);
}
@@ -319,11 +294,10 @@ expected1(exp1)
* error, token encountered was not one of two expected ones
*/
void
-expected2(exp1, exp2)
- tok_kind exp1, exp2;
+expected2(tok_kind exp1, tok_kind exp2)
{
- s_print(expectbuf, "expected '%s' or '%s'",
- toktostr(exp1),
+ (void) snprintf(expectbuf,
+ sizeof (expectbuf), "expected '%s' or '%s'", toktostr(exp1),
toktostr(exp2));
error(expectbuf);
}
@@ -332,27 +306,21 @@ expected2(exp1, exp2)
* error, token encountered was not one of 3 expected ones
*/
void
-expected3(exp1, exp2, exp3)
- tok_kind exp1, exp2, exp3;
+expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3)
{
- s_print(expectbuf, "expected '%s', '%s' or '%s'",
- toktostr(exp1),
- toktostr(exp2),
- toktostr(exp3));
+ (void) snprintf(expectbuf,
+ sizeof (expectbuf), "expected '%s', '%s' or '%s'",
+ toktostr(exp1), toktostr(exp2), toktostr(exp3));
error(expectbuf);
}
void
-tabify(f, tab)
- FILE *f;
- int tab;
+tabify(FILE *f, int tab)
{
- while (tab--) {
+ while (tab--)
(void) fputc('\t', f);
- }
}
-
static token tokstrings[] = {
{TOK_IDENT, "identifier"},
{TOK_CONST, "const"},
@@ -391,8 +359,7 @@ static token tokstrings[] = {
};
static char *
-toktostr(kind)
- tok_kind kind;
+toktostr(tok_kind kind)
{
token *sp;
@@ -400,30 +367,29 @@ toktostr(kind)
return (sp->str);
}
-static
-printbuf()
+static void
+printbuf(void)
{
char c;
int i;
int cnt;
-# define TABSIZE 4
+#define TABSIZE 4
- for (i = 0; c = curline[i]; i++) {
+ for (i = 0; (c = curline[i]) != '\0'; i++) {
if (c == '\t') {
cnt = 8 - (i % TABSIZE);
c = ' ';
} else {
cnt = 1;
}
- while (cnt--) {
+ while (cnt--)
(void) fputc(c, stderr);
- }
}
}
-static
-printwhere()
+static void
+printwhere(void)
{
int i;
char c;
@@ -437,73 +403,64 @@ printwhere()
} else {
cnt = 1;
}
- while (cnt--) {
+ while (cnt--)
(void) fputc('^', stderr);
- }
}
(void) fputc('\n', stderr);
}
char *
-make_argname(pname, vname)
- char *pname;
- char *vname;
+make_argname(char *pname, char *vname)
{
char *name;
+ size_t nlen;
- name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3);
- if (!name) {
- fprintf(stderr, "failed in malloc");
+ nlen = strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3;
+ name = malloc(nlen);
+ if (name == NULL) {
+ (void) fprintf(stderr, "failed in malloc");
exit(1);
}
- sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT);
+ (void) snprintf(name, nlen, "%s_%s_%s", locase(pname), vname, ARGEXT);
return (name);
}
bas_type *typ_list_h;
bas_type *typ_list_t;
-add_type(len, type)
-int len;
-char *type;
+void
+add_type(int len, char *type)
{
bas_type *ptr;
- if ((ptr = (bas_type *) malloc(sizeof (bas_type))) ==
- (bas_type *)NULL) {
- fprintf(stderr, "failed in malloc");
+ if ((ptr = malloc(sizeof (bas_type))) == NULL) {
+ (void) fprintf(stderr, "failed in malloc");
exit(1);
}
ptr->name = type;
ptr->length = len;
ptr->next = NULL;
- if (typ_list_t == NULL)
- {
-
+ if (typ_list_t == NULL) {
typ_list_t = ptr;
typ_list_h = ptr;
- }
- else
- {
+ } else {
typ_list_t->next = ptr;
typ_list_t = ptr;
- };
+ }
}
-bas_type *find_type(type)
-char *type;
+bas_type *
+find_type(char *type)
{
- bas_type * ptr;
+ bas_type *ptr;
ptr = typ_list_h;
- while (ptr != NULL)
- {
+ while (ptr != NULL) {
if (strcmp(ptr->name, type) == 0)
return (ptr);
- else
- ptr = ptr->next;
- };
+ ptr = ptr->next;
+ }
return (NULL);
}
diff --git a/usr/src/cmd/rpcgen/rpc_util.h b/usr/src/cmd/rpcgen/rpc_util.h
index 499701af84..b58e6ccf71 100644
--- a/usr/src/cmd/rpcgen/rpc_util.h
+++ b/usr/src/cmd/rpcgen/rpc_util.h
@@ -19,6 +19,7 @@
*
* CDDL HEADER END
*/
+
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -42,6 +43,7 @@
#include <sys/types.h>
#include <stdlib.h>
+#include "rpc_scan.h"
#ifdef __cplusplus
extern "C" {
@@ -56,10 +58,6 @@ extern "C" {
#define RPCGEN_MAJOR 1
#define RPCGEN_MINOR 1
-#define alloc(size) malloc((unsigned)(size))
-#define ALLOC(object) (object *) calloc(1, sizeof (object))
-
-#define s_print (void) sprintf
#define f_print (void) fprintf
struct list {
@@ -107,7 +105,6 @@ extern FILE *fin;
extern list *defined;
-
extern bas_type *typ_list_h;
extern bas_type *typ_list_t;
extern xdrfunc *xdrfunc_head, *xdrfunc_tail;
@@ -142,64 +139,62 @@ extern pid_t childpid;
/*
* rpc_util routines
*/
-void storeval();
+extern void storeval(list **, definition *);
#define STOREVAL(list, item) \
storeval(list, item)
-definition *findval();
+extern definition *findval(list *, char *, int (*)());
#define FINDVAL(list, item, finder) \
findval(list, item, finder)
-char *fixtype();
-char *stringfix();
-char *locase();
-void pvname_svc();
-void pvname();
-void ptype();
-int isvectordef();
-int streq();
-void error();
-void expected1();
-void expected2();
-void expected3();
-void tabify();
-void record_open();
-bas_type *find_type();
+extern char *fixtype(char *);
+extern char *stringfix(char *);
+extern char *locase(char *);
+extern void pvname_svc(char *, char *);
+extern void pvname(char *, char *);
+extern void ptype(char *, char *, int);
+extern int isvectordef(char *, relation);
+extern int streq(char *, char *);
+extern void error(char *);
+extern void expected1(tok_kind);
+extern void expected2(tok_kind, tok_kind);
+extern void expected3(tok_kind, tok_kind, tok_kind);
+extern void tabify(FILE *, int);
+extern void record_open(char *);
+extern bas_type *find_type(char *);
+
/*
* rpc_cout routines
*/
-void cprint();
-void emit();
+extern void emit(definition *);
/*
* rpc_hout routines
*/
-void print_datadef();
-void print_funcdef();
-void print_xdr_func_def();
+extern void print_datadef(definition *);
+extern void print_funcdef(definition *);
+extern void print_xdr_func_def(char *, int, int);
/*
* rpc_svcout routines
*/
-void write_most();
-void write_register();
-void write_rest();
-void write_programs();
-void write_svc_aux();
-void write_inetd_register();
-void write_netid_register();
-void write_nettype_register();
+extern void write_most(char *, int, int);
+extern void write_rest(void);
+extern void write_inetd_register(char *);
+extern void write_netid_register(char *);
+extern void write_nettype_register(char *);
+
/*
* rpc_clntout routines
*/
-void write_stubs();
+extern void write_stubs(void);
/*
* rpc_tblout routines
*/
-void write_tables();
+extern void write_tables(void);
#ifdef __cplusplus
}