* sysdeps/m68k/fpu/s_isinf.c (INTDEFX): Define to get correct
[glibc.git] / sunrpc / rpc_clntout.c
blob1e6bb5672825e8a8bd4990e3a837592fa0d3125c
1 /*
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.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
32 * From: @(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI
34 char clntout_rcsid[] =
35 "$Id$";
38 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
39 * Copyright (C) 1987, Sun Microsystems, Inc.
41 #include <stdio.h>
42 #include <string.h>
43 #include <rpc/types.h>
44 #include "rpc_parse.h"
45 #include "rpc_util.h"
46 #include "proto.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);
57 void
58 write_stubs (void)
60 list *l;
61 definition *def;
63 fprintf (fout,
64 "\n/* Default timeout can be changed using clnt_control() */\n");
65 fprintf (fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
66 DEFAULT_TIMEOUT);
67 for (l = defined; l != NULL; l = l->next)
69 def = (definition *) l->val;
70 if (def->def_kind == DEF_PROGRAM)
72 write_program (def);
77 static void
78 write_program (definition * def)
80 version_list *vp;
81 proc_list *proc;
83 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
85 for (proc = vp->procs; proc != NULL; proc = proc->next)
87 fprintf (fout, "\n");
88 if (mtflag == 0)
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 *");
95 else
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");
102 printbody (proc);
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 * " */
115 void
116 printarglist (proc_list * proc, const char *result,
117 const char *addargname, const char *addargtype)
120 decl_list *l;
122 if (!newstyle)
123 { /* old style: always pass argument by reference */
124 if (Cflag)
125 { /* C++ style heading */
126 fprintf (fout, "(");
127 ptype (proc->args.decls->decl.prefix,
128 proc->args.decls->decl.type, 1);
130 if (mtflag)
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);
136 else
137 fprintf (fout, "*argp, %s%s)\n", addargtype, addargname);
139 else
141 if (!mtflag)
142 fprintf (fout, "(argp, %s)\n", addargname);
143 else
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");
149 if (mtflag)
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 */
160 if (mtflag)
162 fprintf (fout, "(");
163 if (Cflag)
165 ptype(proc->res_prefix, proc->res_type, 1);
166 fprintf (fout, "*%s, %s%s)\n", result, addargtype, addargname);
168 else
169 fprintf (fout, "(%s)\n", addargname);
171 else if (Cflag)
172 fprintf (fout, "(%s%s)\n", addargtype, addargname);
173 else
174 fprintf (fout, "(%s)\n", addargname);
176 else
178 /* new style, 1 or multiple arguments */
179 if (!Cflag)
181 fprintf (fout, "(");
182 for (l = proc->args.decls; l != NULL; l = l->next)
183 fprintf (fout, "%s, ", l->decl.name);
184 if (mtflag)
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");
191 if (mtflag)
193 fprintf (fout, "\t");
194 ptype (proc->res_prefix, proc->res_type, 1);
195 fprintf (fout, "*%s;\n", result);
198 else
199 { /* C++ style header */
200 fprintf (fout, "(");
201 for (l = proc->args.decls; l != NULL; l = l->next)
203 pdeclaration (proc->args.argname, &l->decl, 0, ", ");
205 if (mtflag)
207 ptype (proc->res_prefix, proc->res_type, 1);
208 fprintf (fout, "*%s, ", result);
210 fprintf (fout, " %s%s)\n", addargtype, addargname);
214 if (!Cflag)
215 fprintf (fout, "\t%s%s;\n", addargtype, addargname);
219 static
220 const char *
221 ampr (const char *type)
223 if (isvectordef (type, REL_ALIAS))
225 return "";
227 else
229 return "&";
233 static void
234 printbody (proc_list * proc)
236 decl_list *l;
237 bool_t args2 = (proc->arg_num > 1);
238 /* int i; */
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");
247 if (!mtflag)
249 fprintf (fout, "\tstatic ");
250 if (streq (proc->res_type, "void"))
252 fprintf (fout, "char ");
254 else
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 */
266 if (mtflag)
267 fprintf (fout, "\t return ");
268 else
269 fprintf (fout, "\t if ");
270 fprintf (fout,
271 "(clnt_call (clnt, %s, (xdrproc_t) xdr_void, ", proc->proc_name);
273 fprintf (fout,
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),
276 RESULT);
277 if (mtflag)
278 fprintf (fout, "\n\t\tTIMEOUT));\n\n");
279 else
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);
290 if (mtflag)
291 fprintf (fout, "\treturn ");
292 else
293 fprintf (fout, "\tif ");
295 fprintf (fout,
296 "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc->proc_name,
297 proc->args.argname);
298 fprintf (fout,
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),
301 RESULT);
302 if (mtflag)
303 fprintf (fout, "\n\t\tTIMEOUT));\n");
304 else
305 fprintf (fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
307 else
308 { /* single argument, new or old style */
309 if (!mtflag)
310 fprintf (fout,
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",
312 proc->proc_name,
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),
317 RESULT);
318 else
319 fprintf(fout,
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",
321 proc->proc_name,
322 stringfix (proc->args.decls->decl.type),
323 (newstyle ? "&" : ""),
324 (newstyle ? proc->args.decls->decl.name : "argp"),
325 stringfix (proc->res_type), "",
326 RESULT);
328 if (!mtflag)
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);
337 else
339 fprintf (fout, "\treturn (%s%s);\n", ampr (proc->res_type), RESULT);