rpc_tblout.c revision 1.11 1 1.11 jmc /* $NetBSD: rpc_tblout.c,v 1.11 2004/06/20 22:20:16 jmc Exp $ */
2 1.1 pk /*
3 1.1 pk * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 1.1 pk * unrestricted use provided that this legend is included on all tape
5 1.1 pk * media and as a part of the software program in whole or part. Users
6 1.1 pk * may copy or modify Sun RPC without charge, but are not authorized
7 1.1 pk * to license or distribute it to anyone else except as part of a product or
8 1.1 pk * program developed by the user or with the express written consent of
9 1.1 pk * Sun Microsystems, Inc.
10 1.1 pk *
11 1.1 pk * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.1 pk * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.1 pk * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.1 pk *
15 1.1 pk * Sun RPC is provided with no support and without any obligation on the
16 1.1 pk * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.1 pk * modification or enhancement.
18 1.1 pk *
19 1.1 pk * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.1 pk * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.1 pk * OR ANY PART THEREOF.
22 1.1 pk *
23 1.1 pk * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.1 pk * or profits or other special, indirect and consequential damages, even if
25 1.1 pk * Sun has been advised of the possibility of such damages.
26 1.1 pk *
27 1.1 pk * Sun Microsystems, Inc.
28 1.1 pk * 2550 Garcia Avenue
29 1.1 pk * Mountain View, California 94043
30 1.1 pk */
31 1.1 pk
32 1.11 jmc #if HAVE_NBTOOL_CONFIG_H
33 1.11 jmc #include "nbtool_config.h"
34 1.11 jmc #endif
35 1.11 jmc
36 1.4 christos #include <sys/cdefs.h>
37 1.9 tv #if defined(__RCSID) && !defined(lint)
38 1.4 christos #if 0
39 1.1 pk static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
40 1.4 christos #else
41 1.11 jmc __RCSID("$NetBSD: rpc_tblout.c,v 1.11 2004/06/20 22:20:16 jmc Exp $");
42 1.4 christos #endif
43 1.1 pk #endif
44 1.1 pk
45 1.1 pk /*
46 1.1 pk * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
47 1.1 pk */
48 1.1 pk #include <stdio.h>
49 1.1 pk #include <string.h>
50 1.4 christos #include <stdlib.h>
51 1.4 christos #include "rpc_scan.h"
52 1.1 pk #include "rpc_parse.h"
53 1.1 pk #include "rpc_util.h"
54 1.1 pk
55 1.1 pk #define TABSIZE 8
56 1.1 pk #define TABCOUNT 5
57 1.1 pk #define TABSTOP (TABSIZE*TABCOUNT)
58 1.1 pk
59 1.7 lukem static char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
60 1.1 pk
61 1.8 is static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
62 1.8 is static const char tbl_end[] = "};\n";
63 1.1 pk
64 1.8 is static const char null_entry[] = "\t(char *(*)())0,\n\
65 1.6 mycroft \t(xdrproc_t)xdr_void,\t\t0,\n\
66 1.6 mycroft \t(xdrproc_t)xdr_void,\t\t0,\n";
67 1.1 pk
68 1.10 christos static const char tbl_nproc[] =
69 1.10 christos "u_int %s_nproc =\n\t(u_int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n";
70 1.1 pk
71 1.4 christos static void write_table __P((definition *));
72 1.4 christos static void printit __P((char *, char *));
73 1.1 pk
74 1.1 pk void
75 1.1 pk write_tables()
76 1.1 pk {
77 1.7 lukem list *l;
78 1.1 pk definition *def;
79 1.1 pk
80 1.1 pk f_print(fout, "\n");
81 1.1 pk for (l = defined; l != NULL; l = l->next) {
82 1.1 pk def = (definition *) l->val;
83 1.1 pk if (def->def_kind == DEF_PROGRAM) {
84 1.1 pk write_table(def);
85 1.1 pk }
86 1.1 pk }
87 1.1 pk }
88 1.1 pk
89 1.4 christos static void
90 1.1 pk write_table(def)
91 1.1 pk definition *def;
92 1.1 pk {
93 1.1 pk version_list *vp;
94 1.1 pk proc_list *proc;
95 1.7 lukem int current;
96 1.7 lukem int expected;
97 1.7 lukem char progvers[100];
98 1.7 lukem int warning;
99 1.1 pk
100 1.1 pk for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
101 1.1 pk warning = 0;
102 1.1 pk s_print(progvers, "%s_%s",
103 1.1 pk locase(def->def_name), vp->vers_num);
104 1.1 pk /* print the table header */
105 1.1 pk f_print(fout, tbl_hdr, progvers);
106 1.1 pk
107 1.1 pk if (nullproc(vp->procs)) {
108 1.1 pk expected = 0;
109 1.1 pk } else {
110 1.1 pk expected = 1;
111 1.1 pk f_print(fout, null_entry);
112 1.1 pk }
113 1.1 pk for (proc = vp->procs; proc != NULL; proc = proc->next) {
114 1.5 mycroft if (expected != 0)
115 1.5 mycroft f_print(fout, "\n");
116 1.1 pk current = atoi(proc->proc_num);
117 1.1 pk if (current != expected++) {
118 1.1 pk f_print(fout,
119 1.7 lukem "/*\n * WARNING: table out of order\n */\n\n");
120 1.1 pk if (warning == 0) {
121 1.1 pk f_print(stderr,
122 1.7 lukem "WARNING %s table is out of order\n",
123 1.1 pk progvers);
124 1.1 pk warning = 1;
125 1.1 pk nonfatalerrors = 1;
126 1.1 pk }
127 1.1 pk expected = current + 1;
128 1.1 pk }
129 1.5 mycroft f_print(fout, "\t(char *(*)())RPCGEN_ACTION(");
130 1.1 pk
131 1.1 pk /* routine to invoke */
132 1.7 lukem if (!newstyle)
133 1.7 lukem pvname_svc(proc->proc_name, vp->vers_num);
134 1.1 pk else {
135 1.7 lukem if (newstyle)
136 1.7 lukem f_print(fout, "_"); /* calls internal func */
137 1.7 lukem pvname(proc->proc_name, vp->vers_num);
138 1.1 pk }
139 1.1 pk f_print(fout, "),\n");
140 1.1 pk
141 1.1 pk /* argument info */
142 1.7 lukem if (proc->arg_num > 1)
143 1.7 lukem printit((char *) NULL, proc->args.argname);
144 1.7 lukem else
145 1.7 lukem /* do we have to do something special for
146 1.7 lukem * newstyle */
147 1.7 lukem printit(proc->args.decls->decl.prefix,
148 1.7 lukem proc->args.decls->decl.type);
149 1.1 pk /* result info */
150 1.1 pk printit(proc->res_prefix, proc->res_type);
151 1.1 pk }
152 1.1 pk
153 1.1 pk /* print the table trailer */
154 1.1 pk f_print(fout, tbl_end);
155 1.1 pk f_print(fout, tbl_nproc, progvers, progvers, progvers);
156 1.1 pk }
157 1.1 pk }
158 1.1 pk
159 1.4 christos static void
160 1.1 pk printit(prefix, type)
161 1.7 lukem char *prefix;
162 1.7 lukem char *type;
163 1.1 pk {
164 1.7 lukem int len;
165 1.7 lukem int tabs;
166 1.1 pk
167 1.1 pk
168 1.7 lukem len = fprintf(fout, "\txdr_%s,", stringfix(type));
169 1.1 pk /* account for leading tab expansion */
170 1.1 pk len += TABSIZE - 1;
171 1.1 pk /* round up to tabs required */
172 1.7 lukem tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
173 1.7 lukem f_print(fout, "%s", &tabstr[TABCOUNT - tabs]);
174 1.1 pk
175 1.1 pk if (streq(type, "void")) {
176 1.1 pk f_print(fout, "0");
177 1.1 pk } else {
178 1.10 christos f_print(fout, "(u_int)sizeof(");
179 1.1 pk /* XXX: should "follow" be 1 ??? */
180 1.1 pk ptype(prefix, type, 0);
181 1.1 pk f_print(fout, ")");
182 1.1 pk }
183 1.1 pk f_print(fout, ",\n");
184 1.1 pk }
185