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>
53 #include "rpc_parse.h"
56 /* Static declarations */
57 static void pconstdef(definition * def);
58 static void pstructdef(definition * def);
59 static void puniondef(definition * def);
60 static void puldefine(char *name, char *num);
61 static int define_printed(proc_list * stop, version_list * start);
62 static void pprogramdef(definition * def);
63 static void psproc1(definition * defp, int callTconnF, char *type,
64 char *prefix, int iomask);
65 static void psprocdef(definition * defp);
66 static void penumdef(definition * def);
67 static void ptypedef(definition * def);
68 static void pdeclaration(char *name, declaration * dec, int tab);
69 static int undefined2(char *type, char *stop);
72 * Print the C-version of an xdr definition
75 print_datadef(definition * def)
79 if ((def->def_kind != DEF_CONST) && (!IsRxgenDefinition(def))) {
82 switch (def->def_kind) {
106 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST
107 && (!IsRxgenDefinition(def))) {
108 f_print(fout, "bool_t xdr_%s(XDR *xdrs, %s *objp);\n", def->def_name,
111 if (def->def_kind != DEF_CONST && (!IsRxgenDefinition(def))) {
119 pconstdef(definition * def)
121 pdefine(def->def_name, def->def.co);
125 pstructdef(definition * def)
128 char *name = def->def_name;
130 f_print(fout, "struct %s {\n", name);
131 for (l = def->def.st.decls; l != NULL; l = l->next) {
132 pdeclaration(name, &l->decl, 1);
134 f_print(fout, "};\n");
135 f_print(fout, "typedef struct %s %s;\n", name, name);
139 puniondef(definition * def)
142 char *name = def->def_name;
145 f_print(fout, "struct %s {\n", name);
146 decl = &def->def.un.enum_decl;
147 if (streq(decl->type, "bool")) {
148 f_print(fout, "\tbool_t %s;\n", decl->name);
150 f_print(fout, "\t%s %s;\n", decl->type, decl->name);
152 f_print(fout, "\tunion {\n");
153 for (l = def->def.un.cases; l != NULL; l = l->next) {
154 pdeclaration(name, &l->case_decl, 2);
156 decl = def->def.un.default_decl;
157 if (decl && !streq(decl->type, "void")) {
158 pdeclaration(name, decl, 2);
160 f_print(fout, "\t} %s_u;\n", name);
161 f_print(fout, "};\n");
162 f_print(fout, "typedef struct %s %s;\n", name, name);
163 STOREVAL(&uniondef_defined, def);
168 pdefine(char *name, char *num)
170 f_print(fout, "#define %s %s\n", name, num);
174 puldefine(char *name, char *num)
176 f_print(fout, "#define %s ((afs_uint32)%s)\n", name, num);
180 define_printed(proc_list * stop, version_list * start)
185 for (vers = start; vers != NULL; vers = vers->next) {
186 for (proc = vers->procs; proc != NULL; proc = proc->next) {
189 } else if (streq(proc->proc_name, stop->proc_name)) {
195 return 0;/* NOTREACHED */
200 pprogramdef(definition * def)
205 puldefine(def->def_name, def->def.pr.prog_num);
206 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
207 puldefine(vers->vers_name, vers->vers_num);
208 for (proc = vers->procs; proc != NULL; proc = proc->next) {
209 if (!define_printed(proc, def->def.pr.versions)) {
210 puldefine(proc->proc_name, proc->proc_num);
212 pprocdef(proc, vers);
218 psproc1(definition * defp, int callTconnF, char *type, char *prefix,
223 f_print(fout, "\nextern %s %s%s%s(\n", type, prefix, defp->pc.proc_prefix,
226 if (callTconnF == 1) {
227 f_print(fout, "\t/*IN */ struct rx_call *z_call");
228 } else if (callTconnF == 2) {
229 f_print(fout, "\tregister struct ubik_client *aclient, afs_int32 aflags");
231 f_print(fout, "\t/*IN */ struct rx_connection *z_conn");
234 for (plist = defp->pc.plists; plist; plist = plist->next) {
235 if (plist->component_kind == DEF_PARAM
236 && (iomask & (1 << plist->pl.param_kind))) {
237 switch (plist->pl.param_kind) {
239 f_print(fout, ",\n\t/*IN */ ");
242 f_print(fout, ",\n\t/*OUT*/ ");
245 f_print(fout, ",\n\t/*I/O*/ ");
248 if (plist->pl.param_flag & OUT_STRING) {
249 f_print(fout, "%s *%s", plist->pl.param_type,
250 plist->pl.param_name);
252 f_print(fout, "%s %s", plist->pl.param_type,
253 plist->pl.param_name);
257 f_print(fout, ");\n");
261 psprocdef(definition * defp)
263 int split_flag = defp->pc.split_flag;
264 int multi_flag = defp->pc.multi_flag;
266 if (split_flag || multi_flag) {
267 psproc1(defp, 1, "int", "Start",
268 (1 << DEF_INPARAM) | (1 << DEF_INOUTPARAM));
269 psproc1(defp, 1, "int", "End",
270 (1 << DEF_OUTPARAM) | (1 << DEF_INOUTPARAM));
272 psproc1(defp, 0, "int", "", 0xFFFFFFFF);
276 psproc1(defp, 2, "int", "ubik_", 0xFFFFFFFF);
279 psproc1(defp, 1, "afs_int32", ServerPrefix, 0xFFFFFFFF);
284 pprocdef(proc_list * proc, version_list * vp)
286 f_print(fout, "extern ");
287 if (proc->res_prefix) {
288 if (streq(proc->res_prefix, "enum")) {
289 f_print(fout, "enum ");
291 f_print(fout, "struct ");
294 if (streq(proc->res_type, "bool")) {
295 f_print(fout, "bool_t *");
296 } else if (streq(proc->res_type, "string")) {
297 f_print(fout, "char **");
299 f_print(fout, "%s *", fixtype(proc->res_type));
301 pvname(proc->proc_name, vp->vers_num);
302 f_print(fout, "();\n");
306 penumdef(definition * def)
308 char *name = def->def_name;
313 f_print(fout, "enum %s {\n", name);
314 for (l = def->def.en.vals; l != NULL; l = l->next) {
315 f_print(fout, "\t%s", l->name);
317 f_print(fout, " = %s", l->assignment);
318 last = l->assignment;
322 f_print(fout, " = %d", count++);
324 f_print(fout, " = %s + %d", last, count++);
327 f_print(fout, ",\n");
329 f_print(fout, "};\n");
330 f_print(fout, "typedef enum %s %s;\n", name, name);
334 ptypedef(definition * def)
336 char *name = def->def_name;
337 char *old = def->def.ty.old_type;
338 char prefix[8]; /* enough to contain "struct ", including NUL */
339 relation rel = def->def.ty.rel;
342 if (!streq(name, old)) {
343 if (streq(old, "string")) {
346 } else if (streq(old, "opaque")) {
348 } else if (streq(old, "bool")) {
351 if (undefined2(old, name) && def->def.ty.old_prefix) {
352 s_print(prefix, "%s ", def->def.ty.old_prefix);
356 f_print(fout, "typedef ");
359 f_print(fout, "struct %s {\n", name);
360 f_print(fout, "\tu_int %s_len;\n", name);
361 f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
362 f_print(fout, "} %s", name);
365 f_print(fout, "%s%s *%s", prefix, old, name);
368 f_print(fout, "%s%s %s[%s]", prefix, old, name,
369 def->def.ty.array_max);
372 f_print(fout, "%s%s %s", prefix, old, name);
376 STOREVAL(&typedef_defined, def);
377 f_print(fout, ";\n");
383 pdeclaration(char *name, declaration * dec, int tab)
385 char buf[8]; /* enough to hold "struct ", include NUL */
389 if (streq(dec->type, "void")) {
393 if (streq(dec->type, name) && !dec->prefix) {
394 f_print(fout, "struct ");
396 if (streq(dec->type, "string")) {
397 f_print(fout, "char *%s", dec->name);
400 if (streq(dec->type, "bool")) {
402 } else if (streq(dec->type, "opaque")) {
406 s_print(buf, "%s ", dec->prefix);
413 f_print(fout, "%s%s %s", prefix, type, dec->name);
416 f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
420 f_print(fout, "%s%s *%s", prefix, type, dec->name);
423 f_print(fout, "struct %s {\n", dec->name);
425 f_print(fout, "\tu_int %s_len;\n", dec->name);
427 f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
429 f_print(fout, "} %s", dec->name);
433 f_print(fout, ";\n");
439 undefined2(char *type, char *stop)
444 for (l = defined; l != NULL; l = l->next) {
445 def = (definition *) l->val;
446 if (def->def_kind != DEF_PROGRAM) {
447 if (streq(def->def_name, stop)) {
449 } else if (streq(def->def_name, type)) {