Deleted Added
full compact
rpc_cout.c (12798) rpc_cout.c (17142)
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 *

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

34#endif
35
36/*
37 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
38 * Copyright (C) 1987, Sun Microsystems, Inc.
39 */
40#include <stdio.h>
41#include <string.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 *

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

34#endif
35
36/*
37 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
38 * Copyright (C) 1987, Sun Microsystems, Inc.
39 */
40#include <stdio.h>
41#include <string.h>
42#include <ctype.h>
42#include "rpc_parse.h"
43#include "rpc_util.h"
44
43#include "rpc_parse.h"
44#include "rpc_util.h"
45
45static int print_header __P(( definition * ));
46static int print_trailer __P(( void ));
47static int print_stat __P(( int , declaration * ));
48static int emit_enum __P(( definition * ));
49static int emit_program __P(( definition * ));
50static int emit_union __P(( definition * ));
51static int emit_struct __P(( definition * ));
52static int emit_typedef __P(( definition * ));
46static void print_header __P(( definition * ));
47static void print_trailer __P(( void ));
48static void print_stat __P(( int , declaration * ));
49static void emit_enum __P(( definition * ));
50static void emit_program __P(( definition * ));
51static void emit_union __P(( definition * ));
52static void emit_struct __P(( definition * ));
53static void emit_typedef __P(( definition * ));
54static void emit_inline __P(( int, declaration *, int ));
55static void emit_single_in_line __P(( int, declaration *, int, relation ));
53
54/*
55 * Emit the C-routine for the given definition
56 */
57void
58emit(def)
59 definition *def;
60{

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

84 emit_enum(def);
85 break;
86 case DEF_STRUCT:
87 emit_struct(def);
88 break;
89 case DEF_TYPEDEF:
90 emit_typedef(def);
91 break;
56
57/*
58 * Emit the C-routine for the given definition
59 */
60void
61emit(def)
62 definition *def;
63{

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

87 emit_enum(def);
88 break;
89 case DEF_STRUCT:
90 emit_struct(def);
91 break;
92 case DEF_TYPEDEF:
93 emit_typedef(def);
94 break;
95 /* DEF_CONST and DEF_PROGRAM have already been handled */
96 default:
92 }
93 print_trailer();
94}
95
97 }
98 print_trailer();
99}
100
96static
101static int
97findtype(def, type)
98 definition *def;
99 char *type;
100{
101
102 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
103 return (0);
104 } else {
105 return (streq(def->def_name, type));
106 }
107}
108
102findtype(def, type)
103 definition *def;
104 char *type;
105{
106
107 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
108 return (0);
109 } else {
110 return (streq(def->def_name, type));
111 }
112}
113
109static
114static int
110undefined(type)
111 char *type;
112{
113 definition *def;
114
115 def = (definition *) FINDVAL(defined, type, findtype);
116 return (def == NULL);
117}
118
119
115undefined(type)
116 char *type;
117{
118 definition *def;
119
120 def = (definition *) FINDVAL(defined, type, findtype);
121 return (def == NULL);
122}
123
124
120static
125static void
121print_generic_header(procname, pointerp)
122 char* procname;
123 int pointerp;
124{
125 f_print(fout, "\n");
126 f_print(fout, "bool_t\n");
127 if (Cflag) {
128 f_print(fout, "xdr_%s(", procname);

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

136 f_print(fout, "\tregister XDR *xdrs;\n");
137 f_print(fout, "\t%s ", procname);
138 if (pointerp)
139 f_print(fout, "*");
140 f_print(fout, "objp;\n{\n\n");
141 }
142}
143
126print_generic_header(procname, pointerp)
127 char* procname;
128 int pointerp;
129{
130 f_print(fout, "\n");
131 f_print(fout, "bool_t\n");
132 if (Cflag) {
133 f_print(fout, "xdr_%s(", procname);

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

141 f_print(fout, "\tregister XDR *xdrs;\n");
142 f_print(fout, "\t%s ", procname);
143 if (pointerp)
144 f_print(fout, "*");
145 f_print(fout, "objp;\n{\n\n");
146 }
147}
148
144static
149static void
145print_header(def)
146 definition *def;
147{
150print_header(def)
151 definition *def;
152{
148
149 decl_list *dl;
150 bas_type *ptr;
151 int i;
152
153 print_generic_header(def->def_name,
154 def->def_kind != DEF_TYPEDEF ||
155 !isvectordef(def->def.ty.old_type,
156 def->def.ty.rel));
157 /* Now add Inline support */
158
159 if (inline == 0)
160 return;
161 /* May cause lint to complain. but ... */
162 f_print(fout, "\tregister long *buf;\n\n");
163}
164
153 print_generic_header(def->def_name,
154 def->def_kind != DEF_TYPEDEF ||
155 !isvectordef(def->def.ty.old_type,
156 def->def.ty.rel));
157 /* Now add Inline support */
158
159 if (inline == 0)
160 return;
161 /* May cause lint to complain. but ... */
162 f_print(fout, "\tregister long *buf;\n\n");
163}
164
165static
165static void
166print_prog_header(plist)
167 proc_list *plist;
168{
169 print_generic_header(plist->args.argname, 1);
170}
171
166print_prog_header(plist)
167 proc_list *plist;
168{
169 print_generic_header(plist->args.argname, 1);
170}
171
172static
172static void
173print_trailer()
174{
175 f_print(fout, "\treturn (TRUE);\n");
176 f_print(fout, "}\n");
177}
178
179
173print_trailer()
174{
175 f_print(fout, "\treturn (TRUE);\n");
176 f_print(fout, "}\n");
177}
178
179
180static
180static void
181print_ifopen(indent, name)
182 int indent;
183 char *name;
184{
185 tabify(fout, indent);
186 f_print(fout, "if (!xdr_%s(xdrs", name);
187}
188
181print_ifopen(indent, name)
182 int indent;
183 char *name;
184{
185 tabify(fout, indent);
186 f_print(fout, "if (!xdr_%s(xdrs", name);
187}
188
189static
189static void
190print_ifarg(arg)
191 char *arg;
192{
193 f_print(fout, ", %s", arg);
194}
195
190print_ifarg(arg)
191 char *arg;
192{
193 f_print(fout, ", %s", arg);
194}
195
196static
196static void
197print_ifsizeof(indent, prefix, type)
198 int indent;
199 char *prefix;
200 char *type;
201{
202 if (indent) {
203 f_print(fout, ",\n");
204 tabify(fout, indent);

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

211 f_print(fout, "sizeof (");
212 if (undefined(type) && prefix) {
213 f_print(fout, "%s ", prefix);
214 }
215 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
216 }
217}
218
197print_ifsizeof(indent, prefix, type)
198 int indent;
199 char *prefix;
200 char *type;
201{
202 if (indent) {
203 f_print(fout, ",\n");
204 tabify(fout, indent);

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

211 f_print(fout, "sizeof (");
212 if (undefined(type) && prefix) {
213 f_print(fout, "%s ", prefix);
214 }
215 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
216 }
217}
218
219static
219static void
220print_ifclose(indent)
221 int indent;
222{
223 f_print(fout, "))\n");
224 tabify(fout, indent);
225 f_print(fout, "\treturn (FALSE);\n");
226}
227
220print_ifclose(indent)
221 int indent;
222{
223 f_print(fout, "))\n");
224 tabify(fout, indent);
225 f_print(fout, "\treturn (FALSE);\n");
226}
227
228static
228static void
229print_ifstat(indent, prefix, type, rel, amax, objname, name)
230 int indent;
231 char *prefix;
232 char *type;
233 relation rel;
234 char *amax;
235 char *objname;
236 char *name;

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

