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
29 * @(#)rpc_tblout.c 1.11 93/07/05 SMI; 1.4 89/02/22 (C) 1988 SMI
30 * $FreeBSD: src/usr.bin/rpcgen/rpc_tblout.c,v 1.12 2005/11/13 21:17:24 dwmalone Exp $
31 * $DragonFly: src/usr.bin/rpcgen/rpc_tblout.c,v 1.4 2004/06/19 16:40:36 joerg Exp $
35 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
36 * Copyright (C) 1989, Sun Microsystems, Inc.
41 #include "rpc_parse.h"
47 #define TABSTOP (TABSIZE*TABCOUNT)
49 static char tabstr
[TABCOUNT
+1] = "\t\t\t\t\t";
51 static char tbl_hdr
[] = "struct rpcgen_table %s_table[] = {\n";
52 static char tbl_end
[] = "};\n";
54 static char null_entry
[] = "\n\t(char *(*)())0,\n\
55 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
56 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
59 static char tbl_nproc
[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
61 static void write_table(definition
*);
62 static void printit(const char *, const char *);
71 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
72 def
= (definition
*) l
->val
;
73 if (def
->def_kind
== DEF_PROGRAM
) {
80 write_table(definition
*def
)
89 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
91 s_print(progvers
, "%s_%s",
92 locase(def
->def_name
), vp
->vers_num
);
93 /* print the table header */
94 f_print(fout
, tbl_hdr
, progvers
);
96 if (nullproc(vp
->procs
)) {
100 f_print(fout
, null_entry
);
102 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
103 current
= atoi(proc
->proc_num
);
104 if (current
!= expected
++) {
106 "\n/*\n * WARNING: table out of order\n */\n");
108 warnx("WARNING %s table is out of order", progvers
);
112 expected
= current
+ 1;
114 f_print(fout
, "\n\t(char *(*)())RPCGEN_ACTION(");
116 /* routine to invoke */
118 pvname_svc(proc
->proc_name
, vp
->vers_num
);
121 f_print(fout
, "_"); /* calls internal func */
122 pvname(proc
->proc_name
, vp
->vers_num
);
124 f_print(fout
, "),\n");
127 if (proc
->arg_num
> 1) {
128 printit(NULL
, proc
->args
.argname
);
131 * do we have to do something special for
134 printit(proc
->args
.decls
->decl
.prefix
,
135 proc
->args
.decls
->decl
.type
);
138 printit(proc
->res_prefix
, proc
->res_type
);
141 /* print the table trailer */
142 f_print(fout
, tbl_end
);
143 f_print(fout
, tbl_nproc
, progvers
, progvers
, progvers
);
148 printit(const char *prefix
, const char *type
)
154 len
= fprintf(fout
, "\txdr_%s,", stringfix(type
));
155 /* account for leading tab expansion */
157 /* round up to tabs required */
158 tabs
= (TABSTOP
- len
+ TABSIZE
- 1)/TABSIZE
;
159 f_print(fout
, "%s", &tabstr
[TABCOUNT
-tabs
]);
161 if (streq(type
, "void")) {
164 f_print(fout
, "sizeof ( ");
165 /* XXX: should "follow" be 1 ??? */
166 ptype(prefix
, type
, 0);
169 f_print(fout
, ",\n");