Print this page
rpcgen should only produce ANSI code
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/rpcgen/rpc_clntout.c
+++ new/usr/src/cmd/rpcgen/rpc_clntout.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 + *
23 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 26 * Use is subject to license terms.
25 27 */
26 28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 29 /* All Rights Reserved */
28 30 /*
29 31 * University Copyright- Copyright (c) 1982, 1986, 1988
30 32 * The Regents of the University of California
31 33 * All Rights Reserved
32 34 *
33 35 * University Acknowledgment- Portions of this document are derived from
34 36 * software developed by the University of California, Berkeley, and its
35 37 * contributors.
36 38 */
37 39
38 40 /*
39 41 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
40 42 */
41 43 #include <stdio.h>
42 44 #include <string.h>
43 45 #include <rpc/types.h>
44 46 #include "rpc_parse.h"
45 47 #include "rpc_util.h"
46 48
47 49 extern void pdeclaration(char *, declaration *, int, char *);
48 50 extern void printarglist(proc_list *, char *, char *, char *);
49 51
50 52 static void write_program(definition *);
51 53 static void printbody(proc_list *);
52 54
53 55 static char RESULT[] = "clnt_res";
54 56
55 57 #define DEFAULT_TIMEOUT 25 /* in seconds */
56 58
57 59 void
58 60 write_stubs(void)
59 61 {
60 62 list *l;
61 63 definition *def;
62 64
63 65 f_print(fout,
64 66 "\n/* Default timeout can be changed using clnt_control() */\n");
65 67 f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
66 68 DEFAULT_TIMEOUT);
67 69 for (l = defined; l != NULL; l = l->next) {
68 70 def = (definition *) l->val;
69 71 if (def->def_kind == DEF_PROGRAM) {
70 72 write_program(def);
71 73 }
72 74 }
73 75 }
74 76
75 77 static void
76 78 write_program(definition *def)
77 79 {
78 80 version_list *vp;
79 81 proc_list *proc;
80 82
81 83 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
82 84 for (proc = vp->procs; proc != NULL; proc = proc->next) {
83 85 f_print(fout, "\n");
84 86 if (mtflag == 0) {
85 87 ptype(proc->res_prefix, proc->res_type, 1);
86 88 f_print(fout, "*\n");
87 89 pvname(proc->proc_name, vp->vers_num);
88 90 printarglist(proc, RESULT, "clnt", "CLIENT *");
89 91 } else {
90 92 f_print(fout, "enum clnt_stat \n");
91 93 pvname(proc->proc_name, vp->vers_num);
92 94 printarglist(proc, RESULT, "clnt", "CLIENT *");
93 95
94 96 }
95 97 f_print(fout, "{\n");
96 98 printbody(proc);
97 99
98 100 f_print(fout, "}\n");
99 101 }
100 102 }
101 103 }
102 104
103 105 /*
104 106 * Writes out declarations of procedure's argument list.
105 107 * In either ANSI C style, in one of old rpcgen style (pass by reference),
106 108 * or new rpcgen style (multiple arguments, pass by value);
107 109 */
108 110
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
109 111 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
110 112
111 113 void
112 114 printarglist(proc_list *proc, char *result, char *addargname, char *addargtype)
113 115 {
114 116 bool_t oneway = streq(proc->res_type, "oneway");
115 117 decl_list *l;
116 118
117 119 if (!newstyle) {
118 120 /* old style: always pass argument by reference */
119 - if (Cflag) { /* C++ style heading */
120 - f_print(fout, "(");
121 - ptype(proc->args.decls->decl.prefix,
122 - proc->args.decls->decl.type, 1);
121 + f_print(fout, "(");
122 + ptype(proc->args.decls->decl.prefix,
123 + proc->args.decls->decl.type, 1);
123 124
124 - if (mtflag) { /* Generate result field */
125 - f_print(fout, "*argp, ");
126 - if (!oneway) {
127 - ptype(proc->res_prefix,
128 - proc->res_type, 1);
129 - f_print(fout, "*%s, ", result);
130 - }
131 - f_print(fout, "%s%s)\n",
132 - addargtype, addargname);
133 - } else
134 - f_print(fout, "*argp, %s%s)\n",
135 - addargtype, addargname);
136 - } else {
137 - if (!mtflag)
138 - f_print(fout, "(argp, %s)\n", addargname);
139 - else {
140 - f_print(fout, "(argp, ");
141 - if (!oneway) {
142 - f_print(fout, "%s, ",
143 - result);
144 - }
145 - f_print(fout, "%s)\n",
146 - addargname);
147 - }
148 - f_print(fout, "\t");
149 - ptype(proc->args.decls->decl.prefix,
150 - proc->args.decls->decl.type, 1);
151 - f_print(fout, "*argp;\n");
152 - if (mtflag && !oneway) {
153 - f_print(fout, "\t");
125 + if (mtflag) { /* Generate result field */
126 + f_print(fout, "*argp, ");
127 + if (!oneway) {
154 128 ptype(proc->res_prefix, proc->res_type, 1);
155 - f_print(fout, "*%s;\n", result);
129 + f_print(fout, "*%s, ", result);
156 130 }
157 - }
131 + f_print(fout, "%s%s)\n", addargtype, addargname);
132 + } else
133 + f_print(fout, "*argp, %s%s)\n", addargtype, addargname);
158 134 } else if (streq(proc->args.decls->decl.type, "void")) {
159 135 /* newstyle, 0 argument */
160 136 if (mtflag) {
161 137 f_print(fout, "(");
162 138
163 - if (Cflag) {
164 - if (!oneway) {
165 - ptype(proc->res_prefix,
166 - proc->res_type, 1);
167 - f_print(fout, "*%s, ", result);
168 - }
169 - f_print(fout, "%s%s)\n",
170 - addargtype, addargname);
171 - } else
172 - f_print(fout, "(%s)\n", addargname);
139 + if (!oneway) {
140 + ptype(proc->res_prefix, proc->res_type, 1);
141 + f_print(fout, "*%s, ", result);
142 + }
143 + f_print(fout, "%s%s)\n", addargtype, addargname);
173 144
174 145 } else
175 - if (Cflag)
176 146 f_print(fout, "(%s%s)\n", addargtype, addargname);
177 - else
178 - f_print(fout, "(%s)\n", addargname);
179 147 } else {
180 148 /* new style, 1 or multiple arguments */
181 - if (!Cflag) {
182 - f_print(fout, "(");
183 - for (l = proc->args.decls; l != NULL; l = l->next)
184 - f_print(fout, "%s, ", l->decl.name);
185 - if (mtflag && !oneway)
186 - f_print(fout, "%s, ", result);
149 + f_print(fout, "(");
150 + for (l = proc->args.decls; l != NULL; l = l->next) {
151 + pdeclaration(proc->args.argname, &l->decl, 0, ", ");
152 + }
153 + if (mtflag && !oneway) {
154 + ptype(proc->res_prefix, proc->res_type, 1);
155 + f_print(fout, "*%s, ", result);
187 156
188 - f_print(fout, "%s)\n", addargname);
189 - for (l = proc->args.decls; l != NULL; l = l->next) {
190 - pdeclaration(proc->args.argname,
191 - &l->decl, 1, ";\n");
192 - }
193 - if (mtflag && !oneway) {
194 - f_print(fout, "\t");
195 - ptype(proc->res_prefix, proc->res_type, 1);
196 - f_print(fout, "*%s;\n", result);
197 - }
198 -
199 - } else { /* C++ style header */
200 - f_print(fout, "(");
201 - for (l = proc->args.decls; l != NULL; l = l->next) {
202 - pdeclaration(proc->args.argname, &l->decl, 0,
203 - ", ");
204 - }
205 - if (mtflag && !oneway) {
206 - ptype(proc->res_prefix, proc->res_type, 1);
207 - f_print(fout, "*%s, ", result);
208 -
209 - }
210 - f_print(fout, "%s%s)\n", addargtype, addargname);
211 157 }
158 + f_print(fout, "%s%s)\n", addargtype, addargname);
212 159 }
213 -
214 - if (!Cflag)
215 - f_print(fout, "\t%s%s;\n", addargtype, addargname);
216 160 }
217 161
218 162
219 163
220 164 static char *
221 165 ampr(char *type)
222 166 {
223 167 if (isvectordef(type, REL_ALIAS)) {
224 168 return ("");
225 169 } else {
226 170 return ("&");
227 171 }
228 172 }
229 173
230 174 static void
231 175 printbody(proc_list *proc)
232 176 {
233 177 decl_list *l;
234 178 bool_t args2 = (proc->arg_num > 1);
235 179 bool_t oneway = streq(proc->res_type, "oneway");
236 180
237 181 /*
238 182 * For new style with multiple arguments, need a structure in which
239 183 * to stuff the arguments.
240 184 */
241 185 if (newstyle && args2) {
242 186 f_print(fout, "\t%s", proc->args.argname);
243 187 f_print(fout, " arg;\n");
244 188 }
245 189 if (!oneway) {
246 190 if (!mtflag) {
247 191 f_print(fout, "\tstatic ");
248 192 if (streq(proc->res_type, "void")) {
249 193 f_print(fout, "char ");
250 194 } else {
251 195 ptype(proc->res_prefix, proc->res_type, 0);
252 196 }
253 197 f_print(fout, "%s;\n", RESULT);
254 198 f_print(fout, "\n");
255 199 f_print(fout,
256 200 "\t(void) memset(%s%s, 0, sizeof (%s));\n",
257 201 ampr(proc->res_type), RESULT, RESULT);
258 202
259 203 }
260 204 if (newstyle && !args2 &&
261 205 (streq(proc->args.decls->decl.type, "void"))) {
262 206 /* newstyle, 0 arguments */
263 207
264 208 if (mtflag)
265 209 f_print(fout, "\t return ");
266 210 else
267 211 f_print(fout, "\t if ");
268 212
269 213 f_print(fout,
270 214 "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
271 215 proc->proc_name);
272 216 f_print(fout,
273 217 "NULL,\n\t\t(xdrproc_t)xdr_%s, "
274 218 "(caddr_t)%s%s,",
275 219 stringfix(proc->res_type),
276 220 (mtflag)?"":ampr(proc->res_type),
277 221 RESULT);
278 222
279 223 if (mtflag)
280 224 f_print(fout, "\n\t\tTIMEOUT));\n");
281 225 else
282 226 f_print(fout,
283 227 "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
284 228
285 229 } else if (newstyle && args2) {
286 230 /*
287 231 * Newstyle, multiple arguments
288 232 * stuff arguments into structure
289 233 */
290 234 for (l = proc->args.decls; l != NULL; l = l->next) {
291 235 f_print(fout, "\targ.%s = %s;\n",
292 236 l->decl.name, l->decl.name);
293 237 }
294 238 if (mtflag)
295 239 f_print(fout, "\treturn ");
296 240 else
297 241 f_print(fout, "\tif ");
298 242 f_print(fout,
299 243 "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
300 244 proc->proc_name, proc->args.argname);
301 245 f_print(fout,
302 246 ", (caddr_t)&arg,\n\t\t(xdrproc_t)xdr_%s, "
303 247 "(caddr_t)%s%s,",
304 248 stringfix(proc->res_type),
305 249 (mtflag)?"":ampr(proc->res_type),
306 250 RESULT);
307 251 if (mtflag)
308 252 f_print(fout, "\n\t\tTIMEOUT));\n");
309 253 else
310 254 f_print(fout,
311 255 "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
312 256 } else { /* single argument, new or old style */
313 257 if (!mtflag)
314 258 f_print(fout,
315 259 "\tif (clnt_call(clnt, "
316 260 "%s,\n\t\t(xdrproc_t)xdr_%s, "
317 261 "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
318 262 "(caddr_t)%s%s,\n\t\tTIMEOUT) != "
319 263 "RPC_SUCCESS) {\n",
320 264 proc->proc_name,
321 265 stringfix(proc->args.decls->decl.type),
322 266 (newstyle ? "&" : ""),
323 267 (newstyle ?
324 268 proc->args.decls->decl.name :
325 269 "argp"),
326 270 stringfix(proc->res_type),
327 271 ampr(proc->res_type),
328 272 RESULT);
329 273 else
330 274 f_print(fout,
331 275 "\treturn (clnt_call(clnt, "
332 276 "%s,\n\t\t(xdrproc_t)xdr_%s, "
333 277 "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
334 278 "(caddr_t)%s%s,\n\t\tTIMEOUT));\n",
335 279 proc->proc_name,
336 280 stringfix(proc->args.decls->decl.type),
337 281 (newstyle ? "&" : ""),
338 282 (newstyle ?
339 283 proc->args.decls->decl.name :
340 284 "argp"),
341 285 stringfix(proc->res_type), "",
342 286 RESULT);
343 287 }
344 288 if (!mtflag) {
345 289 f_print(fout, "\t\treturn (NULL);\n");
346 290 f_print(fout, "\t}\n");
347 291
348 292 if (streq(proc->res_type, "void")) {
349 293 f_print(fout, "\treturn ((void *)%s%s);\n",
350 294 ampr(proc->res_type), RESULT);
351 295 } else {
352 296 f_print(fout, "\treturn (%s%s);\n",
353 297 ampr(proc->res_type), RESULT);
354 298 }
355 299 }
356 300 } else {
357 301 /* oneway call */
358 302 if (!mtflag) {
359 303 f_print(fout, "\tstatic enum clnt_stat ");
360 304 f_print(fout, "%s;\n", RESULT);
361 305 f_print(fout, "\n");
362 306 f_print(fout,
363 307 "\t(void) memset(&%s, 0, sizeof (%s));\n",
364 308 RESULT, RESULT);
365 309
366 310 }
367 311 if (newstyle && !args2 &&
368 312 (streq(proc->args.decls->decl.type, "void"))) {
369 313 /* newstyle, 0 arguments */
370 314
371 315 if (mtflag)
372 316 f_print(fout, "\t return (");
373 317 else
374 318 f_print(fout, "\t if ((%s = ", RESULT);
375 319
376 320 f_print(fout,
377 321 "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
378 322 proc->proc_name);
379 323 f_print(fout, "NULL)");
380 324
381 325 if (mtflag)
382 326 f_print(fout, ");\n");
383 327 else
384 328 f_print(fout, ") != RPC_SUCCESS) {\n");
385 329
386 330 } else if (newstyle && args2) {
387 331 /*
388 332 * Newstyle, multiple arguments
389 333 * stuff arguments into structure
390 334 */
391 335 for (l = proc->args.decls; l != NULL; l = l->next) {
392 336 f_print(fout, "\targ.%s = %s;\n",
393 337 l->decl.name, l->decl.name);
394 338 }
395 339 if (mtflag)
396 340 f_print(fout, "\treturn (");
397 341 else
398 342 f_print(fout, "\tif ((%s =", RESULT);
399 343 f_print(fout,
400 344 "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
401 345 proc->proc_name, proc->args.argname);
402 346 f_print(fout,
403 347 ", (caddr_t)&arg)");
404 348 if (mtflag)
405 349 f_print(fout, ");\n");
406 350 else
407 351 f_print(fout, ") != RPC_SUCCESS) {\n");
408 352 } else { /* single argument, new or old style */
409 353 if (!mtflag)
410 354 f_print(fout,
411 355 "\tif ((%s = clnt_send(clnt, "
412 356 "%s,\n\t\t(xdrproc_t)xdr_%s, "
413 357 "(caddr_t)%s%s)) != RPC_SUCCESS) {\n",
414 358 RESULT,
415 359 proc->proc_name,
416 360 stringfix(proc->args.decls->decl.type),
417 361 (newstyle ? "&" : ""),
418 362 (newstyle ?
419 363 proc->args.decls->decl.name :
420 364 "argp"));
421 365 else
422 366
423 367 f_print(fout,
424 368 "\treturn (clnt_send(clnt, "
425 369 "%s,\n\t\t(xdrproc_t)xdr_%s, "
426 370 "(caddr_t)%s%s));\n",
427 371 proc->proc_name,
428 372 stringfix(proc->args.decls->decl.type),
429 373 (newstyle ? "&" : ""),
430 374 (newstyle ?
431 375 proc->args.decls->decl.name :
432 376 "argp"));
433 377 }
434 378 if (!mtflag) {
435 379 f_print(fout, "\t\treturn (NULL);\n");
436 380 f_print(fout, "\t}\n");
437 381
438 382 f_print(fout, "\treturn ((void *)&%s);\n",
439 383 RESULT);
440 384 }
441 385 }
442 386 }
↓ open down ↓ |
217 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX