| 227 |
dpurdie |
1 |
/*
|
|
|
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.
|
|
|
9 |
*
|
|
|
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.
|
|
|
13 |
*
|
|
|
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.
|
|
|
17 |
*
|
|
|
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.
|
|
|
21 |
*
|
|
|
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.
|
|
|
25 |
*
|
|
|
26 |
* Sun Microsystems, Inc.
|
|
|
27 |
* 2550 Garcia Avenue
|
|
|
28 |
* Mountain View, California 94043
|
|
|
29 |
*/
|
|
|
30 |
|
|
|
31 |
#ifndef lint
|
|
|
32 |
static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
|
|
|
33 |
#endif
|
|
|
34 |
|
|
|
35 |
/*
|
|
|
36 |
* rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
|
|
|
37 |
*/
|
|
|
38 |
#include <stdio.h>
|
|
|
39 |
#include <string.h>
|
|
|
40 |
#include "rpc_parse.h"
|
|
|
41 |
#include "rpc_util.h"
|
|
|
42 |
|
|
|
43 |
#define TABSIZE 8
|
|
|
44 |
#define TABCOUNT 5
|
|
|
45 |
#define TABSTOP (TABSIZE*TABCOUNT)
|
|
|
46 |
|
|
|
47 |
static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
|
|
|
48 |
|
|
|
49 |
static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
|
|
|
50 |
static char tbl_end[] = "};\n";
|
|
|
51 |
|
|
|
52 |
static char null_entry[] = "\n\t(char *(*)())0,\n\
|
|
|
53 |
\t(xdrproc_t) xdr_void,\t\t\t0,\n\
|
|
|
54 |
\t(xdrproc_t) xdr_void,\t\t\t0,\n";
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
|
|
|
58 |
|
|
|
59 |
void
|
|
|
60 |
write_tables()
|
|
|
61 |
{
|
|
|
62 |
list *l;
|
|
|
63 |
definition *def;
|
|
|
64 |
|
|
|
65 |
f_print(fout, "\n");
|
|
|
66 |
for (l = defined; l != NULL; l = l->next) {
|
|
|
67 |
def = (definition *) l->val;
|
|
|
68 |
if (def->def_kind == DEF_PROGRAM) {
|
|
|
69 |
write_table(def);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
static
|
|
|
75 |
write_table(def)
|
|
|
76 |
definition *def;
|
|
|
77 |
{
|
|
|
78 |
version_list *vp;
|
|
|
79 |
proc_list *proc;
|
|
|
80 |
int current;
|
|
|
81 |
int expected;
|
|
|
82 |
char progvers[100];
|
|
|
83 |
int warning;
|
|
|
84 |
|
|
|
85 |
for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
|
|
|
86 |
warning = 0;
|
|
|
87 |
s_print(progvers, "%s_%s",
|
|
|
88 |
locase(def->def_name), vp->vers_num);
|
|
|
89 |
/* print the table header */
|
|
|
90 |
f_print(fout, tbl_hdr, progvers);
|
|
|
91 |
|
|
|
92 |
if (nullproc(vp->procs)) {
|
|
|
93 |
expected = 0;
|
|
|
94 |
} else {
|
|
|
95 |
expected = 1;
|
|
|
96 |
f_print(fout, null_entry);
|
|
|
97 |
}
|
|
|
98 |
for (proc = vp->procs; proc != NULL; proc = proc->next) {
|
|
|
99 |
current = atoi(proc->proc_num);
|
|
|
100 |
if (current != expected++) {
|
|
|
101 |
f_print(fout,
|
|
|
102 |
"\n/*\n * WARNING: table out of order\n */\n");
|
|
|
103 |
if (warning == 0) {
|
|
|
104 |
f_print(stderr,
|
|
|
105 |
"WARNING %s table is out of order\n",
|
|
|
106 |
progvers);
|
|
|
107 |
warning = 1;
|
|
|
108 |
nonfatalerrors = 1;
|
|
|
109 |
}
|
|
|
110 |
expected = current + 1;
|
|
|
111 |
}
|
|
|
112 |
f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
|
|
|
113 |
|
|
|
114 |
/* routine to invoke */
|
|
|
115 |
if( Cflag && !newstyle )
|
|
|
116 |
pvname_svc(proc->proc_name, vp->vers_num);
|
|
|
117 |
else {
|
|
|
118 |
if( newstyle )
|
|
|
119 |
f_print( fout, "_"); /* calls internal func */
|
|
|
120 |
pvname(proc->proc_name, vp->vers_num);
|
|
|
121 |
}
|
|
|
122 |
f_print(fout, "),\n");
|
|
|
123 |
|
|
|
124 |
/* argument info */
|
|
|
125 |
if( proc->arg_num > 1 )
|
|
|
126 |
printit((char*) NULL, proc->args.argname );
|
|
|
127 |
else
|
|
|
128 |
/* do we have to do something special for newstyle */
|
|
|
129 |
printit( proc->args.decls->decl.prefix,
|
|
|
130 |
proc->args.decls->decl.type );
|
|
|
131 |
/* result info */
|
|
|
132 |
printit(proc->res_prefix, proc->res_type);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/* print the table trailer */
|
|
|
136 |
f_print(fout, tbl_end);
|
|
|
137 |
f_print(fout, tbl_nproc, progvers, progvers, progvers);
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
static
|
|
|
142 |
printit(prefix, type)
|
|
|
143 |
char *prefix;
|
|
|
144 |
char *type;
|
|
|
145 |
{
|
|
|
146 |
int len;
|
|
|
147 |
int tabs;
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
len = fprintf(fout, "\txdr_%s,", stringfix(type));
|
|
|
151 |
/* account for leading tab expansion */
|
|
|
152 |
len += TABSIZE - 1;
|
|
|
153 |
/* round up to tabs required */
|
|
|
154 |
tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
|
|
|
155 |
f_print(fout, "%s", &tabstr[TABCOUNT-tabs]);
|
|
|
156 |
|
|
|
157 |
if (streq(type, "void")) {
|
|
|
158 |
f_print(fout, "0");
|
|
|
159 |
} else {
|
|
|
160 |
f_print(fout, "sizeof ( ");
|
|
|
161 |
/* XXX: should "follow" be 1 ??? */
|
|
|
162 |
ptype(prefix, type, 0);
|
|
|
163 |
f_print(fout, ")");
|
|
|
164 |
}
|
|
|
165 |
f_print(fout, ",\n");
|
|
|
166 |
}
|