297 print_ifopen(indent, type);
298 print_ifarg(objname);
299 break;
300 }
301 print_ifclose(indent);
302}
303
304/* ARGSUSED */
229print_ifstat(indent, prefix, type, rel, amax, objname, name)
230 int indent;
231 char *prefix;
232 char *type;
233 relation rel;
234 char *amax;
235 char *objname;
236 char *name;

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

297 print_ifopen(indent, type);
298 print_ifarg(objname);
299 break;
300 }
301 print_ifclose(indent);
302}
303
304/* ARGSUSED */
305static
305static void
306emit_enum(def)
307 definition *def;
308{
309 print_ifopen(1, "enum");
310 print_ifarg("(enum_t *)objp");
311 print_ifclose(1);
312}
313
306emit_enum(def)
307 definition *def;
308{
309 print_ifopen(1, "enum");
310 print_ifarg("(enum_t *)objp");
311 print_ifclose(1);
312}
313
314static
314static void
315emit_program(def)
316 definition *def;
317{
318 decl_list *dl;
319 version_list *vlist;
320 proc_list *plist;
321
322 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next)

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

327 for (dl = plist->args.decls; dl != NULL;
328 dl = dl->next)
329 print_stat(1, &dl->decl);
330 print_trailer();
331 }
332}
333
334
315emit_program(def)
316 definition *def;
317{
318 decl_list *dl;
319 version_list *vlist;
320 proc_list *plist;
321
322 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next)

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

327 for (dl = plist->args.decls; dl != NULL;
328 dl = dl->next)
329 print_stat(1, &dl->decl);
330 print_trailer();
331 }
332}
333
334
335static
335static void
336emit_union(def)
337 definition *def;
338{
339 declaration *dflt;
340 case_list *cl;
341 declaration *cs;
342 char *object;
343 char *vecformat = "objp->%s_u.%s";

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

380 s_print(object, format, def->def_name,
381 dflt->name);
382 }
383
384 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
385 dflt->array_max, object, dflt->name);
386 free(object);
387 f_print(fout, "\t\tbreak;\n");
336emit_union(def)
337 definition *def;
338{
339 declaration *dflt;
340 case_list *cl;
341 declaration *cs;
342 char *object;
343 char *vecformat = "objp->%s_u.%s";

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

380 s_print(object, format, def->def_name,
381 dflt->name);
382 }
383
384 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
385 dflt->array_max, object, dflt->name);
386 free(object);
387 f_print(fout, "\t\tbreak;\n");
388 } else {
389 f_print(fout, "\tdefault:\n");
390 f_print(fout, "\t\tbreak;\n");
388 }
389 } else {
390 f_print(fout, "\tdefault:\n");
391 f_print(fout, "\t\treturn (FALSE);\n");
392 }
393
394 f_print(fout, "\t}\n");
395}

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

