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 or with the express written consent of
8 * Sun Microsystems, Inc.
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 * From: @(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI
36 * rpc_hout.c, Header file outputter for the RPC protocol compiler
40 #include "rpc_parse.h"
44 static void pconstdef (definition
* def
);
45 static void pargdef (definition
* def
);
46 static void pstructdef (definition
* def
);
47 static void puniondef (definition
* def
);
48 static void pdefine (const char *name
, const char *num
);
49 static int define_printed (proc_list
* stop
, version_list
* start
);
50 static void pprogramdef (definition
* def
);
51 static void parglist (proc_list
* proc
, const char *addargtype
);
52 static void penumdef (definition
* def
);
53 static void ptypedef (definition
* def
);
54 static int undefined2 (const char *type
, const char *stop
);
56 /* store away enough information to allow the XDR functions to be spat
57 out at the end of the file */
60 storexdrfuncdecl (const char *name
, int pointerp
)
64 xdrptr
= (xdrfunc
*) malloc(sizeof (struct xdrfunc
));
66 xdrptr
->name
= (char *)name
;
67 xdrptr
->pointerp
= pointerp
;
70 if (xdrfunc_tail
== NULL
)
72 xdrfunc_head
= xdrptr
;
73 xdrfunc_tail
= xdrptr
;
77 xdrfunc_tail
->next
= xdrptr
;
78 xdrfunc_tail
= xdrptr
;
83 * Print the C-version of an xdr definition
86 print_datadef (definition
*def
)
89 if (def
->def_kind
== DEF_PROGRAM
) /* handle data only */
92 if (def
->def_kind
!= DEF_CONST
)
96 switch (def
->def_kind
)
117 if (def
->def_kind
!= DEF_PROGRAM
&& def
->def_kind
!= DEF_CONST
)
119 storexdrfuncdecl(def
->def_name
,
120 def
->def_kind
!= DEF_TYPEDEF
||
121 !isvectordef(def
->def
.ty
.old_type
,
128 print_funcdef (definition
*def
)
130 switch (def
->def_kind
)
133 f_print (fout
, "\n");
138 /* ?... shouldn't happen I guess */
143 print_xdr_func_def (char *name
, int pointerp
, int i
)
147 f_print (fout
, "extern bool_t xdr_%s ();\n", name
);
151 f_print(fout
, "extern bool_t xdr_%s (XDR *, %s%s);\n", name
,
152 name
, pointerp
? "*" : "");
156 pconstdef (definition
*def
)
158 pdefine (def
->def_name
, def
->def
.co
);
161 /* print out the definitions for the arguments of functions in the
165 pargdef (definition
* def
)
172 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
)
174 for (plist
= vers
->procs
; plist
!= NULL
;
178 if (!newstyle
|| plist
->arg_num
< 2)
180 continue; /* old style or single args */
182 name
= plist
->args
.argname
;
183 f_print (fout
, "struct %s {\n", name
);
184 for (l
= plist
->args
.decls
;
185 l
!= NULL
; l
= l
->next
)
187 pdeclaration (name
, &l
->decl
, 1, ";\n");
189 f_print (fout
, "};\n");
190 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
191 storexdrfuncdecl (name
, 1);
192 f_print (fout
, "\n");
199 pstructdef (definition
*def
)
202 const char *name
= def
->def_name
;
204 f_print (fout
, "struct %s {\n", name
);
205 for (l
= def
->def
.st
.decls
; l
!= NULL
; l
= l
->next
)
207 pdeclaration (name
, &l
->decl
, 1, ";\n");
209 f_print (fout
, "};\n");
210 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
214 puniondef (definition
*def
)
217 const char *name
= def
->def_name
;
220 f_print (fout
, "struct %s {\n", name
);
221 decl
= &def
->def
.un
.enum_decl
;
222 if (streq (decl
->type
, "bool"))
224 f_print (fout
, "\tbool_t %s;\n", decl
->name
);
228 f_print (fout
, "\t%s %s;\n", decl
->type
, decl
->name
);
230 f_print (fout
, "\tunion {\n");
231 for (l
= def
->def
.un
.cases
; l
!= NULL
; l
= l
->next
)
233 if (l
->contflag
== 0)
234 pdeclaration (name
, &l
->case_decl
, 2, ";\n");
236 decl
= def
->def
.un
.default_decl
;
237 if (decl
&& !streq (decl
->type
, "void"))
239 pdeclaration (name
, decl
, 2, ";\n");
241 f_print (fout
, "\t} %s_u;\n", name
);
242 f_print (fout
, "};\n");
243 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
247 pdefine (const char *name
, const char *num
)
249 f_print (fout
, "#define %s %s\n", name
, num
);
253 define_printed (proc_list
*stop
, version_list
*start
)
258 for (vers
= start
; vers
!= NULL
; vers
= vers
->next
)
260 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
)
266 else if (streq (proc
->proc_name
, stop
->proc_name
))
277 pfreeprocdef (const char *name
, const char *vers
, int mode
)
279 f_print (fout
, "extern int ");
282 f_print (fout
,"_freeresult (SVCXPRT *, xdrproc_t, caddr_t);\n");
284 f_print (fout
,"_freeresult ();\n");
288 pprogramdef (definition
*def
)
297 pdefine (def
->def_name
, def
->def
.pr
.prog_num
);
298 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
)
302 f_print (fout
, "extern struct rpcgen_table %s_%s_table[];\n",
303 locase (def
->def_name
), vers
->vers_num
);
304 f_print (fout
, "extern %s_%s_nproc;\n",
305 locase (def
->def_name
), vers
->vers_num
);
307 pdefine (vers
->vers_name
, vers
->vers_num
);
310 * Print out 2 definitions, one for ANSI-C, another for
317 for (proc
= vers
->procs
; proc
!= NULL
;
320 if (!define_printed(proc
, def
->def
.pr
.versions
))
322 pdefine (proc
->proc_name
, proc
->proc_num
);
324 f_print (fout
, "%s", ext
);
325 pprocdef (proc
, vers
, NULL
, 0, 2);
329 f_print(fout
, "%s", ext
);
330 pprocdef (proc
, vers
, NULL
, 1, 2);
333 pfreeprocdef (def
->def_name
, vers
->vers_num
, 2);
337 for (i
= 1; i
< 3; i
++)
341 f_print (fout
, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
346 f_print (fout
, "\n#else /* K&R C */\n");
350 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
)
352 if (!define_printed(proc
, def
->def
.pr
.versions
))
354 pdefine(proc
->proc_name
, proc
->proc_num
);
356 f_print (fout
, "%s", ext
);
357 pprocdef (proc
, vers
, "CLIENT *", 0, i
);
358 f_print (fout
, "%s", ext
);
359 pprocdef (proc
, vers
, "struct svc_req *", 1, i
);
361 pfreeprocdef (def
->def_name
, vers
->vers_num
, i
);
363 f_print (fout
, "#endif /* K&R C */\n");
369 pprocdef (proc_list
* proc
, version_list
* vp
,
370 const char *addargtype
, int server_p
, int mode
)
373 {/* Print MT style stubs */
375 f_print (fout
, "bool_t ");
377 f_print (fout
, "enum clnt_stat ");
381 ptype (proc
->res_prefix
, proc
->res_type
, 1);
382 f_print (fout
, "* ");
385 pvname_svc (proc
->proc_name
, vp
->vers_num
);
387 pvname (proc
->proc_name
, vp
->vers_num
);
390 * mode 1 = ANSI-C, mode 2 = K&R C
393 parglist (proc
, addargtype
);
395 f_print (fout
, "();\n");
398 /* print out argument list of procedure */
400 parglist (proc_list
*proc
, const char *addargtype
)
405 if (proc
->arg_num
< 2 && newstyle
&&
406 streq (proc
->args
.decls
->decl
.type
, "void"))
408 /* 0 argument in new style: do nothing */
412 for (dl
= proc
->args
.decls
; dl
!= NULL
; dl
= dl
->next
)
414 ptype (dl
->decl
.prefix
, dl
->decl
.type
, 1);
416 f_print (fout
, "*"); /* old style passes by reference */
418 f_print (fout
, ", ");
423 ptype(proc
->res_prefix
, proc
->res_type
, 1);
424 f_print(fout
, "*, ");
427 f_print (fout
, "%s);\n", addargtype
);
431 penumdef (definition
*def
)
433 const char *name
= def
->def_name
;
435 const char *last
= NULL
;
438 f_print (fout
, "enum %s {\n", name
);
439 for (l
= def
->def
.en
.vals
; l
!= NULL
; l
= l
->next
)
441 f_print (fout
, "\t%s", l
->name
);
444 f_print (fout
, " = %s", l
->assignment
);
445 last
= l
->assignment
;
452 f_print (fout
, " = %d", count
++);
456 f_print (fout
, " = %s + %d", last
, count
++);
459 f_print (fout
, ",\n");
461 f_print (fout
, "};\n");
462 f_print (fout
, "typedef enum %s %s;\n", name
, name
);
466 ptypedef (definition
*def
)
468 const char *name
= def
->def_name
;
469 const char *old
= def
->def
.ty
.old_type
;
470 char prefix
[8]; /* enough to contain "struct ", including NUL */
471 relation rel
= def
->def
.ty
.rel
;
473 if (!streq (name
, old
))
475 if (streq (old
, "string"))
480 else if (streq (old
, "opaque"))
484 else if (streq (old
, "bool"))
488 if (undefined2 (old
, name
) && def
->def
.ty
.old_prefix
)
490 s_print (prefix
, "%s ", def
->def
.ty
.old_prefix
);
496 f_print (fout
, "typedef ");
500 f_print (fout
, "struct {\n");
501 f_print (fout
, "\tu_int %s_len;\n", name
);
502 f_print (fout
, "\t%s%s *%s_val;\n", prefix
, old
, name
);
503 f_print (fout
, "} %s", name
);
506 f_print (fout
, "%s%s *%s", prefix
, old
, name
);
509 f_print (fout
, "%s%s %s[%s]", prefix
, old
, name
,
510 def
->def
.ty
.array_max
);
513 f_print (fout
, "%s%s %s", prefix
, old
, name
);
516 f_print (fout
, ";\n");
521 pdeclaration (const char *name
, declaration
* dec
, int tab
,
522 const char *separator
)
524 char buf
[8]; /* enough to hold "struct ", include NUL */
528 if (streq (dec
->type
, "void"))
533 if (streq (dec
->type
, name
) && !dec
->prefix
)
535 f_print (fout
, "struct ");
537 if (streq (dec
->type
, "string"))
539 f_print (fout
, "char *%s", dec
->name
);
544 if (streq (dec
->type
, "bool"))
548 else if (streq (dec
->type
, "opaque"))
556 s_print (buf
, "%s ", dec
->prefix
);
564 f_print (fout
, "%s%s %s", prefix
, type
, dec
->name
);
567 f_print (fout
, "%s%s %s[%s]", prefix
, type
, dec
->name
,
571 f_print (fout
, "%s%s *%s", prefix
, type
, dec
->name
);
574 f_print (fout
, "struct {\n");
576 f_print (fout
, "\tu_int %s_len;\n", dec
->name
);
578 f_print (fout
, "\t%s%s *%s_val;\n", prefix
, type
, dec
->name
);
580 f_print (fout
, "} %s", dec
->name
);
584 f_print (fout
, separator
);
588 undefined2 (const char *type
, const char *stop
)
593 for (l
= defined
; l
!= NULL
; l
= l
->next
)
595 def
= (definition
*) l
->val
;
596 if (def
->def_kind
!= DEF_PROGRAM
)
598 if (streq (def
->def_name
, stop
))
602 else if (streq (def
->def_name
, type
))