]>
git.cameronkatri.com Git - apple_cmds.git/blob - developer_cmds/rpcgen/rpc_clntout.c
1 /* $NetBSD: rpc_clntout.c,v 1.8 1997/10/18 10:53:37 lukem 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 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI";
37 __RCSID("$NetBSD: rpc_clntout.c,v 1.8 1997/10/18 10:53:37 lukem Exp $");
42 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
43 * Copyright (C) 1987, Sun Microsytsems, Inc.
47 #include <rpc/types.h>
49 #include "rpc_parse.h"
52 static void write_program
__P((definition
*));
53 static char *ampr
__P((char *));
54 static void printbody
__P((proc_list
*));
56 #define DEFAULT_TIMEOUT 25 /* in seconds */
57 static char RESULT
[] = "clnt_res";
67 "\n/* Default timeout can be changed using clnt_control() */\n");
68 f_print(fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
70 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
71 def
= (definition
*) l
->val
;
72 if (def
->def_kind
== DEF_PROGRAM
) {
85 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
86 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
88 ptype(proc
->res_prefix
, proc
->res_type
, 1);
90 pvname(proc
->proc_name
, vp
->vers_num
);
91 printarglist(proc
, "clnt", "CLIENT *");
98 /* Writes out declarations of procedure's argument list.
99 In either ANSI C style, in one of old rpcgen style (pass by reference),
100 or new rpcgen style (multiple arguments, pass by value);
103 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
106 printarglist(proc
, addargname
, addargtype
)
108 char *addargname
, *addargtype
;
113 if (!newstyle
) { /* old style: always pass argument by
115 if (Cflag
) { /* C++ style heading */
117 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
118 f_print(fout
, "*argp, %s%s)\n", addargtype
, addargname
);
120 f_print(fout
, "(argp, %s)\n", addargname
);
122 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
123 f_print(fout
, "*argp;\n");
126 if (streq(proc
->args
.decls
->decl
.type
, "void")) {
127 /* newstyle, 0 argument */
129 f_print(fout
, "(%s%s)\n", addargtype
, addargname
);
131 f_print(fout
, "(%s)\n", addargname
);
133 /* new style, 1 or multiple arguments */
136 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
137 f_print(fout
, "%s, ", l
->decl
.name
);
138 f_print(fout
, "%s)\n", addargname
);
139 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
140 pdeclaration(proc
->args
.argname
, &l
->decl
, 1, ";\n");
142 } else {/* C++ style header */
144 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
145 pdeclaration(proc
->args
.argname
, &l
->decl
, 0, ", ");
147 f_print(fout
, " %s%s)\n", addargtype
, addargname
);
152 f_print(fout
, "\t%s%s;\n", addargtype
, addargname
);
161 if (isvectordef(type
, REL_ALIAS
)) {
173 bool_t args2
= (proc
->arg_num
> 1);
175 /* For new style with multiple arguments, need a structure in which to
176 * stuff the arguments. */
177 if (newstyle
&& args2
) {
178 f_print(fout
, "\t%s", proc
->args
.argname
);
179 f_print(fout
, " arg;\n");
181 f_print(fout
, "\tstatic ");
182 if (streq(proc
->res_type
, "void")) {
183 f_print(fout
, "char ");
185 ptype(proc
->res_prefix
, proc
->res_type
, 0);
187 f_print(fout
, "%s;\n", RESULT
);
189 f_print(fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
190 ampr(proc
->res_type
), RESULT
, RESULT
);
191 if (newstyle
&& !args2
&& (streq(proc
->args
.decls
->decl
.type
, "void"))) {
192 /* newstyle, 0 arguments */
194 "\tif (clnt_call(clnt, %s, xdr_void", proc
->proc_name
);
196 ", NULL, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
197 stringfix(proc
->res_type
), ampr(proc
->res_type
), RESULT
);
200 if (newstyle
&& args2
) {
201 /* newstyle, multiple arguments: stuff arguments into
203 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
204 f_print(fout
, "\targ.%s = %s;\n",
205 l
->decl
.name
, l
->decl
.name
);
208 "\tif (clnt_call(clnt, %s, xdr_%s, &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n",
211 stringfix(proc
->res_type
),
212 ampr(proc
->res_type
), RESULT
);
213 } else { /* single argument, new or old style */
215 "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n",
217 stringfix(proc
->args
.decls
->decl
.type
),
218 (newstyle
? "&" : ""),
219 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
220 stringfix(proc
->res_type
),
221 ampr(proc
->res_type
), RESULT
);
223 f_print(fout
, "\t\treturn (NULL);\n");
224 if (streq(proc
->res_type
, "void")) {
225 f_print(fout
, "\treturn ((void *)%s%s);\n",
226 ampr(proc
->res_type
), RESULT
);
228 f_print(fout
, "\treturn (%s%s);\n", ampr(proc
->res_type
), RESULT
);