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
34 #if defined(LIBC_SCCS) && !defined(lint)
35 static const char clntout_rcsid
[] =
40 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
41 * Copyright (C) 1987, Sun Microsystems, Inc.
45 #include <rpc/types.h>
46 #include "rpc_parse.h"
50 #define DEFAULT_TIMEOUT 25 /* in seconds */
51 static const char RESULT
[] = "clnt_res";
53 static void write_program (definition
* def
);
54 static void printbody (proc_list
* proc
);
55 static const char *ampr (const char *type
);
56 static void printbody (proc_list
* proc
);
66 "\n/* Default timeout can be changed using clnt_control() */\n");
67 fprintf (fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
69 for (l
= defined
; l
!= NULL
; l
= l
->next
)
71 def
= (definition
*) l
->val
;
72 if (def
->def_kind
== DEF_PROGRAM
)
80 write_program (definition
* def
)
85 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
)
87 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
)
92 ptype (proc
->res_prefix
, proc
->res_type
, 1);
93 fprintf (fout
, "*\n");
94 pvname (proc
->proc_name
, vp
->vers_num
);
95 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
99 fprintf (fout
, "enum clnt_stat \n");
100 pvname (proc
->proc_name
, vp
->vers_num
);
101 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
103 fprintf (fout
, "{\n");
105 fprintf (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 * " */
118 printarglist (proc_list
* proc
, const char *result
,
119 const char *addargname
, const char *addargtype
)
125 { /* old style: always pass argument by reference */
127 { /* C++ style heading */
129 ptype (proc
->args
.decls
->decl
.prefix
,
130 proc
->args
.decls
->decl
.type
, 1);
133 {/* Generate result field */
134 fprintf (fout
, "*argp, ");
135 ptype(proc
->res_prefix
, proc
->res_type
, 1);
136 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
139 fprintf (fout
, "*argp, %s%s)\n", addargtype
, addargname
);
144 fprintf (fout
, "(argp, %s)\n", addargname
);
146 fprintf (fout
, "(argp, %s, %s)\n", result
, addargname
);
147 fprintf (fout
, "\t");
148 ptype (proc
->args
.decls
->decl
.prefix
,
149 proc
->args
.decls
->decl
.type
, 1);
150 fprintf (fout
, "*argp;\n");
153 fprintf (fout
, "\t");
154 ptype (proc
->res_prefix
, proc
->res_type
, 1);
155 fprintf (fout
, "*%s;\n", result
);
159 else if (streq (proc
->args
.decls
->decl
.type
, "void"))
161 /* newstyle, 0 argument */
167 ptype(proc
->res_prefix
, proc
->res_type
, 1);
168 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
171 fprintf (fout
, "(%s)\n", addargname
);
174 fprintf (fout
, "(%s%s)\n", addargtype
, addargname
);
176 fprintf (fout
, "(%s)\n", addargname
);
180 /* new style, 1 or multiple arguments */
184 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
185 fprintf (fout
, "%s, ", l
->decl
.name
);
187 fprintf (fout
, "%s, ", result
);
188 fprintf (fout
, "%s)\n", addargname
);
189 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
191 pdeclaration (proc
->args
.argname
, &l
->decl
, 1, ";\n");
195 fprintf (fout
, "\t");
196 ptype (proc
->res_prefix
, proc
->res_type
, 1);
197 fprintf (fout
, "*%s;\n", result
);
201 { /* C++ style header */
203 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
205 pdeclaration (proc
->args
.argname
, &l
->decl
, 0, ", ");
209 ptype (proc
->res_prefix
, proc
->res_type
, 1);
210 fprintf (fout
, "*%s, ", result
);
212 fprintf (fout
, " %s%s)\n", addargtype
, addargname
);
217 fprintf (fout
, "\t%s%s;\n", addargtype
, addargname
);
223 ampr (const char *type
)
225 if (isvectordef (type
, REL_ALIAS
))
236 printbody (proc_list
* proc
)
239 bool_t args2
= (proc
->arg_num
> 1);
242 /* For new style with multiple arguments, need a structure in which
243 to stuff the arguments. */
244 if (newstyle
&& args2
)
246 fprintf (fout
, "\t%s", proc
->args
.argname
);
247 fprintf (fout
, " arg;\n");
251 fprintf (fout
, "\tstatic ");
252 if (streq (proc
->res_type
, "void"))
254 fprintf (fout
, "char ");
258 ptype (proc
->res_prefix
, proc
->res_type
, 0);
260 fprintf (fout
, "%s;\n", RESULT
);
261 fprintf (fout
, "\n");
262 fprintf (fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
263 ampr (proc
->res_type
), RESULT
, RESULT
);
265 if (newstyle
&& !args2
&& (streq (proc
->args
.decls
->decl
.type
, "void")))
267 /* newstyle, 0 arguments */
269 fprintf (fout
, "\t return ");
271 fprintf (fout
, "\t if ");
273 "(clnt_call (clnt, %s, (xdrproc_t) xdr_void, ", proc
->proc_name
);
276 "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
277 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
280 fprintf (fout
, "\n\t\tTIMEOUT));\n\n");
282 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
284 else if (newstyle
&& args2
)
286 /* newstyle, multiple arguments: stuff arguments into structure */
287 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
289 fprintf (fout
, "\targ.%s = %s;\n",
290 l
->decl
.name
, l
->decl
.name
);
293 fprintf (fout
, "\treturn ");
295 fprintf (fout
, "\tif ");
298 "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc
->proc_name
,
301 ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
302 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
305 fprintf (fout
, "\n\t\tTIMEOUT));\n");
307 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
310 { /* single argument, new or old style */
313 "\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",
315 stringfix (proc
->args
.decls
->decl
.type
),
316 (newstyle
? "&" : ""),
317 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
318 stringfix (proc
->res_type
), ampr (proc
->res_type
),
322 "\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",
324 stringfix (proc
->args
.decls
->decl
.type
),
325 (newstyle
? "&" : ""),
326 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
327 stringfix (proc
->res_type
), "",
332 fprintf (fout
, "\t\treturn (NULL);\n");
333 fprintf (fout
, "\t}\n");
334 if (streq (proc
->res_type
, "void"))
336 fprintf (fout
, "\treturn ((void *)%s%s);\n",
337 ampr (proc
->res_type
), RESULT
);
341 fprintf (fout
, "\treturn (%s%s);\n", ampr (proc
->res_type
), RESULT
);