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 <afsconfig.h>
36 #include <afs/param.h>
43 #include "rpc_parse.h"
46 /* Static declarations */
47 static void pconstdef(definition * def);
48 static void pstructdef(definition * def);
49 static void puniondef(definition * def);
50 static void puldefine(char *name, char *num);
51 static int define_printed(proc_list * stop, version_list * start);
52 static void pprogramdef(definition * def);
53 static void psproc1(definition * defp, int callTconnF, char *type,
54 char *prefix, int iomask);
55 static void psprocdef(definition * defp);
56 static void penumdef(definition * def);
57 static void ptypedef(definition * def);
58 static void pdeclaration(char *name, declaration * dec, int tab);
59 static int undefined2(char *type, char *stop);
62 * Print the C-version of an xdr definition
65 print_datadef(definition * def)
69 if ((def->def_kind != DEF_CONST) && (!IsRxgenDefinition(def))) {
72 switch (def->def_kind) {
98 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST
99 && (!IsRxgenDefinition(def))) {
100 f_print(fout, "bool_t xdr_%s(XDR *xdrs, %s *objp);\n", def->def_name,
103 if (def->def_kind != DEF_CONST && (!IsRxgenDefinition(def))) {
111 pconstdef(definition * def)
113 pdefine(def->def_name, def->def.co);
117 pstructdef(definition * def)
120 char *name = def->def_name;
122 f_print(fout, "struct %s {\n", name);
123 for (l = def->def.st.decls; l != NULL; l = l->next) {
124 pdeclaration(name, &l->decl, 1);
126 f_print(fout, "};\n");
127 f_print(fout, "typedef struct %s %s;\n", name, name);
131 puniondef(definition * def)
134 char *name = def->def_name;
137 f_print(fout, "struct %s {\n", name);
138 decl = &def->def.un.enum_decl;
139 if (streq(decl->type, "bool")) {
140 f_print(fout, "\tbool_t %s;\n", decl->name);
142 f_print(fout, "\t%s %s;\n", decl->type, decl->name);
144 f_print(fout, "\tunion {\n");
145 for (l = def->def.un.cases; l != NULL; l = l->next) {
146 pdeclaration(name, &l->case_decl, 2);
148 decl = def->def.un.default_decl;
149 if (decl && !streq(decl->type, "void")) {
150 pdeclaration(name, decl, 2);
153 f_print(fout, "\t} u;\n");
155 f_print(fout, "\t} %s_u;\n", name);
157 f_print(fout, "};\n");
158 f_print(fout, "typedef struct %s %s;\n", name, name);
159 STOREVAL(&uniondef_defined, def);
164 pdefine(char *name, char *num)
166 f_print(fout, "#define %s %s\n", name, num);
170 puldefine(char *name, char *num)
172 f_print(fout, "#define %s ((afs_uint32)%s)\n", name, num);
176 define_printed(proc_list * stop, version_list * start)
181 for (vers = start; vers != NULL; vers = vers->next) {
182 for (proc = vers->procs; proc != NULL; proc = proc->next) {
185 } else if (streq(proc->proc_name, stop->proc_name)) {
191 return 0;/* NOTREACHED */
196 pprogramdef(definition * def)
201 puldefine(def->def_name, def->def.pr.prog_num);
202 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
203 puldefine(vers->vers_name, vers->vers_num);
204 for (proc = vers->procs; proc != NULL; proc = proc->next) {
205 if (!define_printed(proc, def->def.pr.versions)) {
206 puldefine(proc->proc_name, proc->proc_num);
208 pprocdef(proc, vers);
214 psproc1(definition * defp, int callTconnF, char *type, char *prefix,
219 f_print(fout, "\nextern %s %s%s%s(\n", type, prefix, defp->pc.proc_prefix,
222 if (callTconnF == 1 || callTconnF == 3) {
223 f_print(fout, "\t/*IN */ struct rx_call *z_call");
224 } else if (callTconnF == 2) {
225 f_print(fout, "\tstruct ubik_client *aclient, afs_int32 aflags");
227 f_print(fout, "\t/*IN */ struct rx_connection *z_conn");
230 for (plist = defp->pc.plists; plist; plist = plist->next) {
231 if (plist->component_kind == DEF_PARAM
232 && (iomask & (1 << plist->pl.param_kind))) {
233 switch (plist->pl.param_kind) {
235 f_print(fout, ",\n\t/*IN %d*/ ",callTconnF);
236 if ((callTconnF != 3)
237 && strcmp(plist->pl.param_type, "char *")== 0)
238 f_print(fout, "const ");
241 f_print(fout, ",\n\t/*OUT*/ ");
244 f_print(fout, ",\n\t/*I/O*/ ");
249 if (plist->pl.param_flag & OUT_STRING) {
250 f_print(fout, "%s *%s", plist->pl.param_type,
251 plist->pl.param_name);
253 f_print(fout, "%s %s", plist->pl.param_type,
254 plist->pl.param_name);
258 f_print(fout, ");\n");
262 psprocdef(definition * defp)
264 int split_flag = defp->pc.split_flag;
265 int multi_flag = defp->pc.multi_flag;
267 if (split_flag || multi_flag) {
268 psproc1(defp, 1, "int", "Start",
269 (1 << DEF_INPARAM) | (1 << DEF_INOUTPARAM));
270 psproc1(defp, 1, "int", "End",
271 (1 << DEF_OUTPARAM) | (1 << DEF_INOUTPARAM));
273 if (!(!multi_flag && split_flag))
274 psproc1(defp, 0, "int", "", 0xFFFFFFFF);
277 psproc1(defp, 2, "int", "ubik_", 0xFFFFFFFF);
280 psproc1(defp, 3, "afs_int32", ServerPrefix, 0xFFFFFFFF);
285 pprocdef(proc_list * proc, version_list * vp)
287 f_print(fout, "extern ");
288 if (proc->res_prefix) {
289 if (streq(proc->res_prefix, "enum")) {
290 f_print(fout, "enum ");
292 f_print(fout, "struct ");
295 if (streq(proc->res_type, "bool")) {
296 f_print(fout, "bool_t *");
297 } else if (streq(proc->res_type, "string")) {
298 f_print(fout, "char **");
300 f_print(fout, "%s *", fixtype(proc->res_type));
302 pvname(proc->proc_name, vp->vers_num);
303 f_print(fout, "();\n");
307 penumdef(definition * def)
309 char *name = def->def_name;
314 f_print(fout, "enum %s {\n", name);
315 for (l = def->def.en.vals; l != NULL; l = l->next) {
316 f_print(fout, "\t%s", l->name);
318 f_print(fout, " = %s", l->assignment);
319 last = l->assignment;
323 f_print(fout, " = %d", count++);
325 f_print(fout, " = %s + %d", last, count++);
328 f_print(fout, ",\n");
330 f_print(fout, "};\n");
331 f_print(fout, "typedef enum %s %s;\n", name, name);
335 ptypedef(definition * def)
337 char *name = def->def_name;
338 char *old = def->def.ty.old_type;
339 char prefix[8]; /* enough to contain "struct ", including NUL */
340 relation rel = def->def.ty.rel;
343 if (!streq(name, old)) {
344 if (streq(old, "string")) {
347 } else if (!brief_flag && streq(old, "opaque")) {
349 } else if (streq(old, "bool")) {
352 if (undefined2(old, name) && def->def.ty.old_prefix) {
353 s_print(prefix, "%s ", def->def.ty.old_prefix);
357 f_print(fout, "typedef ");
361 if (streq(old, "opaque")) {
362 f_print(fout, "struct rx_opaque %s", name);
364 f_print(fout, "struct {\n");
365 f_print(fout, "\tu_int len;\n");
366 f_print(fout, "\t%s%s *val;\n", prefix, old);
367 f_print(fout, "} %s", name);
370 f_print(fout, "struct %s {\n", name);
371 f_print(fout, "\tu_int %s_len;\n", name);
372 f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
373 f_print(fout, "} %s", name);
377 f_print(fout, "%s%s *%s", prefix, old, name);
380 f_print(fout, "%s%s %s[%s]", prefix, old, name,
381 def->def.ty.array_max);
384 f_print(fout, "%s%s %s", prefix, old, name);
388 STOREVAL(&typedef_defined, def);
389 f_print(fout, ";\n");
395 pdeclaration(char *name, declaration * dec, int tab)
397 char buf[8]; /* enough to hold "struct ", include NUL */
401 if (streq(dec->type, "void")) {
405 if (streq(dec->type, name) && !dec->prefix) {
406 f_print(fout, "struct ");
408 if (streq(dec->type, "string")) {
409 f_print(fout, "char *%s", dec->name);
412 if (streq(dec->type, "bool")) {
414 } else if (streq(dec->type, "opaque")) {
418 s_print(buf, "%s ", dec->prefix);
425 f_print(fout, "%s%s %s", prefix, type, dec->name);
428 f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
432 f_print(fout, "%s%s *%s", prefix, type, dec->name);
436 if (streq(dec->type, "opaque")) {
437 f_print(fout, "struct rx_opaque %s",dec->name);
439 f_print(fout, "struct {\n");
441 f_print(fout, "\tu_int len;\n");
443 f_print(fout, "\t%s%s *val;\n", prefix, type);
445 f_print(fout, "} %s", dec->name);
448 f_print(fout, "struct %s {\n", dec->name);
450 f_print(fout, "\tu_int %s_len;\n", dec->name);
452 f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
454 f_print(fout, "} %s", dec->name);
459 f_print(fout, ";\n");
465 undefined2(char *type, char *stop)
470 for (l = defined; l != NULL; l = l->next) {
471 def = (definition *) l->val;
472 if (def->def_kind != DEF_PROGRAM) {
473 if (streq(def->def_name, stop)) {
475 } else if (streq(def->def_name, type)) {