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 psproc1(definition
* defp
, int callTconnF
, char *type
,
51 char *prefix
, int iomask
);
52 static void psprocdef(definition
* defp
);
53 static void penumdef(definition
* def
);
54 static void ptypedef(definition
* def
);
55 static void pdeclaration(char *name
, declaration
* dec
, int tab
);
56 static int undefined2(char *type
, char *stop
);
59 * Print the C-version of an xdr definition
62 print_datadef(definition
* def
)
66 if ((def
->def_kind
!= DEF_CONST
) && (!IsRxgenDefinition(def
))) {
69 switch (def
->def_kind
) {
92 if (def
->def_kind
!= DEF_CONST
&& (!IsRxgenDefinition(def
))) {
93 f_print(fout
, "bool_t xdr_%s(XDR *xdrs, %s *objp);\n", def
->def_name
,
96 if (def
->def_kind
!= DEF_CONST
&& (!IsRxgenDefinition(def
))) {
104 pconstdef(definition
* def
)
106 pdefine(def
->def_name
, def
->def
.co
);
110 pstructdef(definition
* def
)
113 char *name
= def
->def_name
;
115 f_print(fout
, "struct %s {\n", name
);
116 for (l
= def
->def
.st
.decls
; l
!= NULL
; l
= l
->next
) {
117 pdeclaration(name
, &l
->decl
, 1);
119 f_print(fout
, "};\n");
120 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
124 puniondef(definition
* def
)
127 char *name
= def
->def_name
;
130 f_print(fout
, "struct %s {\n", name
);
131 decl
= &def
->def
.un
.enum_decl
;
132 if (streq(decl
->type
, "bool")) {
133 f_print(fout
, "\tbool_t %s;\n", decl
->name
);
135 f_print(fout
, "\t%s %s;\n", decl
->type
, decl
->name
);
137 f_print(fout
, "\tunion {\n");
138 for (l
= def
->def
.un
.cases
; l
!= NULL
; l
= l
->next
) {
139 pdeclaration(name
, &l
->case_decl
, 2);
141 decl
= def
->def
.un
.default_decl
;
142 if (decl
&& !streq(decl
->type
, "void")) {
143 pdeclaration(name
, decl
, 2);
146 f_print(fout
, "\t} u;\n");
148 f_print(fout
, "\t} %s_u;\n", name
);
150 f_print(fout
, "};\n");
151 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
152 STOREVAL(&uniondef_defined
, def
);
157 pdefine(char *name
, char *num
)
159 f_print(fout
, "#define %s %s\n", name
, num
);
163 psproc1(definition
* defp
, int callTconnF
, char *type
, char *prefix
,
168 f_print(fout
, "\nextern %s %s%s%s(\n", type
, prefix
, defp
->pc
.proc_prefix
,
171 if (callTconnF
== 1 || callTconnF
== 3) {
172 f_print(fout
, "\t/*IN */ struct rx_call *z_call");
173 } else if (callTconnF
== 2) {
174 f_print(fout
, "\tstruct ubik_client *aclient, afs_int32 aflags");
176 f_print(fout
, "\t/*IN */ struct rx_connection *z_conn");
179 for (plist
= defp
->pc
.plists
; plist
; plist
= plist
->next
) {
180 if (plist
->component_kind
== DEF_PARAM
181 && (iomask
& (1 << plist
->pl
.param_kind
))) {
182 switch (plist
->pl
.param_kind
) {
184 f_print(fout
, ",\n\t/*IN %d*/ ",callTconnF
);
185 if ((callTconnF
!= 3)
186 && strcmp(plist
->pl
.param_type
, "char *")== 0)
187 f_print(fout
, "const ");
190 f_print(fout
, ",\n\t/*OUT*/ ");
193 f_print(fout
, ",\n\t/*I/O*/ ");
198 if (plist
->pl
.param_flag
& OUT_STRING
) {
199 f_print(fout
, "%s *%s", plist
->pl
.param_type
,
200 plist
->pl
.param_name
);
202 f_print(fout
, "%s %s", plist
->pl
.param_type
,
203 plist
->pl
.param_name
);
207 f_print(fout
, ");\n");
211 psprocdef(definition
* defp
)
213 int split_flag
= defp
->pc
.split_flag
;
214 int multi_flag
= defp
->pc
.multi_flag
;
216 if (split_flag
|| multi_flag
) {
217 psproc1(defp
, 1, "int", "Start",
218 (1 << DEF_INPARAM
) | (1 << DEF_INOUTPARAM
));
219 psproc1(defp
, 1, "int", "End",
220 (1 << DEF_OUTPARAM
) | (1 << DEF_INOUTPARAM
));
222 if (!(!multi_flag
&& split_flag
))
223 psproc1(defp
, 0, "int", "", 0xFFFFFFFF);
225 if (uflag
&& !kflag
) {
226 f_print(fout
, "\n#ifndef KERNEL");
227 psproc1(defp
, 2, "int", "ubik_", 0xFFFFFFFF);
228 f_print(fout
, "#endif /* KERNEL */\n");
232 psproc1(defp
, 3, "afs_int32", ServerPrefix
, 0xFFFFFFFF);
236 penumdef(definition
* def
)
238 char *name
= def
->def_name
;
243 f_print(fout
, "enum %s {\n", name
);
244 for (l
= def
->def
.en
.vals
; l
!= NULL
; l
= l
->next
) {
245 f_print(fout
, "\t%s", l
->name
);
247 f_print(fout
, " = %s", l
->assignment
);
248 last
= l
->assignment
;
252 f_print(fout
, " = %d", count
++);
254 f_print(fout
, " = %s + %d", last
, count
++);
257 f_print(fout
, ",\n");
259 f_print(fout
, "};\n");
260 f_print(fout
, "typedef enum %s %s;\n", name
, name
);
264 ptypedef(definition
* def
)
266 char *name
= def
->def_name
;
267 char *old
= def
->def
.ty
.old_type
;
268 char prefix
[8]; /* enough to contain "struct ", including NUL */
269 relation rel
= def
->def
.ty
.rel
;
272 if (!streq(name
, old
)) {
273 if (streq(old
, "string")) {
276 } else if (!brief_flag
&& streq(old
, "opaque")) {
278 } else if (streq(old
, "bool")) {
281 if (undefined2(old
, name
) && def
->def
.ty
.old_prefix
) {
282 s_print(prefix
, "%s ", def
->def
.ty
.old_prefix
);
286 f_print(fout
, "typedef ");
290 if (streq(old
, "opaque")) {
291 f_print(fout
, "struct rx_opaque %s", name
);
293 f_print(fout
, "struct {\n");
294 f_print(fout
, "\tu_int len;\n");
295 f_print(fout
, "\t%s%s *val;\n", prefix
, old
);
296 f_print(fout
, "} %s", name
);
299 f_print(fout
, "struct %s {\n", name
);
300 f_print(fout
, "\tu_int %s_len;\n", name
);
301 f_print(fout
, "\t%s%s *%s_val;\n", prefix
, old
, name
);
302 f_print(fout
, "} %s", name
);
306 f_print(fout
, "%s%s *%s", prefix
, old
, name
);
309 f_print(fout
, "%s%s %s[%s]", prefix
, old
, name
,
310 def
->def
.ty
.array_max
);
313 f_print(fout
, "%s%s %s", prefix
, old
, name
);
317 STOREVAL(&typedef_defined
, def
);
318 f_print(fout
, ";\n");
324 pdeclaration(char *name
, declaration
* dec
, int tab
)
326 char buf
[8]; /* enough to hold "struct ", include NUL */
330 if (streq(dec
->type
, "void")) {
334 if (streq(dec
->type
, name
) && !dec
->prefix
) {
335 f_print(fout
, "struct ");
337 if (streq(dec
->type
, "string")) {
338 f_print(fout
, "char *%s", dec
->name
);
341 if (streq(dec
->type
, "bool")) {
343 } else if (streq(dec
->type
, "opaque")) {
347 s_print(buf
, "%s ", dec
->prefix
);
354 f_print(fout
, "%s%s %s", prefix
, type
, dec
->name
);
357 f_print(fout
, "%s%s %s[%s]", prefix
, type
, dec
->name
,
361 f_print(fout
, "%s%s *%s", prefix
, type
, dec
->name
);
365 if (streq(dec
->type
, "opaque")) {
366 f_print(fout
, "struct rx_opaque %s",dec
->name
);
368 f_print(fout
, "struct {\n");
370 f_print(fout
, "\tu_int len;\n");
372 f_print(fout
, "\t%s%s *val;\n", prefix
, type
);
374 f_print(fout
, "} %s", dec
->name
);
377 f_print(fout
, "struct %s {\n", dec
->name
);
379 f_print(fout
, "\tu_int %s_len;\n", dec
->name
);
381 f_print(fout
, "\t%s%s *%s_val;\n", prefix
, type
, dec
->name
);
383 f_print(fout
, "} %s", dec
->name
);
388 f_print(fout
, ";\n");
394 undefined2(char *type
, char *stop
)
399 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
400 def
= (definition
*) l
->val
;
401 if (streq(def
->def_name
, stop
)) {
403 } else if (streq(def
->def_name
, type
)) {