2 * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
37 #include "rpc_parse.h"
43 #define TABSTOP (TABSIZE*TABCOUNT)
45 static const char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
47 static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
48 static const char tbl_end[] = "};\n";
50 static const char null_entry[] = "\n\t(char *(*)())0,\n\
51 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
52 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
55 static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
57 static void write_table (const definition * def);
58 static void printit (const char *prefix, const char *type);
67 for (l = defined; l != NULL; l = l->next)
69 def = (definition *) l->val;
70 if (def->def_kind == DEF_PROGRAM)
78 write_table (const definition * def)
87 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
90 s_print (progvers, "%s_%s",
91 locase (def->def_name), vp->vers_num);
92 /* print the table header */
93 f_print (fout, tbl_hdr, progvers);
95 if (nullproc (vp->procs))
102 f_print (fout, null_entry);
104 for (proc = vp->procs; proc != NULL; proc = proc->next)
106 current = atoi (proc->proc_num);
107 if (current != expected++)
110 "\n/*\n * WARNING: table out of order\n */\n");
114 "WARNING %s table is out of order\n",
119 expected = current + 1;
121 f_print (fout, "\n\t(char *(*)())RPCGEN_ACTION(");
123 /* routine to invoke */
124 if (Cflag && !newstyle)
125 pvname_svc (proc->proc_name, vp->vers_num);
129 f_print (fout, "_"); /* calls internal func */
130 pvname (proc->proc_name, vp->vers_num);
132 f_print (fout, "),\n");
135 if (proc->arg_num > 1)
136 printit ((char *) NULL, proc->args.argname);
138 /* do we have to do something special for newstyle */
139 printit (proc->args.decls->decl.prefix,
140 proc->args.decls->decl.type);
142 printit (proc->res_prefix, proc->res_type);
145 /* print the table trailer */
146 f_print (fout, tbl_end);
147 f_print (fout, tbl_nproc, progvers, progvers, progvers);
152 printit (const char *prefix, const char *type)
158 len = fprintf (fout, "\txdr_%s,", stringfix (type));
159 /* account for leading tab expansion */
161 /* round up to tabs required */
162 tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
163 f_print (fout, "%s", &tabstr[TABCOUNT - tabs]);
165 if (streq (type, "void"))
171 f_print (fout, "sizeof ( ");
172 /* XXX: should "follow" be 1 ??? */
173 ptype (prefix, type, 0);
176 f_print (fout, ",\n");