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 or with the express written consent of
8 * Sun Microsystems, Inc.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 static char sccsid[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI";
36 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
37 * Copyright (C) 1987, Sun Microsytsems, Inc.
41 #include <rpc/types.h>
42 #include "rpc_parse.h"
44 #include "rpc_output.h"
46 /* extern pdeclaration(); */
47 /* void printarglist(); */
49 #define DEFAULT_TIMEOUT 25 /* in seconds */
50 static char RESULT[] = "clnt_res";
52 static void write_program(definition *def);
53 static void printbody(proc_list *proc);
63 "\n/* Default timeout can be changed using clnt_control() */\n");
64 f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
66 for (l = defined; l != NULL; l = l->next) {
67 def = (definition *) l->val;
68 if (def->def_kind == DEF_PROGRAM) {
75 write_program(definition *def)
80 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
81 for (proc = vp->procs; proc != NULL; proc = proc->next) {
83 ptype(proc->res_prefix, proc->res_type, 1);
85 pvname(proc->proc_name, vp->vers_num);
86 printarglist(proc, "clnt", "CLIENT *");
95 * Writes out declarations of procedure's argument list.
96 * In either ANSI C style, in one of old rpcgen style (pass by reference),
97 * or new rpcgen style (multiple arguments, pass by value);
100 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
103 printarglist(proc_list *proc, char *addargname, char *addargtype)
108 if (!newstyle) { /* old style: always pass arg by reference */
109 if (Cflag) { /* C++ style heading */
111 ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
112 f_print(fout, "*argp, %s%s)\n", addargtype, addargname);
114 f_print(fout, "(argp, %s)\n", addargname);
116 ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
117 f_print(fout, "*argp;\n");
119 } else if (streq(proc->args.decls->decl.type, "void")) {
120 /* newstyle, 0 argument */
122 f_print(fout, "(%s%s)\n", addargtype, addargname);
124 f_print(fout, "(%s)\n", addargname);
126 /* new style, 1 or multiple arguments */
129 for (l = proc->args.decls; l != NULL; l = l->next)
130 f_print(fout, "%s, ", l->decl.name);
131 f_print(fout, "%s)\n", addargname);
132 for (l = proc->args.decls; l != NULL; l = l->next) {
133 pdeclaration(proc->args.argname, &l->decl, 1, ";\n");
135 } else { /* C++ style header */
137 for (l = proc->args.decls; l != NULL; l = l->next) {
138 pdeclaration(proc->args.argname, &l->decl, 0, ", ");
140 f_print(fout, " %s%s)\n", addargtype, addargname);
145 f_print(fout, "\t%s%s;\n", addargtype, addargname);
153 if (isvectordef(type, REL_ALIAS)) {
161 printbody(proc_list *proc)
164 bool_t args2 = (proc->arg_num > 1);
166 /* For new style with multiple arguments, need a structure in which
167 * to stuff the arguments. */
168 if (newstyle && args2) {
169 f_print(fout, "\t%s", proc->args.argname);
170 f_print(fout, " arg;\n");
172 f_print(fout, "\tstatic ");
173 if (streq(proc->res_type, "void")) {
174 f_print(fout, "char ");
176 ptype(proc->res_prefix, proc->res_type, 0);
178 f_print(fout, "%s;\n", RESULT);
180 f_print(fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
181 ampr(proc->res_type), RESULT, RESULT);
182 if (newstyle && !args2 && (streq(proc->args.decls->decl.type, "void"))) {
183 /* newstyle, 0 arguments */
185 "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_void, (caddr_t) NULL, "
186 "(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
188 stringfix(proc->res_type), ampr(proc->res_type), RESULT);
190 } else if (newstyle && args2) {
191 /* newstyle, multiple arguments: stuff arguments into structure */
192 for (l = proc->args.decls; l != NULL; l = l->next) {
193 f_print(fout, "\targ.%s = %s;\n",
194 l->decl.name, l->decl.name);
197 "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, (caddr_t) &arg, "
198 "(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
199 proc->proc_name, proc->args.argname,
200 stringfix(proc->res_type), ampr(proc->res_type), RESULT);
201 } else { /* single argument, new or old style */
203 "\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, "
204 "(caddr_t) %s%s, (xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
206 stringfix(proc->args.decls->decl.type),
207 (newstyle ? "&" : ""),
208 (newstyle ? proc->args.decls->decl.name : "argp"),
209 stringfix(proc->res_type), ampr(proc->res_type), RESULT);
211 f_print(fout, "\t\treturn (NULL);\n");
212 f_print(fout, "\t}\n");
213 if (streq(proc->res_type, "void")) {
214 f_print(fout, "\treturn ((void *)%s%s);\n",
215 ampr(proc->res_type), RESULT);
217 f_print(fout, "\treturn (%s%s);\n", ampr(proc->res_type), RESULT);