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
34 #if defined(LIBC_SCCS) && !defined(lint)
35 static const char hout_rcsid
[] =
40 * rpc_hout.c, Header file outputter for the RPC protocol compiler
44 #include "rpc_parse.h"
48 static void pconstdef (definition
* def
);
49 static void pargdef (definition
* def
);
50 static void pstructdef (definition
* def
);
51 static void puniondef (definition
* def
);
52 static void pdefine (const char *name
, const char *num
);
53 static int define_printed (proc_list
* stop
, version_list
* start
);
54 static void pprogramdef (definition
* def
);
55 static void parglist (proc_list
* proc
, const char *addargtype
);
56 static void penumdef (definition
* def
);
57 static void ptypedef (definition
* def
);
58 static int undefined2 (const char *type
, const char *stop
);
60 /* store away enough information to allow the XDR functions to be spat
61 out at the end of the file */
64 storexdrfuncdecl (const char *name
, int pointerp
)
68 xdrptr
= (xdrfunc
*) malloc(sizeof (struct xdrfunc
));
70 xdrptr
->name
= (char *)name
;
71 xdrptr
->pointerp
= pointerp
;
74 if (xdrfunc_tail
== NULL
)
76 xdrfunc_head
= xdrptr
;
77 xdrfunc_tail
= xdrptr
;
81 xdrfunc_tail
->next
= xdrptr
;
82 xdrfunc_tail
= xdrptr
;
87 * Print the C-version of an xdr definition
90 print_datadef (definition
*def
)
93 if (def
->def_kind
== DEF_PROGRAM
) /* handle data only */
96 if (def
->def_kind
!= DEF_CONST
)
100 switch (def
->def_kind
)
121 if (def
->def_kind
!= DEF_PROGRAM
&& def
->def_kind
!= DEF_CONST
)
123 storexdrfuncdecl(def
->def_name
,
124 def
->def_kind
!= DEF_TYPEDEF
||
125 !isvectordef(def
->def
.ty
.old_type
,
132 print_funcdef (definition
*def
)
134 switch (def
->def_kind
)
137 f_print (fout
, "\n");
142 /* ?... shouldn't happen I guess */
147 print_xdr_func_def (char *name
, int pointerp
, int i
)
151 f_print (fout
, "extern bool_t xdr_%s ();\n", name
);
155 f_print(fout
, "extern bool_t xdr_%s (XDR *, %s%s);\n", name
,
156 name
, pointerp
? "*" : "");
160 pconstdef (definition
*def
)
162 pdefine (def
->def_name
, def
->def
.co
);
165 /* print out the definitions for the arguments of functions in the
169 pargdef (definition
* def
)
176 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
)
178 for (plist
= vers
->procs
; plist
!= NULL
;
182 if (!newstyle
|| plist
->arg_num
< 2)
184 continue; /* old style or single args */
186 name
= plist
->args
.argname
;
187 f_print (fout
, "struct %s {\n", name
);
188 for (l
= plist
->args
.decls
;
189 l
!= NULL
; l
= l
->next
)
191 pdeclaration (name
, &l
->decl
, 1, ";\n");
193 f_print (fout
, "};\n");
194 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
195 storexdrfuncdecl (name
, 1);
196 f_print (fout
, "\n");
203 pstructdef (definition
*def
)
206 const char *name
= def
->def_name
;
208 f_print (fout
, "struct %s {\n", name
);
209 for (l
= def
->def
.st
.decls
; l
!= NULL
; l
= l
->next
)
211 pdeclaration (name
, &l
->decl
, 1, ";\n");
213 f_print (fout
, "};\n");
214 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
218 puniondef (definition
*def
)
221 const char *name
= def
->def_name
;
224 f_print (fout
, "struct %s {\n", name
);
225 decl
= &def
->def
.un
.enum_decl
;
226 if (streq (decl
->type
, "bool"))
228 f_print (fout
, "\tbool_t %s;\n", decl
->name
);
232 f_print (fout
, "\t%s %s;\n", decl
->type
, decl
->name
);
234 f_print (fout
, "\tunion {\n");
235 for (l
= def
->def
.un
.cases
; l
!= NULL
; l
= l
->next
)
237 if (l
->contflag
== 0)
238 pdeclaration (name
, &l
->case_decl
, 2, ";\n");
240 decl
= def
->def
.un
.default_decl
;
241 if (decl
&& !streq (decl
->type
, "void"))
243 pdeclaration (name
, decl
, 2, ";\n");
245 f_print (fout
, "\t} %s_u;\n", name
);
246 f_print (fout
, "};\n");
247 f_print (fout
, "typedef struct %s %s;\n", name
, name
);
251 pdefine (const char *name
, const char *num
)
253 f_print (fout
, "#define %s %s\n", name
, num
);
257 define_printed (proc_list
*stop
, version_list
*start
)
262 for (vers
= start
; vers
!= NULL
; vers
= vers
->next
)
264 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
)
270 else if (streq (proc
->proc_name
, stop
->proc_name
))
281 pfreeprocdef (const char *name
, const char *vers
, int mode
)
283 f_print (fout
, "extern int ");
286 f_print (fout
,"_freeresult (SVCXPRT *, xdrproc_t, caddr_t);\n");
288 f_print (fout
,"_freeresult ();\n");
292 pprogramdef (definition
*def
)
301 pdefine (def
->def_name
, def
->def
.pr
.prog_num
);
302 for (vers
= def
->def
.pr
.versions
; vers
!= NULL
; vers
= vers
->next
)
306 f_print (fout
, "extern struct rpcgen_table %s_%s_table[];\n",
307 locase (def
->def_name
), vers
->vers_num
);
308 f_print (fout
, "extern %s_%s_nproc;\n",
309 locase (def
->def_name
), vers
->vers_num
);
311 pdefine (vers
->vers_name
, vers
->vers_num
);
314 * Print out 2 definitions, one for ANSI-C, another for
321 for (proc
= vers
->procs
; proc
!= NULL
;
324 if (!define_printed(proc
, def
->def
.pr
.versions
))
326 pdefine (proc
->proc_name
, proc
->proc_num
);
328 f_print (fout
, "%s", ext
);
329 pprocdef (proc
, vers
, NULL
, 0, 2);
333 f_print(fout
, "%s", ext
);
334 pprocdef (proc
, vers
, NULL
, 1, 2);
337 pfreeprocdef (def
->def_name
, vers
->vers_num
, 2);
341 for (i
= 1; i
< 3; i
++)
345 f_print (fout
, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
350 f_print (fout
, "\n#else /* K&R C */\n");
354 for (proc
= vers
->procs
; proc
!= NULL
; proc
= proc
->next
)
356 if (!define_printed(proc
, def
->def
.pr
.versions
))
358 pdefine(proc
->proc_name
, proc
->proc_num
);
360 f_print (fout
, "%s", ext
);
361 pprocdef (proc
, vers
, "CLIENT *", 0, i
);
362 f_print (fout
, "%s", ext
);
363 pprocdef (proc
, vers
, "struct svc_req *", 1, i
);
365 pfreeprocdef (def
->def_name
, vers
->vers_num
, i
);
367 f_print (fout
, "#endif /* K&R C */\n");
373 pprocdef (proc_list
* proc
, version_list
* vp
,
374 const char *addargtype
, int server_p
, int mode
)
377 {/* Print MT style stubs */
379 f_print (fout
, "bool_t ");
381 f_print (fout
, "enum clnt_stat ");
385 ptype (proc
->res_prefix
, proc
->res_type
, 1);
386 f_print (fout
, "* ");
389 pvname_svc (proc
->proc_name
, vp
->vers_num
);
391 pvname (proc
->proc_name
, vp
->vers_num
);
394 * mode 1 = ANSI-C, mode 2 = K&R C
397 parglist (proc
, addargtype
);
399 f_print (fout
, "();\n");
402 /* print out argument list of procedure */
404 parglist (proc_list
*proc
, const char *addargtype
)
409 if (proc
->arg_num
< 2 && newstyle
&&
410 streq (proc
->args
.decls
->decl
.type
, "void"))
412 /* 0 argument in new style: do nothing */
416 for (dl
= proc
->args
.decls
; dl
!= NULL
; dl
= dl
->next
)
418 ptype (dl
->decl
.prefix
, dl
->decl
.type
, 1);
420 f_print (fout
, "*"); /* old style passes by reference */
422 f_print (fout
, ", ");
427 ptype(proc
->res_prefix
, proc
->res_type
, 1);
428 f_print(fout
, "*, ");
431 f_print (fout
, "%s);\n", addargtype
);
435 penumdef (definition
*def
)
437 const char *name
= def
->def_name
;
439 const char *last
= NULL
;
442 f_print (fout
, "enum %s {\n", name
);
443 for (l
= def
->def
.en
.vals
; l
!= NULL
; l
= l
->next
)
445 f_print (fout
, "\t%s", l
->name
);
448 f_print (fout
, " = %s", l
->assignment
);
449 last
= l
->assignment
;
456 f_print (fout
, " = %d", count
++);
460 f_print (fout
, " = %s + %d", last
, count
++);
463 f_print (fout
, ",\n");
465 f_print (fout
, "};\n");
466 f_print (fout
, "typedef enum %s %s;\n", name
, name
);
470 ptypedef (definition
*def
)
472 const char *name
= def
->def_name
;
473 const char *old
= def
->def
.ty
.old_type
;
474 char prefix
[8]; /* enough to contain "struct ", including NUL */
475 relation rel
= def
->def
.ty
.rel
;
477 if (!streq (name
, old
))
479 if (streq (old
, "string"))
484 else if (streq (old
, "opaque"))
488 else if (streq (old
, "bool"))
492 if (undefined2 (old
, name
) && def
->def
.ty
.old_prefix
)
494 s_print (prefix
, "%s ", def
->def
.ty
.old_prefix
);
500 f_print (fout
, "typedef ");
504 f_print (fout
, "struct {\n");
505 f_print (fout
, "\tu_int %s_len;\n", name
);
506 f_print (fout
, "\t%s%s *%s_val;\n", prefix
, old
, name
);
507 f_print (fout
, "} %s", name
);
510 f_print (fout
, "%s%s *%s", prefix
, old
, name
);
513 f_print (fout
, "%s%s %s[%s]", prefix
, old
, name
,
514 def
->def
.ty
.array_max
);
517 f_print (fout
, "%s%s %s", prefix
, old
, name
);
520 f_print (fout
, ";\n");
525 pdeclaration (const char *name
, declaration
* dec
, int tab
,
526 const char *separator
)
528 char buf
[8]; /* enough to hold "struct ", include NUL */
532 if (streq (dec
->type
, "void"))
537 if (streq (dec
->type
, name
) && !dec
->prefix
)
539 f_print (fout
, "struct ");
541 if (streq (dec
->type
, "string"))
543 f_print (fout
, "char *%s", dec
->name
);
548 if (streq (dec
->type
, "bool"))
552 else if (streq (dec
->type
, "opaque"))
560 s_print (buf
, "%s ", dec
->prefix
);
568 f_print (fout
, "%s%s %s", prefix
, type
, dec
->name
);
571 f_print (fout
, "%s%s %s[%s]", prefix
, type
, dec
->name
,
575 f_print (fout
, "%s%s *%s", prefix
, type
, dec
->name
);
578 f_print (fout
, "struct {\n");
580 f_print (fout
, "\tu_int %s_len;\n", dec
->name
);
582 f_print (fout
, "\t%s%s *%s_val;\n", prefix
, type
, dec
->name
);
584 f_print (fout
, "} %s", dec
->name
);
588 f_print (fout
, separator
);
592 undefined2 (const char *type
, const char *stop
)
597 for (l
= defined
; l
!= NULL
; l
= l
->next
)
599 def
= (definition
*) l
->val
;
600 if (def
->def_kind
!= DEF_PROGRAM
)
602 if (streq (def
->def_name
, stop
))
606 else if (streq (def
->def_name
, type
))