Test math.
[glibc/history.git] / sunrpc / rpc_clntout.c
blobfb086047bafd9c5b3f245685df8cb44af349daf8
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 f_print (fout,
64 "\n/* Default timeout can be changed using clnt_control() */\n");
65 f_print (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 f_print (fout, "\n");
88 ptype (proc->res_prefix, proc->res_type, 1);
89 f_print (fout, "*\n");
90 pvname (proc->proc_name, vp->vers_num);
91 printarglist (proc, "clnt", "CLIENT *");
92 f_print (fout, "{\n");
93 printbody (proc);
94 f_print (fout, "}\n");
99 /* Writes out declarations of procedure's argument list.
100 In either ANSI C style, in one of old rpcgen style (pass by reference),
101 or new rpcgen style (multiple arguments, pass by value);
104 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
106 void
107 printarglist (proc_list * proc,
108 const char *addargname, const char *addargtype)
111 decl_list *l;
113 if (!newstyle)
114 { /* old style: always pass argument by reference */
115 if (Cflag)
116 { /* C++ style heading */
117 f_print (fout, "(");
118 ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
119 f_print (fout, "*argp, %s%s)\n", addargtype, addargname);
121 else
123 f_print (fout, "(argp, %s)\n", addargname);
124 f_print (fout, "\t");
125 ptype (proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
126 f_print (fout, "*argp;\n");
129 else if (streq (proc->args.decls->decl.type, "void"))
131 /* newstyle, 0 argument */
132 if (Cflag)
133 f_print (fout, "(%s%s)\n", addargtype, addargname);
134 else
135 f_print (fout, "(%s)\n", addargname);
137 else
139 /* new style, 1 or multiple arguments */
140 if (!Cflag)
142 f_print (fout, "(");
143 for (l = proc->args.decls; l != NULL; l = l->next)
144 f_print (fout, "%s, ", l->decl.name);
145 f_print (fout, "%s)\n", addargname);
146 for (l = proc->args.decls; l != NULL; l = l->next)
148 pdeclaration (proc->args.argname, &l->decl, 1, ";\n");
151 else
152 { /* C++ style header */
153 f_print (fout, "(");
154 for (l = proc->args.decls; l != NULL; l = l->next)
156 pdeclaration (proc->args.argname, &l->decl, 0, ", ");
158 f_print (fout, " %s%s)\n", addargtype, addargname);
162 if (!Cflag)
163 f_print (fout, "\t%s%s;\n", addargtype, addargname);
168 static
169 const char *
170 ampr (const char *type)
172 if (isvectordef (type, REL_ALIAS))
174 return "";
176 else
178 return "&";
182 static void
183 printbody (proc_list * proc)
185 decl_list *l;
186 bool_t args2 = (proc->arg_num > 1);
187 /* int i; */
189 /* For new style with multiple arguments, need a structure in which
190 to stuff the arguments. */
191 if (newstyle && args2)
193 f_print (fout, "\t%s", proc->args.argname);
194 f_print (fout, " arg;\n");
196 f_print (fout, "\tstatic ");
197 if (streq (proc->res_type, "void"))
199 f_print (fout, "char ");
201 else
203 ptype (proc->res_prefix, proc->res_type, 0);
205 f_print (fout, "%s;\n", RESULT);
206 f_print (fout, "\n");
207 f_print (fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
208 ampr (proc->res_type), RESULT, RESULT);
209 if (newstyle && !args2 && (streq (proc->args.decls->decl.type, "void")))
211 /* newstyle, 0 arguments */
212 f_print (fout,
213 "\tif (clnt_call(clnt, %s, xdr_void", proc->proc_name);
214 f_print (fout,
215 ", NULL, xdr_%s, %s,%s, TIMEOUT) != RPC_SUCCESS) {\n",
216 stringfix (proc->res_type), ampr (proc->res_type), RESULT);
219 else if (newstyle && args2)
221 /* newstyle, multiple arguments: stuff arguments into structure */
222 for (l = proc->args.decls; l != NULL; l = l->next)
224 f_print (fout, "\targ.%s = %s;\n",
225 l->decl.name, l->decl.name);
227 f_print (fout,
228 "\tif (clnt_call(clnt, %s, xdr_%s", proc->proc_name,
229 proc->args.argname);
230 f_print (fout,
231 ", &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
232 stringfix (proc->res_type), ampr (proc->res_type), RESULT);
234 else
235 { /* single argument, new or old style */
236 f_print (fout,
237 "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
238 proc->proc_name,
239 stringfix (proc->args.decls->decl.type),
240 (newstyle ? "&" : ""),
241 (newstyle ? proc->args.decls->decl.name : "argp"),
242 stringfix (proc->res_type), ampr (proc->res_type), RESULT);
244 f_print (fout, "\t\treturn (NULL);\n");
245 f_print (fout, "\t}\n");
246 if (streq (proc->res_type, "void"))
248 f_print (fout, "\treturn ((void *)%s%s);\n",
249 ampr (proc->res_type), RESULT);
251 else
253 f_print (fout, "\treturn (%s%s);\n", ampr (proc->res_type), RESULT);