1 /* @(#)rpc_hout.c 1.2 87/11/30 3.9 RPCSRC */
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
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.
28 * Mountain View, California 94043
32 * rpc_hout.c, Header file outputter for the RPC protocol compiler
33 * Copyright (C) 1987, Sun Microsystems, Inc.
35 #include <afs/param.h>
36 #include <afsconfig.h>
43 #include "rpc_parse.h"
51 static pdeclaration();
56 * Print the C-version of an xdr definition
62 extern int IsRxgenDefinition();
64 if (Sflag) scan_print = 0;
65 if ((def->def_kind != DEF_CONST) && (!IsRxgenDefinition(def))) {
68 switch (def->def_kind) {
89 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST && (!IsRxgenDefinition(def))) {
90 f_print(fout, "bool_t xdr_%s();\n", def->def_name);
92 if (def->def_kind != DEF_CONST && (!IsRxgenDefinition(def))) {
95 if (Sflag) scan_print = 1;
102 pdefine(def->def_name, def->def.co);
110 char *name = def->def_name;
112 f_print(fout, "struct %s {\n", name);
113 for (l = def->def.st.decls; l != NULL; l = l->next) {
114 pdeclaration(name, &l->decl, 1);
116 f_print(fout, "};\n");
117 f_print(fout, "typedef struct %s %s;\n", name, name);
125 char *name = def->def_name;
128 f_print(fout, "struct %s {\n", name);
129 decl = &def->def.un.enum_decl;
130 if (streq(decl->type, "bool")) {
131 f_print(fout, "\tbool_t %s;\n", decl->name);
133 f_print(fout, "\t%s %s;\n", decl->type, decl->name);
135 f_print(fout, "\tunion {\n");
136 for (l = def->def.un.cases; l != NULL; l = l->next) {
137 pdeclaration(name, &l->case_decl, 2);
139 decl = def->def.un.default_decl;
140 if (decl && !streq(decl->type, "void")) {
141 pdeclaration(name, decl, 2);
143 f_print(fout, "\t} %s_u;\n", name);
144 f_print(fout, "};\n");
145 f_print(fout, "typedef struct %s %s;\n", name, name);
146 STOREVAL(&uniondef_defined, def);
154 f_print(fout, "#define %s %s\n", name, num);
162 f_print(fout, "#define %s ((afs_uint32)%s)\n", name, num);
166 define_printed(stop, start)
173 for (vers = start; vers != NULL; vers = vers->next) {
174 for (proc = vers->procs; proc != NULL; proc = proc->next) {
177 } else if (streq(proc->proc_name, stop->proc_name)) {
194 puldefine(def->def_name, def->def.pr.prog_num);
195 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
196 puldefine(vers->vers_name, vers->vers_num);
197 for (proc = vers->procs; proc != NULL; proc = proc->next) {
198 if (!define_printed(proc, def->def.pr.versions)) {
199 puldefine(proc->proc_name, proc->proc_num);
201 pprocdef(proc, vers);
211 f_print(fout, "extern ");
212 if (proc->res_prefix) {
213 if (streq(proc->res_prefix, "enum")) {
214 f_print(fout, "enum ");
216 f_print(fout, "struct ");
219 if (streq(proc->res_type, "bool")) {
220 f_print(fout, "bool_t *");
221 } else if (streq(proc->res_type, "string")) {
222 f_print(fout, "char **");
224 f_print(fout, "%s *", fixtype(proc->res_type));
226 pvname(proc->proc_name, vp->vers_num);
227 f_print(fout, "();\n");
234 char *name = def->def_name;
239 f_print(fout, "enum %s {\n", name);
240 for (l = def->def.en.vals; l != NULL; l = l->next) {
241 f_print(fout, "\t%s", l->name);
243 f_print(fout, " = %s", l->assignment);
244 last = l->assignment;
248 f_print(fout, " = %d", count++);
250 f_print(fout, " = %s + %d", last, count++);
253 f_print(fout, ",\n");
255 f_print(fout, "};\n");
256 f_print(fout, "typedef enum %s %s;\n", name, name);
263 char *name = def->def_name;
264 char *old = def->def.ty.old_type;
265 char prefix[8]; /* enough to contain "struct ", including NUL */
266 relation rel = def->def.ty.rel;
269 if (!streq(name, old)) {
270 if (streq(old, "string")) {
273 } else if (streq(old, "opaque")) {
275 } else if (streq(old, "bool")) {
278 if (undefined2(old, name) && def->def.ty.old_prefix) {
279 s_print(prefix, "%s ", def->def.ty.old_prefix);
283 f_print(fout, "typedef ");
286 f_print(fout, "struct %s {\n", name);
287 f_print(fout, "\tu_int %s_len;\n", name);
288 f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
289 f_print(fout, "} %s", name);
292 f_print(fout, "%s%s *%s", prefix, old, name);
295 f_print(fout, "%s%s %s[%s]", prefix, old, name,
296 def->def.ty.array_max);
299 f_print(fout, "%s%s %s", prefix, old, name);
303 STOREVAL(&typedef_defined, def);
304 f_print(fout, ";\n");
310 pdeclaration(name, dec, tab)
315 char buf[8]; /* enough to hold "struct ", include NUL */
319 if (streq(dec->type, "void")) {
323 if (streq(dec->type, name) && !dec->prefix) {
324 f_print(fout, "struct ");
326 if (streq(dec->type, "string")) {
327 f_print(fout, "char *%s", dec->name);
330 if (streq(dec->type, "bool")) {
332 } else if (streq(dec->type, "opaque")) {
336 s_print(buf, "%s ", dec->prefix);
343 f_print(fout, "%s%s %s", prefix, type, dec->name);
346 f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
350 f_print(fout, "%s%s *%s", prefix, type, dec->name);
353 f_print(fout, "struct %s {\n", dec->name);
355 f_print(fout, "\tu_int %s_len;\n", dec->name);
357 f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
359 f_print(fout, "} %s", dec->name);
363 f_print(fout, ";\n");
369 undefined2(type, stop)
376 for (l = defined; l != NULL; l = l->next) {
377 def = (definition *) l->val;
378 if (def->def_kind != DEF_PROGRAM) {
379 if (streq(def->def_name, stop)) {
381 } else if (streq(def->def_name, type)) {