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 or with the express written consent of
8 * Sun Microsystems, Inc.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
38 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
42 #include "rpc_parse.h"
48 #define TABSTOP (TABSIZE*TABCOUNT)
50 static const char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
52 static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
53 static const char tbl_end[] = "};\n";
55 static const char null_entry[] = "\n\t(char *(*)())0,\n\
56 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
57 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
60 static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
62 static void write_table (const definition * def);
63 static void printit (const char *prefix, const char *type);
72 for (l = defined; l != NULL; l = l->next)
74 def = (definition *) l->val;
75 if (def->def_kind == DEF_PROGRAM)
83 write_table (const definition * def)
92 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
95 s_print (progvers, "%s_%s",
96 locase (def->def_name), vp->vers_num);
97 /* print the table header */
98 f_print (fout, tbl_hdr, progvers);
100 if (nullproc (vp->procs))
107 f_print (fout, null_entry);
109 for (proc = vp->procs; proc != NULL; proc = proc->next)
111 current = atoi (proc->proc_num);
112 if (current != expected++)
115 "\n/*\n * WARNING: table out of order\n */\n");
119 "WARNING %s table is out of order\n",
124 expected = current + 1;
126 f_print (fout, "\n\t(char *(*)())RPCGEN_ACTION(");
128 /* routine to invoke */
129 if (Cflag && !newstyle)
130 pvname_svc (proc->proc_name, vp->vers_num);
134 f_print (fout, "_"); /* calls internal func */
135 pvname (proc->proc_name, vp->vers_num);
137 f_print (fout, "),\n");
140 if (proc->arg_num > 1)
141 printit ((char *) NULL, proc->args.argname);
143 /* do we have to do something special for newstyle */
144 printit (proc->args.decls->decl.prefix,
145 proc->args.decls->decl.type);
147 printit (proc->res_prefix, proc->res_type);
150 /* print the table trailer */
151 f_print (fout, tbl_end);
152 f_print (fout, tbl_nproc, progvers, progvers, progvers);
157 printit (const char *prefix, const char *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"))
176 f_print (fout, "sizeof ( ");
177 /* XXX: should "follow" be 1 ??? */
178 ptype (prefix, type, 0);
181 f_print (fout, ",\n");