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
32 #ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI"
33 static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
41 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
42 * Copyright (C) 1989, Sun Microsystems, Inc.
47 #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[] = "\n\t(char *(*)())0,\n\
61 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
62 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
65 static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
67 static void write_table( definition * );
68 static void printit(const char *, const char *);
77 for (l = defined; l != NULL; l = l->next) {
78 def = (definition *) l->val;
79 if (def->def_kind == DEF_PROGRAM) {
86 write_table(definition *def)
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 fputs(null_entry, fout);
108 for (proc = vp->procs; proc != NULL; proc = proc->next) {
109 current = atoi(proc->proc_num);
110 if (current != expected++) {
112 "\n/*\n * WARNING: table out of order\n */\n");
114 warnx("WARNING %s table is out of order", progvers);
118 expected = current + 1;
120 f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
122 /* routine to invoke */
124 pvname_svc(proc->proc_name, vp->vers_num);
127 f_print( fout, "_"); /* calls internal func */
128 pvname(proc->proc_name, vp->vers_num);
130 f_print(fout, "),\n");
133 if( proc->arg_num > 1 )
134 printit((char*) NULL, proc->args.argname );
136 /* do we have to do something special for newstyle */
137 printit( proc->args.decls->decl.prefix,
138 proc->args.decls->decl.type );
140 printit(proc->res_prefix, proc->res_type);
143 /* print the table trailer */
144 fputs(tbl_end, fout);
145 f_print(fout, tbl_nproc, progvers, progvers, progvers);
150 printit(const char *prefix, const char *type)
156 len = fprintf(fout, "\txdr_%s,", stringfix(type));
157 /* account for leading tab expansion */
159 /* round up to tabs required */
160 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
161 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]);
163 if (streq(type, "void")) {
166 f_print(fout, "sizeof ( ");
167 /* XXX: should "follow" be 1 ??? */
168 ptype(prefix, type, 0);
171 f_print(fout, ",\n");