1 /* $NetBSD: rpc_tblout.c,v 1.10 2002/02/05 22:41:47 christos Exp $ */
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 or with the express written consent of
9 * Sun Microsystems, Inc.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
36 #include <sys/cdefs.h>
37 #if defined(__RCSID) && !defined(lint)
39 static char sccsid
[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
41 __RCSID("$NetBSD: rpc_tblout.c,v 1.10 2002/02/05 22:41:47 christos Exp $");
46 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
52 #include "rpc_parse.h"
57 #define TABSTOP (TABSIZE*TABCOUNT)
59 static char tabstr
[TABCOUNT
+ 1] = "\t\t\t\t\t";
61 static const char tbl_hdr
[] = "struct rpcgen_table %s_table[] = {\n";
62 static const char tbl_end
[] = "};\n";
64 static const char null_entry
[] = "\t(char *(*)())0,\n\
65 \t(xdrproc_t)xdr_void,\t\t0,\n\
66 \t(xdrproc_t)xdr_void,\t\t0,\n";
68 static const char tbl_nproc
[] =
69 "u_int %s_nproc =\n\t(u_int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n";
71 static void write_table
__P((definition
*));
72 static void printit
__P((char *, char *));
81 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
82 def
= (definition
*) l
->val
;
83 if (def
->def_kind
== DEF_PROGRAM
) {
100 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
102 s_print(progvers
, "%s_%s",
103 locase(def
->def_name
), vp
->vers_num
);
104 /* print the table header */
105 f_print(fout
, tbl_hdr
, progvers
);
107 if (nullproc(vp
->procs
)) {
111 f_print(fout
, null_entry
);
113 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
116 current
= atoi(proc
->proc_num
);
117 if (current
!= expected
++) {
119 "/*\n * WARNING: table out of order\n */\n\n");
122 "WARNING %s table is out of order\n",
127 expected
= current
+ 1;
129 f_print(fout
, "\t(char *(*)())RPCGEN_ACTION(");
131 /* routine to invoke */
133 pvname_svc(proc
->proc_name
, vp
->vers_num
);
136 f_print(fout
, "_"); /* calls internal func */
137 pvname(proc
->proc_name
, vp
->vers_num
);
139 f_print(fout
, "),\n");
142 if (proc
->arg_num
> 1)
143 printit((char *) NULL
, proc
->args
.argname
);
145 /* do we have to do something special for
147 printit(proc
->args
.decls
->decl
.prefix
,
148 proc
->args
.decls
->decl
.type
);
150 printit(proc
->res_prefix
, proc
->res_type
);
153 /* print the table trailer */
154 f_print(fout
, tbl_end
);
155 f_print(fout
, tbl_nproc
, progvers
, progvers
, progvers
);
160 printit(prefix
, type
)
168 len
= fprintf(fout
, "\txdr_%s,", stringfix(type
));
169 /* account for leading tab expansion */
171 /* round up to tabs required */
172 tabs
= (TABSTOP
- len
+ TABSIZE
- 1) / TABSIZE
;
173 f_print(fout
, "%s", &tabstr
[TABCOUNT
- tabs
]);
175 if (streq(type
, "void")) {
178 f_print(fout
, "(u_int)sizeof(");
179 /* XXX: should "follow" be 1 ??? */
180 ptype(prefix
, type
, 0);
183 f_print(fout
, ",\n");