rpc_tblout.c revision 1.15 1 1.15 dholland /* $NetBSD: rpc_tblout.c,v 1.15 2016/01/23 02:33:09 dholland 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.15 dholland __RCSID("$NetBSD: rpc_tblout.c,v 1.15 2016/01/23 02:33:09 dholland 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.15 dholland "unsigned int %s_nproc =\n\t(unsigned int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n";
70 1.1 pk
71 1.14 christos static void write_table(definition *);
72 1.14 christos static void printit(const char *, const char *);
73 1.1 pk
74 1.1 pk void
75 1.13 dholland write_tables(void)
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.13 dholland write_table(definition *def)
91 1.1 pk {
92 1.1 pk version_list *vp;
93 1.1 pk proc_list *proc;
94 1.7 lukem int current;
95 1.7 lukem int expected;
96 1.7 lukem char progvers[100];
97 1.7 lukem int warning;
98 1.1 pk
99 1.1 pk for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
100 1.1 pk warning = 0;
101 1.1 pk s_print(progvers, "%s_%s",
102 1.1 pk locase(def->def_name), vp->vers_num);
103 1.1 pk /* print the table header */
104 1.1 pk f_print(fout, tbl_hdr, progvers);
105 1.1 pk
106 1.1 pk if (nullproc(vp->procs)) {
107 1.1 pk expected = 0;
108 1.1 pk } else {
109 1.1 pk expected = 1;
110 1.1 pk f_print(fout, null_entry);
111 1.1 pk }
112 1.1 pk for (proc = vp->procs; proc != NULL; proc = proc->next) {
113 1.5 mycroft if (expected != 0)
114 1.5 mycroft f_print(fout, "\n");
115 1.1 pk current = atoi(proc->proc_num);
116 1.1 pk if (current != expected++) {
117 1.1 pk f_print(fout,
118 1.7 lukem "/*\n * WARNING: table out of order\n */\n\n");
119 1.1 pk if (warning == 0) {
120 1.1 pk f_print(stderr,
121 1.7 lukem "WARNING %s table is out of order\n",
122 1.1 pk progvers);
123 1.1 pk warning = 1;
124 1.1 pk nonfatalerrors = 1;
125 1.1 pk }
126 1.1 pk expected = current + 1;
127 1.1 pk }
128 1.5 mycroft f_print(fout, "\t(char *(*)())RPCGEN_ACTION(");
129 1.1 pk
130 1.1 pk /* routine to invoke */
131 1.7 lukem if (!newstyle)
132 1.7 lukem pvname_svc(proc->proc_name, vp->vers_num);
133 1.1 pk else {
134 1.7 lukem if (newstyle)
135 1.7 lukem f_print(fout, "_"); /* calls internal func */
136 1.7 lukem pvname(proc->proc_name, vp->vers_num);
137 1.1 pk }
138 1.1 pk f_print(fout, "),\n");
139 1.1 pk
140 1.1 pk /* argument info */
141 1.7 lukem if (proc->arg_num > 1)
142 1.12 plunky printit(NULL, proc->args.argname);
143 1.7 lukem else
144 1.7 lukem /* do we have to do something special for
145 1.7 lukem * newstyle */
146 1.7 lukem printit(proc->args.decls->decl.prefix,
147 1.7 lukem proc->args.decls->decl.type);
148 1.1 pk /* result info */
149 1.1 pk printit(proc->res_prefix, proc->res_type);
150 1.1 pk }
151 1.1 pk
152 1.1 pk /* print the table trailer */
153 1.1 pk f_print(fout, tbl_end);
154 1.1 pk f_print(fout, tbl_nproc, progvers, progvers, progvers);
155 1.1 pk }
156 1.1 pk }
157 1.1 pk
158 1.4 christos static void
159 1.13 dholland printit(const char *prefix, const char *type)
160 1.1 pk {
161 1.7 lukem int len;
162 1.7 lukem int tabs;
163 1.1 pk
164 1.1 pk
165 1.7 lukem len = fprintf(fout, "\txdr_%s,", stringfix(type));
166 1.1 pk /* account for leading tab expansion */
167 1.1 pk len += TABSIZE - 1;
168 1.1 pk /* round up to tabs required */
169 1.7 lukem tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
170 1.7 lukem f_print(fout, "%s", &tabstr[TABCOUNT - tabs]);
171 1.1 pk
172 1.1 pk if (streq(type, "void")) {
173 1.1 pk f_print(fout, "0");
174 1.1 pk } else {
175 1.15 dholland f_print(fout, "(unsigned int)sizeof(");
176 1.1 pk /* XXX: should "follow" be 1 ??? */
177 1.1 pk ptype(prefix, type, 0);
178 1.1 pk f_print(fout, ")");
179 1.1 pk }
180 1.1 pk f_print(fout, ",\n");
181 1.1 pk }
182