1 /* @(#)rpc_hout.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_hout.c 1.6 87/07/28 (C) 1987 SMI";
35 * rpc_hout.c, Header file outputter for the RPC protocol compiler
36 * Copyright (C) 1987, Sun Microsystems, Inc.
41 #include "rpc_parse.h"
45 * Print the C-version of an xdr definition
51 if (def
->def_kind
!= DEF_CONST
) {
54 switch (def
->def_kind
) {
74 if (def
->def_kind
!= DEF_PROGRAM
&& def
->def_kind
!= DEF_CONST
) {
75 f_print(fout
, "bool_t xdr_%s();\n", def
->def_name
);
77 if (def
->def_kind
!= DEF_CONST
) {
86 pdefine(def
->def_name
, def
->def
.co
);
94 char *name
= def
->def_name
;
96 f_print(fout
, "struct %s {\n", name
);
97 for (l
= def
->def
.st
.decls
; l
!= NULL
; l
= l
->next
) {
98 pdeclaration(name
, &l
->decl
, 1);
100 f_print(fout
, "};\n");
101 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
109 char *name
= def
->def_name
;
112 f_print(fout
, "struct %s {\n", name
);
113 decl
= &def
->def
.un
.enum_decl
;
114 if (streq(decl
->type
, "bool")) {
115 f_print(fout
, "\tbool_t %s;\n", decl
->name
);
117 f_print(fout
, "\t%s %s;\n", decl
->type
, decl
->name
);
119 f_print(fout
, "\tunion {\n");
120 for (l
= def
->def
.un
.cases
; l
!= NULL
; l
= l
->next
) {
121 pdeclaration(name
, &l
->case_decl
, 2);
123 decl
= def
->def
.un
.default_decl
;
124 if (decl
&& !streq(decl
->type
, "void")) {
125 pdeclaration(name
, decl
, 2);
127 f_print(fout
, "\t} %s_u;\n", name
);
128 f_print(fout
, "};\n");
129 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
139 f_print(fout
, "#define %s %s\n", name
, num
);
147 f_print(fout
, "#define %s ((u_long)%s)\n", name
, num
);
151 define_printed(stop
, start
)
158 for (vers
= start
; vers
!= NULL
; vers
= vers
->next
) {
159 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
) {
162 } else if (streq(proc
->proc_name
, stop
->proc_name
)) {
179 puldefine(def
->def_name
, def
->def
.pr
.prog_num
);
180 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
) {
181 puldefine(vers
->vers_name
, vers
->vers_num
);
182 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
) {
183 if (!define_printed(proc
, def
->def
.pr
.versions
)) {
184 puldefine(proc
->proc_name
, proc
->proc_num
);
186 pprocdef(proc
, vers
);
196 f_print(fout
, "extern ");
197 if (proc
->res_prefix
) {
198 if (streq(proc
->res_prefix
, "enum")) {
199 f_print(fout
, "enum ");
201 f_print(fout
, "struct ");
204 if (streq(proc
->res_type
, "bool")) {
205 f_print(fout
, "bool_t *");
206 } else if (streq(proc
->res_type
, "string")) {
207 f_print(fout
, "char **");
209 f_print(fout
, "%s *", fixtype(proc
->res_type
));
211 pvname(proc
->proc_name
, vp
->vers_num
);
212 f_print(fout
, "();\n");
219 char *name
= def
->def_name
;
224 f_print(fout
, "enum %s {\n", name
);
225 for (l
= def
->def
.en
.vals
; l
!= NULL
; l
= l
->next
) {
226 f_print(fout
, "\t%s", l
->name
);
228 f_print(fout
, " = %s", l
->assignment
);
229 last
= l
->assignment
;
233 f_print(fout
, " = %d", count
++);
235 f_print(fout
, " = %s + %d", last
, count
++);
238 f_print(fout
, ",\n");
240 f_print(fout
, "};\n");
241 f_print(fout
, "typedef enum %s %s;\n", name
, name
);
248 char *name
= def
->def_name
;
249 char *old
= def
->def
.ty
.old_type
;
250 char prefix
[8]; /* enough to contain "struct ", including NUL */
251 relation rel
= def
->def
.ty
.rel
;
254 if (!streq(name
, old
)) {
255 if (streq(old
, "string")) {
258 } else if (streq(old
, "opaque")) {
260 } else if (streq(old
, "bool")) {
263 if (undefined2(old
, name
) && def
->def
.ty
.old_prefix
) {
264 s_print(prefix
, "%s ", def
->def
.ty
.old_prefix
);
268 f_print(fout
, "typedef ");
271 f_print(fout
, "struct {\n");
272 f_print(fout
, "\tu_int %s_len;\n", name
);
273 f_print(fout
, "\t%s%s *%s_val;\n", prefix
, old
, name
);
274 f_print(fout
, "} %s", name
);
277 f_print(fout
, "%s%s *%s", prefix
, old
, name
);
280 f_print(fout
, "%s%s %s[%s]", prefix
, old
, name
,
281 def
->def
.ty
.array_max
);
284 f_print(fout
, "%s%s %s", prefix
, old
, name
);
287 f_print(fout
, ";\n");
293 pdeclaration(name
, dec
, tab
)
298 char buf
[8]; /* enough to hold "struct ", include NUL */
302 if (streq(dec
->type
, "void")) {
306 if (streq(dec
->type
, name
) && !dec
->prefix
) {
307 f_print(fout
, "struct ");
309 if (streq(dec
->type
, "string")) {
310 f_print(fout
, "char *%s", dec
->name
);
313 if (streq(dec
->type
, "bool")) {
315 } else if (streq(dec
->type
, "opaque")) {
319 s_print(buf
, "%s ", dec
->prefix
);
326 f_print(fout
, "%s%s %s", prefix
, type
, dec
->name
);
329 f_print(fout
, "%s%s %s[%s]", prefix
, type
, dec
->name
,
333 f_print(fout
, "%s%s *%s", prefix
, type
, dec
->name
);
336 f_print(fout
, "struct {\n");
338 f_print(fout
, "\tu_int %s_len;\n", dec
->name
);
340 f_print(fout
, "\t%s%s *%s_val;\n", prefix
, type
, dec
->name
);
342 f_print(fout
, "} %s", dec
->name
);
346 f_print(fout
, ";\n");
352 undefined2(type
, stop
)
359 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
360 def
= (definition
*) l
->val
;
361 if (def
->def_kind
!= DEF_PROGRAM
) {
362 if (streq(def
->def_name
, stop
)) {
364 } else if (streq(def
->def_name
, type
)) {