1 /* @(#)rpc_cout.c 2.1 88/08/01 4.0 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
31 /*static char sccsid[] = "from: @(#)rpc_cout.c 1.8 87/06/24 (C) 1987 SMI";*/
32 static char rcsid[] = "$Id: rpc_cout.c,v 1.1 1993/09/13 23:20:13 jtc Exp $";
36 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
37 * Copyright (C) 1987, Sun Microsystems, Inc.
42 #include "rpc_parse.h"
44 static int print_header(), print_trailer(), space(), emit_enum(),
45 emit_union(), emit_struct(), emit_typedef(), print_stat();
49 * Emit the C-routine for the given definition
55 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
59 switch (def->def_kind) {
81 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
84 return (streq(def->def_name, type));
94 def = (definition *) FINDVAL(defined, type, findtype);
104 f_print(fout, "bool_t\n");
105 f_print(fout, "xdr_%s(xdrs, objp)\n", def->def_name);
106 f_print(fout, "\tXDR *xdrs;\n");
107 f_print(fout, "\t%s ", def->def_name);
108 if (def->def_kind != DEF_TYPEDEF ||
109 !isvectordef(def->def.ty.old_type, def->def.ty.rel)) {
112 f_print(fout, "objp;\n");
113 f_print(fout, "{\n");
119 f_print(fout, "\treturn (TRUE);\n");
120 f_print(fout, "}\n");
126 print_ifopen(indent, name)
130 tabify(fout, indent);
131 f_print(fout, "if (!xdr_%s(xdrs", name);
139 f_print(fout, ", %s", arg);
144 print_ifsizeof(prefix, type)
148 if (streq(type, "bool")) {
149 f_print(fout, ", sizeof(bool_t), xdr_bool");
151 f_print(fout, ", sizeof(");
152 if (undefined(type) && prefix) {
153 f_print(fout, "%s ", prefix);
155 f_print(fout, "%s), xdr_%s", type, type);
160 print_ifclose(indent)
163 f_print(fout, ")) {\n");
164 tabify(fout, indent);
165 f_print(fout, "\treturn (FALSE);\n");
166 tabify(fout, indent);
167 f_print(fout, "}\n");
173 f_print(fout, "\n\n");
177 print_ifstat(indent, prefix, type, rel, amax, objname, name)
190 print_ifopen(indent, "pointer");
191 print_ifarg("(char **)");
192 f_print(fout, "%s", objname);
193 print_ifsizeof(prefix, type);
196 if (streq(type, "string")) {
198 } else if (streq(type, "opaque")) {
202 print_ifopen(indent, alt);
203 print_ifarg(objname);
205 print_ifopen(indent, "vector");
206 print_ifarg("(char *)");
207 f_print(fout, "%s", objname);
211 print_ifsizeof(prefix, type);
215 if (streq(type, "string")) {
217 } else if (streq(type, "opaque")) {
220 if (streq(type, "string")) {
221 print_ifopen(indent, alt);
222 print_ifarg(objname);
225 print_ifopen(indent, alt);
227 print_ifopen(indent, "array");
229 print_ifarg("(char **)");
230 if (*objname == '&') {
231 f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
232 objname, name, objname, name);
234 f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
235 objname, name, objname, name);
240 print_ifsizeof(prefix, type);
244 print_ifopen(indent, type);
245 print_ifarg(objname);
248 print_ifclose(indent);
257 print_ifopen(1, "enum");
258 print_ifarg("(enum_t *)objp");
271 char *format = "&objp->%s_u.%s";
273 print_stat(&def->def.un.enum_decl);
274 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
275 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
277 f_print(fout, "\tcase %s:\n", cl->case_name);
278 if (!streq(cs->type, "void")) {
279 object = alloc(strlen(def->def_name) + strlen(format) +
280 strlen(cs->name) + 1);
281 s_print(object, format, def->def_name, cs->name);
282 print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
286 f_print(fout, "\t\tbreak;\n");
288 dflt = def->def.un.default_decl;
290 if (!streq(dflt->type, "void")) {
291 f_print(fout, "\tdefault:\n");
292 object = alloc(strlen(def->def_name) + strlen(format) +
293 strlen(dflt->name) + 1);
294 s_print(object, format, def->def_name, dflt->name);
295 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
296 dflt->array_max, object, dflt->name);
298 f_print(fout, "\t\tbreak;\n");
301 f_print(fout, "\tdefault:\n");
302 f_print(fout, "\t\treturn (FALSE);\n");
304 f_print(fout, "\t}\n");
315 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) {
316 print_stat(&dl->decl);
327 char *prefix = def->def.ty.old_prefix;
328 char *type = def->def.ty.old_type;
329 char *amax = def->def.ty.array_max;
330 relation rel = def->def.ty.rel;
332 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
343 char *prefix = dec->prefix;
344 char *type = dec->type;
345 char *amax = dec->array_max;
346 relation rel = dec->rel;
349 if (isvectordef(type, rel)) {
350 s_print(name, "objp->%s", dec->name);
352 s_print(name, "&objp->%s", dec->name);
354 print_ifstat(1, prefix, type, rel, amax, name, dec->name);