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 char clntout_rcsid
[] =
38 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
39 * Copyright (C) 1987, Sun Microsystems, Inc.
43 #include <rpc/types.h>
44 #include "rpc_parse.h"
48 #define DEFAULT_TIMEOUT 25 /* in seconds */
49 static const char RESULT
[] = "clnt_res";
51 static void write_program (definition
* def
);
52 static void printbody (proc_list
* proc
);
53 static const char *ampr (const char *type
);
54 static void printbody (proc_list
* proc
);
64 "\n/* Default timeout can be changed using clnt_control() */\n");
65 fprintf (fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
67 for (l
= defined
; l
!= NULL
; l
= l
->next
)
69 def
= (definition
*) l
->val
;
70 if (def
->def_kind
== DEF_PROGRAM
)
78 write_program (definition
* def
)
83 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
)
85 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
)
90 ptype (proc
->res_prefix
, proc
->res_type
, 1);
91 fprintf (fout
, "*\n");
92 pvname (proc
->proc_name
, vp
->vers_num
);
93 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
97 fprintf (fout
, "enum clnt_stat \n");
98 pvname (proc
->proc_name
, vp
->vers_num
);
99 printarglist (proc
, RESULT
, "clnt", "CLIENT *");
101 fprintf (fout
, "{\n");
103 fprintf (fout
, "}\n");
108 /* Writes out declarations of procedure's argument list.
109 In either ANSI C style, in one of old rpcgen style (pass by reference),
110 or new rpcgen style (multiple arguments, pass by value);
113 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
116 printarglist (proc_list
* proc
, const char *result
,
117 const char *addargname
, const char *addargtype
)
123 { /* old style: always pass argument by reference */
125 { /* C++ style heading */
127 ptype (proc
->args
.decls
->decl
.prefix
,
128 proc
->args
.decls
->decl
.type
, 1);
131 {/* Generate result field */
132 fprintf (fout
, "*argp, ");
133 ptype(proc
->res_prefix
, proc
->res_type
, 1);
134 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
137 fprintf (fout
, "*argp, %s%s)\n", addargtype
, addargname
);
142 fprintf (fout
, "(argp, %s)\n", addargname
);
144 fprintf (fout
, "(argp, %s, %s)\n", result
, addargname
);
145 fprintf (fout
, "\t");
146 ptype (proc
->args
.decls
->decl
.prefix
,
147 proc
->args
.decls
->decl
.type
, 1);
148 fprintf (fout
, "*argp;\n");
151 fprintf (fout
, "\t");
152 ptype (proc
->res_prefix
, proc
->res_type
, 1);
153 fprintf (fout
, "*%s;\n", result
);
157 else if (streq (proc
->args
.decls
->decl
.type
, "void"))
159 /* newstyle, 0 argument */
165 ptype(proc
->res_prefix
, proc
->res_type
, 1);
166 fprintf (fout
, "*%s, %s%s)\n", result
, addargtype
, addargname
);
169 fprintf (fout
, "(%s)\n", addargname
);
172 fprintf (fout
, "(%s%s)\n", addargtype
, addargname
);
174 fprintf (fout
, "(%s)\n", addargname
);
178 /* new style, 1 or multiple arguments */
182 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
183 fprintf (fout
, "%s, ", l
->decl
.name
);
185 fprintf (fout
, "%s, ", result
);
186 fprintf (fout
, "%s)\n", addargname
);
187 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
189 pdeclaration (proc
->args
.argname
, &l
->decl
, 1, ";\n");
193 fprintf (fout
, "\t");
194 ptype (proc
->res_prefix
, proc
->res_type
, 1);
195 fprintf (fout
, "*%s;\n", result
);
199 { /* C++ style header */
201 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
203 pdeclaration (proc
->args
.argname
, &l
->decl
, 0, ", ");
207 ptype (proc
->res_prefix
, proc
->res_type
, 1);
208 fprintf (fout
, "*%s, ", result
);
210 fprintf (fout
, " %s%s)\n", addargtype
, addargname
);
215 fprintf (fout
, "\t%s%s;\n", addargtype
, addargname
);
221 ampr (const char *type
)
223 if (isvectordef (type
, REL_ALIAS
))
234 printbody (proc_list
* proc
)
237 bool_t args2
= (proc
->arg_num
> 1);
240 /* For new style with multiple arguments, need a structure in which
241 to stuff the arguments. */
242 if (newstyle
&& args2
)
244 fprintf (fout
, "\t%s", proc
->args
.argname
);
245 fprintf (fout
, " arg;\n");
249 fprintf (fout
, "\tstatic ");
250 if (streq (proc
->res_type
, "void"))
252 fprintf (fout
, "char ");
256 ptype (proc
->res_prefix
, proc
->res_type
, 0);
258 fprintf (fout
, "%s;\n", RESULT
);
259 fprintf (fout
, "\n");
260 fprintf (fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
261 ampr (proc
->res_type
), RESULT
, RESULT
);
263 if (newstyle
&& !args2
&& (streq (proc
->args
.decls
->decl
.type
, "void")))
265 /* newstyle, 0 arguments */
267 fprintf (fout
, "\t return ");
269 fprintf (fout
, "\t if ");
271 "(clnt_call (clnt, %s, (xdrproc_t) xdr_void, ", proc
->proc_name
);
274 "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
275 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
278 fprintf (fout
, "\n\t\tTIMEOUT));\n\n");
280 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
282 else if (newstyle
&& args2
)
284 /* newstyle, multiple arguments: stuff arguments into structure */
285 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
287 fprintf (fout
, "\targ.%s = %s;\n",
288 l
->decl
.name
, l
->decl
.name
);
291 fprintf (fout
, "\treturn ");
293 fprintf (fout
, "\tif ");
296 "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc
->proc_name
,
299 ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
300 stringfix(proc
->res_type
), (mtflag
)?"":ampr(proc
->res_type
),
303 fprintf (fout
, "\n\t\tTIMEOUT));\n");
305 fprintf (fout
, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
308 { /* single argument, new or old style */
311 "\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",
313 stringfix (proc
->args
.decls
->decl
.type
),
314 (newstyle
? "&" : ""),
315 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
316 stringfix (proc
->res_type
), ampr (proc
->res_type
),
320 "\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",
322 stringfix (proc
->args
.decls
->decl
.type
),
323 (newstyle
? "&" : ""),
324 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
325 stringfix (proc
->res_type
), "",
330 fprintf (fout
, "\t\treturn (NULL);\n");
331 fprintf (fout
, "\t}\n");
332 if (streq (proc
->res_type
, "void"))
334 fprintf (fout
, "\treturn ((void *)%s%s);\n",
335 ampr (proc
->res_type
), RESULT
);
339 fprintf (fout
, "\treturn (%s%s);\n", ampr (proc
->res_type
), RESULT
);