2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
30 #ident "@(#)rpc_clntout.c 1.15 94/04/25 SMI"
34 static char sccsid[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI";
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
43 * Copyright (C) 1987, Sun Microsytsems, Inc.
47 #include <rpc/types.h>
48 #include "rpc_parse.h"
51 extern void pdeclaration( char *, declaration *, int, char * );
52 void printarglist( proc_list *, char *, char *, char *);
53 static void write_program( definition * );
54 static void printbody( proc_list * );
56 static char RESULT[] = "clnt_res";
59 #define DEFAULT_TIMEOUT 25 /* in seconds */
69 "\n/* Default timeout can be changed using clnt_control() */\n");
70 f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
72 for (l = defined; l != NULL; l = l->next) {
73 def = (definition *) l->val;
74 if (def->def_kind == DEF_PROGRAM) {
87 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
88 for (proc = vp->procs; proc != NULL; proc = proc->next) {
91 ptype(proc->res_prefix, proc->res_type, 1);
93 pvname(proc->proc_name, vp->vers_num);
94 printarglist(proc, RESULT, "clnt", "CLIENT *");
96 f_print(fout, "enum clnt_stat \n");
97 pvname(proc->proc_name, vp->vers_num);
98 printarglist(proc, RESULT, "clnt", "CLIENT *");
101 f_print(fout, "{\n");
104 f_print(fout, "}\n");
110 * Writes out declarations of procedure's argument list.
111 * In either ANSI C style, in one of old rpcgen style (pass by reference),
112 * or new rpcgen style (multiple arguments, pass by value);
115 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
117 void printarglist(proc, result, addargname, addargtype)
120 char* addargname, * addargtype;
126 /* old style: always pass argument by reference */
127 if (Cflag) { /* C++ style heading */
129 ptype(proc->args.decls->decl.prefix,
130 proc->args.decls->decl.type, 1);
132 if (mtflag) {/* Generate result field */
133 f_print(fout, "*argp, ");
134 ptype(proc->res_prefix, proc->res_type, 1);
135 f_print(fout, "*%s, %s%s)\n",
136 result, addargtype, addargname);
138 f_print(fout, "*argp, %s%s)\n", addargtype, addargname);
141 f_print(fout, "(argp, %s)\n", addargname);
143 f_print(fout, "(argp, %s, %s)\n",
146 ptype(proc->args.decls->decl.prefix,
147 proc->args.decls->decl.type, 1);
148 f_print(fout, "*argp;\n");
151 ptype(proc->res_prefix, proc->res_type, 1);
152 f_print(fout, "*%s;\n", result);
155 } else if (streq(proc->args.decls->decl.type, "void")) {
156 /* newstyle, 0 argument */
162 ptype(proc->res_prefix, proc->res_type, 1);
163 f_print(fout, "*%s, %s%s)\n",
164 result, addargtype, addargname);
167 f_print(fout, "(%s)\n", addargname);
171 f_print(fout, "(%s%s)\n", addargtype, addargname);
173 f_print(fout, "(%s)\n", addargname);
175 /* new style, 1 or multiple arguments */
178 for (l = proc->args.decls; l != NULL; l = l->next)
179 f_print(fout, "%s, ", l->decl.name);
181 f_print(fout, "%s, ", result);
183 f_print(fout, "%s)\n", addargname);
184 for (l = proc->args.decls; l != NULL; l = l->next) {
185 pdeclaration(proc->args.argname,
190 ptype(proc->res_prefix, proc->res_type, 1);
191 f_print(fout, "*%s;\n", result);
194 } else { /* C++ style header */
196 for (l = proc->args.decls; l != NULL; l = l->next) {
197 pdeclaration(proc->args.argname, &l->decl, 0,
201 ptype(proc->res_prefix, proc->res_type, 1);
202 f_print(fout, "*%s, ", result);
205 f_print(fout, "%s%s)\n", addargtype, addargname);
210 f_print(fout, "\t%s%s;\n", addargtype, addargname);
219 if (isvectordef(type, REL_ALIAS)) {
231 bool_t args2 = (proc->arg_num > 1);
234 * For new style with multiple arguments, need a structure in which
235 * to stuff the arguments.
239 if (newstyle && args2) {
240 f_print(fout, "\t%s", proc->args.argname);
241 f_print(fout, " arg;\n");
244 f_print(fout, "\tstatic ");
245 if (streq(proc->res_type, "void")) {
246 f_print(fout, "char ");
248 ptype(proc->res_prefix, proc->res_type, 0);
250 f_print(fout, "%s;\n", RESULT);
252 f_print(fout, "\tmemset((char *)%s%s, 0, sizeof (%s));\n",
253 ampr(proc->res_type), RESULT, RESULT);
256 if (newstyle && !args2 &&
257 (streq(proc->args.decls->decl.type, "void"))) {
258 /* newstyle, 0 arguments */
261 f_print(fout, "\t return ");
263 f_print(fout, "\t if ");
266 "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ",
269 "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
270 stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type),
274 f_print(fout, "\n\t\tTIMEOUT));\n");
276 f_print(fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
278 } else if (newstyle && args2) {
280 * Newstyle, multiple arguments
281 * stuff arguments into structure
283 for (l = proc->args.decls; l != NULL; l = l->next) {
284 f_print(fout, "\targ.%s = %s;\n",
285 l->decl.name, l->decl.name);
288 f_print(fout, "\treturn ");
290 f_print(fout, "\tif ");
292 "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_%s",
293 proc->proc_name,proc->args.argname);
295 ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
296 stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type),
299 f_print(fout, "\n\t\tTIMEOUT));\n");
301 f_print(fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
302 } else { /* single argument, new or old style */
305 "\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",
307 stringfix(proc->args.decls->decl.type),
308 (newstyle ? "&" : ""),
309 (newstyle ? proc->args.decls->decl.name : "argp"),
310 stringfix(proc->res_type), ampr(proc->res_type),
315 "\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",
317 stringfix(proc->args.decls->decl.type),
318 (newstyle ? "&" : ""),
319 (newstyle ? proc->args.decls->decl.name : "argp"),
320 stringfix(proc->res_type), "",
324 f_print(fout, "\t\treturn (NULL);\n");
325 f_print(fout, "\t}\n");
327 if (streq(proc->res_type, "void")) {
328 f_print(fout, "\treturn ((void *)%s%s);\n",
329 ampr(proc->res_type), RESULT);
331 f_print(fout, "\treturn (%s%s);\n",
332 ampr(proc->res_type), RESULT);