548 while (cur != dl){
549 emit_inline(indent + 2, &cur->decl, flag);
550 cur = cur->next;
551 }
552 f_print(fout, "\t\t}\n");
553 }
554}
555
391 }
392 } else {
393 f_print(fout, "\tdefault:\n");
394 f_print(fout, "\t\treturn (FALSE);\n");
395 }
396
397 f_print(fout, "\t}\n");
398}

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

551 while (cur != dl){
552 emit_inline(indent + 2, &cur->decl, flag);
553 cur = cur->next;
554 }
555 f_print(fout, "\t\t}\n");
556 }
557}
558
556static
559static void
557emit_struct(def)
558 definition *def;
559{
560 decl_list *dl;
560emit_struct(def)
561 definition *def;
562{
563 decl_list *dl;
561 int i, j, size, flag;
564 int j, size, flag;
562 bas_type *ptr;
563 int can_inline;
564
565 if (inline == 0) {
566 /* No xdr_inlining at all */
567 for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
568 print_stat(1, &dl->decl);
569 return;

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

618
619 /* now take care of XDR_FREE case */
620
621 for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
622 print_stat(1, &dl->decl);
623
624}
625
565 bas_type *ptr;
566 int can_inline;
567
568 if (inline == 0) {
569 /* No xdr_inlining at all */
570 for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
571 print_stat(1, &dl->decl);
572 return;

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

621
622 /* now take care of XDR_FREE case */
623
624 for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
625 print_stat(1, &dl->decl);
626
627}
628
626static
629static void
627emit_typedef(def)
628 definition *def;
629{
630 char *prefix = def->def.ty.old_prefix;
631 char *type = def->def.ty.old_type;
632 char *amax = def->def.ty.array_max;
633 relation rel = def->def.ty.rel;
634
635 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
636}
637
630emit_typedef(def)
631 definition *def;
632{
633 char *prefix = def->def.ty.old_prefix;
634 char *type = def->def.ty.old_type;
635 char *amax = def->def.ty.array_max;
636 relation rel = def->def.ty.rel;
637
638 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
639}
640
638static
641static void
639print_stat(indent, dec)
640 int indent;
641 declaration *dec;
642{
643 char *prefix = dec->prefix;
644 char *type = dec->type;
645 char *amax = dec->array_max;
646 relation rel = dec->rel;

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

652 s_print(name, "&objp->%s", dec->name);
653 }
654 print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
655}
656
657
658char *upcase ();
659
642print_stat(indent, dec)
643 int indent;
644 declaration *dec;
645{
646 char *prefix = dec->prefix;
647 char *type = dec->type;
648 char *amax = dec->array_max;
649 relation rel = dec->rel;

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

655 s_print(name, "&objp->%s", dec->name);
656 }
657 print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
658}
659
660
661char *upcase ();
662
663static void
660emit_inline(indent, decl, flag)
661int indent;
662declaration *decl;
663int flag;
664{
665 switch (decl->rel) {
666 case REL_ALIAS :
667 emit_single_in_line(indent, decl, flag, REL_ALIAS);

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

676 "for (i = 0, genp = objp->%s;\n", decl->name);
677 tabify(fout, indent + 2);
678 f_print(fout, "i < %s; i++) {\n", decl->array_max);
679 emit_single_in_line(indent + 2, decl, flag, REL_VECTOR);
680 tabify(fout, indent + 1);
681 f_print(fout, "}\n");
682 tabify(fout, indent);
683 f_print(fout, "}\n");
664emit_inline(indent, decl, flag)
665int indent;
666declaration *decl;
667int flag;
668{
669 switch (decl->rel) {
670 case REL_ALIAS :
671 emit_single_in_line(indent, decl, flag, REL_ALIAS);

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

680 "for (i = 0, genp = objp->%s;\n", decl->name);
681 tabify(fout, indent + 2);
682 f_print(fout, "i < %s; i++) {\n", decl->array_max);
683 emit_single_in_line(indent + 2, decl, flag, REL_VECTOR);
684 tabify(fout, indent + 1);
685 f_print(fout, "}\n");
686 tabify(fout, indent);
687 f_print(fout, "}\n");
688 default:
684 }
685}
686
689 }
690}
691
692static void
687emit_single_in_line(indent, decl, flag, rel)
688int indent;
689declaration *decl;
690int flag;
691relation rel;
692{
693 char *upp_case;
694 int freed = 0;

--- 58 unchanged lines hidden ---
693emit_single_in_line(indent, decl, flag, rel)
694int indent;
695declaration *decl;
696int flag;
697relation rel;
698{
699 char *upp_case;
700 int freed = 0;

--- 58 unchanged lines hidden ---