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 * From: @(#)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 Microsystems, Inc.
41 #include <rpc/types.h>
42 #include "rpc_parse.h"
46 #define DEFAULT_TIMEOUT 25 /* in seconds */
47 static const char RESULT
[] = "clnt_res";
49 static void write_program (definition
* def
);
50 static void printbody (proc_list
* proc
);
51 static const char *ampr (const char *type
);
52 static void printbody (proc_list
* proc
);
62 "\n/* Default timeout can be changed using clnt_control() */\n");
63 fprintf (fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
65 for (l
= defined
; l
!= NULL
; l
= l
->next
)
67 def
= (definition
*) l
->val
;
68 if (def
->def_kind
== DEF_PROGRAM
)
76 write_program (definition
* def
)
81 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
)
83 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
)
88 ptype (proc
->res_prefix
, proc
->res_type
, 1);
89 fprintf (fout
, "*\n");
90 pvname (proc
->proc_name
, vp
->vers_num
);
91 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
95 fprintf (fout
, "enum clnt_stat \n");
96 pvname (proc
->proc_name
, vp
->vers_num
);
97 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
99 fprintf (fout
, "{\n");
101 fprintf (fout
, "}\n");
106 /* Writes out declarations of procedure's argument list.
107 In either ANSI C style, in one of old rpcgen style (pass by reference),
108 or new rpcgen style (multiple arguments, pass by value);
111 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
114 printarglist (proc_list
* proc
, const char *result
,
115 const char *addargname
, const char *addargtype
)
121 { /* old style: always pass argument by reference */
123 { /* C++ style heading */
125 ptype (proc
->args
.decls
->decl
.prefix
,
126 proc
->args
.decls
->decl
.type
, 1);
129 {/* Generate result field */
130 fprintf (fout
, "*argp, ");
131 ptype(proc
->res_prefix
, proc
->res_type
, 1);
132 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
135 fprintf (fout
, "*argp, %s%s)\n", addargtype
, addargname
);
140 fprintf (fout
, "(argp, %s)\n", addargname
);
142 fprintf (fout
, "(argp, %s, %s)\n", result
, addargname
);
143 fprintf (fout
, "\t");
144 ptype (proc
->args
.decls
->decl
.prefix
,
145 proc
->args
.decls
->decl
.type
, 1);
146 fprintf (fout
, "*argp;\n");
149 fprintf (fout
, "\t");
150 ptype (proc
->res_prefix
, proc
->res_type
, 1);
151 fprintf (fout
, "*%s;\n", result
);
155 else if (streq (proc
->args
.decls
->decl
.type
, "void"))
157 /* newstyle, 0 argument */
163 ptype(proc
->res_prefix
, proc
->res_type
, 1);
164 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
167 fprintf (fout
, "(%s)\n", addargname
);
170 fprintf (fout
, "(%s%s)\n", addargtype
, addargname
);
172 fprintf (fout
, "(%s)\n", addargname
);
176 /* new style, 1 or multiple arguments */
180 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
181 fprintf (fout
, "%s, ", l
->decl
.name
);
183 fprintf (fout
, "%s, ", result
);
184 fprintf (fout
, "%s)\n", addargname
);
185 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
187 pdeclaration (proc
->args
.argname
, &l
->decl
, 1, ";\n");
191 fprintf (fout
, "\t");
192 ptype (proc
->res_prefix
, proc
->res_type
, 1);
193 fprintf (fout
, "*%s;\n", result
);
197 { /* C++ style header */
199 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
201 pdeclaration (proc
->args
.argname
, &l
->decl
, 0, ", ");
205 ptype (proc
->res_prefix
, proc
->res_type
, 1);
206 fprintf (fout
, "*%s, ", result
);
208 fprintf (fout
, " %s%s)\n", addargtype
, addargname
);
213 fprintf (fout
, "\t%s%s;\n", addargtype
, addargname
);
219 ampr (const char *type
)
221 if (isvectordef (type
, REL_ALIAS
))
232 printbody (proc_list
* proc
)
235 bool_t args2
= (proc
->arg_num
> 1);
238 /* For new style with multiple arguments, need a structure in which
239 to stuff the arguments. */
240 if (newstyle
&& args2
)
242 fprintf (fout
, "\t%s", proc
->args
.argname
);
243 fprintf (fout
, " arg;\n");
247 fprintf (fout
, "\tstatic ");
248 if (streq (proc
->res_type
, "void"))
250 fprintf (fout
, "char ");
254 ptype (proc
->res_prefix
, proc
->res_type
, 0);
256 fprintf (fout
, "%s;\n", RESULT
);
257 fprintf (fout
, "\n");
258 fprintf (fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
259 ampr (proc
->res_type
), RESULT
, RESULT
);
261 if (newstyle
&& !args2
&& (streq (proc
->args
.decls
->decl
.type
, "void")))
263 /* newstyle, 0 arguments */
265 fprintf (fout
, "\t return ");
267 fprintf (fout
, "\t if ");
269 "(clnt_call (clnt, %s, (xdrproc_t) xdr_void, ", proc
->proc_name
);
272 "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
273 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
276 fprintf (fout
, "\n\t\tTIMEOUT));\n\n");
278 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
280 else if (newstyle
&& args2
)
282 /* newstyle, multiple arguments: stuff arguments into structure */
283 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
285 fprintf (fout
, "\targ.%s = %s;\n",
286 l
->decl
.name
, l
->decl
.name
);
289 fprintf (fout
, "\treturn ");
291 fprintf (fout
, "\tif ");
294 "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc
->proc_name
,
297 ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
298 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
301 fprintf (fout
, "\n\t\tTIMEOUT));\n");
303 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
306 { /* single argument, new or old style */
309 "\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",
311 stringfix (proc
->args
.decls
->decl
.type
),
312 (newstyle
? "&" : ""),
313 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
314 stringfix (proc
->res_type
), ampr (proc
->res_type
),
318 "\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",
320 stringfix (proc
->args
.decls
->decl
.type
),
321 (newstyle
? "&" : ""),
322 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
323 stringfix (proc
->res_type
), "",
328 fprintf (fout
, "\t\treturn (NULL);\n");
329 fprintf (fout
, "\t}\n");
330 if (streq (proc
->res_type
, "void"))
332 fprintf (fout
, "\treturn ((void *)%s%s);\n",
333 ampr (proc
->res_type
), RESULT
);
337 fprintf (fout
, "\treturn (%s%s);\n", ampr (proc
->res_type
), RESULT
);