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
[] = "@(#)rpc_cout.c 1.8 87/06/24 (C) 1987 SMI";
35 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
36 * Copyright (C) 1987, Sun Microsystems, Inc.
41 #include "rpc_parse.h"
44 * Emit the C-routine for the given definition
50 if (def
->def_kind
== DEF_PROGRAM
|| def
->def_kind
== DEF_CONST
) {
54 switch (def
->def_kind
) {
76 if (def
->def_kind
== DEF_PROGRAM
|| def
->def_kind
== DEF_CONST
) {
79 return (streq(def
->def_name
, type
));
89 def
= (definition
*) FINDVAL(defined
, type
, findtype
);
99 f_print(fout
, "bool_t\n");
100 f_print(fout
, "xdr_%s(xdrs, objp)\n", def
->def_name
);
101 f_print(fout
, "\tXDR *xdrs;\n");
102 f_print(fout
, "\t%s ", def
->def_name
);
103 if (def
->def_kind
!= DEF_TYPEDEF
||
104 !isvectordef(def
->def
.ty
.old_type
, def
->def
.ty
.rel
)) {
107 f_print(fout
, "objp;\n");
108 f_print(fout
, "{\n");
114 f_print(fout
, "\treturn (TRUE);\n");
115 f_print(fout
, "}\n");
121 print_ifopen(indent
, name
)
125 tabify(fout
, indent
);
126 f_print(fout
, "if (!xdr_%s(xdrs", name
);
134 f_print(fout
, ", %s", arg
);
139 print_ifsizeof(prefix
, type
)
143 if (streq(type
, "bool")) {
144 f_print(fout
, ", sizeof(bool_t), xdr_bool");
146 f_print(fout
, ", sizeof(");
147 if (undefined(type
) && prefix
) {
148 f_print(fout
, "%s ", prefix
);
150 f_print(fout
, "%s), xdr_%s", type
, type
);
155 print_ifclose(indent
)
158 f_print(fout
, ")) {\n");
159 tabify(fout
, indent
);
160 f_print(fout
, "\treturn (FALSE);\n");
161 tabify(fout
, indent
);
162 f_print(fout
, "}\n");
168 f_print(fout
, "\n\n");
172 print_ifstat(indent
, prefix
, type
, rel
, amax
, objname
, name
)
185 print_ifopen(indent
, "pointer");
186 print_ifarg("(char **)");
187 f_print(fout
, "%s", objname
);
188 print_ifsizeof(prefix
, type
);
191 if (streq(type
, "string")) {
193 } else if (streq(type
, "opaque")) {
197 print_ifopen(indent
, alt
);
198 print_ifarg(objname
);
200 print_ifopen(indent
, "vector");
201 print_ifarg("(char *)");
202 f_print(fout
, "%s", objname
);
206 print_ifsizeof(prefix
, type
);
210 if (streq(type
, "string")) {
212 } else if (streq(type
, "opaque")) {
215 if (streq(type
, "string")) {
216 print_ifopen(indent
, alt
);
217 print_ifarg(objname
);
220 print_ifopen(indent
, alt
);
222 print_ifopen(indent
, "array");
224 print_ifarg("(char **)");
225 if (*objname
== '&') {
226 f_print(fout
, "%s.%s_val, (u_int *)%s.%s_len",
227 objname
, name
, objname
, name
);
229 f_print(fout
, "&%s->%s_val, (u_int *)&%s->%s_len",
230 objname
, name
, objname
, name
);
235 print_ifsizeof(prefix
, type
);
239 print_ifopen(indent
, type
);
240 print_ifarg(objname
);
243 print_ifclose(indent
);
252 print_ifopen(1, "enum");
253 print_ifarg("(enum_t *)objp");
266 char *format
= "&objp->%s_u.%s";
268 print_stat(&def
->def
.un
.enum_decl
);
269 f_print(fout
, "\tswitch (objp->%s) {\n", def
->def
.un
.enum_decl
.name
);
270 for (cl
= def
->def
.un
.cases
; cl
!= NULL
; cl
= cl
->next
) {
272 f_print(fout
, "\tcase %s:\n", cl
->case_name
);
273 if (!streq(cs
->type
, "void")) {
274 object
= alloc(strlen(def
->def_name
) + strlen(format
) +
275 strlen(cs
->name
) + 1);
276 s_print(object
, format
, def
->def_name
, cs
->name
);
277 print_ifstat(2, cs
->prefix
, cs
->type
, cs
->rel
, cs
->array_max
,
281 f_print(fout
, "\t\tbreak;\n");
283 dflt
= def
->def
.un
.default_decl
;
285 if (!streq(dflt
->type
, "void")) {
286 f_print(fout
, "\tdefault:\n");
287 object
= alloc(strlen(def
->def_name
) + strlen(format
) +
288 strlen(dflt
->name
) + 1);
289 s_print(object
, format
, def
->def_name
, dflt
->name
);
290 print_ifstat(2, dflt
->prefix
, dflt
->type
, dflt
->rel
,
291 dflt
->array_max
, object
, dflt
->name
);
293 f_print(fout
, "\t\tbreak;\n");
296 f_print(fout
, "\tdefault:\n");
297 f_print(fout
, "\t\treturn (FALSE);\n");
299 f_print(fout
, "\t}\n");
310 for (dl
= def
->def
.st
.decls
; dl
!= NULL
; dl
= dl
->next
) {
311 print_stat(&dl
->decl
);
322 char *prefix
= def
->def
.ty
.old_prefix
;
323 char *type
= def
->def
.ty
.old_type
;
324 char *amax
= def
->def
.ty
.array_max
;
325 relation rel
= def
->def
.ty
.rel
;
327 print_ifstat(1, prefix
, type
, rel
, amax
, "objp", def
->def_name
);
338 char *prefix
= dec
->prefix
;
339 char *type
= dec
->type
;
340 char *amax
= dec
->array_max
;
341 relation rel
= dec
->rel
;
344 if (isvectordef(type
, rel
)) {
345 s_print(name
, "objp->%s", dec
->name
);
347 s_print(name
, "&objp->%s", dec
->name
);
349 print_ifstat(1, prefix
, type
, rel
, amax
, name
, dec
->name
);