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 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 f_print(fout
, "static struct timeval TIMEOUT = { %d, 0 };\n",
67 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
68 def
= (definition
*) l
->val
;
69 if (def
->def_kind
== DEF_PROGRAM
) {
76 write_program(definition
*def
)
81 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
82 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
84 ptype(proc
->res_prefix
, proc
->res_type
, 1);
86 pvname(proc
->proc_name
, vp
->vers_num
);
87 printarglist( proc
, "clnt", "CLIENT *" );
95 /* Writes out declarations of procedure's argument list.
96 In either ANSI C style, in one of old rpcgen style (pass by reference),
97 or new rpcgen style (multiple arguments, pass by value);
100 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
102 void printarglist(proc_list
*proc
,
103 const char *addargname
, const char *addargtype
)
108 if (!newstyle
) { /* old style: always pass argument by reference */
109 if (Cflag
) { /* C++ style heading */
111 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
112 f_print(fout
, "*argp, %s%s)\n", addargtype
, addargname
);
115 f_print(fout
, "(argp, %s)\n", addargname
);
117 ptype(proc
->args
.decls
->decl
.prefix
, proc
->args
.decls
->decl
.type
, 1);
118 f_print(fout
, "*argp;\n");
120 } else if (streq( proc
->args
.decls
->decl
.type
, "void")) {
121 /* newstyle, 0 argument */
123 f_print(fout
, "(%s%s)\n", addargtype
, addargname
);
125 f_print(fout
, "(%s)\n", addargname
);
127 /* new style, 1 or multiple arguments */
130 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
)
131 f_print(fout
, "%s, ", l
->decl
.name
);
132 f_print(fout
, "%s)\n", addargname
);
133 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
134 pdeclaration(proc
->args
.argname
, &l
->decl
, 1, ";\n" );
136 } else { /* C++ style header */
138 for(l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
139 pdeclaration(proc
->args
.argname
, &l
->decl
, 0, ", " );
141 f_print(fout
, " %s%s)\n", addargtype
, addargname
);
146 f_print(fout
, "\t%s%s;\n", addargtype
, addargname
);
153 ampr(const char *type
)
155 if (isvectordef(type
, REL_ALIAS
)) {
163 printbody(proc_list
*proc
)
166 bool_t args2
= (proc
->arg_num
> 1);
169 /* For new style with multiple arguments, need a structure in which
170 to stuff the arguments. */
171 if ( newstyle
&& args2
) {
172 f_print(fout
, "\t%s", proc
->args
.argname
);
173 f_print(fout
, " arg;\n");
175 f_print(fout
, "\tstatic ");
176 if (streq(proc
->res_type
, "void")) {
177 f_print(fout
, "char ");
179 ptype(proc
->res_prefix
, proc
->res_type
, 0);
181 f_print(fout
, "%s;\n",RESULT
);
183 f_print(fout
, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
184 ampr(proc
->res_type
), RESULT
, RESULT
);
185 if (newstyle
&& !args2
&& (streq( proc
->args
.decls
->decl
.type
, "void"))) {
186 /* newstyle, 0 arguments */
188 "\tif (clnt_call(clnt, %s, xdr_void", proc
->proc_name
);
190 ", NULL, xdr_%s, %s,%s, TIMEOUT) != RPC_SUCCESS) {\n",
191 stringfix(proc
->res_type
), ampr(proc
->res_type
), RESULT
);
193 } else if ( newstyle
&& args2
) {
194 /* newstyle, multiple arguments: stuff arguments into structure */
195 for (l
= proc
->args
.decls
; l
!= NULL
; l
= l
->next
) {
196 f_print(fout
, "\targ.%s = %s;\n",
197 l
->decl
.name
, l
->decl
.name
);
200 "\tif (clnt_call(clnt, %s, xdr_%s", proc
->proc_name
,
203 ", &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
204 stringfix(proc
->res_type
), ampr(proc
->res_type
), RESULT
);
205 } else { /* single argument, new or old style */
207 "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
209 stringfix(proc
->args
.decls
->decl
.type
),
210 (newstyle
? "&" : ""),
211 (newstyle
? proc
->args
.decls
->decl
.name
: "argp"),
212 stringfix(proc
->res_type
), ampr(proc
->res_type
),RESULT
);
214 f_print(fout
, "\t\treturn (NULL);\n");
215 f_print(fout
, "\t}\n");
216 if (streq(proc
->res_type
, "void")) {
217 f_print(fout
, "\treturn ((void *)%s%s);\n",
218 ampr(proc
->res_type
),RESULT
);
220 f_print(fout
, "\treturn (%s%s);\n", ampr(proc
->res_type
),RESULT
);