Deleted Added
full compact
rpc_hout.c (149710) rpc_hout.c (152398)
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.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_hout.c 1.16 94/04/25 SMI"
33static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
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.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_hout.c 1.16 94/04/25 SMI"
33static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_hout.c 149710 2005-09-02 10:32:05Z stefanf $");
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_hout.c 152398 2005-11-13 21:17:24Z dwmalone $");
39
40/*
41 * rpc_hout.c, Header file outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <ctype.h>
46#include "rpc_parse.h"
47#include "rpc_scan.h"
48#include "rpc_util.h"
49
39
40/*
41 * rpc_hout.c, Header file outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <ctype.h>
46#include "rpc_parse.h"
47#include "rpc_scan.h"
48#include "rpc_util.h"
49
50void storexdrfuncdecl( char *, int );
50void storexdrfuncdecl(const char *, int );
51static void pconstdef( definition * );
52static void pstructdef( definition * );
53static void puniondef( definition * );
54static void pprogramdef( definition *, int );
51static void pconstdef( definition * );
52static void pstructdef( definition * );
53static void puniondef( definition * );
54static void pprogramdef( definition *, int );
55static void pstructdef( definition * );
56static void penumdef( definition * );
57static void ptypedef( definition * );
55static void penumdef( definition * );
56static void ptypedef( definition * );
58static void pdefine( char *, char * );
59static int undefined2( char *, char * );
60static void parglist( proc_list *, char * );
61static void pprocdef( proc_list *, version_list *, char *, int );
62void pdeclaration( char *, declaration *, int, char * );
57static void pdefine(const char *, const char *);
58static int undefined2(const char *, const char *);
59static void parglist(proc_list *, const char *);
60static void pprocdef(proc_list *, version_list *, const char *, int);
63
64/*
65 * Print the C-version of an xdr definition
66 */
67void
68print_datadef(definition *def, int headeronly)
69{
70

--- 44 unchanged lines hidden (view full) ---

115 break;
116 }
117}
118
119/* store away enough information to allow the XDR functions to be spat
120 out at the end of the file */
121
122void
61
62/*
63 * Print the C-version of an xdr definition
64 */
65void
66print_datadef(definition *def, int headeronly)
67{
68

--- 44 unchanged lines hidden (view full) ---

113 break;
114 }
115}
116
117/* store away enough information to allow the XDR functions to be spat
118 out at the end of the file */
119
120void
123storexdrfuncdecl(name, pointerp)
124char *name;
125int pointerp;
121storexdrfuncdecl(const char *name, int pointerp)
126{
127 xdrfunc * xdrptr;
128
129 xdrptr = XALLOC(struct xdrfunc);
130
131 xdrptr->name = name;
132 xdrptr->pointerp = pointerp;
133 xdrptr->next = NULL;

--- 5 unchanged lines hidden (view full) ---

139 xdrfunc_tail->next = xdrptr;
140 xdrfunc_tail = xdrptr;
141 }
142
143
144}
145
146void
122{
123 xdrfunc * xdrptr;
124
125 xdrptr = XALLOC(struct xdrfunc);
126
127 xdrptr->name = name;
128 xdrptr->pointerp = pointerp;
129 xdrptr->next = NULL;

--- 5 unchanged lines hidden (view full) ---

135 xdrfunc_tail->next = xdrptr;
136 xdrfunc_tail = xdrptr;
137 }
138
139
140}
141
142void
147print_xdr_func_def(char *name, int pointerp)
143print_xdr_func_def(const char *name, int pointerp)
148{
149 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
150 name, pointerp ? "*" : "");
151}
152
153
154static void
155pconstdef(def)
156 definition *def;
157{
158 pdefine(def->def_name, def->def.co);
159}
160
161/* print out the definitions for the arguments of functions in the
162 header file
163*/
164static void
144{
145 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
146 name, pointerp ? "*" : "");
147}
148
149
150static void
151pconstdef(def)
152 definition *def;
153{
154 pdefine(def->def_name, def->def.co);
155}
156
157/* print out the definitions for the arguments of functions in the
158 header file
159*/
160static void
165pargdef(def)
166 definition *def;
161pargdef(definition *def)
167{
168 decl_list *l;
169 version_list *vers;
170 char *name;
171 proc_list *plist;
172
173
174 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {

--- 16 unchanged lines hidden (view full) ---

191 storexdrfuncdecl(name, 1);
192 f_print(fout, "\n");
193 }
194 }
195}
196
197
198static void
162{
163 decl_list *l;
164 version_list *vers;
165 char *name;
166 proc_list *plist;
167
168
169 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {

--- 16 unchanged lines hidden (view full) ---

186 storexdrfuncdecl(name, 1);
187 f_print(fout, "\n");
188 }
189 }
190}
191
192
193static void
199pstructdef(def)
200 definition *def;
194pstructdef(definition *def)
201{
202 decl_list *l;
195{
196 decl_list *l;
203 char *name = def->def_name;
197 const char *name = def->def_name;
204
205 f_print(fout, "struct %s {\n", name);
206 for (l = def->def.st.decls; l != NULL; l = l->next) {
207 pdeclaration(name, &l->decl, 1, ";\n");
208 }
209 f_print(fout, "};\n");
210 f_print(fout, "typedef struct %s %s;\n", name, name);
211}
212
213static void
214puniondef(def)
215 definition *def;
216{
217 case_list *l;
198
199 f_print(fout, "struct %s {\n", name);
200 for (l = def->def.st.decls; l != NULL; l = l->next) {
201 pdeclaration(name, &l->decl, 1, ";\n");
202 }
203 f_print(fout, "};\n");
204 f_print(fout, "typedef struct %s %s;\n", name, name);
205}
206
207static void
208puniondef(def)
209 definition *def;
210{
211 case_list *l;
218 char *name = def->def_name;
212 const char *name = def->def_name;
219 declaration *decl;
220
221 f_print(fout, "struct %s {\n", name);
222 decl = &def->def.un.enum_decl;
223 if (streq(decl->type, "bool")) {
224 f_print(fout, "\tbool_t %s;\n", decl->name);
225 } else {
226 f_print(fout, "\t%s %s;\n", decl->type, decl->name);

--- 8 unchanged lines hidden (view full) ---

235 pdeclaration(name, decl, 2, ";\n");
236 }
237 f_print(fout, "\t} %s_u;\n", name);
238 f_print(fout, "};\n");
239 f_print(fout, "typedef struct %s %s;\n", name, name);
240}
241
242static void
213 declaration *decl;
214
215 f_print(fout, "struct %s {\n", name);
216 decl = &def->def.un.enum_decl;
217 if (streq(decl->type, "bool")) {
218 f_print(fout, "\tbool_t %s;\n", decl->name);
219 } else {
220 f_print(fout, "\t%s %s;\n", decl->type, decl->name);

--- 8 unchanged lines hidden (view full) ---

229 pdeclaration(name, decl, 2, ";\n");
230 }
231 f_print(fout, "\t} %s_u;\n", name);
232 f_print(fout, "};\n");
233 f_print(fout, "typedef struct %s %s;\n", name, name);
234}
235
236static void
243pdefine(name, num)
244 char *name;
245 char *num;
237pdefine(const char *name, const char *num)
246{
247 f_print(fout, "#define\t%s %s\n", name, num);
248}
249
250static void
238{
239 f_print(fout, "#define\t%s %s\n", name, num);
240}
241
242static void
251puldefine(name, num)
252 char *name;
253 char *num;
243puldefine(const char *name, const char *num)
254{
255 f_print(fout, "#define\t%s ((unsigned long)(%s))\n", name, num);
256}
257
258static int
244{
245 f_print(fout, "#define\t%s ((unsigned long)(%s))\n", name, num);
246}
247
248static int
259define_printed(stop, start)
260 proc_list *stop;
261 version_list *start;
249define_printed(proc_list *stop, version_list *start)
262{
263 version_list *vers;
264 proc_list *proc;
265
266 for (vers = start; vers != NULL; vers = vers->next) {
267 for (proc = vers->procs; proc != NULL; proc = proc->next) {
268 if (proc == stop) {
269 return (0);
270 } else if (streq(proc->proc_name, stop->proc_name)) {
271 return (1);
272 }
273 }
274 }
275 abort();
276 /* NOTREACHED */
277}
278
279static void
250{
251 version_list *vers;
252 proc_list *proc;
253
254 for (vers = start; vers != NULL; vers = vers->next) {
255 for (proc = vers->procs; proc != NULL; proc = proc->next) {
256 if (proc == stop) {
257 return (0);
258 } else if (streq(proc->proc_name, stop->proc_name)) {
259 return (1);
260 }
261 }
262 }
263 abort();
264 /* NOTREACHED */
265}
266
267static void
280pfreeprocdef(char * name, char *vers)
268pfreeprocdef(const char * name, const char *vers)
281{
282 f_print(fout, "extern int ");
283 pvname(name, vers);
284 f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
285}
286
287static void
269{
270 f_print(fout, "extern int ");
271 pvname(name, vers);
272 f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
273}
274
275static void
288pdispatch(char * name, char *vers)
276pdispatch(const char * name, const char *vers)
289{
290
291 f_print(fout, "void ");
292 pvname(name, vers);
293 f_print(fout, "(struct svc_req *rqstp, SVCXPRT *transp);\n");
294}
295
296static void
297pprogramdef(definition *def, int headeronly)
298{
299 version_list *vers;
300 proc_list *proc;
277{
278
279 f_print(fout, "void ");
280 pvname(name, vers);
281 f_print(fout, "(struct svc_req *rqstp, SVCXPRT *transp);\n");
282}
283
284static void
285pprogramdef(definition *def, int headeronly)
286{
287 version_list *vers;
288 proc_list *proc;
301 char *ext;
289 const char *ext;
302
303 pargdef(def);
304
305 puldefine(def->def_name, def->def.pr.prog_num);
306 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
307 if (tblflag) {
308 f_print(fout,
309 "extern struct rpcgen_table %s_%s_table[];\n",

--- 19 unchanged lines hidden (view full) ---

329 f_print(fout, "%s", ext);
330 pprocdef(proc, vers, "struct svc_req *", 1);
331 }
332 pfreeprocdef(def->def_name, vers->vers_num);
333 }
334}
335
336static void
290
291 pargdef(def);
292
293 puldefine(def->def_name, def->def.pr.prog_num);
294 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
295 if (tblflag) {
296 f_print(fout,
297 "extern struct rpcgen_table %s_%s_table[];\n",

--- 19 unchanged lines hidden (view full) ---

317 f_print(fout, "%s", ext);
318 pprocdef(proc, vers, "struct svc_req *", 1);
319 }
320 pfreeprocdef(def->def_name, vers->vers_num);
321 }
322}
323
324static void
337pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p)
325pprocdef(proc_list *proc, version_list *vp, const char *addargtype, int server_p)
338{
339 if (mtflag) {/* Print MT style stubs */
340 if (server_p)
341 f_print(fout, "bool_t ");
342 else
343 f_print(fout, "enum clnt_stat ");
344 } else {
345 ptype(proc->res_prefix, proc->res_type, 1);

--- 6 unchanged lines hidden (view full) ---

352
353 parglist(proc, addargtype);
354}
355
356
357
358/* print out argument list of procedure */
359static void
326{
327 if (mtflag) {/* Print MT style stubs */
328 if (server_p)
329 f_print(fout, "bool_t ");
330 else
331 f_print(fout, "enum clnt_stat ");
332 } else {
333 ptype(proc->res_prefix, proc->res_type, 1);

--- 6 unchanged lines hidden (view full) ---

340
341 parglist(proc, addargtype);
342}
343
344
345
346/* print out argument list of procedure */
347static void
360parglist(proc, addargtype)
361 proc_list *proc;
362 char* addargtype;
348parglist(proc_list *proc, const char *addargtype)
363{
364 decl_list *dl;
365
366 f_print(fout, "(");
367 if (proc->arg_num < 2 && newstyle &&
368 streq(proc->args.decls->decl.type, "void")) {
369 /* 0 argument in new style: do nothing*/
370 }

--- 15 unchanged lines hidden (view full) ---

386 f_print(fout, "%s);\n", addargtype);
387
388}
389
390static void
391penumdef(def)
392 definition *def;
393{
349{
350 decl_list *dl;
351
352 f_print(fout, "(");
353 if (proc->arg_num < 2 && newstyle &&
354 streq(proc->args.decls->decl.type, "void")) {
355 /* 0 argument in new style: do nothing*/
356 }

--- 15 unchanged lines hidden (view full) ---

372 f_print(fout, "%s);\n", addargtype);
373
374}
375
376static void
377penumdef(def)
378 definition *def;
379{
394 char *name = def->def_name;
380 const char *name = def->def_name;
395 enumval_list *l;
381 enumval_list *l;
396 char *last = NULL;
382 const char *last = NULL;
397 int count = 0;
398
399 f_print(fout, "enum %s {\n", name);
400 for (l = def->def.en.vals; l != NULL; l = l->next) {
401 f_print(fout, "\t%s", l->name);
402 if (l->assignment) {
403 f_print(fout, " = %s", l->assignment);
404 last = l->assignment;

--- 13 unchanged lines hidden (view full) ---

418 f_print(fout, "};\n");
419 f_print(fout, "typedef enum %s %s;\n", name, name);
420}
421
422static void
423ptypedef(def)
424 definition *def;
425{
383 int count = 0;
384
385 f_print(fout, "enum %s {\n", name);
386 for (l = def->def.en.vals; l != NULL; l = l->next) {
387 f_print(fout, "\t%s", l->name);
388 if (l->assignment) {
389 f_print(fout, " = %s", l->assignment);
390 last = l->assignment;

--- 13 unchanged lines hidden (view full) ---

404 f_print(fout, "};\n");
405 f_print(fout, "typedef enum %s %s;\n", name, name);
406}
407
408static void
409ptypedef(def)
410 definition *def;
411{
426 char *name = def->def_name;
427 char *old = def->def.ty.old_type;
412 const char *name = def->def_name;
413 const char *old = def->def.ty.old_type;
428 char prefix[8]; /* enough to contain "struct ", including NUL */
429 relation rel = def->def.ty.rel;
430
431
432 if (!streq(name, old)) {
433 if (streq(old, "string")) {
434 old = "char";
435 rel = REL_POINTER;

--- 26 unchanged lines hidden (view full) ---

462 f_print(fout, "%s%s %s", prefix, old, name);
463 break;
464 }
465 f_print(fout, ";\n");
466 }
467}
468
469void
414 char prefix[8]; /* enough to contain "struct ", including NUL */
415 relation rel = def->def.ty.rel;
416
417
418 if (!streq(name, old)) {
419 if (streq(old, "string")) {
420 old = "char";
421 rel = REL_POINTER;

--- 26 unchanged lines hidden (view full) ---

448 f_print(fout, "%s%s %s", prefix, old, name);
449 break;
450 }
451 f_print(fout, ";\n");
452 }
453}
454
455void
470pdeclaration(name, dec, tab, separator)
471 char *name;
472 declaration *dec;
473 int tab;
474 char *separator;
456pdeclaration(const char *name, declaration *dec, int tab, const char *separator)
475{
476 char buf[8]; /* enough to hold "struct ", include NUL */
457{
458 char buf[8]; /* enough to hold "struct ", include NUL */
477 char *prefix;
478 char *type;
459 const char *prefix;
460 const char *type;
479
480 if (streq(dec->type, "void")) {
481 return;
482 }
483 tabify(fout, tab);
484 if (streq(dec->type, name) && !dec->prefix) {
485 f_print(fout, "struct ");
486 }

--- 34 unchanged lines hidden (view full) ---

521 f_print(fout, "} %s", dec->name);
522 break;
523 }
524 }
525 f_print(fout, separator);
526}
527
528static int
461
462 if (streq(dec->type, "void")) {
463 return;
464 }
465 tabify(fout, tab);
466 if (streq(dec->type, name) && !dec->prefix) {
467 f_print(fout, "struct ");
468 }

--- 34 unchanged lines hidden (view full) ---

503 f_print(fout, "} %s", dec->name);
504 break;
505 }
506 }
507 f_print(fout, separator);
508}
509
510static int
529undefined2(type, stop)
530 char *type;
531 char *stop;
511undefined2(const char *type, const char *stop)
532{
533 list *l;
534 definition *def;
535
536 for (l = defined; l != NULL; l = l->next) {
537 def = (definition *) l->val;
538 if (def->def_kind != DEF_PROGRAM) {
539 if (streq(def->def_name, stop)) {
540 return (1);
541 } else if (streq(def->def_name, type)) {
542 return (0);
543 }
544 }
545 }
546 return (1);
547}
512{
513 list *l;
514 definition *def;
515
516 for (l = defined; l != NULL; l = l->next) {
517 def = (definition *) l->val;
518 if (def->def_kind != DEF_PROGRAM) {
519 if (streq(def->def_name, stop)) {
520 return (1);
521 } else if (streq(def->def_name, type)) {
522 return (0);
523 }
524 }
525 }
526 return (1);
527}