2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
34 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
38 #include "rpc_parse.h"
40 #include "rpc_output.h"
42 static void write_table(definition *def);
43 static void printit(char *prefix, char *type);
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";
68 for (l = defined; l != NULL; l = l->next) {
69 def = (definition *) l->val;
70 if (def->def_kind == DEF_PROGRAM) {
77 write_table(definition *def)
86 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
88 s_print(progvers, "%s_%s",
89 locase(def->def_name), vp->vers_num);
90 /* print the table header */
91 f_print(fout, tbl_hdr, progvers);
93 if (nullproc(vp->procs)) {
97 f_print(fout, null_entry);
99 for (proc = vp->procs; proc != NULL; proc = proc->next) {
100 current = atoi(proc->proc_num);
101 if (current != expected++) {
103 "\n/*\n * WARNING: table out of order\n */\n");
106 "WARNING %s table is out of order\n",
111 expected = current + 1;
113 f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
115 /* routine to invoke */
116 if( Cflag && !newstyle )
117 pvname_svc(proc->proc_name, vp->vers_num);
120 f_print( fout, "_"); /* calls internal func */
121 pvname(proc->proc_name, vp->vers_num);
123 f_print(fout, "),\n");
126 if( proc->arg_num > 1 )
127 printit((char*) NULL, proc->args.argname );
129 /* do we have to do something special for newstyle */
130 printit( proc->args.decls->decl.prefix,
131 proc->args.decls->decl.type );
133 printit(proc->res_prefix, proc->res_type);
136 /* print the table trailer */
137 f_print(fout, tbl_end);
138 f_print(fout, tbl_nproc, progvers, progvers, progvers);
143 printit(char *prefix, char *type)
149 len = fprintf(fout, "\txdr_%s,", stringfix(type));
150 /* account for leading tab expansion */
152 /* round up to tabs required */
153 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
154 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]);
156 if (streq(type, "void")) {
159 f_print(fout, "sizeof ( ");
160 /* XXX: should "follow" be 1 ??? */
161 ptype(prefix, type, 0);
164 f_print(fout, ",\n");