2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
32 #ident "@(#)rpc_hout.c 1.16 94/04/25 SMI"
33 static char sccsid
[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
41 * rpc_hout.c, Header file outputter for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
46 #include "rpc_parse.h"
50 void storexdrfuncdecl(const char *, int );
51 static void pconstdef( definition
* );
52 static void pstructdef( definition
* );
53 static void puniondef( definition
* );
54 static void pprogramdef( definition
*, int );
55 static void penumdef( definition
* );
56 static void ptypedef( definition
* );
57 static void pdefine(const char *, const char *);
58 static int undefined2(const char *, const char *);
59 static void parglist(proc_list
*, const char *);
60 static void pprocdef(proc_list
*, version_list
*, const char *, int);
63 * Print the C-version of an xdr definition
66 print_datadef(definition
*def
, int headeronly
)
69 if (def
->def_kind
== DEF_PROGRAM
) /* handle data only */
72 if (def
->def_kind
!= DEF_CONST
) {
75 switch (def
->def_kind
) {
89 pprogramdef(def
, headeronly
);
95 if (def
->def_kind
!= DEF_PROGRAM
&& def
->def_kind
!= DEF_CONST
) {
96 storexdrfuncdecl(def
->def_name
,
97 def
->def_kind
!= DEF_TYPEDEF
||
98 !isvectordef(def
->def
.ty
.old_type
,
105 print_funcdef(definition
*def
, int headeronly
)
107 switch (def
->def_kind
) {
110 pprogramdef(def
, headeronly
);
117 /* store away enough information to allow the XDR functions to be spat
118 out at the end of the file */
121 storexdrfuncdecl(const char *name
, int pointerp
)
125 xdrptr
= XALLOC(struct xdrfunc
);
128 xdrptr
->pointerp
= pointerp
;
131 if (xdrfunc_tail
== NULL
){
132 xdrfunc_head
= xdrptr
;
133 xdrfunc_tail
= xdrptr
;
135 xdrfunc_tail
->next
= xdrptr
;
136 xdrfunc_tail
= xdrptr
;
143 print_xdr_func_def(const char *name
, int pointerp
)
145 f_print(fout
, "extern bool_t xdr_%s(XDR *, %s%s);\n", name
,
146 name
, pointerp
? "*" : "");
154 pdefine(def
->def_name
, def
->def
.co
);
157 /* print out the definitions for the arguments of functions in the
161 pargdef(definition
*def
)
169 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
) {
170 for (plist
= vers
->procs
; plist
!= NULL
;
171 plist
= plist
->next
) {
173 if (!newstyle
|| plist
->arg_num
< 2) {
174 continue; /* old style or single args */
176 name
= plist
->args
.argname
;
177 f_print(fout
, "struct %s {\n", name
);
178 for (l
= plist
->args
.decls
;
179 l
!= NULL
; l
= l
->next
) {
180 pdeclaration(name
, &l
->decl
, 1,
183 f_print(fout
, "};\n");
184 f_print(fout
, "typedef struct %s %s;\n",
186 storexdrfuncdecl(name
, 1);
194 pstructdef(definition
*def
)
197 const char *name
= def
->def_name
;
199 f_print(fout
, "struct %s {\n", name
);
200 for (l
= def
->def
.st
.decls
; l
!= NULL
; l
= l
->next
) {
201 pdeclaration(name
, &l
->decl
, 1, ";\n");
203 f_print(fout
, "};\n");
204 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
212 const char *name
= def
->def_name
;
215 f_print(fout
, "struct %s {\n", name
);
216 decl
= &def
->def
.un
.enum_decl
;
217 if (streq(decl
->type
, "bool")) {
218 f_print(fout
, "\tbool_t %s;\n", decl
->name
);
220 f_print(fout
, "\t%s %s;\n", decl
->type
, decl
->name
);
222 f_print(fout
, "\tunion {\n");
223 for (l
= def
->def
.un
.cases
; l
!= NULL
; l
= l
->next
) {
224 if (l
->contflag
== 0)
225 pdeclaration(name
, &l
->case_decl
, 2, ";\n");
227 decl
= def
->def
.un
.default_decl
;
228 if (decl
&& !streq(decl
->type
, "void")) {
229 pdeclaration(name
, decl
, 2, ";\n");
231 f_print(fout
, "\t} %s_u;\n", name
);
232 f_print(fout
, "};\n");
233 f_print(fout
, "typedef struct %s %s;\n", name
, name
);
237 pdefine(const char *name
, const char *num
)
239 f_print(fout
, "#define\t%s %s\n", name
, num
);
243 puldefine(const char *name
, const char *num
)
245 f_print(fout
, "#define\t%s ((unsigned long)(%s))\n", name
, num
);
249 define_printed(proc_list
*stop
, version_list
*start
)
254 for (vers
= start
; vers
!= NULL
; vers
= vers
->next
) {
255 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
) {
258 } else if (streq(proc
->proc_name
, stop
->proc_name
)) {
268 pfreeprocdef(const char * name
, const char *vers
)
270 f_print(fout
, "extern int ");
272 f_print(fout
, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
276 pdispatch(const char * name
, const char *vers
)
279 f_print(fout
, "void ");
281 f_print(fout
, "(struct svc_req *rqstp, SVCXPRT *transp);\n");
285 pprogramdef(definition
*def
, int headeronly
)
293 puldefine(def
->def_name
, def
->def
.pr
.prog_num
);
294 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
) {
297 "extern struct rpcgen_table %s_%s_table[];\n",
298 locase(def
->def_name
), vers
->vers_num
);
300 "extern %s_%s_nproc;\n",
301 locase(def
->def_name
), vers
->vers_num
);
303 puldefine(vers
->vers_name
, vers
->vers_num
);
308 f_print(fout
, "%s", ext
);
309 pdispatch(def
->def_name
, vers
->vers_num
);
311 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
) {
312 if (!define_printed(proc
, def
->def
.pr
.versions
)) {
313 puldefine(proc
->proc_name
, proc
->proc_num
);
315 f_print(fout
, "%s", ext
);
316 pprocdef(proc
, vers
, "CLIENT *", 0);
317 f_print(fout
, "%s", ext
);
318 pprocdef(proc
, vers
, "struct svc_req *", 1);
320 pfreeprocdef(def
->def_name
, vers
->vers_num
);
325 pprocdef(proc_list
*proc
, version_list
*vp
, const char *addargtype
, int server_p
)
327 if (mtflag
) {/* Print MT style stubs */
329 f_print(fout
, "bool_t ");
331 f_print(fout
, "enum clnt_stat ");
333 ptype(proc
->res_prefix
, proc
->res_type
, 1);
337 pvname_svc(proc
->proc_name
, vp
->vers_num
);
339 pvname(proc
->proc_name
, vp
->vers_num
);
341 parglist(proc
, addargtype
);
346 /* print out argument list of procedure */
348 parglist(proc_list
*proc
, const char *addargtype
)
353 if (proc
->arg_num
< 2 && newstyle
&&
354 streq(proc
->args
.decls
->decl
.type
, "void")) {
355 /* 0 argument in new style: do nothing*/
358 for (dl
= proc
->args
.decls
; dl
!= NULL
; dl
= dl
->next
) {
359 ptype(dl
->decl
.prefix
, dl
->decl
.type
, 1);
362 /* old style passes by reference */
368 ptype(proc
->res_prefix
, proc
->res_type
, 1);
369 f_print(fout
, "*, ");
372 f_print(fout
, "%s);\n", addargtype
);
380 const char *name
= def
->def_name
;
382 const char *last
= NULL
;
385 f_print(fout
, "enum %s {\n", name
);
386 for (l
= def
->def
.en
.vals
; l
!= NULL
; l
= l
->next
) {
387 f_print(fout
, "\t%s", l
->name
);
389 f_print(fout
, " = %s", l
->assignment
);
390 last
= l
->assignment
;
394 f_print(fout
, " = %d", count
++);
396 f_print(fout
, " = %s + %d", last
, count
++);
400 f_print(fout
, ",\n");
404 f_print(fout
, "};\n");
405 f_print(fout
, "typedef enum %s %s;\n", name
, name
);
412 const char *name
= def
->def_name
;
413 const char *old
= def
->def
.ty
.old_type
;
414 char prefix
[8]; /* enough to contain "struct ", including NUL */
415 relation rel
= def
->def
.ty
.rel
;
418 if (!streq(name
, old
)) {
419 if (streq(old
, "string")) {
422 } else if (streq(old
, "opaque")) {
424 } else if (streq(old
, "bool")) {
427 if (undefined2(old
, name
) && def
->def
.ty
.old_prefix
) {
428 s_print(prefix
, "%s ", def
->def
.ty
.old_prefix
);
432 f_print(fout
, "typedef ");
435 f_print(fout
, "struct {\n");
436 f_print(fout
, "\tu_int %s_len;\n", name
);
437 f_print(fout
, "\t%s%s *%s_val;\n", prefix
, old
, name
);
438 f_print(fout
, "} %s", name
);
441 f_print(fout
, "%s%s *%s", prefix
, old
, name
);
444 f_print(fout
, "%s%s %s[%s]", prefix
, old
, name
,
445 def
->def
.ty
.array_max
);
448 f_print(fout
, "%s%s %s", prefix
, old
, name
);
451 f_print(fout
, ";\n");
456 pdeclaration(const char *name
, declaration
*dec
, int tab
, const char *separator
)
458 char buf
[8]; /* enough to hold "struct ", include NUL */
462 if (streq(dec
->type
, "void")) {
466 if (streq(dec
->type
, name
) && !dec
->prefix
) {
467 f_print(fout
, "struct ");
469 if (streq(dec
->type
, "string")) {
470 f_print(fout
, "char *%s", dec
->name
);
473 if (streq(dec
->type
, "bool")) {
475 } else if (streq(dec
->type
, "opaque")) {
479 s_print(buf
, "%s ", dec
->prefix
);
486 f_print(fout
, "%s%s %s", prefix
, type
, dec
->name
);
489 f_print(fout
, "%s%s %s[%s]", prefix
, type
, dec
->name
,
493 f_print(fout
, "%s%s *%s", prefix
, type
, dec
->name
);
496 f_print(fout
, "struct {\n");
498 f_print(fout
, "\tu_int %s_len;\n", dec
->name
);
501 "\t%s%s *%s_val;\n", prefix
, type
, dec
->name
);
503 f_print(fout
, "} %s", dec
->name
);
507 f_print(fout
, separator
);
511 undefined2(const char *type
, const char *stop
)
516 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
517 def
= (definition
*) l
->val
;
518 if (def
->def_kind
!= DEF_PROGRAM
) {
519 if (streq(def
->def_name
, stop
)) {
521 } else if (streq(def
->def_name
, type
)) {