1 /* $NetBSD: rpc_clntout.c,v 1.12 2002/01/31 19:36:48 tv Exp $ */
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user or with the express written consent of
9 * Sun Microsystems, Inc.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
36 #include <sys/cdefs.h>
37 #if defined(__RCSID) && !defined(lint)
39 static char sccsid
[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI";
41 __RCSID("$NetBSD: rpc_clntout.c,v 1.12 2002/01/31 19:36:48 tv Exp $");
46 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
47 * Copyright (C) 1987, Sun Microsytsems, Inc.
51 #include <rpc/types.h>
53 #include "rpc_parse.h"
56 static void write_program
__P((definition
*));
57 static char *ampr
__P((char *));
58 static char *aster
__P((char *));
59 static void printbody
__P((proc_list
*));
61 #define DEFAULT_TIMEOUT 25 /* in seconds */
62 static char RESULT
[] = "clnt_res";
72 "\n/* Default timeout can be changed using clnt_control() */\n");
73 f_print(fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
75 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
76 def
= (definition
*) l
->val
;
77 if (def
->def_kind
== DEF_PROGRAM
) {
90 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
91 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
94 f_print(fout
, "enum clnt_stat\n");
96 ptype(proc
->res_prefix
, proc
->res_type
, 1);
99 pvname(proc
->proc_name
, vp
->vers_num
);
100 printarglist(proc
, RESULT
, "clnt", "CLIENT *");
101 f_print(fout
, "{\n");
103 f_print(fout
, "}\n");
107 /* Writes out declarations of procedure's argument list.
108 In either ANSI C style, in one of old rpcgen style (pass by reference),
109 or new rpcgen style (multiple arguments, pass by value);
112 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
115 printarglist(proc
, result
, addargname
, addargtype
)
117 char *result
, *addargname
, *addargtype
;
122 if (!newstyle
) { /* old style: always pass argument by
124 if (Cflag
) { /* C++ style heading */
126 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
127 f_print(fout
, "*argp, ");
129 if (streq(proc
->res_type
, "void"))
130 f_print(fout
, "char ");
132 ptype(proc
->res_prefix
, proc
->res_type
, 0);
133 f_print(fout
, "%s%s, ", aster(proc
->res_type
),
136 f_print(fout
, "%s%s)\n", addargtype
, addargname
);
138 f_print(fout
, "(argp, ");
140 f_print(fout
, "%s, ", result
);
141 f_print(fout
, "%s)\n", addargname
);
143 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
144 f_print(fout
, "*argp;\n");
147 if (streq(proc
->res_type
, "void"))
148 f_print(fout
, "char ");
150 ptype(proc
->res_prefix
, proc
->res_type
, 0);
151 f_print(fout
, "%s%s;\n", aster(proc
->res_type
),
157 if (!streq(proc
->args
.decls
->decl
.type
, "void")) {
158 /* new style, 1 or multiple arguments */
160 for (l
= proc
->args
.decls
; l
!= NULL
;
162 f_print(fout
, "%s, ", l
->decl
.name
);
163 } else {/* C++ style header */
164 for (l
= proc
->args
.decls
; l
!= NULL
;
166 pdeclaration(proc
->args
.argname
,
173 if (streq(proc
->res_type
, "void"))
174 f_print(fout
, "char ");
176 ptype(proc
->res_prefix
, proc
->res_type
, 0);
177 f_print(fout
, "%s%s;\n", aster(proc
->res_type
),
180 f_print(fout
, "%s)\n", addargname
);
181 if (!streq(proc
->args
.decls
->decl
.type
, "void")) {
182 for (l
= proc
->args
.decls
; l
!= NULL
;
184 pdeclaration(proc
->args
.argname
,
189 if (streq(proc
->res_type
, "void"))
190 f_print(fout
, "char ");
192 ptype(proc
->res_prefix
, proc
->res_type
, 0);
193 f_print(fout
, "%s%s, ", aster(proc
->res_type
),
196 f_print(fout
, "%s%s)\n", addargtype
, addargname
);
201 f_print(fout
, "\t%s%s;\n", addargtype
, addargname
);
209 if (isvectordef(type
, REL_ALIAS
)) {
220 if (isvectordef(type
, REL_ALIAS
)) {
232 bool_t args2
= (proc
->arg_num
> 1);
234 /* For new style with multiple arguments, need a structure in which to
235 * stuff the arguments. */
236 if (newstyle
&& args2
) {
237 f_print(fout
, "\t%s", proc
->args
.argname
);
238 f_print(fout
, " arg;\n");
241 f_print(fout
, "\tstatic ");
242 if (streq(proc
->res_type
, "void"))
243 f_print(fout
, "char ");
245 ptype(proc
->res_prefix
, proc
->res_type
, 0);
246 f_print(fout
, "%s;\n", RESULT
);
250 f_print(fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
251 ampr(proc
->res_type
), RESULT
, RESULT
);
252 if (newstyle
&& !args2
&& (streq(proc
->args
.decls
->decl
.type
, "void"))) {
253 /* newstyle, 0 arguments */
255 f_print(fout
, "\treturn (clnt_call(clnt, %s, xdr_void",
257 f_print(fout
, ", NULL, xdr_%s, %s, TIMEOUT));\n",
258 stringfix(proc
->res_type
), RESULT
);
260 f_print(fout
, "\tif (clnt_call(clnt, %s, xdr_void, ",
263 "NULL, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n",
264 stringfix(proc
->res_type
), ampr(proc
->res_type
),
268 if (newstyle
&& args2
) {
269 /* newstyle, multiple arguments: stuff arguments into
271 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
272 f_print(fout
, "\targ.%s = %s;\n",
273 l
->decl
.name
, l
->decl
.name
);
277 "\treturn (clnt_call(clnt, %s, xdr_%s, &arg, xdr_%s, %s, TIMEOUT));\n",
278 proc
->proc_name
, proc
->args
.argname
,
279 stringfix(proc
->res_type
), RESULT
);
282 "\tif (clnt_call(clnt, %s, xdr_%s, &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n",
283 proc
->proc_name
, proc
->args
.argname
,
284 stringfix(proc
->res_type
),
285 ampr(proc
->res_type
), RESULT
);
287 } else { /* single argument, new or old style */
290 "\treturn (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s, TIMEOUT));\n",
292 stringfix(proc
->args
.decls
->decl
.type
),
293 (newstyle
? "&" : ""),
294 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
295 stringfix(proc
->res_type
), RESULT
);
298 "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n",
300 stringfix(proc
->args
.decls
->decl
.type
),
301 (newstyle
? "&" : ""),
302 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
303 stringfix(proc
->res_type
),
304 ampr(proc
->res_type
), RESULT
);
309 f_print(fout
, "\t\treturn (NULL);\n");
310 if (streq(proc
->res_type
, "void"))
311 f_print(fout
, "\treturn ((void *)%s%s);\n",
312 ampr(proc
->res_type
), RESULT
);
314 f_print(fout
, "\treturn (%s%s);\n",
315 ampr(proc
->res_type
), RESULT
);