]>
git.cameronkatri.com Git - apple_cmds.git/blob - developer_cmds/rpcgen/rpc_tblout.c
1 /* $NetBSD: rpc_tblout.c,v 1.7 1997/10/18 10:54:11 lukem 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 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
37 __RCSID("$NetBSD: rpc_tblout.c,v 1.7 1997/10/18 10:54:11 lukem Exp $");
42 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
48 #include "rpc_parse.h"
53 #define TABSTOP (TABSIZE*TABCOUNT)
55 static char tabstr
[TABCOUNT
+ 1] = "\t\t\t\t\t";
57 static char tbl_hdr
[] = "struct rpcgen_table %s_table[] = {\n";
58 static char tbl_end
[] = "};\n";
60 static char null_entry
[] = "\t(char *(*)())0,\n\
61 \t(xdrproc_t)xdr_void,\t\t0,\n\
62 \t(xdrproc_t)xdr_void,\t\t0,\n";
64 static char tbl_nproc
[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
66 static void write_table
__P((definition
*));
67 static void printit
__P((char *, char *));
76 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
77 def
= (definition
*) l
->val
;
78 if (def
->def_kind
== DEF_PROGRAM
) {
95 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
) {
97 s_print(progvers
, "%s_%s",
98 locase(def
->def_name
), vp
->vers_num
);
99 /* print the table header */
100 f_print(fout
, tbl_hdr
, progvers
);
102 if (nullproc(vp
->procs
)) {
106 f_print(fout
, "%s", null_entry
);
108 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
) {
111 current
= atoi(proc
->proc_num
);
112 if (current
!= expected
++) {
114 "/*\n * WARNING: table out of order\n */\n\n");
117 "WARNING %s table is out of order\n",
122 expected
= current
+ 1;
124 f_print(fout
, "\t(char *(*)())RPCGEN_ACTION(");
126 /* routine to invoke */
128 pvname_svc(proc
->proc_name
, vp
->vers_num
);
131 f_print(fout
, "_"); /* calls internal func */
132 pvname(proc
->proc_name
, vp
->vers_num
);
134 f_print(fout
, "),\n");
137 if (proc
->arg_num
> 1)
138 printit((char *) NULL
, proc
->args
.argname
);
140 /* do we have to do something special for
142 printit(proc
->args
.decls
->decl
.prefix
,
143 proc
->args
.decls
->decl
.type
);
145 printit(proc
->res_prefix
, proc
->res_type
);
148 /* print the table trailer */
149 f_print(fout
, "%s", tbl_end
);
150 f_print(fout
, tbl_nproc
, progvers
, progvers
, progvers
);
155 printit(prefix
, type
)
163 len
= fprintf(fout
, "\txdr_%s,", stringfix(type
));
164 /* account for leading tab expansion */
166 /* round up to tabs required */
167 tabs
= (TABSTOP
- len
+ TABSIZE
- 1) / TABSIZE
;
168 f_print(fout
, "%s", &tabstr
[TABCOUNT
- tabs
]);
170 if (streq(type
, "void")) {
173 f_print(fout
, "sizeof ( ");
174 /* XXX: should "follow" be 1 ??? */
175 ptype(prefix
, type
, 0);
178 f_print(fout
, ",\n");