diff options
Diffstat (limited to 'sunrpc')
-rw-r--r-- | sunrpc/Makefile | 2 | ||||
-rw-r--r-- | sunrpc/proto.h | 7 | ||||
-rw-r--r-- | sunrpc/rpc_clntout.c | 223 | ||||
-rw-r--r-- | sunrpc/rpc_cout.c | 1185 | ||||
-rw-r--r-- | sunrpc/rpc_hout.c | 859 | ||||
-rw-r--r-- | sunrpc/rpc_main.c | 1861 | ||||
-rw-r--r-- | sunrpc/rpc_parse.c | 965 | ||||
-rw-r--r-- | sunrpc/rpc_sample.c | 170 | ||||
-rw-r--r-- | sunrpc/rpc_scan.c | 18 | ||||
-rw-r--r-- | sunrpc/rpc_svcout.c | 303 | ||||
-rw-r--r-- | sunrpc/rpc_util.c | 13 | ||||
-rw-r--r-- | sunrpc/rpc_util.h | 31 |
12 files changed, 3231 insertions, 2406 deletions
diff --git a/sunrpc/Makefile b/sunrpc/Makefile index efc826530f..345a23a3dd 100644 --- a/sunrpc/Makefile +++ b/sunrpc/Makefile @@ -118,7 +118,7 @@ $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs)) \ # Tell rpcgen that it should unset LD_LIBRARY_PATH before executing the # preprocessor. -rpcgen-cmd = $(built-program-cmd) -$$ +rpcgen-cmd = $(built-program-cmd) # The proper file name is longer than 14 chars, so we install it under # a shorter name. But if the filesystem can handle it, we want to diff --git a/sunrpc/proto.h b/sunrpc/proto.h index 6d2747f728..30ef18856b 100644 --- a/sunrpc/proto.h +++ b/sunrpc/proto.h @@ -1,14 +1,12 @@ /****** rpc_clntout.c ******/ void write_stubs(void); -void printarglist(proc_list *proc, +void printarglist(proc_list *proc, const char *result, const char *addargname, const char *addargtype); /****** rpc_cout.c ******/ -void emit(definition *def); -void emit_inline(declaration *decl, int flag); -void emit_single_in_line(declaration *decl, int flag, relation rel); +void emit (definition *def); /****** rpc_hout.c ******/ @@ -19,6 +17,7 @@ void pprocdef(proc_list *proc, version_list *vp, const char *addargtype, int server_p, int mode); void pdeclaration(const char *name, declaration *dec, int tab, const char *separator); +void print_xdr_func_def (char* name, int pointerp, int i); /****** rpc_main.c ******/ /* nil */ diff --git a/sunrpc/rpc_clntout.c b/sunrpc/rpc_clntout.c index fb086047ba..0b4f645c07 100644 --- a/sunrpc/rpc_clntout.c +++ b/sunrpc/rpc_clntout.c @@ -60,9 +60,9 @@ write_stubs (void) list *l; definition *def; - f_print (fout, + fprintf (fout, "\n/* Default timeout can be changed using clnt_control() */\n"); - f_print (fout, "static struct timeval TIMEOUT = { %d, 0 };\n", + fprintf (fout, "static struct timeval TIMEOUT = { %d, 0 };\n", DEFAULT_TIMEOUT); for (l = defined; l != NULL; l = l->next) { @@ -84,14 +84,23 @@ write_program (definition * def) { for (proc = vp->procs; proc != NULL; proc = proc->next) { - f_print (fout, "\n"); - ptype (proc->res_prefix, proc->res_type, 1); - f_print (fout, "*\n"); - pvname (proc->proc_name, vp->vers_num); - printarglist (proc, "clnt", "CLIENT *"); - f_print (fout, "{\n"); + fprintf (fout, "\n"); + if (mtflag == 0) + { + ptype (proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*\n"); + pvname (proc->proc_name, vp->vers_num); + printarglist (proc, RESULT, "clnt", "CLIENT *"); + } + else + { + fprintf (fout, "enum clnt_stat \n"); + pvname (proc->proc_name, vp->vers_num); + printarglist (proc, RESULT, "clnt", "CLIENT *"); + } + fprintf (fout, "{\n"); printbody (proc); - f_print (fout, "}\n"); + fprintf (fout, "}\n"); } } } @@ -104,67 +113,109 @@ write_program (definition * def) /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */ void -printarglist (proc_list * proc, +printarglist (proc_list * proc, const char *result, const char *addargname, const char *addargtype) { decl_list *l; if (!newstyle) - { /* old style: always pass argument by reference */ + { /* old style: always pass argument by reference */ if (Cflag) { /* C++ style heading */ - f_print (fout, "("); - ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); - f_print (fout, "*argp, %s%s)\n", addargtype, addargname); + fprintf (fout, "("); + ptype (proc->args.decls->decl.prefix, + proc->args.decls->decl.type, 1); + + if (mtflag) + {/* Generate result field */ + fprintf (fout, "*argp, "); + ptype(proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*%s, %s%s)\n", result, addargtype, addargname); + } + else + fprintf (fout, "*argp, %s%s)\n", addargtype, addargname); } else { - f_print (fout, "(argp, %s)\n", addargname); - f_print (fout, "\t"); - ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); - f_print (fout, "*argp;\n"); + if (!mtflag) + fprintf (fout, "(argp, %s)\n", addargname); + else + fprintf (fout, "(argp, %s, %s)\n", result, addargname); + fprintf (fout, "\t"); + ptype (proc->args.decls->decl.prefix, + proc->args.decls->decl.type, 1); + fprintf (fout, "*argp;\n"); + if (mtflag) + { + fprintf (fout, "\t"); + ptype (proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*%s;\n", result); + } } } else if (streq (proc->args.decls->decl.type, "void")) { /* newstyle, 0 argument */ - if (Cflag) - f_print (fout, "(%s%s)\n", addargtype, addargname); + if (mtflag) + { + fprintf (fout, "("); + if (Cflag) + { + ptype(proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*%s, %s%s)\n", result, addargtype, addargname); + } + else + fprintf (fout, "(%s)\n", addargname); + } + else if (Cflag) + fprintf (fout, "(%s%s)\n", addargtype, addargname); else - f_print (fout, "(%s)\n", addargname); + fprintf (fout, "(%s)\n", addargname); } else { /* new style, 1 or multiple arguments */ if (!Cflag) { - f_print (fout, "("); + fprintf (fout, "("); for (l = proc->args.decls; l != NULL; l = l->next) - f_print (fout, "%s, ", l->decl.name); - f_print (fout, "%s)\n", addargname); + fprintf (fout, "%s, ", l->decl.name); + if (mtflag) + fprintf (fout, "%s, ", result); + fprintf (fout, "%s)\n", addargname); for (l = proc->args.decls; l != NULL; l = l->next) { pdeclaration (proc->args.argname, &l->decl, 1, ";\n"); } + if (mtflag) + { + fprintf (fout, "\t"); + ptype (proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*%s;\n", result); + } } else { /* C++ style header */ - f_print (fout, "("); + fprintf (fout, "("); for (l = proc->args.decls; l != NULL; l = l->next) { pdeclaration (proc->args.argname, &l->decl, 0, ", "); } - f_print (fout, " %s%s)\n", addargtype, addargname); + if (mtflag) + { + ptype (proc->res_prefix, proc->res_type, 1); + fprintf (fout, "*%s, ", result); + } + fprintf (fout, " %s%s)\n", addargtype, addargname); } } if (!Cflag) - f_print (fout, "\t%s%s;\n", addargtype, addargname); + fprintf (fout, "\t%s%s;\n", addargtype, addargname); } - static const char * ampr (const char *type) @@ -190,66 +241,102 @@ printbody (proc_list * proc) to stuff the arguments. */ if (newstyle && args2) { - f_print (fout, "\t%s", proc->args.argname); - f_print (fout, " arg;\n"); - } - f_print (fout, "\tstatic "); - if (streq (proc->res_type, "void")) - { - f_print (fout, "char "); + fprintf (fout, "\t%s", proc->args.argname); + fprintf (fout, " arg;\n"); } - else + if (!mtflag) { - ptype (proc->res_prefix, proc->res_type, 0); + fprintf (fout, "\tstatic "); + if (streq (proc->res_type, "void")) + { + fprintf (fout, "char "); + } + else + { + ptype (proc->res_prefix, proc->res_type, 0); + } + fprintf (fout, "%s;\n", RESULT); + fprintf (fout, "\n"); + fprintf (fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n", + ampr (proc->res_type), RESULT, RESULT); } - f_print (fout, "%s;\n", RESULT); - f_print (fout, "\n"); - f_print (fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n", - ampr (proc->res_type), RESULT, RESULT); if (newstyle && !args2 && (streq (proc->args.decls->decl.type, "void"))) { /* newstyle, 0 arguments */ - f_print (fout, - "\tif (clnt_call(clnt, %s, xdr_void", proc->proc_name); - f_print (fout, - ", NULL, xdr_%s, %s,%s, TIMEOUT) != RPC_SUCCESS) {\n", - stringfix (proc->res_type), ampr (proc->res_type), RESULT); + if (mtflag) + fprintf (fout, "\t return "); + else + fprintf (fout, "\t if "); + fprintf (fout, + "(clnt_call (clnt, %s, (xdrproc_t) xdr_void", proc->proc_name); + fprintf (fout, + "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,", + stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type), + RESULT); + if (mtflag) + fprintf (fout, "\n\t\tTIMEOUT));\n}\n"); + else + fprintf (fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); } else if (newstyle && args2) { /* newstyle, multiple arguments: stuff arguments into structure */ for (l = proc->args.decls; l != NULL; l = l->next) { - f_print (fout, "\targ.%s = %s;\n", + fprintf (fout, "\targ.%s = %s;\n", l->decl.name, l->decl.name); } - f_print (fout, - "\tif (clnt_call(clnt, %s, xdr_%s", proc->proc_name, + if (mtflag) + fprintf (fout, "\treturn "); + else + fprintf (fout, "\tif "); + + fprintf (fout, + "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc->proc_name, proc->args.argname); - f_print (fout, - ", &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n", - stringfix (proc->res_type), ampr (proc->res_type), RESULT); + fprintf (fout, + ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,", + stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type), + RESULT); + if (mtflag) + fprintf (fout, "\n\t\tTIMEOUT));\n"); + else + fprintf (fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); } else { /* single argument, new or old style */ - f_print (fout, - "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n", - proc->proc_name, - stringfix (proc->args.decls->decl.type), - (newstyle ? "&" : ""), - (newstyle ? proc->args.decls->decl.name : "argp"), - stringfix (proc->res_type), ampr (proc->res_type), RESULT); - } - f_print (fout, "\t\treturn (NULL);\n"); - f_print (fout, "\t}\n"); - if (streq (proc->res_type, "void")) - { - f_print (fout, "\treturn ((void *)%s%s);\n", - ampr (proc->res_type), RESULT); + if (!mtflag) + fprintf (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) != RPC_SUCCESS) {\n", + proc->proc_name, + stringfix (proc->args.decls->decl.type), + (newstyle ? "&" : ""), + (newstyle ? proc->args.decls->decl.name : "argp"), + stringfix (proc->res_type), ampr (proc->res_type), + RESULT); + else + fprintf(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", + proc->proc_name, + stringfix (proc->args.decls->decl.type), + (newstyle ? "&" : ""), + (newstyle ? proc->args.decls->decl.name : "argp"), + stringfix (proc->res_type), "", + RESULT); } - else + if (!mtflag) { - f_print (fout, "\treturn (%s%s);\n", ampr (proc->res_type), RESULT); + fprintf (fout, "\t\treturn (NULL);\n"); + fprintf (fout, "\t}\n"); + if (streq (proc->res_type, "void")) + { + fprintf (fout, "\treturn ((void *)%s%s);\n", + ampr (proc->res_type), RESULT); + } + else + { + fprintf (fout, "\treturn (%s%s);\n", ampr (proc->res_type), RESULT); + } } } diff --git a/sunrpc/rpc_cout.c b/sunrpc/rpc_cout.c index 3b1102d2bb..44ff8d59b5 100644 --- a/sunrpc/rpc_cout.c +++ b/sunrpc/rpc_cout.c @@ -32,7 +32,7 @@ * From: @(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI */ char cout_rcsid[] = - "$Id$"; +"$Id$"; /* * rpc_cout.c, XDR routine outputter for the RPC protocol compiler @@ -44,280 +44,321 @@ char cout_rcsid[] = #include "rpc_util.h" #include "proto.h" -static void emit_enum(definition *def); -static void emit_program(const definition *def); -static void emit_union(const definition *def); -static void emit_struct(definition *def); -static void emit_typedef(const definition *def); -static int findtype(const definition *def, const char *type); -static int undefined(const char *type); -static void print_generic_header(const char *procname, int pointerp); -static void print_ifopen(int indent, const char *name); -static void print_ifarg(const char *arg); -static void print_ifsizeof(const char *prefix, const char *type); -static void print_ifclose(int indent); -static void print_ifstat(int indent, const char *prefix, const char *type, - relation rel, const char *amax, - const char *objname, const char *name); -static void print_stat(int indent, const declaration *dec); -static void print_header(const definition *def); -static void print_trailer(void); -static char *upcase(const char *str); +static void emit_enum (definition * def); +static void emit_program (const definition * def); +static void emit_union (const definition * def); +static void emit_struct (definition * def); +static void emit_typedef (const definition * def); +static void emit_inline (int indent, declaration * decl, int flag); +static void emit_single_in_line (int indent, declaration *decl, int flag, + relation rel); +static int findtype (const definition * def, const char *type); +static int undefined (const char *type); +static void print_generic_header (const char *procname, int pointerp); +static void print_ifopen (int indent, const char *name); +static void print_ifarg (const char *arg); +static void print_ifsizeof (int indent, const char *prefix, const char *type); +static void print_ifclose (int indent); +static void print_ifstat (int indent, const char *prefix, const char *type, + relation rel, const char *amax, + const char *objname, const char *name); +static void print_stat (int indent, const declaration * dec); +static void print_header (const definition * def); +static void print_trailer (void); +static char *upcase (const char *str); /* * Emit the C-routine for the given definition */ void -emit(definition *def) +emit (definition * def) { - if (def->def_kind == DEF_CONST) { - return; - } - if (def->def_kind == DEF_PROGRAM) { - emit_program(def); - return; - } - if (def->def_kind == DEF_TYPEDEF) - { - /* now we need to handle declarations like - struct typedef foo foo; - since we don't want this to be expanded - into 2 calls to xdr_foo */ - - if (strcmp(def->def.ty.old_type,def->def_name)==0) - return; - }; - - print_header(def); - switch (def->def_kind) { - case DEF_UNION: - emit_union(def); - break; - case DEF_ENUM: - emit_enum(def); - break; - case DEF_STRUCT: - emit_struct(def); - break; - case DEF_TYPEDEF: - emit_typedef(def); - break; - default: - /* can't happen */ - break; - } - print_trailer(); + if (def->def_kind == DEF_CONST) + { + return; + } + if (def->def_kind == DEF_PROGRAM) + { + emit_program (def); + return; + } + if (def->def_kind == DEF_TYPEDEF) + { + /* now we need to handle declarations like + struct typedef foo foo; + since we don't want this to be expanded + into 2 calls to xdr_foo */ + + if (strcmp (def->def.ty.old_type, def->def_name) == 0) + return; + }; + + print_header (def); + switch (def->def_kind) + { + case DEF_UNION: + emit_union (def); + break; + case DEF_ENUM: + emit_enum (def); + break; + case DEF_STRUCT: + emit_struct (def); + break; + case DEF_TYPEDEF: + emit_typedef (def); + break; + default: + /* can't happen */ + break; + } + print_trailer (); } static int -findtype(const definition *def, const char *type) +findtype (const definition * def, const char *type) { - if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { - return (0); - } else { - return (streq(def->def_name, type)); - } + if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) + { + return 0; + } + else + { + return (streq (def->def_name, type)); + } } static int -undefined(const char *type) +undefined (const char *type) { - definition *def; - def = (definition *) FINDVAL(defined, type, findtype); - return (def == NULL); + definition *def; + def = (definition *) FINDVAL (defined, type, findtype); + return (def == NULL); } static void -print_generic_header(const char *procname, int pointerp) +print_generic_header (const 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, "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, "\tXDR *xdrs;\n"); - f_print(fout, "\t%s ", procname); - if( pointerp ) - f_print(fout, "*"); - f_print(fout, "objp;\n{\n\n"); - } + f_print (fout, "\n"); + f_print (fout, "bool_t\n"); + if (Cflag) + { + 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"); + } + else + { + 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"); + } } static void -print_header(const definition *def) +print_header (const definition * def) { - print_generic_header(def->def_name, - def->def_kind != DEF_TYPEDEF || - !isvectordef(def->def.ty.old_type, - def->def.ty.rel)); + print_generic_header (def->def_name, + def->def_kind != DEF_TYPEDEF || + !isvectordef (def->def.ty.old_type, + def->def.ty.rel)); - /* Now add Inline support */ + /* Now add Inline support */ - if(inlineflag == 0 ) - return; - /*May cause lint to complain. but ... */ - f_print(fout, "\t register long *buf;\n\n"); + if (inlineflag == 0) + return; + /*May cause lint to complain. but ... */ + f_print (fout, "\t register long *buf;\n\n"); } static void -print_prog_header(const proc_list *plist) +print_prog_header (const proc_list * plist) { - print_generic_header(plist->args.argname, 1 ); + print_generic_header (plist->args.argname, 1); } static void -print_trailer(void) +print_trailer (void) { - f_print(fout, "\treturn TRUE;\n"); - f_print(fout, "}\n"); + f_print (fout, "\treturn TRUE;\n"); + f_print (fout, "}\n"); } static void -print_ifopen(int indent, const char *name) +print_ifopen (int indent, const char *name) { - tabify(fout, indent); - f_print(fout, " if (!xdr_%s(xdrs", name); + tabify (fout, indent); + f_print (fout, " if (!xdr_%s (xdrs", name); } static void -print_ifarg(const char *arg) +print_ifarg (const char *arg) { - f_print(fout, ", %s", arg); + f_print (fout, ", %s", arg); } static void -print_ifsizeof(const char *prefix, const char *type) +print_ifsizeof (int indent, const char *prefix, const char *type) { - if (streq(type, "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); + if (indent) + { + fprintf (fout, ",\n"); + tabify (fout, indent); + } + else + fprintf (fout, ", "); + + if (streq (type, "bool")) + fprintf (fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); + else + { + fprintf (fout, "sizeof ("); + if (undefined (type) && prefix) + { + f_print (fout, "%s ", prefix); } + fprintf (fout, "%s), (xdrproc_t) xdr_%s", type, type); + } } static void -print_ifclose(int indent) +print_ifclose (int indent) { - f_print(fout, ")) {\n"); - tabify(fout, indent); - f_print(fout, "\t return FALSE;\n"); - tabify(fout, indent); - f_print(fout, " }\n"); + f_print (fout, "))\n"); + tabify (fout, indent); + f_print (fout, "\t return FALSE;\n"); } static void -print_ifstat(int indent, const char *prefix, const char *type, relation rel, - const char *amax, const char *objname, const char *name) +print_ifstat (int indent, const char *prefix, const char *type, relation rel, + const char *amax, const char *objname, const char *name) { - const char *alt = NULL; - - switch (rel) { - case REL_POINTER: - print_ifopen(indent, "pointer"); - print_ifarg("(char **)"); - f_print(fout, "%s", objname); - print_ifsizeof(prefix, type); - break; - case REL_VECTOR: - if (streq(type, "string")) { - alt = "string"; - } else if (streq(type, "opaque")) { - alt = "opaque"; - } - if (alt) { - print_ifopen(indent, alt); - print_ifarg(objname); - } else { - print_ifopen(indent, "vector"); - print_ifarg("(char *)"); - f_print(fout, "%s", objname); - } - print_ifarg(amax); - if (!alt) { - print_ifsizeof(prefix, type); - } - break; - case REL_ARRAY: - if (streq(type, "string")) { - alt = "string"; - } else if (streq(type, "opaque")) { - alt = "bytes"; - } - if (streq(type, "string")) { - print_ifopen(indent, alt); - print_ifarg(objname); - } else { - if (alt) { - print_ifopen(indent, alt); - } else { - print_ifopen(indent, "array"); - } - print_ifarg("(char **)"); - if (*objname == '&') { - f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", - objname, name, objname, name); - } else { - f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", - objname, name, objname, name); - } - } - print_ifarg(amax); - if (!alt) { - print_ifsizeof(prefix, type); - } - break; - case REL_ALIAS: - print_ifopen(indent, type); - print_ifarg(objname); - break; + const char *alt = NULL; + + switch (rel) + { + case REL_POINTER: + print_ifopen (indent, "pointer"); + print_ifarg ("(char **)"); + f_print (fout, "%s", objname); + print_ifsizeof (0, prefix, type); + break; + case REL_VECTOR: + if (streq (type, "string")) + { + alt = "string"; + } + else if (streq (type, "opaque")) + { + alt = "opaque"; + } + if (alt) + { + print_ifopen (indent, alt); + print_ifarg (objname); + } + else + { + print_ifopen (indent, "vector"); + print_ifarg ("(char *)"); + f_print (fout, "%s", objname); + } + print_ifarg (amax); + if (!alt) + { + print_ifsizeof (indent + 1, prefix, type); + } + break; + case REL_ARRAY: + if (streq (type, "string")) + { + alt = "string"; } - print_ifclose(indent); + else if (streq (type, "opaque")) + { + alt = "bytes"; + } + if (streq (type, "string")) + { + print_ifopen (indent, alt); + print_ifarg (objname); + } + else + { + if (alt) + { + print_ifopen (indent, alt); + } + else + { + print_ifopen (indent, "array"); + } + print_ifarg ("(char **)"); + if (*objname == '&') + { + f_print (fout, "%s.%s_val, (u_int *) %s.%s_len", + objname, name, objname, name); + } + else + { + f_print (fout, "&%s->%s_val, (u_int *) &%s->%s_len", + objname, name, objname, name); + } + } + print_ifarg (amax); + if (!alt) + { + print_ifsizeof (indent + 1, prefix, type); + } + break; + case REL_ALIAS: + print_ifopen (indent, type); + print_ifarg (objname); + break; + } + print_ifclose (indent); } static void -emit_enum(definition *def) +emit_enum (definition * def) { - (void)def; + (void) def; - print_ifopen(1, "enum"); - print_ifarg("(enum_t *)objp"); - print_ifclose(1); + print_ifopen (1, "enum"); + print_ifarg ("(enum_t *) objp"); + print_ifclose (1); } static void -emit_program(const definition *def) +emit_program (const definition * def) { - decl_list *dl; - version_list *vlist; - proc_list *plist; - - for (vlist = def->def.pr.versions; vlist != NULL;vlist = vlist->next) - for(plist = vlist->procs; plist != NULL; plist = plist->next) { - if (!newstyle || plist->arg_num < 2) - continue; /* old style, or single argument */ - print_prog_header(plist); - for (dl = plist->args.decls; dl != NULL; - dl = dl->next) - print_stat(1,&dl->decl); - print_trailer(); - } + decl_list *dl; + version_list *vlist; + proc_list *plist; + + for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) + for (plist = vlist->procs; plist != NULL; plist = plist->next) + { + if (!newstyle || plist->arg_num < 2) + continue; /* old style, or single argument */ + print_prog_header (plist); + for (dl = plist->args.decls; dl != NULL; + dl = dl->next) + print_stat (1, &dl->decl); + print_trailer (); + } } static void -emit_union(const definition *def) +emit_union (const definition * def) { declaration *dflt; case_list *cl; @@ -326,378 +367,440 @@ emit_union(const definition *def) const char *vecformat = "objp->%s_u.%s"; const 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); - for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { - - f_print(fout, "\tcase %s:\n", cl->case_name); - if(cl->contflag == 1) /* a continued case statement */ - 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); - } - print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max, - object, cs->name); - free(object); + print_stat (1, &def->def.un.enum_decl); + f_print (fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); + for (cl = def->def.un.cases; cl != NULL; cl = cl->next) + { + + f_print (fout, "\tcase %s:\n", cl->case_name); + if (cl->contflag == 1) /* a continued case statement */ + 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); + } + print_ifstat (2, cs->prefix, cs->type, cs->rel, cs->array_max, + object, cs->name); + free (object); + } + f_print (fout, "\t\tbreak;\n"); } - f_print(fout, "\t\tbreak;\n"); - } dflt = def->def.un.default_decl; - if (dflt != NULL) { - if (!streq(dflt->type, "void")) { - 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); - } + if (dflt != NULL) + { + if (!streq (dflt->type, "void")) + { + 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); + } - print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, - dflt->array_max, object, dflt->name); - free(object); - f_print(fout, "\t\tbreak;\n"); - } + print_ifstat (2, dflt->prefix, dflt->type, dflt->rel, + dflt->array_max, object, dflt->name); + free (object); + f_print (fout, "\t\tbreak;\n"); + } #ifdef __GNU_LIBRARY__ - else { - f_print(fout, "\tdefault:\n"); - f_print(fout, "\t\tbreak;\n"); - } + else + { + f_print (fout, "\tdefault:\n"); + f_print (fout, "\t\tbreak;\n"); + } #endif - } else { - f_print(fout, "\tdefault:\n"); - f_print(fout, "\t\treturn FALSE;\n"); - } + } + else + { + f_print (fout, "\tdefault:\n"); + f_print (fout, "\t\treturn FALSE;\n"); + } - f_print(fout, "\t}\n"); + f_print (fout, "\t}\n"); +} + +static void +inline_struct (definition *def, int flag) +{ + decl_list *dl; + int i, size; + decl_list *cur, *psav; + bas_type *ptr; + char *sizestr, *plus; + char ptemp[256]; + int indent = 1; + + if (flag == PUT) + f_print (fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); + else + f_print(fout, + "\t\treturn TRUE;\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); + + i = 0; + size = 0; + sizestr = NULL; + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + { /* xxx */ + /* now walk down the list and check for basic types */ + if ((dl->decl.prefix == NULL) && + ((ptr = find_type (dl->decl.type)) != NULL) && + ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) + { + if (i == 0) + cur = dl; + ++i; + + if (dl->decl.rel == REL_ALIAS) + size += ptr->length; + else + { + /* this is required to handle arrays */ + if (sizestr == NULL) + plus = ""; + else + plus = "+ "; + + if (ptr->length != 1) + s_print (ptemp, " %s %s * %d", plus, dl->decl.array_max, + ptr->length); + else + s_print (ptemp, " %s%s ", plus, dl->decl.array_max); + + /*now concatenate to sizestr !!!! */ + if (sizestr == NULL) + sizestr = strdup (ptemp); + else + { + sizestr = realloc (sizestr, strlen (sizestr) + + strlen (ptemp) + 1); + if (sizestr == NULL) + { + f_print (stderr, "Fatal error : no memory \n"); + crash (); + }; + sizestr = strcat (sizestr, ptemp); + /*build up length of array */ + } + } + } + else + { + if (i > 0) + if (sizestr == NULL && size < inlineflag) + { + /* don't expand into inline code if size < inlineflag */ + while (cur != dl) + { + print_stat (indent + 1, &cur->decl); + cur = cur->next; + } + } + else + { + /* were already looking at a xdr_inlineable structure */ + tabify (fout, indent + 1); + if (sizestr == NULL) + f_print (fout, "buf = XDR_INLINE (xdrs, %d * BYTES_PER_XDR_UNIT);", size); + else if (size == 0) + f_print (fout, + "buf = XDR_INLINE (xdrs, %s * BYTES_PER_XDR_UNIT);", + sizestr); + else + f_print (fout, + "buf = XDR_INLINE(xdrs, (%d + (%s)) * BYTES_PER_XDR_UNIT);", + size, sizestr); + f_print (fout, "\n"); + tabify (fout, indent + 1); + fprintf (fout, "if (buf == NULL) {\n"); + psav = cur; + while (cur != dl) + { + print_stat (indent + 2, &cur->decl); + cur = cur->next; + } + + f_print (fout, "\n\t\t} else {\n"); + cur = psav; + while (cur != dl) + { + emit_inline (indent + 1, &cur->decl, flag); + cur = cur->next; + } + tabify (fout, indent + 1); + f_print (fout, "}\n"); + } + size = 0; + i = 0; + sizestr = NULL; + print_stat (indent + 1, &dl->decl); + } + } + if (i > 0) + if (sizestr == NULL && size < inlineflag) + { + /* don't expand into inline code if size < inlineflag */ + while (cur != dl) + { + print_stat (indent + 1, &cur->decl); + cur = cur->next; + } + } + else + { + /* were already looking at a xdr_inlineable structure */ + if (sizestr == NULL) + f_print (fout, "\t\tbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);", + size); + else if (size == 0) + f_print (fout, + "\t\tbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);", + sizestr); + else + f_print (fout, + "\t\tbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);", + size, sizestr); + f_print (fout, "\n\t\tif (buf == NULL) {\n"); + psav = cur; + while (cur != NULL) + { + print_stat (indent + 2, &cur->decl); + cur = cur->next; + } + f_print (fout, "\t\t} else {\n"); + + cur = psav; + while (cur != dl) + { + emit_inline (indent + 2, &cur->decl, flag); + cur = cur->next; + } + f_print (fout, "\t\t}\n"); + } } /* this may be const. i haven't traced this one through yet. */ static void -emit_struct(definition *def) +emit_struct (definition * def) { - decl_list *dl; - int i,j,size,flag; - decl_list *cur = NULL,*psav; - bas_type *ptr; - char *sizestr; - const char *plus; - char ptemp[256]; - int can_inline; - - - if(inlineflag == 0) { - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - print_stat(1,&dl->decl); - } + decl_list *dl; + int j, size, flag; + bas_type *ptr; + int can_inline; + + + if (inlineflag == 0) + { + /* No xdr_inlining at all */ + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + print_stat (1, &dl->decl); + return; + } - else { - - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - if(dl->decl.rel == REL_VECTOR){ - f_print(fout,"\t int i;\n"); - break; - } - - size=0;can_inline=0; - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - if((dl->decl.prefix == NULL) && ((ptr=find_type(dl->decl.type))!= NULL) && ((dl->decl.rel == REL_ALIAS)||(dl->decl.rel == REL_VECTOR))){ - - if(dl->decl.rel == REL_ALIAS) - size+=ptr->length; - else { - can_inline=1; - break; /* can be inlined */ - }; - } - else { - if(size >= inlineflag){ - can_inline=1; - break; /* can be inlined */ - } - size=0; - } - if(size > inlineflag) - can_inline=1; - - if(can_inline == 0){ /* can not inline, drop back to old mode */ - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - print_stat(1,&dl->decl); - return; - }; - - flag=PUT; - for(j=0; j<2; j++){ - - if(flag == PUT) - f_print(fout,"\n\t if (xdrs->x_op == XDR_ENCODE) {\n"); - else - f_print(fout,"\n \t return TRUE;\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); - - - i=0; - size=0; - sizestr=NULL; - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */ - - /* now walk down the list and check for basic types */ - if((dl->decl.prefix == NULL) && ((ptr=find_type(dl->decl.type))!= NULL) && ((dl->decl.rel == REL_ALIAS)||(dl->decl.rel == REL_VECTOR))){ - if(i ==0 ) - cur=dl; - i++; - - if(dl->decl.rel == REL_ALIAS) - size+=ptr->length; - else { - /* this is required to handle arrays */ - - if(sizestr == NULL) - plus = " "; - else - plus = "+"; - - if(ptr->length != 1) - s_print(ptemp," %s %s * %d",plus,dl->decl.array_max,ptr->length); - else - s_print(ptemp," %s %s ",plus,dl->decl.array_max); - - /*now concatenate to sizestr !!!! */ - if (sizestr == NULL) - sizestr=strdup(ptemp); - else{ - sizestr=realloc(sizestr,strlen(sizestr)+strlen(ptemp)+1); - if(sizestr == NULL){ - - f_print(stderr, "Fatal error : no memory \n"); - crash(); - }; - sizestr=strcat(sizestr,ptemp); /*build up length of array */ - - } - } - - } - else{ - if(i > 0 ) - if(sizestr == NULL && size < inlineflag){ - /* don't expand into inline code if size < inlineflag */ - while(cur != dl){ - print_stat(1,&cur->decl); - cur=cur->next; - } - } - else{ - - - - /* were already looking at a xdr_inlineable structure */ - if(sizestr == NULL) - f_print(fout,"\t buf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);", - size); - else - if(size == 0) - f_print(fout, - "\t buf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);", - sizestr); - else - f_print(fout, - "\t buf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);", - size,sizestr); - - f_print(fout,"\n\t if (buf == NULL) {\n"); - - psav=cur; - while(cur != dl){ - print_stat(2,&cur->decl); - cur=cur->next; - } - - f_print(fout,"\n\t }\n\t else {\n"); - - cur=psav; - while(cur != dl){ - emit_inline(&cur->decl,flag); - cur=cur->next; - } - - f_print(fout,"\t }\n"); - } - size=0;i=0;sizestr=NULL; - print_stat(1,&dl->decl); - } - - } - if(i > 0 ) - if(sizestr == NULL && size < inlineflag){ - /* don't expand into inline code if size < inlineflag */ - while(cur != dl){ - print_stat(1,&cur->decl); - cur=cur->next; - } - } - else{ - - /* were already looking at a xdr_inlineable structure */ - if(sizestr == NULL) - f_print(fout,"\t\tbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);", - size); - else - if(size == 0) - f_print(fout, - "\t\tbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);", - sizestr); - else - f_print(fout, - "\t\tbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);", - size,sizestr); - - f_print(fout,"\n\t\tif (buf == NULL) {\n"); - - psav=cur; - while(cur != NULL){ - print_stat(2,&cur->decl); - cur=cur->next; - } - f_print(fout,"\n\t }\n\t else {\n"); - - cur=psav; - while(cur != dl){ - emit_inline(&cur->decl,flag); - cur=cur->next; - } - - f_print(fout,"\t }\n"); - - } - flag=GET; - } - f_print(fout,"\t return TRUE;\n\t}\n\n"); + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + if (dl->decl.rel == REL_VECTOR) + { + f_print (fout, "\tint i;\n"); + break; + } - /* now take care of XDR_FREE case */ + size = 0; + can_inline = 0; + /* + * Make a first pass and see if inling is possible. + */ + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + if ((dl->decl.prefix == NULL) && + ((ptr = find_type (dl->decl.type)) != NULL) && + ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) + { + if (dl->decl.rel == REL_ALIAS) + size += ptr->length; + else + { + can_inline = 1; + break; /* can be inlined */ + } + } + else + { + if (size >= inlineflag) + { + can_inline = 1; + break; /* can be inlined */ + } + size = 0; + } + if (size > inlineflag) + can_inline = 1; + + if (can_inline == 0) + { /* can not inline, drop back to old mode */ + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + print_stat (1, &dl->decl); + return; + }; + + flag = PUT; + for (j = 0; j < 2; j++) + { + inline_struct (def, flag); + if (flag == PUT) + flag = GET; + } - for (dl = def->def.st.decls; dl != NULL; dl = dl->next) - print_stat(1,&dl->decl); - } -} + f_print (fout, "\t return TRUE;\n\t}\n\n"); + /* now take care of XDR_FREE case */ + + for (dl = def->def.st.decls; dl != NULL; dl = dl->next) + print_stat (1, &dl->decl); +} static void -emit_typedef(const definition *def) +emit_typedef (const definition * def) { - const char *prefix = def->def.ty.old_prefix; - const char *type = def->def.ty.old_type; - const char *amax = def->def.ty.array_max; - relation rel = def->def.ty.rel; - + const char *prefix = def->def.ty.old_prefix; + const char *type = def->def.ty.old_type; + const char *amax = def->def.ty.array_max; + relation rel = def->def.ty.rel; - print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); + print_ifstat (1, prefix, type, rel, amax, "objp", def->def_name); } static void -print_stat(int indent, const declaration *dec) +print_stat (int indent, const declaration * dec) { - const char *prefix = dec->prefix; - const char *type = dec->type; - const char *amax = dec->array_max; - 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); - } - print_ifstat(indent, prefix, type, rel, amax, name, dec->name); + const char *prefix = dec->prefix; + const char *type = dec->type; + const char *amax = dec->array_max; + 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); + } + print_ifstat (indent, prefix, type, rel, amax, name, dec->name); } -void -emit_inline(declaration *decl, int flag) +static void +emit_inline (int indent, declaration * decl, int flag) { - -/*check whether an array or not */ - -switch(decl->rel) - { - case REL_ALIAS : - emit_single_in_line(decl,flag,REL_ALIAS); - break; - case REL_VECTOR : - f_print(fout,"\t\t{ register %s *genp; \n",decl->type); - f_print(fout,"\t\t for ( i = 0,genp=objp->%s;\n \t\t\ti < %s; i++){\n\t\t", - decl->name,decl->array_max); - emit_single_in_line(decl,flag,REL_VECTOR); - f_print(fout,"\t\t }\n\t\t };\n"); - - default: - /* ?... do nothing I guess */ - } + switch (decl->rel) + { + case REL_ALIAS: + emit_single_in_line (indent, decl, flag, REL_ALIAS); + break; + case REL_VECTOR: + tabify (fout, indent); + f_print (fout, "{\n"); + tabify (fout, indent + 1); + f_print (fout, "register %s *genp;\n\n", decl->type); + tabify (fout, indent + 1); + f_print (fout, + "for (i = 0, genp = objp->%s;\n", decl->name); + tabify (fout, indent + 2); + f_print (fout, "i < %s; ++i) {\n", decl->array_max); + emit_single_in_line (indent + 2, decl, flag, REL_VECTOR); + tabify (fout, indent + 1); + f_print (fout, "}\n"); + tabify (fout, indent); + f_print (fout, "}\n"); + break; + default: + /* ?... do nothing I guess */ + } } -void -emit_single_in_line(declaration *decl, int flag, relation rel) +static void +emit_single_in_line (int indent, declaration *decl, int flag, relation rel) { - char *upp_case1; - const char *upp_case; + char *upp_case; + int freed = 0; + + tabify (fout, indent); + if (flag == PUT) + f_print (fout, "IXDR_PUT_"); + else + { + if (rel == REL_ALIAS) + f_print (fout, "objp->%s = IXDR_GET_", decl->name); + else + f_print (fout, "*genp++ = IXDR_GET_"); + } - if (flag == PUT) { - f_print(fout,"\t\t IXDR_PUT_"); - } - else { - if(rel== REL_ALIAS) { - f_print(fout, "\t\t objp->%s = IXDR_GET_", decl->name); - } - else { - f_print(fout,"\t\t *genp++ = IXDR_GET_"); - } - } + upp_case = upcase (decl->type); - upp_case1 = upcase(decl->type); - upp_case = upp_case1; + /* hack - XX */ + if (!strcmp (upp_case, "INT")) + { + free (upp_case); + freed = 1; + upp_case = "LONG"; + } - /* hack - XX */ - if (!strcmp(upp_case, "INT")) upp_case="LONG"; - if (!strcmp(upp_case, "U_INT")) upp_case="U_LONG"; + if (!strcmp (upp_case, "U_INT")) + { + free (upp_case); + freed = 1; + upp_case = "U_LONG"; + } - if (flag == PUT) { - if (rel==REL_ALIAS) { - f_print(fout,"%s(buf,objp->%s);\n",upp_case,decl->name); - } - else { - f_print(fout,"%s(buf,*genp++);\n",upp_case); - } - } - else { - f_print(fout,"%s(buf);\n",upp_case); - } + if (flag == PUT) + { + if (rel == REL_ALIAS) + f_print (fout, "%s(buf, objp->%s);\n", upp_case, decl->name); + else + f_print (fout, "%s(buf, *genp++);\n", upp_case); + } + else + { + f_print (fout, "%s(buf);\n", upp_case); + } - free(upp_case1); + if (!freed) + free (upp_case); } -static char *upcase(const char *str) { - char *ptr, *hptr; - ptr = malloc(strlen(str)); - if (ptr == NULL) { - f_print(stderr,"malloc failed\n"); - exit(1); - } - hptr=ptr; - while (*str != 0) { - *ptr++ = toupper(*str++); +static char * +upcase (const char *str) +{ + char *ptr, *hptr; + ptr = malloc (strlen (str)); + if (ptr == NULL) + { + f_print (stderr, "malloc failed\n"); + exit (1); } - *ptr=0; - return hptr; + hptr = ptr; + while (*str != '\0') + *ptr++ = toupper (*str++); + + *ptr = '\0'; + return hptr; } diff --git a/sunrpc/rpc_hout.c b/sunrpc/rpc_hout.c index beca27610f..4c49d10bbe 100644 --- a/sunrpc/rpc_hout.c +++ b/sunrpc/rpc_hout.c @@ -31,11 +31,11 @@ /* * From: @(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI */ -char hout_rcsid[] = +char hout_rcsid[] = "$Id$"; /* - * rpc_hout.c, Header file outputter for the RPC protocol compiler + * rpc_hout.c, Header file outputter for the RPC protocol compiler */ #include <stdio.h> #include <ctype.h> @@ -43,456 +43,575 @@ char hout_rcsid[] = #include "rpc_util.h" #include "proto.h" -static void pconstdef(definition *def); -static void pargdef(definition *def); -static void pstructdef(definition *def); -static void puniondef(definition *def); -static void pdefine(const char *name, const char *num); -static void puldefine(const char *name, const char *num); -static int define_printed(proc_list *stop, version_list *start); -static void pprogramdef(definition *def); -static void parglist(proc_list *proc, const char *addargtype); -static void penumdef(definition *def); -static void ptypedef(definition *def); -static int undefined2(const char *type, const char *stop); +static void pconstdef (definition * def); +static void pargdef (definition * def); +static void pstructdef (definition * def); +static void puniondef (definition * def); +static void pdefine (const char *name, const char *num); +static void puldefine (const char *name, const char *num); +static int define_printed (proc_list * stop, version_list * start); +static void pprogramdef (definition * def); +static void parglist (proc_list * proc, const char *addargtype); +static void penumdef (definition * def); +static void ptypedef (definition * def); +static int undefined2 (const char *type, const char *stop); + +/* store away enough information to allow the XDR functions to be spat + out at the end of the file */ + +void +storexdrfuncdecl (const char *name, int pointerp) +{ + xdrfunc * xdrptr; + + xdrptr = (xdrfunc *) malloc(sizeof (struct xdrfunc)); + + xdrptr->name = (char *)name; + xdrptr->pointerp = pointerp; + xdrptr->next = NULL; + + if (xdrfunc_tail == NULL) + { + xdrfunc_head = xdrptr; + xdrfunc_tail = xdrptr; + } + else + { + xdrfunc_tail->next = xdrptr; + xdrfunc_tail = xdrptr; + } +} /* - * Print the C-version of an xdr definition + * Print the C-version of an xdr definition */ void -print_datadef(definition *def) +print_datadef (definition *def) { - if (def->def_kind == DEF_PROGRAM ) /* handle data only */ - return; - - if (def->def_kind != DEF_CONST) { - f_print(fout, "\n"); - } - switch (def->def_kind) { - case DEF_STRUCT: - pstructdef(def); - break; - case DEF_UNION: - puniondef(def); - break; - case DEF_ENUM: - penumdef(def); - break; - case DEF_TYPEDEF: - ptypedef(def); - break; - case DEF_PROGRAM: - pprogramdef(def); - break; - case DEF_CONST: - pconstdef(def); - break; - } - if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) { - pxdrfuncdecl( def->def_name, - def->def_kind != DEF_TYPEDEF || - !isvectordef(def->def.ty.old_type, def->def.ty.rel)); - - } + if (def->def_kind == DEF_PROGRAM) /* handle data only */ + return; + + if (def->def_kind != DEF_CONST) + { + f_print (fout, "\n"); + } + switch (def->def_kind) + { + case DEF_STRUCT: + pstructdef (def); + break; + case DEF_UNION: + puniondef (def); + break; + case DEF_ENUM: + penumdef (def); + break; + case DEF_TYPEDEF: + ptypedef (def); + break; + case DEF_PROGRAM: + pprogramdef (def); + break; + case DEF_CONST: + pconstdef (def); + break; + } + 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)); + } } void -print_funcdef(definition *def) +print_funcdef (definition *def) { - switch (def->def_kind) { - case DEF_PROGRAM: - f_print(fout, "\n"); - pprogramdef(def); - break; - default: - /* ?... shouldn't happen I guess */ - } + switch (def->def_kind) + { + case DEF_PROGRAM: + f_print (fout, "\n"); + pprogramdef (def); + break; + default: + /* ?... shouldn't happen I guess */ + } } void -pxdrfuncdecl(const char *name, int pointerp) +print_xdr_func_def (char *name, int pointerp, int i) { - - f_print(fout,"#ifdef __cplusplus \n"); - f_print(fout, "extern \"C\" bool_t xdr_%s(XDR *, %s%s);\n", name, name, pointerp ? "*" : ""); - f_print(fout,"#elif __STDC__ \n"); - f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name, name, pointerp ? "*" : ""); - f_print(fout,"#else /* Old Style C */ \n"); - f_print(fout, "bool_t xdr_%s();\n", name); - f_print(fout,"#endif /* Old Style C */ \n\n"); + if (i == 2) + { + f_print (fout, "extern bool_t xdr_%s ();\n", name); + return; + } + else + f_print(fout, "extern bool_t xdr_%s (XDR *, %s%s);\n", name, + name, pointerp ? "*" : ""); } - static void -pconstdef(definition *def) +pconstdef (definition *def) { - pdefine(def->def_name, def->def.co); + pdefine (def->def_name, def->def.co); } -/* print out the definitions for the arguments of functions in the - header file -*/ +/* print out the definitions for the arguments of functions in the + header file + */ static void -pargdef(definition *def) +pargdef (definition * def) { - decl_list *l; - version_list *vers; - const char *name; - 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); - pxdrfuncdecl(name, 0); - f_print( fout, "\n" ); - } - } + decl_list *l; + version_list *vers; + const char *name; + 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, 0); + f_print (fout, "\n"); + } + } } - static void -pstructdef(definition *def) +pstructdef (definition *def) { - decl_list *l; - const char *name = def->def_name; - - f_print(fout, "struct %s {\n", name); - 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); + decl_list *l; + const char *name = def->def_name; + + f_print (fout, "struct %s {\n", name); + 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 void -puniondef(definition *def) +puniondef (definition *def) { - case_list *l; - const char *name = def->def_name; - declaration *decl; - - f_print(fout, "struct %s {\n", name); - decl = &def->def.un.enum_decl; - if (streq(decl->type, "bool")) { - f_print(fout, "\tbool_t %s;\n", decl->name); - } 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")) { - 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); + case_list *l; + const char *name = def->def_name; + declaration *decl; + + f_print (fout, "struct %s {\n", name); + decl = &def->def.un.enum_decl; + if (streq (decl->type, "bool")) + { + f_print (fout, "\tbool_t %s;\n", decl->name); + } + 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")) + { + 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 void -pdefine(const char *name, const char *num) +pdefine (const char *name, const char *num) { - f_print(fout, "#define %s %s\n", name, num); + f_print (fout, "#define %s %s\n", name, num); } static void -puldefine(const char *name, const char *num) +puldefine (const char *name, const char *num) { - f_print(fout, "#define %s ((u_long)%s)\n", name, num); + f_print (fout, "#define %s ((u_long)%s)\n", name, num); } static int -define_printed(proc_list *stop, version_list *start) +define_printed (proc_list *stop, version_list *start) { - version_list *vers; - proc_list *proc; - - for (vers = start; vers != NULL; vers = vers->next) { - for (proc = vers->procs; proc != NULL; proc = proc->next) { - if (proc == stop) { - return (0); - } else if (streq(proc->proc_name, stop->proc_name)) { - return (1); - } - } + version_list *vers; + proc_list *proc; + + for (vers = start; vers != NULL; vers = vers->next) + { + for (proc = vers->procs; proc != NULL; proc = proc->next) + { + if (proc == stop) + { + return 0; + } + else if (streq (proc->proc_name, stop->proc_name)) + { + return 1; + } } - abort(); - /* NOTREACHED */ + } + abort (); + /* NOTREACHED */ } static void -pprogramdef(definition *def) +pfreeprocdef (const char *name, const char *vers, int mode) { - version_list *vers; - proc_list *proc; - int i; - const char *ext; - - pargdef(def); - - puldefine(def->def_name, def->def.pr.prog_num); - for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { - if (tblflag) { - f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", - locase(def->def_name), vers->vers_num); - f_print(fout, "extern %s_%s_nproc;\n", - locase(def->def_name), vers->vers_num); + f_print (fout, "extern int "); + pvname (name, vers); + if (mode == 1) + f_print (fout,"_freeresult (SVCXPRT *, xdrproc_t, caddr_t);\n"); + else + f_print (fout,"_freeresult ();\n"); +} + +static void +pprogramdef (definition *def) +{ + version_list *vers; + proc_list *proc; + int i; + const char *ext; + + pargdef (def); + + puldefine (def->def_name, def->def.pr.prog_num); + for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) + { + if (tblflag) + { + f_print (fout, "extern struct rpcgen_table %s_%s_table[];\n", + locase (def->def_name), vers->vers_num); + f_print (fout, "extern %s_%s_nproc;\n", + locase (def->def_name), vers->vers_num); + } + puldefine (vers->vers_name, vers->vers_num); + + /* + * Print out 2 definitions, one for ANSI-C, another for + * old K & R C + */ + + if(!Cflag) + { + ext = "extern "; + for (proc = vers->procs; proc != NULL; + proc = proc->next) + { + if (!define_printed(proc, def->def.pr.versions)) + { + puldefine (proc->proc_name, proc->proc_num); + } + f_print (fout, "%s", ext); + pprocdef (proc, vers, NULL, 0, 2); + + if (mtflag) + { + f_print(fout, "%s", ext); + pprocdef (proc, vers, NULL, 1, 2); + } + } + pfreeprocdef (def->def_name, vers->vers_num, 2); + } + else + { + for (i = 1; i < 3; i++) + { + if (i == 1) + { + f_print (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); + ext = "extern "; + } + else + { + f_print (fout, "\n#else /* K&R C */\n"); + ext = "extern "; } - puldefine(vers->vers_name, vers->vers_num); - - /* - * Print out 3 definitions, one for ANSI-C, another for C++, - * a third for old style C - */ - - for (i=0;i<3;i++) { - if (i==0) { - f_print(fout,"\n#ifdef __cplusplus\n"); - ext="extern \"C\" "; - } - else if (i==1) { - f_print(fout,"\n#elif __STDC__\n"); - ext="extern " ; - } - else { - f_print(fout,"\n#else /* Old Style C */ \n"); - ext="extern "; - } - - - for (proc = vers->procs; proc != NULL; proc = proc->next) { - if (!define_printed(proc, def->def.pr.versions)) { - puldefine(proc->proc_name, proc->proc_num); - } - f_print(fout,"%s",ext); - pprocdef(proc, vers, "CLIENT *", 0,i); - f_print(fout,"%s",ext); - pprocdef(proc, vers, "struct svc_req *", 1,i); - - } + for (proc = vers->procs; proc != NULL; proc = proc->next) + { + if (!define_printed(proc, def->def.pr.versions)) + { + puldefine(proc->proc_name, proc->proc_num); + } + f_print (fout, "%s", ext); + pprocdef (proc, vers, "CLIENT *", 0, i); + f_print (fout, "%s", ext); + pprocdef (proc, vers, "struct svc_req *", 1, i); } - f_print(fout,"#endif /* Old Style C */ \n"); + pfreeprocdef (def->def_name, vers->vers_num, i); + } + f_print (fout, "#endif /* K&R C */\n"); } + } } void -pprocdef(proc_list *proc, version_list *vp, - const char *addargtype, int server_p, int mode) +pprocdef (proc_list * proc, version_list * vp, + const char *addargtype, int server_p, int mode) { - - - - - ptype( proc->res_prefix, proc->res_type, 1 ); - f_print( fout, "* " ); - if( server_p ) - pvname_svc(proc->proc_name, vp->vers_num); - else - pvname(proc->proc_name, vp->vers_num); - - /* - * mode 0 == cplusplus, mode 1 = ANSI-C, mode 2 = old style C - */ - if(mode == 0 || mode ==1) - parglist(proc, addargtype); - else - f_print(fout, "();\n"); - - - + if (mtflag) + {/* Print MT style stubs */ + if (server_p) + f_print (fout, "bool_t "); + else + f_print (fout, "enum clnt_stat "); + } + else + { + ptype (proc->res_prefix, proc->res_type, 1); + f_print (fout, "* "); + } + if (server_p) + pvname_svc (proc->proc_name, vp->vers_num); + else + pvname (proc->proc_name, vp->vers_num); + + /* + * mode 1 = ANSI-C, mode 2 = K&R C + */ + if (mode == 1) + parglist (proc, addargtype); + else + f_print (fout, "();\n"); } - - /* print out argument list of procedure */ static void -parglist(proc_list *proc, const char *addargtype) +parglist (proc_list *proc, const char *addargtype) { - decl_list *dl; - - f_print(fout,"("); - - if( proc->arg_num < 2 && newstyle && - streq( proc->args.decls->decl.type, "void")) { - /* 0 argument in new style: do nothing */ - } else { - for (dl = proc->args.decls; dl != NULL; dl = dl->next) { - ptype( dl->decl.prefix, dl->decl.type, 1 ); - if( !newstyle ) - f_print( fout, "*" ); /* old style passes by reference */ - - f_print( fout, ", " ); - } - } - - f_print(fout, "%s);\n", addargtype); - + decl_list *dl; + + f_print(fout,"("); + if (proc->arg_num < 2 && newstyle && + streq (proc->args.decls->decl.type, "void")) + { + /* 0 argument in new style: do nothing */ + } + else + { + for (dl = proc->args.decls; dl != NULL; dl = dl->next) + { + ptype (dl->decl.prefix, dl->decl.type, 1); + if (!newstyle) + f_print (fout, "*"); /* old style passes by reference */ + + f_print (fout, ", "); + } + } + if (mtflag) + { + ptype(proc->res_prefix, proc->res_type, 1); + f_print(fout, "*, "); + } + + f_print (fout, "%s);\n", addargtype); } static void -penumdef(definition *def) +penumdef (definition *def) { - const char *name = def->def_name; - enumval_list *l; - const char *last = NULL; - int count = 0; - - f_print(fout, "enum %s {\n", name); - for (l = def->def.en.vals; l != NULL; l = l->next) { - f_print(fout, "\t%s", l->name); - if (l->assignment) { - f_print(fout, " = %s", l->assignment); - last = l->assignment; - count = 1; - } else { - if (last == NULL) { - f_print(fout, " = %d", count++); - } else { - f_print(fout, " = %s + %d", last, count++); - } - } - f_print(fout, ",\n"); + const char *name = def->def_name; + enumval_list *l; + const char *last = NULL; + int count = 0; + + f_print (fout, "enum %s {\n", name); + for (l = def->def.en.vals; l != NULL; l = l->next) + { + f_print (fout, "\t%s", l->name); + if (l->assignment) + { + f_print (fout, " = %s", l->assignment); + last = l->assignment; + count = 1; + } + else + { + if (last == NULL) + { + f_print (fout, " = %d", count++); + } + else + { + f_print (fout, " = %s + %d", last, count++); + } } - f_print(fout, "};\n"); - f_print(fout, "typedef enum %s %s;\n", name, name); + f_print (fout, ",\n"); + } + f_print (fout, "};\n"); + f_print (fout, "typedef enum %s %s;\n", name, name); } static void -ptypedef(definition *def) +ptypedef (definition *def) { - const char *name = def->def_name; - const char *old = def->def.ty.old_type; - char prefix[8]; /* enough to contain "struct ", including NUL */ - relation rel = def->def.ty.rel; - - - if (!streq(name, old)) { - if (streq(old, "string")) { - old = "char"; - rel = REL_POINTER; - } else if (streq(old, "opaque")) { - old = "char"; - } 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 { - prefix[0] = 0; - } - f_print(fout, "typedef "); - switch (rel) { - case REL_ARRAY: - f_print(fout, "struct {\n"); - f_print(fout, "\tu_int %s_len;\n", name); - f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); - f_print(fout, "} %s", name); - break; - case REL_POINTER: - f_print(fout, "%s%s *%s", prefix, old, name); - break; - case REL_VECTOR: - f_print(fout, "%s%s %s[%s]", prefix, old, name, - def->def.ty.array_max); - break; - case REL_ALIAS: - f_print(fout, "%s%s %s", prefix, old, name); - break; - } - f_print(fout, ";\n"); + const char *name = def->def_name; + const char *old = def->def.ty.old_type; + char prefix[8]; /* enough to contain "struct ", including NUL */ + relation rel = def->def.ty.rel; + + if (!streq (name, old)) + { + if (streq (old, "string")) + { + old = "char"; + rel = REL_POINTER; + } + else if (streq (old, "opaque")) + { + old = "char"; + } + 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 + { + prefix[0] = 0; + } + f_print (fout, "typedef "); + switch (rel) + { + case REL_ARRAY: + f_print (fout, "struct {\n"); + f_print (fout, "\tu_int %s_len;\n", name); + f_print (fout, "\t%s%s *%s_val;\n", prefix, old, name); + f_print (fout, "} %s", name); + break; + case REL_POINTER: + f_print (fout, "%s%s *%s", prefix, old, name); + break; + case REL_VECTOR: + f_print (fout, "%s%s %s[%s]", prefix, old, name, + def->def.ty.array_max); + break; + case REL_ALIAS: + f_print (fout, "%s%s %s", prefix, old, name); + break; + } + f_print (fout, ";\n"); + } } void -pdeclaration(const char *name, declaration *dec, int tab, - const char *separator) +pdeclaration (const char *name, declaration * dec, int tab, + const char *separator) { - char buf[8]; /* enough to hold "struct ", include NUL */ - const char *prefix; - const char *type; - - if (streq(dec->type, "void")) { - return; + char buf[8]; /* enough to hold "struct ", include NUL */ + const char *prefix; + const char *type; + + if (streq (dec->type, "void")) + { + return; + } + tabify (fout, tab); + if (streq (dec->type, name) && !dec->prefix) + { + f_print (fout, "struct "); + } + if (streq (dec->type, "string")) + { + f_print (fout, "char *%s", dec->name); + } + else + { + prefix = ""; + if (streq (dec->type, "bool")) + { + type = "bool_t"; } - tabify(fout, tab); - if (streq(dec->type, name) && !dec->prefix) { - f_print(fout, "struct "); + else if (streq (dec->type, "opaque")) + { + type = "char"; } - if (streq(dec->type, "string")) { - f_print(fout, "char *%s", dec->name); - } else { - prefix = ""; - if (streq(dec->type, "bool")) { - type = "bool_t"; - } else if (streq(dec->type, "opaque")) { - type = "char"; - } else { - if (dec->prefix) { - s_print(buf, "%s ", dec->prefix); - prefix = buf; - } - type = dec->type; - } - switch (dec->rel) { - case REL_ALIAS: - f_print(fout, "%s%s %s", prefix, type, dec->name); - break; - case REL_VECTOR: - f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, - dec->array_max); - break; - case REL_POINTER: - f_print(fout, "%s%s *%s", prefix, type, dec->name); - break; - case REL_ARRAY: - f_print(fout, "struct {\n"); - tabify(fout, tab); - f_print(fout, "\tu_int %s_len;\n", dec->name); - tabify(fout, tab); - f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); - tabify(fout, tab); - f_print(fout, "} %s", dec->name); - break; - } + else + { + if (dec->prefix) + { + s_print (buf, "%s ", dec->prefix); + prefix = buf; + } + type = dec->type; + } + switch (dec->rel) + { + case REL_ALIAS: + f_print (fout, "%s%s %s", prefix, type, dec->name); + break; + case REL_VECTOR: + f_print (fout, "%s%s %s[%s]", prefix, type, dec->name, + dec->array_max); + break; + case REL_POINTER: + f_print (fout, "%s%s *%s", prefix, type, dec->name); + break; + case REL_ARRAY: + f_print (fout, "struct {\n"); + tabify (fout, tab); + f_print (fout, "\tu_int %s_len;\n", dec->name); + tabify (fout, tab); + f_print (fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); + tabify (fout, tab); + f_print (fout, "} %s", dec->name); + break; } - f_print(fout, separator ); + } + f_print (fout, separator); } static int -undefined2(const char *type, const char *stop) +undefined2 (const char *type, const char *stop) { - list *l; - definition *def; - - for (l = defined; l != NULL; l = l->next) { - def = (definition *) l->val; - if (def->def_kind != DEF_PROGRAM) { - if (streq(def->def_name, stop)) { - return (1); - } else if (streq(def->def_name, type)) { - return (0); - } - } + list *l; + definition *def; + + for (l = defined; l != NULL; l = l->next) + { + def = (definition *) l->val; + if (def->def_kind != DEF_PROGRAM) + { + if (streq (def->def_name, stop)) + { + return 1; + } + else if (streq (def->def_name, type)) + { + return 0; + } } - return (1); + } + return 1; } diff --git a/sunrpc/rpc_main.c b/sunrpc/rpc_main.c index a7e18070d0..0b30d6f505 100644 --- a/sunrpc/rpc_main.c +++ b/sunrpc/rpc_main.c @@ -31,7 +31,7 @@ /* * From @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI; */ -char main_rcsid[] = +const char main_rcsid[] = "$Id$"; /* @@ -52,85 +52,89 @@ char main_rcsid[] = #include "rpc_scan.h" #include "proto.h" - #define EXTEND 1 /* alias for TRUE */ -#define DONT_EXTEND 0 /* alias for FALSE */ - -#define SVR4_CPP "/usr/ccs/lib/cpp" -#define SUNOS_CPP "/lib/cpp" -static int cppDefined = 0; /* explicit path for C preprocessor */ - -struct commandline { - int cflag; /* xdr C routines */ - int hflag; /* header file */ - int lflag; /* client side stubs */ - int mflag; /* server side stubs */ - int nflag; /* netid flag */ - int sflag; /* server stubs for the given transport */ - int tflag; /* dispatch Table file */ - int Ssflag; /* produce server sample code */ - int Scflag; /* produce client sample code */ - const char *infile; /* input module name */ - const char *outfile; /* output module name */ -}; +#define DONT_EXTEND 0 /* alias for FALSE */ + +struct commandline + { + int cflag; /* xdr C routines */ + int hflag; /* header file */ + int lflag; /* client side stubs */ + int mflag; /* server side stubs */ + int nflag; /* netid flag */ + int sflag; /* server stubs for the given transport */ + int tflag; /* dispatch Table file */ + int Ssflag; /* produce server sample code */ + int Scflag; /* produce client sample code */ + int makefileflag; /* Generate a template Makefile */ + const char *infile; /* input module name */ + const char *outfile; /* output module name */ + }; static const char *cmdname; +#define SVR4_CPP "/usr/ccs/lib/cpp" +#define SUNOS_CPP "/lib/cpp" + static const char *svcclosetime = "120"; -static const char *CPP = SVR4_CPP; +static int cppDefined = 0; /* explicit path for C preprocessor */ +static const char *CPP = SUNOS_CPP; static char CPPFLAGS[] = "-C"; static char *pathbuf; -static const char *allv[] = { - "rpcgen", "-s", "udp", "-s", "tcp", +static const char *allv[] = +{ + "rpcgen", "-s", "udp", "-s", "tcp", }; -static int allc = sizeof(allv)/sizeof(allv[0]); -static const char *allnv[] = { - "rpcgen", "-s", "netpath", +static int allc = sizeof (allv) / sizeof (allv[0]); +static const char *allnv[] = +{ + "rpcgen", "-s", "netpath", }; -static int allnc = sizeof(allnv)/sizeof(allnv[0]); +static int allnc = sizeof (allnv) / sizeof (allnv[0]); /* * machinations for handling expanding argument list */ -static void addarg(const char *); /* add another argument to the list */ -static void putarg(int, const char *); /* put argument at specified location */ -static void clear_args(void); /* clear argument list */ -static void checkfiles(const char *, const char *); - /* check if out file already exists */ - -static void clear_args(void); -static char *extendfile(const char *file, const char *ext); -static void open_output(const char *infile, const char *outfile); -static void add_warning(void); -static void clear_args(void); -static void find_cpp(void); -static void open_input(const char *infile, const char *define); -static int check_nettype(const char *name, const char *list_to_check[]); -static void c_output(const char *infile, const char *define, - int extend, const char *outfile); -static void h_output(const char *infile, const char *define, - int extend, const char *outfile); -static void s_output(int argc, const char *argv[], const char *infile, - const char *define, int extend, - const char *outfile, int nomain, int netflag); -static void l_output(const char *infile, const char *define, - int extend, const char *outfile); -static void t_output(const char *infile, const char *define, - int extend, const char *outfile); -static void svc_output(const char *infile, const char *define, - int extend, const char *outfile); -static void clnt_output(const char *infile, const char *define, +static void addarg (const char *); /* add another argument to the list */ +static void putarg (int, const char *); /* put argument at specified location */ +static void clear_args (void); /* clear argument list */ +static void checkfiles (const char *, const char *); + /* check if out file already exists */ + +static void clear_args (void); +static char *extendfile (const char *file, const char *ext); +static void open_output (const char *infile, const char *outfile); +static void add_warning (void); +static void clear_args (void); +static void find_cpp (void); +static void open_input (const char *infile, const char *define); +static int check_nettype (const char *name, const char *list_to_check[]); +static void c_output (const char *infile, const char *define, + int extend, const char *outfile); +static void h_output (const char *infile, const char *define, + int extend, const char *outfile); +static void s_output (int argc, const char *argv[], const char *infile, + const char *define, int extend, + const char *outfile, int nomain, int netflag); +static void l_output (const char *infile, const char *define, + int extend, const char *outfile); +static void t_output (const char *infile, const char *define, + int extend, const char *outfile); +static void svc_output (const char *infile, const char *define, int extend, const char *outfile); -static int do_registers(int argc, const char *argv[]); -static void addarg(const char *cp); -static void putarg(int whereto, const char *cp); -static void checkfiles(const char *infile, const char *outfile); -static int parseargs(int argc, const char *argv[], struct commandline *cmd); -static void usage(void); -static void options_usage(void); -static void c_initialize(void); -static char *generate_guard(const char *pathname); +static void clnt_output (const char *infile, const char *define, + int extend, const char *outfile); +static void mkfile_output (struct commandline *cmd); +static int do_registers (int argc, const char *argv[]); +static void addarg (const char *cp); +static void putarg (int whereto, const char *cp); +static void checkfiles (const char *infile, const char *outfile); +static int parseargs (int argc, const char *argv[], struct commandline *cmd); +static void usage (void); +static void options_usage (void); +static void c_initialize (void); +static char *generate_guard (const char *pathname); #define ARGLISTLEN 20 @@ -140,235 +144,240 @@ static const char *arglist[ARGLISTLEN]; static int argcount = FIXEDARGS; -int nonfatalerrors; /* errors */ -int inetdflag/* = 1*/; /* Support for inetd */ /* is now the default */ -int pmflag; /* Support for port monitors */ -int logflag; /* Use syslog instead of fprintf for errors */ -int tblflag; /* Support for dispatch table file */ +int nonfatalerrors; /* errors */ +int inetdflag /* = 1 */ ; /* Support for inetd *//* is now the default */ +int pmflag; /* Support for port monitors */ +int logflag; /* Use syslog instead of fprintf for errors */ +int tblflag; /* Support for dispatch table file */ +int mtflag; /* Support for MT */ #define INLINE 3 /*length at which to start doing an inline */ -int inlineflag=INLINE; /* length at which to start doing an inline. 3 = default - if 0, no xdr_inline code */ +int inlineflag = INLINE; /* length at which to start doing an inline. 3 = default + if 0, no xdr_inline code */ -int indefinitewait; /* If started by port monitors, hang till it wants */ -int exitnow; /* If started by port monitors, exit after the call */ -int timerflag; /* TRUE if !indefinite && !exitnow */ -int newstyle; /* newstyle of passing arguments (by value) */ +int indefinitewait; /* If started by port monitors, hang till it wants */ +int exitnow; /* If started by port monitors, exit after the call */ +int timerflag; /* TRUE if !indefinite && !exitnow */ +int newstyle; /* newstyle of passing arguments (by value) */ #ifdef __GNU_LIBRARY__ -int Cflag = 1 ; /* ANSI C syntax */ +int Cflag = 1; /* ANSI C syntax */ #else -int Cflag = 0 ; /* ANSI C syntax */ +int Cflag = 0; /* ANSI C/C++ syntax */ #endif -static int allfiles; /* generate all files */ +int CCflag = 0; /* C++ files */ +static int allfiles; /* generate all files */ #ifdef __GNU_LIBRARY__ -int tirpcflag = 0; /* generating code for tirpc, by default */ +int tirpcflag = 0; /* generating code for tirpc, by default */ #else -int tirpcflag = 1; /* generating code for tirpc, by default */ -#endif - -#ifdef __GNU_LIBRARY__ -int building_libc = 0; /* running as part of libc built process */ +int tirpcflag = 1; /* generating code for tirpc, by default */ #endif +xdrfunc *xdrfunc_head = NULL; /* xdr function list */ +xdrfunc *xdrfunc_tail = NULL; /* xdr function list */ int -main(int argc, const char *argv[]) +main (int argc, const char *argv[]) { - struct commandline cmd; + struct commandline cmd; - (void) memset((char *)&cmd, 0, sizeof (struct commandline)); - clear_args(); - if (!parseargs(argc, argv, &cmd)) - usage(); + (void) memset ((char *) &cmd, 0, sizeof (struct commandline)); + clear_args (); + if (!parseargs (argc, argv, &cmd)) + usage (); - if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag || - cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag ) { - checkfiles(cmd.infile, cmd.outfile); + if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag || + cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag) + { + checkfiles (cmd.infile, cmd.outfile); + } + else + checkfiles (cmd.infile, NULL); + + if (cmd.cflag) + c_output (cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile); + else if (cmd.hflag) + h_output (cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile); + else if (cmd.lflag) + l_output (cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile); + else if (cmd.sflag || cmd.mflag || (cmd.nflag)) + s_output (argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND, + cmd.outfile, cmd.mflag, cmd.nflag); + else if (cmd.tflag) + t_output (cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile); + else if (cmd.Ssflag) + svc_output (cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile); + else if (cmd.Scflag) + clnt_output (cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile); + else if (cmd.makefileflag) + mkfile_output (&cmd); + else + { + /* the rescans are required, since cpp may effect input */ + c_output (cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c"); + reinitialize (); + h_output (cmd.infile, "-DRPC_HDR", EXTEND, ".h"); + reinitialize (); + l_output (cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c"); + reinitialize (); + if (inetdflag || !tirpcflag) + s_output (allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, + "_svc.c", cmd.mflag, cmd.nflag); + else + s_output (allnc, allnv, cmd.infile, "-DRPC_SVC", + EXTEND, "_svc.c", cmd.mflag, cmd.nflag); + if (tblflag) + { + reinitialize (); + t_output (cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i"); } - else - checkfiles(cmd.infile,NULL); - - if (cmd.cflag) { - c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile); - } else if (cmd.hflag) { - h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile); - } else if (cmd.lflag) { - l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile); - } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) { - s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND, - cmd.outfile, cmd.mflag, cmd.nflag); - } else if (cmd.tflag) { - t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile); - } else if (cmd.Ssflag) { - svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile); - } else if (cmd.Scflag) { - clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile); - } else { - /* the rescans are required, since cpp may effect input */ - c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c"); - reinitialize(); - h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h"); - reinitialize(); - l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c"); - reinitialize(); - if (inetdflag || !tirpcflag ) - s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, - "_svc.c", cmd.mflag, cmd.nflag); - else - s_output(allnc, allnv, cmd.infile, "-DRPC_SVC", - EXTEND, "_svc.c", cmd.mflag, cmd.nflag); - if (tblflag) { - reinitialize(); - t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i"); - } - if (allfiles) { - reinitialize(); - svc_output(cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c"); - } - if (allfiles) { - reinitialize(); - clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c"); - } + if (allfiles) + { + reinitialize (); + svc_output (cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c"); + reinitialize (); + clnt_output (cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c"); } - exit(nonfatalerrors); - /* NOTREACHED */ + if (allfiles || (cmd.makefileflag == 1)) + { + reinitialize (); + mkfile_output (&cmd); + } + } + exit (nonfatalerrors); + /* NOTREACHED */ } /* * add extension to filename */ static char * -extendfile(const char *file, const char *ext) +extendfile (const char *file, const char *ext) { - char *res; - const char *p; - - res = alloc(strlen(file) + strlen(ext) + 1); - if (res == NULL) { - abort(); - } - p = strrchr(file, '.'); - if (p == NULL) { - p = file + strlen(file); - } - (void) strcpy(res, file); - (void) strcpy(res + (p - file), ext); - return (res); + char *res; + const char *p; + + res = alloc (strlen (file) + strlen (ext) + 1); + if (res == NULL) + abort (); + p = strrchr (file, '.'); + if (p == NULL) + p = file + strlen (file); + strcpy (res, file); + strcpy (res + (p - file), ext); + return res; } /* * Open output file with given extension */ static void -open_output(const char *infile, const char *outfile) +open_output (const char *infile, const char *outfile) { + if (outfile == NULL) + { + fout = stdout; + return; + } - if (outfile == NULL) { - fout = stdout; - return; - } - - if (infile != NULL && streq(outfile, infile)) { - f_print(stderr, "%s: output would overwrite %s\n", cmdname, - infile); - crash(); - } - fout = fopen(outfile, "w"); - if (fout == NULL) { - f_print(stderr, "%s: unable to open ", cmdname); - perror(outfile); - crash(); - } - record_open(outfile); -} - -static void -add_warning(void) -{ - f_print(fout, "/*\n"); - f_print(fout, " * Please do not edit this file.\n"); - f_print(fout, " * It was generated using rpcgen.\n"); - f_print(fout, " */\n\n"); + if (infile != NULL && streq (outfile, infile)) + { + fprintf (stderr, _ ("%s: output would overwrite %s\n"), cmdname, + infile); + crash (); + } + fout = fopen (outfile, "w"); + if (fout == NULL) + { + fprintf (stderr, _ ("%s: unable to open "), cmdname); + perror (outfile); + crash (); + } + record_open (outfile); } static void -add_stdheaders(void) +add_warning (void) { - f_print(fout, "#include <rpc/types.h>\n"); - f_print(fout, "#include <rpc/xdr.h>\n\n"); + fprintf (fout, "/*\n"); + fprintf (fout, " * Please do not edit this file.\n"); + fprintf (fout, " * It was generated using rpcgen.\n"); + fprintf (fout, " */\n\n"); } /* clear list of arguments */ -static void clear_args(void) +static void +clear_args (void) { int i; - for( i=FIXEDARGS; i<ARGLISTLEN; i++ ) + for (i = FIXEDARGS; i < ARGLISTLEN; ++i) arglist[i] = NULL; argcount = FIXEDARGS; } /* make sure that a CPP exists */ -static void find_cpp(void) +static void +find_cpp (void) { struct stat buf; - if (stat(CPP, &buf) < 0 ) { /* SVR4 or explicit cpp does not exist */ - if (cppDefined) { - 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, "cannot find any C preprocessor (cpp)\n" ); - crash(); - } + if (stat (CPP, &buf) < 0) + { /* /lib/cpp or explicit cpp does not exist */ + if (cppDefined) + { + fprintf (stderr, _ ("cannot find C preprocessor: %s \n"), CPP); + crash (); + } + else + { /* try the other one */ + CPP = SVR4_CPP; + if (stat (CPP, &buf) < 0) + { /* can't find any cpp */ + fputs (_ ("cannot find any C preprocessor (cpp)\n"), stdout); + crash (); + } + } } - } } /* * Open input file with given define for C-preprocessor */ static void -open_input(const char *infile, const char *define) +open_input (const char *infile, const char *define) { - int pd[2]; - - infilename = (infile == NULL) ? "<stdin>" : infile; - (void) pipe(pd); - switch (fork()) { - case 0: -#ifdef __GNU_LIBRARY__ - /* While building libc we don't want to use the libc from - the build directory which may be incompatible with the - installed dynamic linker. */ - if (building_libc) - unsetenv ("LD_LIBRARY_PATH"); -#endif - find_cpp(); - putarg(0, CPP); - putarg(1, CPPFLAGS); - addarg(define); - addarg(infile); - addarg((char *)NULL); - (void) close(1); - (void) dup2(pd[1], 1); - (void) close(pd[0]); - execv(arglist[0], (char **)arglist); - perror("execv"); - exit(1); - case -1: - perror("fork"); - exit(1); - } - (void) close(pd[1]); - fin = fdopen(pd[0], "r"); - if (fin == NULL) { - f_print(stderr, "%s: ", cmdname); - perror(infilename); - crash(); - } + int pd[2]; + + infilename = (infile == NULL) ? "<stdin>" : infile; + pipe (pd); + switch (fork ()) + { + case 0: + find_cpp (); + putarg (0, CPP); + putarg (1, CPPFLAGS); + addarg (define); + if (infile) + addarg (infile); + addarg ((char *) NULL); + close (1); + dup2 (pd[1], 1); + close (pd[0]); + execv (arglist[0], (char **) arglist); + perror ("execv"); + exit (1); + case -1: + perror ("fork"); + exit (1); + } + close (pd[1]); + fin = fdopen (pd[0], "r"); + if (fin == NULL) + { + fprintf (stderr, "%s: ", cmdname); + perror (infilename); + crash (); + } } /* valid tirpc nettypes */ @@ -384,7 +393,7 @@ static const char *valid_ti_nettypes[] = "tcp", "raw", NULL - }; +}; /* valid inetd nettypes */ static const char *valid_i_nettypes[] = @@ -394,14 +403,18 @@ static const char *valid_i_nettypes[] = NULL }; -static int check_nettype(const char *name, const char *list_to_check[]) { +static int +check_nettype (const char *name, const char *list_to_check[]) +{ int i; - for( i = 0; list_to_check[i] != NULL; i++ ) { - if( strcmp( name, list_to_check[i] ) == 0 ) { - return 1; - } - } - f_print( stderr, "illegal nettype :\'%s\'\n", name ); + for (i = 0; list_to_check[i] != NULL; i++) + { + if (strcmp (name, list_to_check[i]) == 0) + { + return 1; + } + } + fprintf (stderr, _ ("illegal nettype :\'%s\'\n"), name); return 0; } @@ -410,49 +423,49 @@ static int check_nettype(const char *name, const char *list_to_check[]) { */ static void -c_output(const char *infile, const char *define, int extend, - const char *outfile) +c_output (const char *infile, const char *define, int extend, + const char *outfile) { - definition *def; - char *include; - const char *outfilename; - long tell; - - c_initialize(); - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - open_output(infile, outfilename); - add_warning(); - add_stdheaders(); - if (infile && (include = extendfile(infile, ".h"))) { - f_print(fout, "#include \"%s\"\n", include); - free(include); - /* .h file already contains rpc/rpc.h */ - } else - f_print(fout, "#include <rpc/rpc.h>\n"); - tell = ftell(fout); - while ((def = get_definition())!=NULL) { - emit(def); - } - if (extend && tell == ftell(fout)) { - (void) unlink(outfilename); - } + definition *def; + char *include; + const char *outfilename; + long tell; + + c_initialize (); + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + open_output (infile, outfilename); + add_warning (); + if (infile && (include = extendfile (infile, ".h"))) + { + fprintf (fout, "#include \"%s\"\n", include); + free (include); + /* .h file already contains rpc/rpc.h */ + } + else + fprintf (fout, "#include <rpc/rpc.h>\n"); + tell = ftell (fout); + while ((def = get_definition ()) != NULL) + emit (def); + + if (extend && tell == ftell (fout)) + unlink (outfilename); } void -c_initialize(void) +c_initialize (void) { /* add all the starting basic types */ - add_type(1,"int"); - add_type(1,"long"); - add_type(1,"short"); - add_type(1,"bool"); + add_type (1, "int"); + add_type (1, "long"); + add_type (1, "short"); + add_type (1, "bool"); - add_type(1,"u_int"); - add_type(1,"u_long"); - add_type(1,"u_short"); + add_type (1, "u_int"); + add_type (1, "u_long"); + add_type (1, "u_short"); } @@ -465,23 +478,26 @@ char rpcgen_table_dcl[] = "struct rpcgen_table {\n\ };\n"; -static char *generate_guard(const char *pathname) { - const char *filename; - char *guard, *tmp; - - filename = strrchr(pathname, '/' ); /* find last component */ - filename = ((filename == NULL) ? pathname : filename+1); - guard = strdup(filename); - /* convert to upper case */ - tmp = guard; - while (*tmp) { - if (islower(*tmp)) - *tmp = toupper(*tmp); - tmp++; - } +static char * +generate_guard (const char *pathname) +{ + const char *filename; + char *guard, *tmp; + + filename = strrchr (pathname, '/'); /* find last component */ + filename = ((filename == NULL) ? pathname : filename + 1); + guard = strdup (filename); + /* convert to upper case */ + tmp = guard; + while (*tmp) + { + if (islower (*tmp)) + *tmp = toupper (*tmp); + tmp++; + } - guard = extendfile(guard, "_H_RPCGEN"); - return guard; + guard = extendfile (guard, "_H_RPCGEN"); + return guard; } /* @@ -490,256 +506,354 @@ static char *generate_guard(const char *pathname) { static void -h_output(const char *infile, const char *define, int extend, - const char *outfile) +h_output (const char *infile, const char *define, int extend, + const char *outfile) { - definition *def; - const char *ifilename; - const char *outfilename; - long tell; - char *guard; - list *l; - - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - open_output(infile, outfilename); - add_warning(); - ifilename = (infile == NULL) ? "STDIN" : infile; - guard = generate_guard( outfilename ? outfilename: ifilename ); - - f_print(fout,"#ifndef _%s\n#define _%s\n\n", guard, - guard); - - f_print(fout, "#include <rpc/rpc.h>\n\n"); - - tell = ftell(fout); - /* print data definitions */ - while ((def = get_definition())!=NULL) { - print_datadef(def); - } + xdrfunc *xdrfuncp; + definition *def; + const char *ifilename; + const char *outfilename; + long tell; + char *guard; + list *l; - /* 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) { - print_funcdef(l->val); + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + open_output (infile, outfilename); + add_warning (); + ifilename = (infile == NULL) ? "STDIN" : infile; + guard = generate_guard (outfilename ? outfilename : ifilename); + + fprintf (fout, "#ifndef _%s\n#define _%s\n\n", guard, + guard); + + fprintf (fout, "#include <rpc/rpc.h>\n\n"); + + if (mtflag) + { + fprintf (fout, "#include <pthread.h>\n"); + } + + /* put the C++ support */ + if (Cflag && !CCflag) + { + fprintf (fout, "\n#ifdef __cplusplus\n"); + fprintf (fout, "extern \"C\" {\n"); + fprintf (fout, "#endif\n\n"); + } + + tell = ftell (fout); + /* print data definitions */ + while ((def = get_definition ()) != NULL) + { + 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) + { + print_funcdef (l->val); + } + /* Now print all xdr func declarations */ + if (xdrfunc_head != NULL) + { + fprintf (fout, "\n/* the xdr functions */\n"); + if (CCflag) + { + fprintf (fout, "\n#ifdef __cplusplus\n"); + fprintf (fout, "extern \"C\" {\n"); + fprintf (fout, "#endif\n"); + } + if (!Cflag) + { + xdrfuncp = xdrfunc_head; + while (xdrfuncp != NULL) + { + print_xdr_func_def (xdrfuncp->name, + xdrfuncp->pointerp, 2); + xdrfuncp = xdrfuncp->next; + } } - if (extend && tell == ftell(fout)) { - (void) unlink(outfilename); - } else if (tblflag) { - f_print(fout, rpcgen_table_dcl); + else + { + int i; + + for (i = 1; i < 3; ++i) + { + if (i == 1) + fprintf (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); + else + fprintf (fout, "\n#else /* K&R C */\n"); + + xdrfuncp = xdrfunc_head; + while (xdrfuncp != NULL) + { + print_xdr_func_def (xdrfuncp->name, + xdrfuncp->pointerp, i); + xdrfuncp = xdrfuncp->next; + } + } + fprintf (fout, "\n#endif /* K&R C */\n"); } - f_print(fout, "\n#endif /* !_%s */\n", guard); + } + + if (extend && tell == ftell (fout)) + { + unlink (outfilename); + } + else if (tblflag) + { + fprintf (fout, rpcgen_table_dcl); + } + + if (Cflag) + { + fprintf (fout, "\n#ifdef __cplusplus\n"); + fprintf (fout, "}\n"); + fprintf (fout, "#endif\n"); + } + + fprintf (fout, "\n#endif /* !_%s */\n", guard); } /* * Compile into an RPC service */ static void -s_output(int argc, const char *argv[], const char *infile, const char *define, - int extend, const char *outfile, int nomain, int netflag) +s_output (int argc, const char *argv[], const char *infile, const char *define, + int extend, const char *outfile, int nomain, int netflag) { - char *include; - definition *def; - int foundprogram = 0; - const char *outfilename; - - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - open_output(infile, outfilename); - add_warning(); - if (infile && (include = extendfile(infile, ".h"))) { - f_print(fout, "#include \"%s\"\n", include); - free(include); - } else - f_print(fout, "#include <rpc/rpc.h>\n"); - - f_print(fout, "#include <stdio.h>\n"); - f_print(fout, "#include <stdlib.h>/* getenv, exit */\n"); - if (Cflag) { - f_print (fout, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n"); - f_print (fout, "#include <string.h> /* strcmp */ \n"); - } - if (strcmp(svcclosetime, "-1") == 0) - indefinitewait = 1; - else if (strcmp(svcclosetime, "0") == 0) - exitnow = 1; - else if (inetdflag || pmflag) { - f_print(fout, "#include <signal.h>\n"); - timerflag = 1; - } + char *include; + definition *def; + int foundprogram = 0; + const char *outfilename; + + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + open_output (infile, outfilename); + add_warning (); + if (infile && (include = extendfile (infile, ".h"))) + { + fprintf (fout, "#include \"%s\"\n", include); + free (include); + } + else + fprintf (fout, "#include <rpc/rpc.h>\n"); + + fprintf (fout, "#include <stdio.h>\n"); + fprintf (fout, "#include <stdlib.h>\n"); + if (Cflag) + { + fprintf (fout, "#include <rpc/pmap_clnt.h>\n"); + fprintf (fout, "#include <string.h>\n"); + } + if (strcmp (svcclosetime, "-1") == 0) + indefinitewait = 1; + else if (strcmp (svcclosetime, "0") == 0) + exitnow = 1; + else if (inetdflag || pmflag) + { + fprintf (fout, "#include <signal.h>\n"); + timerflag = 1; + } - if( !tirpcflag && inetdflag ) + if (!tirpcflag && inetdflag) #ifdef __GNU_LIBRARY__ - f_print(fout, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n"); + fprintf (fout, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n"); #else - f_print(fout, "#include <sys/ttycom.h>/* TIOCNOTTY */\n"); + fprintf (fout, "#include <sys/ttycom.h>/* TIOCNOTTY */\n"); #endif - if( Cflag && (inetdflag || pmflag ) ) { + if (Cflag && (inetdflag || pmflag)) + { #ifdef __GNU_LIBRARY__ - f_print(fout, "#include <sys/types.h> /* open */\n"); - f_print(fout, "#include <sys/stat.h> /* open */\n"); - f_print(fout, "#include <fcntl.h> /* open */\n"); - f_print(fout, "#include <unistd.h> /* getdtablesize */\n"); + fprintf (fout, "#include <sys/types.h> /* open */\n"); + fprintf (fout, "#include <sys/stat.h> /* open */\n"); + fprintf (fout, "#include <fcntl.h> /* open */\n"); + fprintf (fout, "#include <unistd.h> /* getdtablesize */\n"); #else - f_print(fout, "#ifdef __cplusplus\n"); - f_print(fout, "#include <sysent.h> /* getdtablesize, open */\n"); - f_print(fout, "#endif /* __cplusplus */\n"); + fprintf (fout, "#ifdef __cplusplus\n"); + fprintf (fout, "#include <sysent.h> /* getdtablesize, open */\n"); + fprintf (fout, "#endif /* __cplusplus */\n"); + if (tirpcflag) + fprintf (fout, "#include <unistd.h> /* setsid */\n"); #endif - if( tirpcflag ) - f_print(fout, "#include <unistd.h> /* setsid */\n"); - } - if( tirpcflag ) - f_print(fout, "#include <sys/types.h>\n"); + } +#ifdef __GNU_LIBRARY__ + if (tirpcflag && !(Cflag && (inetdflag || pmflag))) +#else + if (tirpcflag) +#endif + fprintf (fout, "#include <sys/types.h>\n"); - f_print(fout, "#include <memory.h>\n"); + fprintf (fout, "#include <memory.h>\n"); #ifndef __GNU_LIBRARY__ - f_print(fout, "#include <stropts.h>\n"); + fprintf (fout, "#include <stropts.h>\n"); #endif - if (inetdflag || !tirpcflag ) { - f_print(fout, "#include <sys/socket.h>\n"); - f_print(fout, "#include <netinet/in.h>\n"); - } + if (inetdflag || !tirpcflag) + { + fprintf (fout, "#include <sys/socket.h>\n"); + fprintf (fout, "#include <netinet/in.h>\n"); + } - if ( (netflag || pmflag) && tirpcflag ) { - f_print(fout, "#include <netconfig.h>\n"); - } - if (/*timerflag &&*/ tirpcflag) - f_print(fout, "#include <sys/resource.h> /* rlimit */\n"); - if (logflag || inetdflag || pmflag) { + if ((netflag || pmflag) && tirpcflag && !nomain) + { + fprintf (fout, "#include <netconfig.h>\n"); + } + if ( /*timerflag && */ tirpcflag) + fprintf (fout, "#include <sys/resource.h> /* rlimit */\n"); + if (logflag || inetdflag || pmflag) + { #ifdef __GNU_LIBRARY__ - f_print(fout, "#include <syslog.h>\n"); + fprintf (fout, "#include <syslog.h>\n"); #else - f_print(fout, "#ifdef SYSLOG\n"); - f_print(fout, "#include <syslog.h>\n"); - f_print(fout, "#else\n"); - f_print(fout, "#define LOG_ERR 1\n"); - f_print(fout, "#define openlog(a, b, c)\n"); - f_print(fout, "#endif\n"); + fprintf (fout, "#ifdef SYSLOG\n"); + fprintf (fout, "#include <syslog.h>\n"); + fprintf (fout, "#else\n"); + fprintf (fout, "#define LOG_ERR 1\n"); + fprintf (fout, "#define openlog(a, b, c)\n"); + fprintf (fout, "#endif\n"); #endif - } + } - /* for ANSI-C */ - f_print(fout, "\n#ifdef __STDC__\n#define SIG_PF void(*)(int)\n#endif\n"); + /* for ANSI-C */ + if (Cflag) + fprintf (fout, "\n#ifndef SIG_PF\n#define SIG_PF void(*)(int)\n#endif\n"); #ifndef __GNU_LIBRARY__ - f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); + fprintf (fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); #endif - if (timerflag) - f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime); - while ((def = get_definition())!=NULL) { - foundprogram |= (def->def_kind == DEF_PROGRAM); - } - if (extend && !foundprogram) { - (void) unlink(outfilename); - return; - } - write_most(infile, netflag, nomain); - if (!nomain) { - if( !do_registers(argc, argv) ) { - if (outfilename) - (void) unlink(outfilename); - usage(); - } - write_rest(); + if (timerflag) + fprintf (fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime); + while ((def = get_definition ()) != NULL) + { + foundprogram |= (def->def_kind == DEF_PROGRAM); + } + if (extend && !foundprogram) + { + unlink (outfilename); + return; + } + write_most (infile, netflag, nomain); + if (!nomain) + { + if (!do_registers (argc, argv)) + { + if (outfilename) + unlink (outfilename); + usage (); } + write_rest (); + } } /* * generate client side stubs */ static void -l_output(const char *infile, const char *define, int extend, - const char *outfile) +l_output (const char *infile, const char *define, int extend, + const char *outfile) { - char *include; - definition *def; - int foundprogram = 0; - const char *outfilename; - - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - open_output(infile, outfilename); - add_warning(); - if (Cflag) - f_print (fout, "#include <memory.h> /* for memset */\n"); - if (infile && (include = extendfile(infile, ".h"))) { - f_print(fout, "#include \"%s\"\n", include); - free(include); - } else - f_print(fout, "#include <rpc/rpc.h>\n"); - while ((def = get_definition())!=NULL) { - foundprogram |= (def->def_kind == DEF_PROGRAM); - } - if (extend && !foundprogram) { - (void) unlink(outfilename); - return; - } - write_stubs(); + char *include; + definition *def; + int foundprogram = 0; + const char *outfilename; + + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + open_output (infile, outfilename); + add_warning (); + if (Cflag) + fprintf (fout, "#include <memory.h> /* for memset */\n"); + if (infile && (include = extendfile (infile, ".h"))) + { + fprintf (fout, "#include \"%s\"\n", include); + free (include); + } + else + fprintf (fout, "#include <rpc/rpc.h>\n"); + while ((def = get_definition ()) != NULL) + { + foundprogram |= (def->def_kind == DEF_PROGRAM); + } + if (extend && !foundprogram) + { + unlink (outfilename); + return; + } + write_stubs (); } /* * generate the dispatch table */ static void -t_output(const char *infile, const char *define, int extend, - const char *outfile) +t_output (const char *infile, const char *define, int extend, + const char *outfile) { - definition *def; - int foundprogram = 0; - const char *outfilename; - - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - open_output(infile, outfilename); - add_warning(); - while ((def = get_definition())!=NULL) { - foundprogram |= (def->def_kind == DEF_PROGRAM); - } - if (extend && !foundprogram) { - (void) unlink(outfilename); - return; - } - write_tables(); + definition *def; + int foundprogram = 0; + const char *outfilename; + + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + open_output (infile, outfilename); + add_warning (); + while ((def = get_definition ()) != NULL) + { + foundprogram |= (def->def_kind == DEF_PROGRAM); + } + if (extend && !foundprogram) + { + unlink (outfilename); + return; + } + write_tables (); } /* sample routine for the server template */ static void -svc_output(const char *infile, const char *define, int extend, - const char *outfile) +svc_output (const char *infile, const char *define, int extend, + const char *outfile) { definition *def; char *include; const char *outfilename; long tell; - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - checkfiles(infile,outfilename); /*check if outfile already exists. - if so, print an error message and exit*/ - open_output(infile, outfilename); - add_sample_msg(); - - if (infile && (include = extendfile(infile, ".h"))) { - f_print(fout, "#include \"%s\"\n", include); - free(include); - } else - f_print(fout, "#include <rpc/rpc.h>\n"); - - tell = ftell(fout); - while ((def = get_definition())!=NULL) { - write_sample_svc(def); - } - if (extend && tell == ftell(fout)) { - (void) unlink(outfilename); - } + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + checkfiles (infile, outfilename); + /*check if outfile already exists. + if so, print an error message and exit */ + open_output (infile, outfilename); + add_sample_msg (); + + if (infile && (include = extendfile (infile, ".h"))) + { + fprintf (fout, "#include \"%s\"\n", include); + free (include); + } + else + fprintf (fout, "#include <rpc/rpc.h>\n"); + + tell = ftell (fout); + while ((def = get_definition ()) != NULL) + { + write_sample_svc (def); + } + if (extend && tell == ftell (fout)) + { + unlink (outfilename); + } } /* sample main routine for client */ static void -clnt_output(const char *infile, const char *define, int extend, - const char *outfile) +clnt_output (const char *infile, const char *define, int extend, + const char *outfile) { definition *def; char *include; @@ -747,87 +861,204 @@ clnt_output(const char *infile, const char *define, int extend, long tell; int has_program = 0; - open_input(infile, define); - outfilename = extend ? extendfile(infile, outfile) : outfile; - checkfiles(infile,outfilename); /*check if outfile already exists. - if so, print an error message and exit*/ - - open_output(infile, outfilename); - add_sample_msg(); - if (infile && (include = extendfile(infile, ".h"))) { - f_print(fout, "#include \"%s\"\n", include); - free(include); - } else - f_print(fout, "#include <rpc/rpc.h>\n"); - tell = ftell(fout); - while ((def = get_definition())!=NULL) { - has_program += write_sample_clnt(def); - } - - if( has_program ) - write_sample_clnt_main(); - - if (extend && tell == ftell(fout)) { - (void) unlink(outfilename); - } + open_input (infile, define); + outfilename = extend ? extendfile (infile, outfile) : outfile; + checkfiles (infile, outfilename); + /*check if outfile already exists. + if so, print an error message and exit */ + + open_output (infile, outfilename); + add_sample_msg (); + if (infile && (include = extendfile (infile, ".h"))) + { + fprintf (fout, "#include \"%s\"\n", include); + free (include); + } + else + fprintf (fout, "#include <rpc/rpc.h>\n"); + tell = ftell (fout); + while ((def = get_definition ()) != NULL) + { + has_program += write_sample_clnt (def); + } + + if (has_program) + write_sample_clnt_main (); + + if (extend && tell == ftell (fout)) + { + unlink (outfilename); + } +} + +static char * +file_name (const char *file, const char *ext) +{ + char *temp; + temp = extendfile (file, ext); + + if (access (temp, F_OK) != -1) + return (temp); + else + return ((char *) " "); +} + +static void +mkfile_output (struct commandline *cmd) +{ + char *mkfilename; + const char *clientname, *clntname, *xdrname, *hdrname; + const char *servername, *svcname, *servprogname, *clntprogname; + char *temp; + + svcname = file_name (cmd->infile, "_svc.c"); + clntname = file_name (cmd->infile, "_clnt.c"); + xdrname = file_name (cmd->infile, "_xdr.c"); + hdrname = file_name (cmd->infile, ".h"); + + if (allfiles) + { + servername = extendfile (cmd->infile, "_server.c"); + clientname = extendfile (cmd->infile, "_client.c"); + } + else + { + servername = " "; + clientname = " "; + } + servprogname = extendfile (cmd->infile, "_server"); + clntprogname = extendfile (cmd->infile, "_client"); + + if (allfiles) + { + mkfilename = alloc (strlen ("Makefile.") + + strlen (cmd->infile) + 1); + temp = (char *) rindex (cmd->infile, '.'); + strcat (mkfilename, "Makefile."); + strncat (mkfilename, cmd->infile, + (temp - cmd->infile)); + } + else + mkfilename = (char *) cmd->outfile; + + checkfiles (NULL, mkfilename); + open_output (NULL, mkfilename); + + fprintf (fout, "\n# This is a template Makefile generated by rpcgen\n"); + + f_print (fout, "\n# Parameters\n\n"); + + f_print (fout, "CLIENT = %s\nSERVER = %s\n\n", clntprogname, servprogname); + f_print (fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n"); + f_print (fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n"); + f_print (fout, "SOURCES.x = %s\n\n", cmd->infile); + f_print (fout, "TARGETS_SVC.c = %s %s %s \n", + svcname, servername, xdrname); + f_print (fout, "TARGETS_CLNT.c = %s %s %s \n", + clntname, clientname, xdrname); + f_print (fout, "TARGETS = %s %s %s %s %s %s\n\n", + hdrname, xdrname, clntname, + svcname, clientname, servername); + + f_print (fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \ +$(TARGETS_CLNT.c:%%.c=%%.o)"); + + f_print (fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \ +$(TARGETS_SVC.c:%%.c=%%.o)"); + + f_print (fout, "\n# Compiler flags \n"); + if (mtflag) + fprintf (fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS \ ++= -lnsl -lpthread \n "); + else + f_print (fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n"); + f_print (fout, "RPCGENFLAGS = \n"); + + f_print (fout, "\n# Targets \n\n"); + + f_print (fout, "all : $(CLIENT) $(SERVER)\n\n"); + f_print (fout, "$(TARGETS) : $(SOURCES.x) \n"); + f_print (fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n"); + f_print (fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \ +$(TARGETS_CLNT.c) \n\n"); + + f_print (fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \ +$(TARGETS_SVC.c) \n\n"); + f_print (fout, "$(CLIENT) : $(OBJECTS_CLNT) \n"); + f_print (fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \ +$(LDLIBS) \n\n"); + f_print (fout, "$(SERVER) : $(OBJECTS_SVC) \n"); + f_print (fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n "); + f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \ +$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n"); } /* * Perform registrations for service output * Return 0 if failed; 1 otherwise. */ -static int do_registers(int argc, const char *argv[]) +static int +do_registers (int argc, const char *argv[]) { - int i; - - if ( inetdflag || !tirpcflag) { - for (i = 1; i < argc; i++) { - if (streq(argv[i], "-s")) { - if(!check_nettype( argv[i + 1], valid_i_nettypes )) - return 0; - write_inetd_register(argv[i + 1]); - i++; - } - } - } else { - for (i = 1; i < argc; i++) - if (streq(argv[i], "-s")) { - if(!check_nettype( argv[i + 1], valid_ti_nettypes )) - return 0; - write_nettype_register(argv[i + 1]); - i++; - } else if (streq(argv[i], "-n")) { - write_netid_register(argv[i + 1]); - i++; - } + int i; + + if (inetdflag || !tirpcflag) + { + for (i = 1; i < argc; i++) + { + if (streq (argv[i], "-s")) + { + if (!check_nettype (argv[i + 1], valid_i_nettypes)) + return 0; + write_inetd_register (argv[i + 1]); + i++; + } } - return 1; + } + else + { + for (i = 1; i < argc; i++) + if (streq (argv[i], "-s")) + { + if (!check_nettype (argv[i + 1], valid_ti_nettypes)) + return 0; + write_nettype_register (argv[i + 1]); + i++; + } + else if (streq (argv[i], "-n")) + { + write_netid_register (argv[i + 1]); + i++; + } + } + return 1; } /* * Add another argument to the arg list */ static void -addarg(const char *cp) +addarg (const char *cp) { - if (argcount >= ARGLISTLEN) { - f_print(stderr, "rpcgen: too many defines\n"); - crash(); - /*NOTREACHED*/ - } - arglist[argcount++] = cp; - + if (argcount >= ARGLISTLEN) + { + fprintf (stderr, _("rpcgen: too many defines\n")); + crash (); + /*NOTREACHED */ + } + arglist[argcount++] = cp; } static void -putarg(int whereto, const char *cp) +putarg (int whereto, const char *cp) { - if (whereto >= ARGLISTLEN) { - f_print(stderr, "rpcgen: arglist coding error\n"); - crash(); - /*NOTREACHED*/ - } - arglist[whereto] = cp; + if (whereto >= ARGLISTLEN) + { + fprintf (stderr, _("rpcgen: arglist coding error\n")); + crash (); + /*NOTREACHED */ + } + arglist[whereto] = cp; } /* @@ -837,292 +1068,328 @@ putarg(int whereto, const char *cp) */ static void -checkfiles(const char *infile, const char *outfile) +checkfiles (const char *infile, const 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(); + perror (infile); + crash (); + } + if (outfile) + { + if (stat (outfile, &buf) < 0) + return; /* file does not exist */ + else + { + fprintf (stderr, + _("file '%s' already exists and may be overwritten\n"), + outfile); + crash (); + } } - } } /* * Parse command line arguments */ static int -parseargs(int argc, const char *argv[], struct commandline *cmd) +parseargs (int argc, const char *argv[], struct commandline *cmd) { - int i; - int j; - int c; - char flag[(1 << 8 * sizeof(char))]; - int nflags; - - cmdname = argv[0]; - cmd->infile = cmd->outfile = NULL; - if (argc < 2) { - return (0); + int i; + int j; + int c; + char flag[(1 << 8 * sizeof (char))]; + int nflags; + + cmdname = argv[0]; + cmd->infile = cmd->outfile = NULL; + if (argc < 2) + { + return (0); + } + allfiles = 0; + flag['c'] = 0; + flag['h'] = 0; + flag['l'] = 0; + flag['m'] = 0; + flag['o'] = 0; + flag['s'] = 0; + flag['n'] = 0; + flag['t'] = 0; + flag['S'] = 0; + flag['C'] = 0; + flag['M'] = 0; + + for (i = 1; i < argc; i++) + { + if (argv[i][0] != '-') + { + if (cmd->infile) + { + fprintf (stderr, + _("Cannot specify more than one input file!\n")); + return 0; + } + cmd->infile = argv[i]; } - allfiles = 0; - flag['c'] = 0; - flag['h'] = 0; - flag['l'] = 0; - flag['m'] = 0; - flag['o'] = 0; - flag['s'] = 0; - flag['n'] = 0; - flag['t'] = 0; - flag['S'] = 0; - flag['C'] = 0; - for (i = 1; i < argc; i++) { - if (argv[i][0] != '-') { - if (cmd->infile) { - f_print( stderr, "Cannot specify more than one input file!\n"); - - return (0); - } - cmd->infile = argv[i]; - } else { - for (j = 1; argv[i][j] != 0; j++) { - c = argv[i][j]; - switch (c) { - case 'a': - allfiles = 1; - break; - case 'c': - case 'h': - case 'l': - case 'm': - case 't': - if (flag[c]) { - return (0); - } - flag[c] = 1; - break; - case 'S': - /* sample flag: Ss or Sc. - Ss means set flag['S']; - Sc means set flag['C']; */ - c = argv[i][++j]; /* get next char */ - if( c == 's' ) - c = 'S'; - else if( c == 'c' ) - c = 'C'; - else - return( 0 ); - - if (flag[c]) { - return (0); - } - flag[c] = 1; - break; - case 'C': /* ANSI C syntax */ - Cflag = 1; - break; + else + { + for (j = 1; argv[i][j] != 0; j++) + { + c = argv[i][j]; + switch (c) + { + case 'a': + allfiles = 1; + break; + case 'c': + case 'h': + case 'l': + case 'm': + case 't': + if (flag[c]) + return 0; + flag[c] = 1; + break; + case 'S': + /* sample flag: Ss or Sc. + Ss means set flag['S']; + Sc means set flag['C']; + Sm means set flag['M']; */ + c = argv[i][++j]; /* get next char */ + if (c == 's') + c = 'S'; + else if (c == 'c') + c = 'C'; + else if (c == 'm') + c = 'M'; + else + return 0; + + if (flag[c]) + return 0; + flag[c] = 1; + break; + case 'C': /* ANSI C syntax */ + Cflag = 1; + break; #ifdef __GNU_LIBRARY__ - case 'k': /* K&R C syntax */ - Cflag = 0; - break; + case 'k': /* K&R C syntax */ + Cflag = 0; + break; #endif - case 'b': /* turn TIRPC flag off for - generating backward compatible - */ - tirpcflag = 0; - break; + case 'b': /* turn TIRPC flag off for + generating backward compatible + */ + tirpcflag = 0; + break; #ifdef __GNU_LIBRARY__ - case '5': /* turn TIRPC flag on for - generating SysVr4 compatible - */ - tirpcflag = 1; - break; - case '$': - building_libc = 1; - break; + case '5': /* turn TIRPC flag on for + generating SysVr4 compatible + */ + tirpcflag = 1; + break; #endif - case 'I': - inetdflag = 1; - break; - case 'N': - newstyle = 1; - break; - case 'L': - logflag = 1; - break; - case 'K': - if (++i == argc) { - return (0); - } - svcclosetime = argv[i]; - goto nextarg; - case 'T': - tblflag = 1; - break; - case 'i' : - if (++i == argc) { - return (0); - } - inlineflag = atoi(argv[i]); - goto nextarg; - case 'n': - case 'o': - case 's': - if (argv[i][j - 1] != '-' || - argv[i][j + 1] != 0) { - return (0); - } - flag[c] = 1; - if (++i == argc) { - return (0); - } - if (c == 's') { - if (!streq(argv[i], "udp") && - !streq(argv[i], "tcp")) { - return (0); - } - } else if (c == 'o') { - if (cmd->outfile) { - return (0); - } - cmd->outfile = argv[i]; - } - goto nextarg; - case 'D': - if (argv[i][j - 1] != '-') { - return (0); - } - (void) addarg(argv[i]); - goto nextarg; - case 'Y': - if (++i == argc) { - return (0); - } - { - size_t len = strlen (argv[i]); - pathbuf = malloc (len + 5); - if (pathbuf == NULL) { - perror(cmdname); - crash(); - } - stpcpy (stpcpy (pathbuf, - argv[i]), - "/cpp"); - CPP = pathbuf; - cppDefined = 1; - goto nextarg; - } - - - default: - return (0); - } - } - nextarg: - ; + case 'I': + inetdflag = 1; + break; + case 'N': + newstyle = 1; + break; + case 'L': + logflag = 1; + break; + case 'K': + if (++i == argc) + { + return (0); + } + svcclosetime = argv[i]; + goto nextarg; + case 'T': + tblflag = 1; + break; + case 'M': + mtflag = 1; + break; + case 'i': + if (++i == argc) + { + return (0); + } + inlineflag = atoi (argv[i]); + goto nextarg; + case 'n': + case 'o': + case 's': + if (argv[i][j - 1] != '-' || + argv[i][j + 1] != 0) + { + return (0); + } + flag[c] = 1; + if (++i == argc) + { + return (0); + } + if (c == 's') + { + if (!streq (argv[i], "udp") && + !streq (argv[i], "tcp")) + return 0; + } + else if (c == 'o') + { + if (cmd->outfile) + return 0; + cmd->outfile = argv[i]; + } + goto nextarg; + case 'D': + if (argv[i][j - 1] != '-') + return 0; + addarg (argv[i]); + goto nextarg; + case 'Y': + if (++i == argc) + return 0; + { + size_t len = strlen (argv[i]); + pathbuf = malloc (len + 5); + if (pathbuf == NULL) + { + perror (cmdname); + crash (); + } + stpcpy (stpcpy (pathbuf, + argv[i]), + "/cpp"); + CPP = pathbuf; + cppDefined = 1; + goto nextarg; + } + + default: + return 0; } + } + nextarg: + ; } + } - cmd->cflag = flag['c']; - cmd->hflag = flag['h']; - cmd->lflag = flag['l']; - cmd->mflag = flag['m']; - cmd->nflag = flag['n']; - cmd->sflag = flag['s']; - cmd->tflag = flag['t']; - cmd->Ssflag = flag['S']; - cmd->Scflag = flag['C']; - - if( tirpcflag ) { - pmflag = inetdflag ? 0 : 1; /* pmflag or inetdflag is always TRUE */ - if( (inetdflag && cmd->nflag)) { /* netid not allowed with inetdflag */ - f_print(stderr, "Cannot use netid flag with inetd flag!\n"); - return (0); - } - } else { /* 4.1 mode */ - pmflag = 0; /* set pmflag only in tirpcmode */ + cmd->cflag = flag['c']; + cmd->hflag = flag['h']; + cmd->lflag = flag['l']; + cmd->mflag = flag['m']; + cmd->nflag = flag['n']; + cmd->sflag = flag['s']; + cmd->tflag = flag['t']; + cmd->Ssflag = flag['S']; + cmd->Scflag = flag['C']; + cmd->makefileflag = flag['M']; + + if (tirpcflag) + { + pmflag = inetdflag ? 0 : 1; /* pmflag or inetdflag is always TRUE */ + if ((inetdflag && cmd->nflag)) + { /* netid not allowed with inetdflag */ + fprintf (stderr, _("Cannot use netid flag with inetd flag!\n")); + return 0; + } + } + else + { /* 4.1 mode */ + pmflag = 0; /* set pmflag only in tirpcmode */ #ifndef __GNU_LIBRARY__ - inetdflag = 1; /* inetdflag is TRUE by default */ + inetdflag = 1; /* inetdflag is TRUE by default */ #endif - if( cmd->nflag ) { /* netid needs TIRPC */ - f_print( stderr, "Cannot use netid flag without TIRPC!\n"); - return( 0 ); - } + if (cmd->nflag) + { /* netid needs TIRPC */ + f_print (stderr, _("Cannot use netid flag without TIRPC!\n")); + return (0); } + } - if( newstyle && ( tblflag || cmd->tflag) ) { - f_print( stderr, "Cannot use table flags with newstyle!\n"); - return( 0 ); - } + if (newstyle && (tblflag || cmd->tflag)) + { + f_print (stderr, _("Cannot use table flags with newstyle!\n")); + return (0); + } - /* check no conflicts with file generation flags */ - nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag + - cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag; + /* check no conflicts with file generation flags */ + nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag + + cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag; - if (nflags == 0) { - if (cmd->outfile != NULL || cmd->infile == NULL) { - return (0); - } - } else if (nflags > 1) { - f_print( stderr, "Cannot have more than one file generation flag!\n"); - return (0); + if (nflags == 0) + { + if (cmd->outfile != NULL || cmd->infile == NULL) + { + return (0); } - return (1); + } + else if (cmd->infile == NULL && + (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) + { + fprintf (stderr, + _("\"infile\" is required for template generation flags.\n")); + return 0; + } + if (nflags > 1) + { + fprintf (stderr, _("Cannot have more than one file generation flag!\n")); + return 0; + } + return 1; } static void -usage(void) +usage (void) { - f_print(stderr, "usage: %s infile\n", cmdname); - f_print(stderr, "\t%s [-a][-b][-C][-Dname[=value]] -i size [-I [-K seconds]] [-L][-N][-T] infile\n", - cmdname); - f_print(stderr, "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss] [-o outfile] [infile]\n", - cmdname); - f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname); - f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname); - options_usage(); - exit(1); + fprintf (stderr, _("usage: %s infile\n"), cmdname); + fprintf (stderr, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \ +[-I [-K seconds]] [-Y path] infile\n"), cmdname); + fprintf (stderr, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \ +[-o outfile] [infile]\n"), cmdname); + fprintf (stderr, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname); + fprintf (stderr, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname); + options_usage (); + exit (1); } static void -options_usage(void) +options_usage (void) { - f_print(stderr, "options:\n"); - f_print(stderr, "-a\t\tgenerate all files, including samples\n"); - f_print(stderr, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n"); - f_print(stderr, "-c\t\tgenerate XDR routines\n"); - f_print(stderr, "-C\t\tANSI C mode\n"); - f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n"); - f_print(stderr, "-h\t\tgenerate header file\n"); - f_print(stderr, "-i size\t\tsize at which to start generating inline code\n"); - f_print(stderr, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n"); - f_print(stderr, "-K seconds\tserver exits after K seconds of inactivity\n"); - f_print(stderr, "-l\t\tgenerate client side stubs\n"); - f_print(stderr, "-L\t\tserver errors will be printed to syslog\n"); - f_print(stderr, "-m\t\tgenerate server side stubs\n"); - f_print(stderr, "-n netid\tgenerate server code that supports named netid\n"); - f_print(stderr, "-N\t\tsupports multiple arguments and call-by-value\n"); - f_print(stderr, "-o outfile\tname of the output file\n"); - f_print(stderr, "-s nettype\tgenerate server code that supports named nettype\n"); - f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote procedures\n"); - f_print(stderr, "-Ss\t\tgenerate sample server code that defines remote procedures\n"); - f_print(stderr, "-t\t\tgenerate RPC dispatch table\n"); - f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n"); - f_print(stderr, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n"); - - exit(1); + f_print (stderr, "options:\n"); + f_print (stderr, "-a\t\tgenerate all files, including samples\n"); + f_print (stderr, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n"); + f_print (stderr, "-c\t\tgenerate XDR routines\n"); + f_print (stderr, "-C\t\tANSI C mode\n"); + f_print (stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n"); + f_print (stderr, "-h\t\tgenerate header file\n"); + f_print (stderr, "-i size\t\tsize at which to start generating inline code\n"); + f_print (stderr, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n"); + f_print (stderr, "-K seconds\tserver exits after K seconds of inactivity\n"); + f_print (stderr, "-l\t\tgenerate client side stubs\n"); + f_print (stderr, "-L\t\tserver errors will be printed to syslog\n"); + f_print (stderr, "-m\t\tgenerate server side stubs\n"); + f_print (stderr, "-M\t\tgenerate MT-safe code\n"); + f_print (stderr, "-n netid\tgenerate server code that supports named netid\n"); + f_print (stderr, "-N\t\tsupports multiple arguments and call-by-value\n"); + f_print (stderr, "-o outfile\tname of the output file\n"); + f_print (stderr, "-s nettype\tgenerate server code that supports named nettype\n"); + f_print (stderr, "-Sc\t\tgenerate sample client code that uses remote procedures\n"); + f_print (stderr, "-Ss\t\tgenerate sample server code that defines remote procedures\n"); + f_print (stderr, "-Sm \t\tgenerate makefile template \n"); + f_print (stderr, "-t\t\tgenerate RPC dispatch table\n"); + f_print (stderr, "-T\t\tgenerate code to support RPC dispatch tables\n"); + f_print (stderr, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n"); + + exit (1); } diff --git a/sunrpc/rpc_parse.c b/sunrpc/rpc_parse.c index 92f365eeb0..e6c4e4a7aa 100644 --- a/sunrpc/rpc_parse.c +++ b/sunrpc/rpc_parse.c @@ -31,11 +31,11 @@ /* * From: @(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI */ -char parse_rcsid[] = +const char parse_rcsid[] = "$Id$"; /* - * rpc_parse.c, Parser for the RPC protocol compiler + * rpc_parse.c, Parser for the RPC protocol compiler * Copyright (C) 1987 Sun Microsystems, Inc. */ #include <stdio.h> @@ -48,241 +48,256 @@ char parse_rcsid[] = #define ARGNAME "arg" -static void isdefined(definition *defp); -static void def_struct(definition *defp); -static void def_program(definition *defp); -static void def_enum(definition *defp); -static void def_const(definition *defp); -static void def_union(definition *defp); -static void check_type_name(const char *name, int new_type); -static void def_typedef(definition *defp); -static void get_declaration(declaration *dec, defkind dkind); -static void get_prog_declaration(declaration *dec, defkind dkind, int num); -static void get_type(const char **prefixp, const char **typep, defkind dkind); -static void unsigned_dec(const char **typep); +static void isdefined (definition * defp); +static void def_struct (definition * defp); +static void def_program (definition * defp); +static void def_enum (definition * defp); +static void def_const (definition * defp); +static void def_union (definition * defp); +static void check_type_name (const char *name, int new_type); +static void def_typedef (definition * defp); +static void get_declaration (declaration * dec, defkind dkind); +static void get_prog_declaration (declaration * dec, defkind dkind, int num); +static void get_type (const char **prefixp, const char **typep, defkind dkind); +static void unsigned_dec (const char **typep); /* * return the next definition you see */ definition * -get_definition(void) +get_definition (void) { - definition *defp; - token tok; - - defp = ALLOC(definition); - get_token(&tok); - switch (tok.kind) { - case TOK_STRUCT: - def_struct(defp); - break; - case TOK_UNION: - def_union(defp); - break; - case TOK_TYPEDEF: - def_typedef(defp); - break; - case TOK_ENUM: - def_enum(defp); - break; - case TOK_PROGRAM: - def_program(defp); - break; - case TOK_CONST: - def_const(defp); - break; - case TOK_EOF: - return (NULL); - default: - error("definition keyword expected"); - } - scan(TOK_SEMICOLON, &tok); - isdefined(defp); - return (defp); + definition *defp; + token tok; + + defp = ALLOC (definition); + get_token (&tok); + switch (tok.kind) + { + case TOK_STRUCT: + def_struct (defp); + break; + case TOK_UNION: + def_union (defp); + break; + case TOK_TYPEDEF: + def_typedef (defp); + break; + case TOK_ENUM: + def_enum (defp); + break; + case TOK_PROGRAM: + def_program (defp); + break; + case TOK_CONST: + def_const (defp); + break; + case TOK_EOF: + return (NULL); + default: + error ("definition keyword expected"); + } + scan (TOK_SEMICOLON, &tok); + isdefined (defp); + return (defp); } static void -isdefined(definition *defp) +isdefined (definition * defp) { - STOREVAL(&defined, defp); + STOREVAL (&defined, defp); } static void -def_struct(definition *defp) +def_struct (definition * defp) { - token tok; - declaration dec; - decl_list *decls; - decl_list **tailp; - - defp->def_kind = DEF_STRUCT; - - scan(TOK_IDENT, &tok); - defp->def_name = tok.str; - scan(TOK_LBRACE, &tok); - tailp = &defp->def.st.decls; - do { - get_declaration(&dec, DEF_STRUCT); - decls = ALLOC(decl_list); - decls->decl = dec; - *tailp = decls; - tailp = &decls->next; - scan(TOK_SEMICOLON, &tok); - peek(&tok); - } while (tok.kind != TOK_RBRACE); - get_token(&tok); - *tailp = NULL; + token tok; + declaration dec; + decl_list *decls; + decl_list **tailp; + + defp->def_kind = DEF_STRUCT; + + scan (TOK_IDENT, &tok); + defp->def_name = tok.str; + scan (TOK_LBRACE, &tok); + tailp = &defp->def.st.decls; + do + { + get_declaration (&dec, DEF_STRUCT); + decls = ALLOC (decl_list); + decls->decl = dec; + *tailp = decls; + tailp = &decls->next; + scan (TOK_SEMICOLON, &tok); + peek (&tok); + } + while (tok.kind != TOK_RBRACE); + get_token (&tok); + *tailp = NULL; } static void -def_program(definition *defp) +def_program (definition * defp) { - token tok; - declaration dec; - decl_list *decls; - decl_list **tailp; - version_list *vlist; - version_list **vtailp; - proc_list *plist; - proc_list **ptailp; - int num_args; - bool_t isvoid = FALSE; /* whether first argument is void */ - defp->def_kind = DEF_PROGRAM; - scan(TOK_IDENT, &tok); - defp->def_name = tok.str; - scan(TOK_LBRACE, &tok); - vtailp = &defp->def.pr.versions; - tailp = &defp->def.st.decls; - scan(TOK_VERSION, &tok); - do { - scan(TOK_IDENT, &tok); - vlist = ALLOC(version_list); - vlist->vers_name = tok.str; - scan(TOK_LBRACE, &tok); - ptailp = &vlist->procs; - do { - /* get result type */ - plist = ALLOC(proc_list); - get_type(&plist->res_prefix, &plist->res_type, - DEF_PROGRAM); - if (streq(plist->res_type, "opaque")) { - error("illegal result type"); - } - scan(TOK_IDENT, &tok); - plist->proc_name = tok.str; - scan(TOK_LPAREN, &tok); - /* get args - first one*/ - num_args = 1; - isvoid = FALSE; - /* type of DEF_PROGRAM in the first - * get_prog_declaration and DEF_STURCT in the next - * allows void as argument if it is the only argument - */ - get_prog_declaration(&dec, DEF_PROGRAM, num_args); - if (streq(dec.type, "void")) - isvoid = TRUE; - decls = ALLOC(decl_list); - plist->args.decls = decls; - decls->decl = dec; - tailp = &decls->next; - /* get args */ - while(peekscan(TOK_COMMA, &tok)) { - num_args++; - get_prog_declaration(&dec, DEF_STRUCT, - num_args); - decls = ALLOC(decl_list); - decls->decl = dec; - *tailp = decls; - if (streq(dec.type, "void")) - isvoid = TRUE; - tailp = &decls->next; - } - /* multiple arguments are only allowed in newstyle */ - if( !newstyle && num_args > 1 ) { - error("only one argument is allowed" ); - } - if (isvoid && num_args > 1) { - error("illegal use of void in program definition"); - } - *tailp = NULL; - scan(TOK_RPAREN, &tok); - scan(TOK_EQUAL, &tok); - scan_num(&tok); - scan(TOK_SEMICOLON, &tok); - plist->proc_num = tok.str; - plist->arg_num = num_args; - *ptailp = plist; - ptailp = &plist->next; - peek(&tok); - } while (tok.kind != TOK_RBRACE); - *ptailp = NULL; - *vtailp = vlist; - vtailp = &vlist->next; - scan(TOK_RBRACE, &tok); - scan(TOK_EQUAL, &tok); - 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) { - plist->args.argname = make_argname(plist->proc_name, - vlist->vers_num); - /* free the memory ??*/ - } - scan(TOK_SEMICOLON, &tok); - scan2(TOK_VERSION, TOK_RBRACE, &tok); - } while (tok.kind == TOK_VERSION); - scan(TOK_EQUAL, &tok); - scan_num(&tok); - defp->def.pr.prog_num = tok.str; - *vtailp = NULL; + token tok; + declaration dec; + decl_list *decls; + decl_list **tailp; + version_list *vlist; + version_list **vtailp; + proc_list *plist; + proc_list **ptailp; + int num_args; + bool_t isvoid = FALSE; /* whether first argument is void */ + defp->def_kind = DEF_PROGRAM; + scan (TOK_IDENT, &tok); + defp->def_name = tok.str; + scan (TOK_LBRACE, &tok); + vtailp = &defp->def.pr.versions; + tailp = &defp->def.st.decls; + scan (TOK_VERSION, &tok); + do + { + scan (TOK_IDENT, &tok); + vlist = ALLOC (version_list); + vlist->vers_name = tok.str; + scan (TOK_LBRACE, &tok); + ptailp = &vlist->procs; + do + { + /* get result type */ + plist = ALLOC (proc_list); + get_type (&plist->res_prefix, &plist->res_type, + DEF_PROGRAM); + if (streq (plist->res_type, "opaque")) + { + error ("illegal result type"); + } + scan (TOK_IDENT, &tok); + plist->proc_name = tok.str; + scan (TOK_LPAREN, &tok); + /* get args - first one */ + num_args = 1; + isvoid = FALSE; + /* type of DEF_PROGRAM in the first + * get_prog_declaration and DEF_STURCT in the next + * allows void as argument if it is the only argument + */ + get_prog_declaration (&dec, DEF_PROGRAM, num_args); + if (streq (dec.type, "void")) + isvoid = TRUE; + decls = ALLOC (decl_list); + plist->args.decls = decls; + decls->decl = dec; + tailp = &decls->next; + /* get args */ + while (peekscan (TOK_COMMA, &tok)) + { + num_args++; + get_prog_declaration (&dec, DEF_STRUCT, + num_args); + decls = ALLOC (decl_list); + decls->decl = dec; + *tailp = decls; + if (streq (dec.type, "void")) + isvoid = TRUE; + tailp = &decls->next; + } + /* multiple arguments are only allowed in newstyle */ + if (!newstyle && num_args > 1) + { + error ("only one argument is allowed"); + } + if (isvoid && num_args > 1) + { + error ("illegal use of void in program definition"); + } + *tailp = NULL; + scan (TOK_RPAREN, &tok); + scan (TOK_EQUAL, &tok); + scan_num (&tok); + scan (TOK_SEMICOLON, &tok); + plist->proc_num = tok.str; + plist->arg_num = num_args; + *ptailp = plist; + ptailp = &plist->next; + peek (&tok); + } + while (tok.kind != TOK_RBRACE); + *ptailp = NULL; + *vtailp = vlist; + vtailp = &vlist->next; + scan (TOK_RBRACE, &tok); + scan (TOK_EQUAL, &tok); + 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) + { + plist->args.argname = make_argname (plist->proc_name, + vlist->vers_num); + /* free the memory ?? */ + } + scan (TOK_SEMICOLON, &tok); + scan2 (TOK_VERSION, TOK_RBRACE, &tok); + } + while (tok.kind == TOK_VERSION); + scan (TOK_EQUAL, &tok); + scan_num (&tok); + defp->def.pr.prog_num = tok.str; + *vtailp = NULL; } static void -def_enum(definition *defp) +def_enum (definition * defp) { - token tok; - enumval_list *elist; - enumval_list **tailp; - - defp->def_kind = DEF_ENUM; - scan(TOK_IDENT, &tok); - defp->def_name = tok.str; - scan(TOK_LBRACE, &tok); - tailp = &defp->def.en.vals; - do { - scan(TOK_IDENT, &tok); - elist = ALLOC(enumval_list); - elist->name = tok.str; - elist->assignment = NULL; - scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok); - if (tok.kind == TOK_EQUAL) { - scan_num(&tok); - elist->assignment = tok.str; - scan2(TOK_COMMA, TOK_RBRACE, &tok); - } - *tailp = elist; - tailp = &elist->next; - } while (tok.kind != TOK_RBRACE); - *tailp = NULL; + token tok; + enumval_list *elist; + enumval_list **tailp; + + defp->def_kind = DEF_ENUM; + scan (TOK_IDENT, &tok); + defp->def_name = tok.str; + scan (TOK_LBRACE, &tok); + tailp = &defp->def.en.vals; + do + { + scan (TOK_IDENT, &tok); + elist = ALLOC (enumval_list); + elist->name = tok.str; + elist->assignment = NULL; + scan3 (TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok); + if (tok.kind == TOK_EQUAL) + { + scan_num (&tok); + elist->assignment = tok.str; + scan2 (TOK_COMMA, TOK_RBRACE, &tok); + } + *tailp = elist; + tailp = &elist->next; + } + while (tok.kind != TOK_RBRACE); + *tailp = NULL; } static void -def_const(definition *defp) +def_const (definition * defp) { - token tok; - - defp->def_kind = DEF_CONST; - scan(TOK_IDENT, &tok); - defp->def_name = tok.str; - scan(TOK_EQUAL, &tok); - scan2(TOK_IDENT, TOK_STRCONST, &tok); - defp->def.co = tok.str; + token tok; + + defp->def_kind = DEF_CONST; + scan (TOK_IDENT, &tok); + defp->def_name = tok.str; + scan (TOK_EQUAL, &tok); + scan2 (TOK_IDENT, TOK_STRCONST, &tok); + defp->def.co = tok.str; } static void -def_union(definition *defp) +def_union (definition *defp) { token tok; declaration dec; @@ -292,67 +307,71 @@ def_union(definition *defp) int flag; defp->def_kind = DEF_UNION; - scan(TOK_IDENT, &tok); + scan (TOK_IDENT, &tok); defp->def_name = tok.str; - scan(TOK_SWITCH, &tok); - scan(TOK_LPAREN, &tok); - get_declaration(&dec, DEF_UNION); + scan (TOK_SWITCH, &tok); + scan (TOK_LPAREN, &tok); + get_declaration (&dec, DEF_UNION); defp->def.un.enum_decl = dec; tailp = &defp->def.un.cases; - scan(TOK_RPAREN, &tok); - scan(TOK_LBRACE, &tok); - scan(TOK_CASE, &tok); - while (tok.kind == TOK_CASE) { - scan2(TOK_IDENT, TOK_CHARCONST, &tok); - cases = ALLOC(case_list); - cases->case_name = tok.str; - scan(TOK_COLON, &tok); - /* now peek at next token */ - flag=0; - if(peekscan(TOK_CASE,&tok)) - { - - do - { - scan2(TOK_IDENT, TOK_CHARCONST, &tok); - cases->contflag=1; /* continued case statement */ - *tailp = cases; - tailp = &cases->next; - cases = ALLOC(case_list); - cases->case_name = tok.str; - scan(TOK_COLON, &tok); - - }while(peekscan(TOK_CASE,&tok)); - } - else - if(flag) + scan (TOK_RPAREN, &tok); + scan (TOK_LBRACE, &tok); + scan (TOK_CASE, &tok); + while (tok.kind == TOK_CASE) + { + scan2 (TOK_IDENT, TOK_CHARCONST, &tok); + cases = ALLOC (case_list); + cases->case_name = tok.str; + scan (TOK_COLON, &tok); + /* now peek at next token */ + flag = 0; + if (peekscan (TOK_CASE, &tok)) + { + + do + { + scan2 (TOK_IDENT, TOK_CHARCONST, &tok); + cases->contflag = 1; /* continued case statement */ + *tailp = cases; + tailp = &cases->next; + cases = ALLOC (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 = ALLOC(case_list); + cases = ALLOC (case_list); }; - get_declaration(&dec, DEF_UNION); - cases->case_decl = dec; - cases->contflag=0; /* no continued case statement */ - *tailp = cases; - tailp = &cases->next; - scan(TOK_SEMICOLON, &tok); + get_declaration (&dec, DEF_UNION); + cases->case_decl = dec; + cases->contflag = 0; /* no continued case statement */ + *tailp = cases; + tailp = &cases->next; + scan (TOK_SEMICOLON, &tok); - scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok); - } + scan3 (TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok); + } *tailp = NULL; - 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 = dec; - scan(TOK_SEMICOLON, &tok); - scan(TOK_RBRACE, &tok); - } else { - defp->def.un.default_decl = NULL; - } + 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 = dec; + scan (TOK_SEMICOLON, &tok); + scan (TOK_RBRACE, &tok); + } + else + { + defp->def.un.default_decl = NULL; + } } static const char *reserved_words[] = @@ -370,253 +389,287 @@ static const char *reserved_words[] = "union", "vector", NULL - }; +}; static const 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. + * xdr routines that would conflict with internal XDR routines. */ -static void check_type_name(const char *name, int new_type) +static void +check_type_name (const 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 ) { - sprintf(tmp, - "illegal (reserved) name :\'%s\' in type definition", name ); - error(tmp); + for (i = 0; reserved_words[i] != NULL; i++) + { + if (strcmp (name, reserved_words[i]) == 0) + { + sprintf (tmp, + "illegal (reserved) name :\'%s\' in type definition", name); + error (tmp); + } } - } - if( new_type ) { - for( i = 0; reserved_types[i] != NULL; i++ ) { - if( strcmp( name, reserved_types[i] ) == 0 ) { - sprintf(tmp, - "illegal (reserved) name :\'%s\' in type definition", name ); - error(tmp); - } + if (new_type) + { + for (i = 0; reserved_types[i] != NULL; i++) + { + if (strcmp (name, reserved_types[i]) == 0) + { + sprintf (tmp, + "illegal (reserved) name :\'%s\' in type definition", name); + error (tmp); + } + } } - } } static void -def_typedef(definition *defp) +def_typedef (definition * defp) { - declaration dec; - - defp->def_kind = DEF_TYPEDEF; - get_declaration(&dec, DEF_TYPEDEF); - defp->def_name = dec.name; - check_type_name(dec.name, 1); - defp->def.ty.old_prefix = dec.prefix; - defp->def.ty.old_type = dec.type; - defp->def.ty.rel = dec.rel; - defp->def.ty.array_max = dec.array_max; + declaration dec; + + defp->def_kind = DEF_TYPEDEF; + get_declaration (&dec, DEF_TYPEDEF); + defp->def_name = dec.name; + check_type_name (dec.name, 1); + defp->def.ty.old_prefix = dec.prefix; + defp->def.ty.old_type = dec.type; + defp->def.ty.rel = dec.rel; + defp->def.ty.array_max = dec.array_max; } static void -get_declaration(declaration *dec, defkind dkind) +get_declaration (declaration * dec, defkind dkind) { - token tok; + token tok; - get_type(&dec->prefix, &dec->type, dkind); - dec->rel = REL_ALIAS; - if (streq(dec->type, "void")) { - return; - } + get_type (&dec->prefix, &dec->type, dkind); + dec->rel = REL_ALIAS; + if (streq (dec->type, "void")) + { + return; + } - check_type_name(dec->type, 0); + check_type_name (dec->type, 0); - scan2(TOK_STAR, TOK_IDENT, &tok); - if (tok.kind == TOK_STAR) { - dec->rel = REL_POINTER; - scan(TOK_IDENT, &tok); + scan2 (TOK_STAR, TOK_IDENT, &tok); + if (tok.kind == TOK_STAR) + { + dec->rel = REL_POINTER; + scan (TOK_IDENT, &tok); + } + dec->name = tok.str; + if (peekscan (TOK_LBRACKET, &tok)) + { + if (dec->rel == REL_POINTER) + { + error ("no array-of-pointer declarations -- use typedef"); } - dec->name = tok.str; - if (peekscan(TOK_LBRACKET, &tok)) { - 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) { - 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 */ - } else { - scan_num(&tok); - dec->array_max = tok.str; - scan(TOK_RANGLE, &tok); - } + 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) + { + error ("no array-of-pointer declarations -- use typedef"); } - if (streq(dec->type, "opaque")) { - if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) { - error("array declaration expected"); - } - } else if (streq(dec->type, "string")) { - if (dec->rel != REL_ARRAY) { - error("variable-length array declaration expected"); - } + dec->rel = REL_ARRAY; + if (peekscan (TOK_RANGLE, &tok)) + { + dec->array_max = "~0"; /* unspecified size, use max */ } + else + { + scan_num (&tok); + dec->array_max = tok.str; + scan (TOK_RANGLE, &tok); + } + } + if (streq (dec->type, "opaque")) + { + if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) + { + error ("array declaration expected"); + } + } + else if (streq (dec->type, "string")) + { + if (dec->rel != REL_ARRAY) + { + error ("variable-length array declaration expected"); + } + } } - static void -get_prog_declaration(declaration *dec, defkind dkind, int num /* arg number */) +get_prog_declaration (declaration * dec, defkind dkind, int num /* arg number */ ) { - token tok; - char name[10]; /* argument name */ - - if (dkind == DEF_PROGRAM) { - peek(&tok); - if (tok.kind == TOK_RPAREN) { /* no arguments */ - dec->rel = REL_ALIAS; - dec->type = "void"; - dec->prefix = NULL; - dec->name = NULL; - return; - } - } - get_type(&dec->prefix, &dec->type, dkind); - dec->rel = REL_ALIAS; - if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ - strcpy(name, tok.str); - else - sprintf(name, "%s%d", ARGNAME, num); /* default name of argument */ - - dec->name = (char *) strdup(name); - - if (streq(dec->type, "void")) { - return; + token tok; + char name[10]; /* argument name */ + + if (dkind == DEF_PROGRAM) + { + peek (&tok); + if (tok.kind == TOK_RPAREN) + { /* no arguments */ + dec->rel = REL_ALIAS; + dec->type = "void"; + dec->prefix = NULL; + dec->name = NULL; + return; } + } + get_type (&dec->prefix, &dec->type, dkind); + dec->rel = REL_ALIAS; + if (peekscan (TOK_IDENT, &tok)) /* optional name of argument */ + strcpy (name, tok.str); + else + sprintf (name, "%s%d", ARGNAME, num); /* default name of argument */ + + dec->name = (char *) strdup (name); + + if (streq (dec->type, "void")) + { + return; + } - if (streq(dec->type, "opaque")) { - error("opaque -- illegal argument type"); + 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 in program arguments\n"); } - if (peekscan(TOK_STAR, &tok)) { - if (streq(dec->type, "string")) { - error("pointer to string not allowed in program arguments\n"); - } - dec->rel = REL_POINTER; - if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ - dec->name = strdup(tok.str); - } - if (peekscan(TOK_LANGLE, &tok)) { - if (!streq(dec->type, "string")) { - error("arrays cannot be declared as arguments to procedures -- use typedef"); - } - dec->rel = REL_ARRAY; - if (peekscan(TOK_RANGLE, &tok)) { - dec->array_max = "~0";/* unspecified size, use max */ - } else { - scan_num(&tok); - dec->array_max = tok.str; - scan(TOK_RANGLE, &tok); - } + dec->rel = REL_POINTER; + if (peekscan (TOK_IDENT, &tok)) /* optional name of argument */ + dec->name = strdup (tok.str); + } + if (peekscan (TOK_LANGLE, &tok)) + { + if (!streq (dec->type, "string")) + { + error ("arrays cannot be declared as arguments to procedures -- use typedef"); + } + dec->rel = REL_ARRAY; + if (peekscan (TOK_RANGLE, &tok)) + { + dec->array_max = "~0"; /* unspecified size, use max */ } - if (streq(dec->type, "string")) { - if (dec->rel != REL_ARRAY) { /* .x specifies just string as - * type of argument - * - make it string<> - */ - dec->rel = REL_ARRAY; - dec->array_max = "~0";/* unspecified size, use max */ - } + else + { + scan_num (&tok); + dec->array_max = tok.str; + scan (TOK_RANGLE, &tok); + } + } + if (streq (dec->type, "string")) + { + if (dec->rel != REL_ARRAY) + { /* .x specifies just string as + * type of argument + * - make it string<> + */ + dec->rel = REL_ARRAY; + dec->array_max = "~0"; /* unspecified size, use max */ } + } } - - static void -get_type(const char **prefixp, const char **typep, defkind dkind) +get_type (const char **prefixp, const char **typep, defkind dkind) { - token tok; - - *prefixp = NULL; - get_token(&tok); - switch (tok.kind) { - case TOK_IDENT: - *typep = tok.str; - break; - case TOK_STRUCT: - case TOK_ENUM: - case TOK_UNION: - *prefixp = tok.str; - scan(TOK_IDENT, &tok); - *typep = tok.str; - break; - case TOK_UNSIGNED: - unsigned_dec(typep); - break; - case TOK_SHORT: - *typep = "short"; - (void) peekscan(TOK_INT, &tok); - break; - case TOK_LONG: - *typep = "long"; - (void) peekscan(TOK_INT, &tok); - break; - case TOK_VOID: - if (dkind != DEF_UNION && dkind != DEF_PROGRAM) { - error("voids allowed only inside union and program definitions with one argument"); - } - *typep = tok.str; - break; - case TOK_STRING: - case TOK_OPAQUE: - case TOK_CHAR: - case TOK_INT: - case TOK_FLOAT: - case TOK_DOUBLE: - case TOK_BOOL: - *typep = tok.str; - break; - default: - error("expected type specifier"); + token tok; + + *prefixp = NULL; + get_token (&tok); + switch (tok.kind) + { + case TOK_IDENT: + *typep = tok.str; + break; + case TOK_STRUCT: + case TOK_ENUM: + case TOK_UNION: + *prefixp = tok.str; + scan (TOK_IDENT, &tok); + *typep = tok.str; + break; + case TOK_UNSIGNED: + unsigned_dec (typep); + break; + case TOK_SHORT: + *typep = "short"; + (void) peekscan (TOK_INT, &tok); + break; + case TOK_LONG: + *typep = "long"; + (void) peekscan (TOK_INT, &tok); + break; + case TOK_VOID: + if (dkind != DEF_UNION && dkind != DEF_PROGRAM) + { + error ("voids allowed only inside union and program definitions with one argument"); } + *typep = tok.str; + break; + case TOK_STRING: + case TOK_OPAQUE: + case TOK_CHAR: + case TOK_INT: + case TOK_FLOAT: + case TOK_DOUBLE: + case TOK_BOOL: + *typep = tok.str; + break; + default: + error ("expected type specifier"); + } } static void -unsigned_dec(const char **typep) +unsigned_dec (const char **typep) { - token tok; - - peek(&tok); - switch (tok.kind) { - case TOK_CHAR: - get_token(&tok); - *typep = "u_char"; - break; - case TOK_SHORT: - get_token(&tok); - *typep = "u_short"; - (void) peekscan(TOK_INT, &tok); - break; - case TOK_LONG: - get_token(&tok); - *typep = "u_long"; - (void) peekscan(TOK_INT, &tok); - break; - case TOK_INT: - get_token(&tok); - *typep = "u_int"; - break; - default: - *typep = "u_int"; - break; - } + token tok; + + peek (&tok); + switch (tok.kind) + { + case TOK_CHAR: + get_token (&tok); + *typep = "u_char"; + break; + case TOK_SHORT: + get_token (&tok); + *typep = "u_short"; + (void) peekscan (TOK_INT, &tok); + break; + case TOK_LONG: + get_token (&tok); + *typep = "u_long"; + (void) peekscan (TOK_INT, &tok); + break; + case TOK_INT: + get_token (&tok); + *typep = "u_int"; + break; + default: + *typep = "u_int"; + break; + } } diff --git a/sunrpc/rpc_sample.c b/sunrpc/rpc_sample.c index d1e1277c5b..89bfc7f5a0 100644 --- a/sunrpc/rpc_sample.c +++ b/sunrpc/rpc_sample.c @@ -69,14 +69,14 @@ write_sample_clnt (definition * def) int count = 0; if (def->def_kind != DEF_PROGRAM) - return (0); + return 0; /* generate sample code for each version */ for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { write_sample_client (def->def_name, vp); ++count; } - return (count); + return count; } @@ -90,7 +90,7 @@ write_sample_client (const char *program_name, version_list * vp) f_print (fout, "\n\nvoid\n"); pvname (program_name, vp->vers_num); if (Cflag) - f_print (fout, "( char* host )\n{\n"); + f_print (fout, "(char *host)\n{\n"); else f_print (fout, "(host)\nchar *host;\n{\n"); f_print (fout, "\tCLIENT *clnt;\n"); @@ -99,17 +99,33 @@ write_sample_client (const char *program_name, version_list * vp) for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print (fout, "\t"); - ptype (proc->res_prefix, proc->res_type, 1); - f_print (fout, " *result_%d;\n", ++i); + ++i; + if (mtflag) + { + f_print (fout, "enum clnt_stat retval_%d;\n\t", i); + ptype (proc->res_prefix, proc->res_type, 1); + if (!streq (proc->res_type, "void")) + f_print (fout, "result_%d;\n", i); + else + fprintf (fout, "*result_%d;\n", i); + } + else + { + ptype (proc->res_prefix, proc->res_type, 1); + f_print (fout, " *result_%d;\n", i); + } /* print out declarations for arguments */ if (proc->arg_num < 2 && !newstyle) { f_print (fout, "\t"); if (!streq (proc->args.decls->decl.type, "void")) - ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); + { + ptype (proc->args.decls->decl.prefix, + proc->args.decls->decl.type, 1); + f_print (fout, " "); + } else - f_print (fout, "char* "); /* cannot have "void" type */ - f_print (fout, " "); + f_print (fout, "char *"); /* cannot have "void" type */ pvname (proc->proc_name, vp->vers_num); f_print (fout, "_arg;\n"); } @@ -119,39 +135,50 @@ write_sample_client (const char *program_name, version_list * vp) { f_print (fout, "\t"); ptype (l->decl.prefix, l->decl.type, 1); - f_print (fout, " "); + if (strcmp (l->decl.type, "string") == 1) + f_print (fout, " "); pvname (proc->proc_name, vp->vers_num); f_print (fout, "_%s;\n", l->decl.name); -/* pdeclaration(proc->args.argname, &l->decl, 1, ";\n" ); */ } } } /* generate creation of client handle */ - f_print (fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n", + f_print(fout, "\n#ifndef\tDEBUG\n"); + f_print (fout, "\tclnt = clnt_create (host, %s, %s, \"%s\");\n", program_name, vp->vers_name, tirpcflag ? "netpath" : "udp"); f_print (fout, "\tif (clnt == NULL) {\n"); - f_print (fout, "\t\tclnt_pcreateerror(host);\n"); - f_print (fout, "\t\texit(1);\n\t}\n"); + f_print (fout, "\t\tclnt_pcreateerror (host);\n"); + f_print (fout, "\t\texit (1);\n\t}\n"); + f_print(fout, "#endif\t/* DEBUG */\n\n"); /* generate calls to procedures */ i = 0; for (proc = vp->procs; proc != NULL; proc = proc->next) { - f_print (fout, "\tresult_%d = ", ++i); + if (mtflag) + f_print(fout, "\tretval_%d = ",++i); + else + f_print (fout, "\tresult_%d = ", ++i); pvname (proc->proc_name, vp->vers_num); if (proc->arg_num < 2 && !newstyle) { f_print (fout, "("); - if (streq (proc->args.decls->decl.type, "void")) /* cast to void* */ + if (streq (proc->args.decls->decl.type, "void"))/* cast to void* */ f_print (fout, "(void*)"); f_print (fout, "&"); pvname (proc->proc_name, vp->vers_num); - f_print (fout, "_arg, clnt);\n"); + if (mtflag) + 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")) { - f_print (fout, "(clnt);\n"); + if (mtflag) + f_print (fout, "(&result_%d, clnt);\n", i); + else + f_print (fout, "(clnt);\n"); } else { @@ -161,14 +188,27 @@ write_sample_client (const char *program_name, version_list * vp) pvname (proc->proc_name, vp->vers_num); f_print (fout, "_%s, ", l->decl.name); } + if (mtflag) + f_print(fout, "&result_%d, ", i); f_print (fout, "clnt);\n"); } - f_print (fout, "\tif (result_%d == NULL) {\n", i); - f_print (fout, "\t\tclnt_perror(clnt, \"call failed:\");\n"); - f_print (fout, "\t}\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); + f_print(fout, "*) NULL) {\n"); + } + f_print(fout, "\t\tclnt_perror (clnt, \"call failed\");\n"); + f_print(fout, "\t}\n"); } - f_print (fout, "\tclnt_destroy( clnt );\n"); + f_print (fout, "#ifndef\tDEBUG\n"); + f_print (fout, "\tclnt_destroy (clnt);\n"); + f_print (fout, "#endif\t /* DEBUG */\n"); f_print (fout, "}\n"); } @@ -183,34 +223,62 @@ write_sample_server (definition * def) for (proc = vp->procs; proc != NULL; proc = proc->next) { f_print (fout, "\n"); -/* if( Cflag ) - f_print( fout, "extern \"C\"{\n"); - */ - return_type (proc); - f_print (fout, "* \n"); - if (Cflag) + if (!mtflag) + { + return_type (proc); + f_print (fout, "*\n"); + } + else + f_print (fout, "bool_t\n"); + if (Cflag || mtflag) pvname_svc (proc->proc_name, vp->vers_num); else - pvname (proc->proc_name, vp->vers_num); - printarglist (proc, RQSTP, "struct svc_req *"); + pvname(proc->proc_name, vp->vers_num); + printarglist(proc, "result", RQSTP, "struct svc_req *"); + f_print(fout, "{\n"); + if (!mtflag) + { + f_print(fout, "\tstatic "); + if(!streq(proc->res_type, "void")) + return_type(proc); + else + f_print(fout, "char *"); + /* cannot have void type */ + /* f_print(fout, " result;\n", proc->res_type); */ + f_print(fout, " result;\n"); + } + else + f_print(fout, "\tbool_t retval;\n"); + fprintf (fout, "\n\t/*\n\t * insert server code here\n\t */\n\n"); - f_print (fout, "{\n"); - f_print (fout, "\n\tstatic "); - if (!streq (proc->res_type, "void")) - return_type (proc); + if (!mtflag) + if(!streq(proc->res_type, "void")) + f_print(fout, "\treturn &result;\n}\n"); + else /* cast back to void * */ + f_print(fout, "\treturn (void *) &result;\n}\n"); else - f_print (fout, "char*"); /* cannot have void type */ - f_print (fout, " result;\n" /*, proc->res_type *//*? */ ); - f_print (fout, - "\n\t/*\n\t * insert server code here\n\t */\n\n"); - if (!streq (proc->res_type, "void")) - f_print (fout, "\treturn(&result);\n}\n"); - else /* cast back to void * */ - f_print (fout, "\treturn((void*) &result);\n}\n"); -/* if( Cflag) - f_print( fout, "};\n"); - */ + f_print(fout, "\treturn retval;\n}\n"); + } + /* put in sample freeing routine */ + if (mtflag) + { + f_print(fout, "\nint\n"); + pvname(def->def_name, vp->vers_num); + if (Cflag) + f_print(fout,"_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result)\n"); + else + { + f_print(fout,"_freeresult (transp, xdr_result, result)\n"); + f_print(fout,"\tSVCXPRT *transp;\n"); + f_print(fout,"\txdrproc_t xdr_result;\n"); + f_print(fout,"\tcaddr_t result;\n"); + } + f_print(fout, "{\n"); + f_print(fout, "\txdr_free (xdr_result, result);\n"); + f_print(fout, + "\n\t/*\n\t * Insert additional freeing code here, if needed\n\t */\n"); + f_print(fout, "\n\treturn 0;\n}\n"); } } } @@ -242,14 +310,14 @@ write_sample_clnt_main (void) 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)\nint argc;\nchar *argv[];\n{\n"); + f_print (fout, "int\nmain (argc, argv)\nint argc;\nchar *argv[];\n{\n"); f_print (fout, "\tchar *host;"); - f_print (fout, "\n\n\tif(argc < 2) {"); - f_print (fout, "\n\t\tprintf(\"usage: %%s server_host\\n\", argv[0]);\n"); - f_print (fout, "\t\texit(1);\n\t}"); + f_print (fout, "\n\n\tif (argc < 2) {"); + f_print (fout, "\n\t\tprintf (\"usage: %%s server_host\\n\", argv[0]);\n"); + f_print (fout, "\t\texit (1);\n\t}"); f_print (fout, "\n\thost = argv[1];\n"); for (l = defined; l != NULL; l = l->next) @@ -263,8 +331,8 @@ write_sample_clnt_main (void) { f_print (fout, "\t"); pvname (def->def_name, vp->vers_num); - f_print (fout, "( host );\n"); + f_print (fout, " (host);\n"); } } - f_print (fout, "}\n"); + f_print (fout, "exit (0);\n}\n"); } diff --git a/sunrpc/rpc_scan.c b/sunrpc/rpc_scan.c index 1c486d1715..aa988052b1 100644 --- a/sunrpc/rpc_scan.c +++ b/sunrpc/rpc_scan.c @@ -70,9 +70,7 @@ scan (tok_kind expect, token * tokp) { get_token (tokp); if (tokp->kind != expect) - { - expected1 (expect); - } + expected1 (expect); } /* @@ -106,7 +104,7 @@ scan3 (tok_kind expect1, tok_kind expect2, tok_kind expect3, token * tokp) * scan expecting a constant, possibly symbolic */ void -scan_num (token * tokp) +scan_num (token *tokp) { get_token (tokp); switch (tokp->kind) @@ -114,7 +112,7 @@ scan_num (token * tokp) case TOK_IDENT: break; default: - error ("constant or identifier expected"); + error (_("constant or identifier expected")); } } @@ -122,7 +120,7 @@ scan_num (token * tokp) * Peek at the next token */ void -peek (token * tokp) +peek (token *tokp) { get_token (tokp); unget_token (tokp); @@ -132,22 +130,22 @@ peek (token * tokp) * Peek at the next token and scan it if it matches what you expect */ int -peekscan (tok_kind expect, token * tokp) +peekscan (tok_kind expect, token *tokp) { peek (tokp); if (tokp->kind == expect) { get_token (tokp); - return (1); + return 1; } - return (0); + return 0; } /* * Get the next token, printing out any directive that are encountered. */ void -get_token (token * tokp) +get_token (token *tokp) { int commenting; diff --git a/sunrpc/rpc_svcout.c b/sunrpc/rpc_svcout.c index 75eb695e87..9b5f1dd0f5 100644 --- a/sunrpc/rpc_svcout.c +++ b/sunrpc/rpc_svcout.c @@ -48,6 +48,7 @@ static const char TRANSP[] = "transp"; static const char ARG[] = "argument"; static const char RESULT[] = "result"; static const char ROUTINE[] = "local"; +static char RETVAL[] = "retval"; char _errbuf[256]; /* For all messages */ @@ -103,12 +104,31 @@ write_most (const char *infile /* our name */ , int netflag, int nomain) #endif f_print (fout, "%s int _rpcpmstart;", var_type); f_print (fout, "\t\t/* Started by a port monitor ? */\n"); - f_print (fout, "%s int _rpcfdtype;", var_type); - f_print (fout, "\t\t/* Whether Stream or Datagram ? */\n"); + if (!tirpcflag) + { + f_print (fout, "%s int _rpcfdtype;", var_type); + f_print (fout, "\t\t/* Whether Stream or Datagram ? */\n"); + } if (timerflag) { +#if 0 f_print (fout, "%s int _rpcsvcdirty;", var_type); f_print (fout, "\t/* Still serving ? */\n"); +#else + f_print(fout, " /* States a server can be in wrt request */\n\n"); + f_print(fout, "#define\t_IDLE 0\n"); + f_print(fout, "#define\t_SERVED 1\n"); + f_print(fout, "#define\t_SERVING 2\n\n"); + f_print(fout, "static int _rpcsvcstate = _IDLE;"); + f_print(fout, "\t /* Set when a request is serviced */\n"); + + if (mtflag) + { + f_print (fout, "mutex_t _svcstate_lock;"); + f_print (fout, + "\t\t\t/* Mutex lock for variable_rpcsvcstate */\n"); + } +#endif } write_svc_aux (nomain); } @@ -120,10 +140,10 @@ write_most (const char *infile /* our name */ , int netflag, int nomain) #ifdef __GNU_LIBRARY__ if (Cflag) - f_print (fout, "\nint\nmain(int argc, char **argv)\n"); + f_print (fout, "\nint\nmain (int argc, char **argv)\n"); else { - f_print (fout, "\nint\nmain(argc, argv)\n"); + f_print (fout, "\nint\nmain (argc, argv)\n"); f_print (fout, "\tint argc;\n"); f_print (fout, "\tchar **argv;\n"); } @@ -147,7 +167,12 @@ write_most (const char *infile /* our name */ , int netflag, int nomain) f_print (fout, "\tpid_t pid;\n"); f_print (fout, "\tint i;\n"); f_print (fout, "\tchar mname[FMNAMESZ + 1];\n\n"); - write_pm_most (infile, netflag); + + if (mtflag & timerflag) + f_print (fout, + "\tmutex_init (&_svcstate_lock, USYNC_THREAD, NULL);\n"); + + write_pm_most (infile, netflag); f_print (fout, "\telse {\n"); write_rpc_svc_fg (infile, "\t\t"); f_print (fout, "\t}\n"); @@ -180,19 +205,19 @@ write_netid_register (const char *transp) sp = ""; f_print (fout, "\n"); - f_print (fout, "%s\tnconf = getnetconfigent(\"%s\");\n", sp, transp); + 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); print_err_message (tmpbuf); - f_print (fout, "%s\t\texit(1);\n", sp); + 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", + f_print (fout, "%s\t%s = svc_tli_create (RPC_ANYFD, nconf, 0, 0, 0);\n", sp, TRANSP /*, transp *//* ?!?... */ ); f_print (fout, "%s\tif (%s == NULL) {\n", sp, TRANSP); - (void) sprintf (_errbuf, "cannot create %s service.", transp); + sprintf (_errbuf, "cannot create %s service.", transp); print_err_message (tmpbuf); - f_print (fout, "%s\t\texit(1);\n", sp); + f_print (fout, "%s\t\texit (1);\n", sp); f_print (fout, "%s\t}\n", sp); for (l = defined; l != NULL; l = l->next) @@ -204,22 +229,20 @@ write_netid_register (const char *transp) } for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { - f_print (fout, - "%s\t(void) rpcb_unset(%s, %s, nconf);\n", + f_print (fout, "%s\t(void) rpcb_unset (%s, %s, nconf);\n", sp, def->def_name, vp->vers_name); - f_print (fout, - "%s\tif (!svc_reg(%s, %s, %s, ", + f_print (fout, "%s\tif (!svc_reg (%s, %s, %s, ", sp, TRANSP, def->def_name, vp->vers_name); pvname (def->def_name, vp->vers_num); f_print (fout, ", nconf)) {\n"); (void) sprintf (_errbuf, "unable to register (%s, %s, %s).", def->def_name, vp->vers_name, transp); print_err_message (tmpbuf); - f_print (fout, "%s\t\texit(1);\n", sp); + f_print (fout, "%s\t\texit (1);\n", sp); f_print (fout, "%s\t}\n", sp); } } - f_print (fout, "%s\tfreenetconfigent(nconf);\n", sp); + f_print (fout, "%s\tfreenetconfigent (nconf);\n", sp); } /* @@ -241,7 +264,7 @@ write_nettype_register (const char *transp) } for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { - f_print (fout, "\tif (!svc_create("); + f_print (fout, "\tif (!svc_create ("); pvname (def->def_name, vp->vers_num); f_print (fout, ", %s, %s, \"%s\")) {\n ", def->def_name, vp->vers_name, transp); @@ -249,7 +272,7 @@ write_nettype_register (const char *transp) "unable to create (%s, %s) for %s.", def->def_name, vp->vers_name, transp); print_err_message ("\t\t"); - f_print (fout, "\t\texit(1);\n"); + f_print (fout, "\t\texit (1);\n"); f_print (fout, "\t}\n"); } } @@ -267,22 +290,22 @@ write_rest (void) f_print (fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP); (void) sprintf (_errbuf, "could not create a handle"); print_err_message ("\t\t"); - f_print (fout, "\t\texit(1);\n"); + f_print (fout, "\t\texit (1);\n"); f_print (fout, "\t}\n"); if (timerflag) { f_print (fout, "\tif (_rpcpmstart) {\n"); f_print (fout, - "\t\t(void) signal(SIGALRM, %s closedown);\n", + "\t\t(void) signal (SIGALRM, %s closedown);\n", Cflag ? "(SIG_PF)" : "(void(*)())"); - f_print (fout, "\t\t(void) alarm(_RPCSVC_CLOSEDOWN);\n"); + f_print (fout, "\t\t(void) alarm (_RPCSVC_CLOSEDOWN);\n"); f_print (fout, "\t}\n"); } } - f_print (fout, "\tsvc_run();\n"); + f_print (fout, "\tsvc_run ();\n"); (void) sprintf (_errbuf, "svc_run returned"); print_err_message ("\t"); - f_print (fout, "\texit(1);\n"); + f_print (fout, "\texit (1);\n"); f_print (fout, "\t/* NOTREACHED */\n"); f_print (fout, "}\n"); } @@ -312,8 +335,6 @@ write_programs (const char *storage) write_program (def, storage); } } - - } /* write out definition of internal function (e.g. _printmsg_1(...)) @@ -333,25 +354,37 @@ write_real_program (const definition * def) { for (proc = vp->procs; proc != NULL; proc = proc->next) { - f_print (fout, "\n"); - internal_proctype (proc); + fprintf (fout, "\n"); + if (!mtflag) + internal_proctype (proc); + else + f_print (fout, "int"); f_print (fout, "\n_"); pvname (proc->proc_name, vp->vers_num); if (Cflag) { - f_print (fout, "("); + f_print (fout, " ("); /* arg name */ if (proc->arg_num > 1) f_print (fout, proc->args.argname); else ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 0); - f_print (fout, " *argp, struct svc_req *%s)\n", - RQSTP); + if (mtflag) + { + f_print(fout, " *argp, void *%s, struct svc_req *%s)\n", + RESULT, RQSTP); + } + else + f_print (fout, " *argp, struct svc_req *%s)\n", + RQSTP); } else { - f_print (fout, "(argp, %s)\n", RQSTP); + if (mtflag) + f_print(fout, " (argp, %s, %s)\n", RESULT, RQSTP); + else + f_print (fout, " (argp, %s)\n", RQSTP); /* arg name */ if (proc->arg_num > 1) f_print (fout, "\t%s *argp;\n", proc->args.argname); @@ -366,8 +399,8 @@ write_real_program (const definition * def) } f_print (fout, "{\n"); - f_print (fout, "\treturn("); - if (Cflag) + f_print (fout, "\treturn ("); + if (Cflag || mtflag) pvname_svc (proc->proc_name, vp->vers_num); else pvname (proc->proc_name, vp->vers_num); @@ -451,33 +484,65 @@ write_program (const definition * def, const char *storage) f_print (fout, "\t\tint fill;\n"); } f_print (fout, "\t} %s;\n", ARG); - f_print (fout, "\tchar *%s;\n", RESULT); + if (mtflag) + { + f_print(fout, "\tunion {\n"); + for (proc = vp->procs; proc != NULL; proc = proc->next) + if (!streq (proc->res_type, "void")) + { + f_print(fout, "\t\t"); + ptype(proc->res_prefix, proc->res_type, 0); + pvname(proc->proc_name, vp->vers_num); + f_print(fout, "_res;\n"); + } + f_print(fout, "\t} %s;\n", RESULT); + f_print(fout, "\tbool_t %s;\n", RETVAL); + + } else + f_print (fout, "\tchar *%s;\n", RESULT); if (Cflag) { f_print (fout, "\txdrproc_t xdr_%s, xdr_%s;\n", ARG, RESULT); - f_print (fout, - "\tchar *(*%s)(char *, struct svc_req *);\n", - ROUTINE); + if (mtflag) + f_print(fout, + "\tbool_t (*%s)(char *, void *, struct svc_req *);\n", + ROUTINE); + else + f_print (fout, "\tchar *(*%s)(char *, struct svc_req *);\n", + ROUTINE); } else { f_print (fout, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG, RESULT); - f_print (fout, "\tchar *(*%s)();\n", ROUTINE); + if (mtflag) + f_print(fout, "\tbool_t (*%s)();\n", ROUTINE); + else + f_print (fout, "\tchar *(*%s)();\n", ROUTINE); } - f_print (fout, "\n"); if (timerflag) +#if 0 f_print (fout, "\t_rpcsvcdirty = 1;\n"); +#else + { + if (mtflag) + f_print(fout, "\tmutex_lock(&_svcstate_lock);\n"); + f_print(fout, "\t_rpcsvcstate = _SERVING;\n"); + if (mtflag) + f_print(fout, "\tmutex_unlock(&_svcstate_lock);\n"); + } +#endif + f_print (fout, "\tswitch (%s->rq_proc) {\n", RQSTP); if (!nullproc (vp->procs)) { f_print (fout, "\tcase NULLPROC:\n"); f_print (fout, Cflag - ? "\t\t(void) svc_sendreply(%s, (xdrproc_t) xdr_void, (char *)NULL);\n" - : "\t\t(void) svc_sendreply(%s, xdr_void, (char *)NULL);\n", + ? "\t\t(void) svc_sendreply (%s, (xdrproc_t) xdr_void, (char *)NULL);\n" + : "\t\t(void) svc_sendreply (%s, xdr_void, (char *)NULL);\n", TRANSP); print_return ("\t\t"); f_print (fout, "\n"); @@ -495,17 +560,27 @@ write_program (const definition * def, const char *storage) } p_xdrfunc (RESULT, proc->res_type); if (Cflag) - f_print (fout, - "\t\t%s = (char *(*)(char *, struct svc_req *)) ", - ROUTINE); + { + if (mtflag) + f_print(fout, + "\t\t%s = (bool_t (*) (char *, void *, struct svc_req *))", + ROUTINE); + else + f_print (fout, + "\t\t%s = (char *(*)(char *, struct svc_req *)) ", + ROUTINE); + } else - f_print (fout, "\t\t%s = (char *(*)()) ", ROUTINE); + if (mtflag) + f_print(fout, "\t\t%s = (bool_t (*)()) ", ROUTINE); + else + f_print (fout, "\t\t%s = (char *(*)()) ", ROUTINE); if (newstyle) { /* new style: calls internal routine */ f_print (fout, "_"); } - if (Cflag && !newstyle) + if ((Cflag || mtflag) && !newstyle) pvname_svc (proc->proc_name, vp->vers_num); else pvname (proc->proc_name, vp->vers_num); @@ -517,7 +592,7 @@ write_program (const definition * def, const char *storage) print_return ("\t\t"); f_print (fout, "\t}\n"); - f_print (fout, "\t(void) memset((char *)&%s, 0, sizeof (%s));\n", ARG, ARG); + f_print (fout, "\tmemset ((char *)&%s, 0, sizeof (%s));\n", ARG, ARG); if (Cflag) printif ("getargs", TRANSP, "(caddr_t) &", ARG); else @@ -526,15 +601,29 @@ write_program (const definition * def, const char *storage) print_return ("\t\t"); f_print (fout, "\t}\n"); - if (Cflag) - f_print (fout, "\t%s = (*%s)((char *)&%s, %s);\n", - RESULT, ROUTINE, ARG, RQSTP); + if (!mtflag) + if (Cflag) + f_print (fout, "\t%s = (*%s)((char *)&%s, %s);\n", + RESULT, ROUTINE, ARG, RQSTP); + else + f_print (fout, "\t%s = (*%s)(&%s, %s);\n", + RESULT, ROUTINE, ARG, RQSTP); else - f_print (fout, "\t%s = (*%s)(&%s, %s);\n", - RESULT, ROUTINE, ARG, RQSTP); - f_print (fout, - "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n", - RESULT, TRANSP, RESULT, RESULT); + if (Cflag) + f_print(fout, "\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", + RETVAL, ROUTINE, ARG, RESULT, RQSTP); + if (mtflag) + f_print(fout, + "\tif (%s > 0 && !svc_sendreply(%s, xdr_%s, (char *)&%s)) {\n", + RETVAL, TRANSP, RESULT, RESULT); + else + f_print(fout, + "\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n", + RESULT, TRANSP, RESULT, RESULT); + printerr ("systemerr", TRANSP); f_print (fout, "\t}\n"); @@ -542,10 +631,22 @@ write_program (const definition * def, const char *storage) printif ("freeargs", TRANSP, "(caddr_t) &", ARG); else printif ("freeargs", TRANSP, "&", ARG); - (void) sprintf (_errbuf, "unable to free arguments"); + + sprintf (_errbuf, "unable to free arguments"); print_err_message ("\t\t"); - f_print (fout, "\t\texit(1);\n"); + f_print (fout, "\t\texit (1);\n"); f_print (fout, "\t}\n"); + /* print out free routine */ + if (mtflag) + { + f_print(fout,"\tif (!"); + pvname(def->def_name, vp->vers_num); + f_print(fout,"_freeresult (%s, xdr_%s, (caddr_t) &%s))\n", + TRANSP, RESULT, RESULT); + (void) sprintf(_errbuf, "unable to free results"); + print_err_message("\t\t"); + f_print(fout, "\n"); + } print_return ("\t"); f_print (fout, "}\n"); } @@ -554,14 +655,14 @@ write_program (const definition * def, const char *storage) static void printerr (const char *err, const char *transp) { - f_print (fout, "\t\tsvcerr_%s(%s);\n", err, transp); + f_print (fout, "\t\tsvcerr_%s (%s);\n", err, transp); } static void printif (const char *proc, const char *transp, const char *prefix, const char *arg) { - f_print (fout, "\tif (!svc_%s(%s, xdr_%s, %s%s)) {\n", + f_print (fout, "\tif (!svc_%s (%s, xdr_%s, %s%s)) {\n", proc, transp, arg, prefix, arg); } @@ -572,10 +673,10 @@ nullproc (const proc_list * proc) { if (streq (proc->proc_num, "0")) { - return (1); + return 1; } } - return (0); + return 0; } static void @@ -588,13 +689,13 @@ write_inetmost (const char *infile) f_print (fout, "\tint asize = sizeof (saddr);\n"); f_print (fout, "\n"); f_print (fout, - "\tif (getsockname(0, (struct sockaddr *)&saddr, &asize) == 0) {\n"); + "\tif (getsockname (0, (struct sockaddr *)&saddr, &asize) == 0) {\n"); f_print (fout, "\t\tint ssize = sizeof (int);\n\n"); f_print (fout, "\t\tif (saddr.sin_family != AF_INET)\n"); - f_print (fout, "\t\t\texit(1);\n"); - f_print (fout, "\t\tif (getsockopt(0, SOL_SOCKET, SO_TYPE,\n"); + f_print (fout, "\t\t\texit (1);\n"); + f_print (fout, "\t\tif (getsockopt (0, SOL_SOCKET, SO_TYPE,\n"); f_print (fout, "\t\t\t\t(char *)&_rpcfdtype, &ssize) == -1)\n"); - f_print (fout, "\t\t\texit(1);\n"); + f_print (fout, "\t\t\texit (1);\n"); f_print (fout, "\t\tsock = 0;\n"); f_print (fout, "\t\t_rpcpmstart = 1;\n"); f_print (fout, "\t\tproto = 0;\n"); @@ -610,11 +711,21 @@ static void print_return (const char *space) { if (exitnow) - f_print (fout, "%sexit(0);\n", space); + f_print (fout, "%sexit (0);\n", space); else { if (timerflag) - f_print (fout, "%s_rpcsvcdirty = 0;\n", space); + { +#if 0 + f_print (fout, "%s_rpcsvcdirty = 0;\n", space); +#else + if (mtflag) + f_print(fout, "%smutex_lock(&_svcstate_lock);\n", space); + f_print(fout, "%s_rpcsvcstate = _SERVED;\n", space); + if (mtflag) + f_print(fout, "%smutex_unlock(&_svcstate_lock);\n", space); +#endif + } f_print (fout, "%sreturn;\n", space); } } @@ -634,7 +745,7 @@ print_pmapunset (const char *space) for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { - f_print (fout, "%s(void) pmap_unset(%s, %s);\n", + f_print (fout, "%spmap_unset (%s, %s);\n", space, def->def_name, vp->vers_name); } } @@ -645,11 +756,11 @@ static void print_err_message (const char *space) { if (logflag) - f_print (fout, "%ssyslog(LOG_ERR, \"%s\");\n", space, _errbuf); + f_print (fout, "%ssyslog (LOG_ERR, \"%s\");\n", space, _errbuf); else if (inetdflag || pmflag) - f_print (fout, "%s_msgout(\"%s\");\n", space, _errbuf); + f_print (fout, "%s_msgout (\"%s\");\n", space, _errbuf); else - f_print (fout, "%sfprintf(stderr, \"%s\");\n", space, _errbuf); + f_print (fout, "%sfprintf (stderr, \"%s\");\n", space, _errbuf); } /* @@ -675,22 +786,22 @@ write_msg_out (void) f_print (fout, "static\n"); if (!Cflag) { - f_print (fout, "void _msgout(msg)\n"); + f_print (fout, "void _msgout (msg)\n"); f_print (fout, "\tchar *msg;\n"); } else { - f_print (fout, "void _msgout(char* msg)\n"); + f_print (fout, "void _msgout (char* msg)\n"); } f_print (fout, "{\n"); f_print (fout, "#ifdef RPC_SVC_FG\n"); if (inetdflag || pmflag) f_print (fout, "\tif (_rpcpmstart)\n"); - f_print (fout, "\t\tsyslog(LOG_ERR, msg);\n"); + f_print (fout, "\t\tsyslog (LOG_ERR, msg);\n"); f_print (fout, "\telse\n"); - f_print (fout, "\t\t(void) fprintf(stderr, \"%%s\\n\", msg);\n"); + f_print (fout, "\t\tfprintf (stderr, \"%%s\\n\", msg);\n"); f_print (fout, "#else\n"); - f_print (fout, "\tsyslog(LOG_ERR, msg);\n"); + f_print (fout, "\tsyslog (LOG_ERR, msg);\n"); f_print (fout, "#endif\n"); f_print (fout, "}\n"); } @@ -705,20 +816,23 @@ write_timeout_func (void) return; f_print (fout, "\n"); f_print (fout, "static void\n"); -#ifdef __GNU_LIBRARY__ if (Cflag) - f_print (fout, "closedown(int sig)\n"); + f_print (fout, "closedown (int sig)\n"); else - f_print (fout, "closedown(sig)\n\tint sig;\n"); -#else - f_print (fout, "closedown()\n"); -#endif + f_print (fout, "closedown (sig)\n\tint sig;\n"); f_print (fout, "{\n"); -#ifdef __GNU_LIBRARY__ - f_print (fout, "\t(void) signal(sig, %s closedown);\n", + +#if defined (__GNU_LIBRARY__) && 0 + f_print (fout, "\t(void) signal (sig, %s closedown);\n", Cflag ? "(SIG_PF)" : "(void(*)())"); #endif + if (mtflag) + f_print(fout, "\tmutex_lock(&_svcstate_lock);\n"); +#if 0 f_print (fout, "\tif (_rpcsvcdirty == 0) {\n"); +#else + f_print(fout, "\tif (_rpcsvcstate == _IDLE) {\n"); +#endif f_print (fout, "\t\textern fd_set svc_fdset;\n"); f_print (fout, "\t\tstatic int size;\n"); f_print (fout, "\t\tint i, openfd;\n"); @@ -731,15 +845,17 @@ write_timeout_func (void) { f_print (fout, "\n\t\tif (_rpcfdtype == SOCK_DGRAM)\n"); } - f_print (fout, "\t\t\texit(0);\n"); + f_print (fout, "\t\t\texit (0);\n"); f_print (fout, "\t\tif (size == 0) {\n"); if (tirpcflag) { f_print (fout, "\t\t\tstruct rlimit rl;\n\n"); f_print (fout, "\t\t\trl.rlim_max = 0;\n"); f_print (fout, "\t\t\tgetrlimit(RLIMIT_NOFILE, &rl);\n"); - f_print (fout, "\t\t\tif ((size = rl.rlim_max) == 0)\n"); - f_print (fout, "\t\t\t\treturn;\n"); + f_print (fout, "\t\t\tif ((size = rl.rlim_max) == 0) {\n"); + if (mtflag) + f_print(fout, "\t\t\t\tmutex_unlock(&_svcstate_lock);\n"); + f_print (fout, "\t\t\t\treturn;\n\t\t\t}\n"); } else { @@ -750,9 +866,15 @@ write_timeout_func (void) f_print (fout, "\t\t\tif (FD_ISSET(i, &svc_fdset))\n"); f_print (fout, "\t\t\t\topenfd++;\n"); f_print (fout, "\t\tif (openfd <= 1)\n"); - f_print (fout, "\t\t\texit(0);\n"); + f_print (fout, "\t\t\texit (0);\n"); f_print (fout, "\t}\n"); - f_print (fout, "\t(void) alarm(_RPCSVC_CLOSEDOWN);\n"); + f_print(fout, "\tif (_rpcsvcstate == _SERVED)\n"); + f_print(fout, "\t\t_rpcsvcstate = _IDLE;\n\n"); + if (mtflag) + f_print(fout, "\tmutex_unlock(&_svcstate_lock);\n"); + f_print(fout, "\t(void) signal(SIGALRM, %s closedown);\n", + Cflag? "(SIG_PF)" : "(void(*)())"); + f_print (fout, "\talarm (_RPCSVC_CLOSEDOWN);\n"); f_print (fout, "}\n"); } @@ -915,9 +1037,6 @@ open_log_file (const char *infile, const char *sp) *s = '.'; } - - - /* * write a registration for the given transport for Inetd */ diff --git a/sunrpc/rpc_util.c b/sunrpc/rpc_util.c index fd696116c9..4c986040ce 100644 --- a/sunrpc/rpc_util.c +++ b/sunrpc/rpc_util.c @@ -95,7 +95,7 @@ streq (const char *a, const char *b) * find a value in a list */ definition * -findval (list * lst, const char *val, +findval (list *lst, const char *val, int (*cmp) (const definition *, const char *)) { @@ -113,7 +113,7 @@ findval (list * lst, const char *val, * store a value in a list */ void -storeval (list ** lstp, definition * val) +storeval (list **lstp, definition *val) { list **l; list *lst; @@ -145,7 +145,10 @@ fixit (const char *type, const char *orig) switch (def->def.ty.rel) { case REL_VECTOR: - return (def->def.ty.old_type); + if (streq (def->def.ty.old_type, "opaque")) + return ("char"); + else + return (def->def.ty.old_type); case REL_ALIAS: return (fixit (def->def.ty.old_type, orig)); default: @@ -227,7 +230,7 @@ isvectordef (const char *type, relation rel) case REL_ARRAY: return 0; case REL_POINTER: - return (0); + return 0; case REL_ALIAS: def = findval (defined, type, typedefed); if (def == NULL) @@ -290,7 +293,7 @@ crash (void) for (i = 0; i < nfiles; i++) { - (void) unlink (outfiles[i]); + unlink (outfiles[i]); } exit (1); } diff --git a/sunrpc/rpc_util.h b/sunrpc/rpc_util.h index bdbe183caa..cb1ceb9921 100644 --- a/sunrpc/rpc_util.h +++ b/sunrpc/rpc_util.h @@ -31,7 +31,7 @@ /* @(#)rpc_util.h 1.5 90/08/29 (C) 1987 SMI */ /* - * rpc_util.h, Useful definitions for the RPC protocol compiler + * rpc_util.h, Useful definitions for the RPC protocol compiler */ #include <stdlib.h> @@ -48,11 +48,18 @@ struct list { }; typedef struct list list; +struct xdrfunc { + char *name; + int pointerp; + struct xdrfunc *next; +}; +typedef struct xdrfunc xdrfunc; + #define PUT 1 #define GET 2 /* - * Global variables + * Global variables */ #define MAXLINESIZE 1024 extern char curline[MAXLINESIZE]; @@ -65,21 +72,23 @@ extern FILE *fin; extern list *defined; - extern bas_type *typ_list_h; extern bas_type *typ_list_t; +extern xdrfunc *xdrfunc_head, *xdrfunc_tail; /* * All the option flags */ extern int inetdflag; -extern int pmflag; +extern int pmflag; extern int tblflag; extern int logflag; extern int newstyle; -extern int Cflag; /* C++ flag */ -extern int tirpcflag; /* flag for generating tirpc code */ +extern int Cflag; /* C++ flag */ +extern int CCflag; /* C++ flag */ +extern int tirpcflag; /* flag for generating tirpc code */ extern int inlineflag; /* if this is 0, then do not generate inline code */ +extern int mtflag; /* * Other flags related with inetd jumpstart. @@ -91,12 +100,12 @@ extern int timerflag; extern int nonfatalerrors; /* - * rpc_util routines + * rpc_util routines */ void storeval(list **lstp, definition *val); #define STOREVAL(list,item) storeval(list,item) -definition *findval(list *lst, const char *val, +definition *findval(list *lst, const char *val, int (*cmp)(const definition *, const char *)); #define FINDVAL(list,item,finder) findval(list, item, finder) @@ -115,18 +124,18 @@ bas_type *find_type(const char *type); /* - * rpc_cout routines + * rpc_cout routines */ void emit(definition *def); /* - * rpc_hout routines + * rpc_hout routines */ void print_datadef(definition *def); void print_funcdef(definition *def); /* - * rpc_svcout routines + * rpc_svcout routines */ void write_most(const char *infile, int netflag, int nomain); void write_register(void); |