u_int -> unsigned int, in some of the output. In the bulk of the output making this change would require reworking a bunch of the internals to allow spaces in type names, which at the moment doesn't seem worthwhile.diff -r1.37 -r1.38 src/usr.bin/rpcgen/rpc_cout.c
(dholland)
--- src/usr.bin/rpcgen/rpc_cout.c 2015/09/20 16:57:13 1.37
+++ src/usr.bin/rpcgen/rpc_cout.c 2016/01/23 02:33:09 1.38
@@ -1,725 +1,725 @@ | @@ -1,725 +1,725 @@ | |||
1 | /* $NetBSD: rpc_cout.c,v 1.37 2015/09/20 16:57:13 kamil Exp $ */ | 1 | /* $NetBSD: rpc_cout.c,v 1.38 2016/01/23 02:33:09 dholland Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
4 | * unrestricted use provided that this legend is included on all tape | 4 | * unrestricted use provided that this legend is included on all tape | |
5 | * media and as a part of the software program in whole or part. Users | 5 | * media and as a part of the software program in whole or part. Users | |
6 | * may copy or modify Sun RPC without charge, but are not authorized | 6 | * may copy or modify Sun RPC without charge, but are not authorized | |
7 | * to license or distribute it to anyone else except as part of a product or | 7 | * to license or distribute it to anyone else except as part of a product or | |
8 | * program developed by the user or with the express written consent of | 8 | * program developed by the user or with the express written consent of | |
9 | * Sun Microsystems, Inc. | 9 | * Sun Microsystems, Inc. | |
10 | * | 10 | * | |
11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
14 | * | 14 | * | |
15 | * Sun RPC is provided with no support and without any obligation on the | 15 | * Sun RPC is provided with no support and without any obligation on the | |
16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
17 | * modification or enhancement. | 17 | * modification or enhancement. | |
18 | * | 18 | * | |
19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
21 | * OR ANY PART THEREOF. | 21 | * OR ANY PART THEREOF. | |
22 | * | 22 | * | |
23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
24 | * or profits or other special, indirect and consequential damages, even if | 24 | * or profits or other special, indirect and consequential damages, even if | |
25 | * Sun has been advised of the possibility of such damages. | 25 | * Sun has been advised of the possibility of such damages. | |
26 | * | 26 | * | |
27 | * Sun Microsystems, Inc. | 27 | * Sun Microsystems, Inc. | |
28 | * 2550 Garcia Avenue | 28 | * 2550 Garcia Avenue | |
29 | * Mountain View, California 94043 | 29 | * Mountain View, California 94043 | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(lint) | 37 | #if defined(__RCSID) && !defined(lint) | |
38 | #if 0 | 38 | #if 0 | |
39 | static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI"; | 39 | static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI"; | |
40 | #else | 40 | #else | |
41 | __RCSID("$NetBSD: rpc_cout.c,v 1.37 2015/09/20 16:57:13 kamil Exp $"); | 41 | __RCSID("$NetBSD: rpc_cout.c,v 1.38 2016/01/23 02:33:09 dholland Exp $"); | |
42 | #endif | 42 | #endif | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | /* | 45 | /* | |
46 | * rpc_cout.c, XDR routine outputter for the RPC protocol compiler | 46 | * rpc_cout.c, XDR routine outputter for the RPC protocol compiler | |
47 | */ | 47 | */ | |
48 | #include <ctype.h> | 48 | #include <ctype.h> | |
49 | #include <err.h> | 49 | #include <err.h> | |
50 | #include <stdio.h> | 50 | #include <stdio.h> | |
51 | #include <stdlib.h> | 51 | #include <stdlib.h> | |
52 | #include <string.h> | 52 | #include <string.h> | |
53 | #include "rpc_scan.h" | 53 | #include "rpc_scan.h" | |
54 | #include "rpc_parse.h" | 54 | #include "rpc_parse.h" | |
55 | #include "rpc_util.h" | 55 | #include "rpc_util.h" | |
56 | 56 | |||
57 | static int findtype(definition *, const char *); | 57 | static int findtype(definition *, const char *); | |
58 | static int undefined(const char *); | 58 | static int undefined(const char *); | |
59 | static void print_generic_header(const char *, int); | 59 | static void print_generic_header(const char *, int); | |
60 | static void print_header(definition *); | 60 | static void print_header(definition *); | |
61 | static void print_prog_header(proc_list *); | 61 | static void print_prog_header(proc_list *); | |
62 | static void print_trailer(void); | 62 | static void print_trailer(void); | |
63 | static void print_ifopen(int, const char *); | 63 | static void print_ifopen(int, const char *); | |
64 | static void print_ifarg(const char *); | 64 | static void print_ifarg(const char *); | |
65 | static void print_ifsizeof(const char *, const char *); | 65 | static void print_ifsizeof(const char *, const char *); | |
66 | static void print_ifclose(int); | 66 | static void print_ifclose(int); | |
67 | static void print_ifstat(int, const char *, const char *, relation, | 67 | static void print_ifstat(int, const char *, const char *, relation, | |
68 | const char *, const char *, const char *); | 68 | const char *, const char *, const char *); | |
69 | static void emit_enum(definition *); | 69 | static void emit_enum(definition *); | |
70 | static void emit_program(definition *); | 70 | static void emit_program(definition *); | |
71 | static void emit_union(definition *); | 71 | static void emit_union(definition *); | |
72 | static void emit_struct(definition *); | 72 | static void emit_struct(definition *); | |
73 | static void emit_typedef(definition *); | 73 | static void emit_typedef(definition *); | |
74 | static void print_stat(int, declaration *); | 74 | static void print_stat(int, declaration *); | |
75 | 75 | |||
76 | /* | 76 | /* | |
77 | * Emit the C-routine for the given definition | 77 | * Emit the C-routine for the given definition | |
78 | */ | 78 | */ | |
79 | void | 79 | void | |
80 | emit(definition *def) | 80 | emit(definition *def) | |
81 | { | 81 | { | |
82 | if (def->def_kind == DEF_CONST) { | 82 | if (def->def_kind == DEF_CONST) { | |
83 | return; | 83 | return; | |
84 | } | 84 | } | |
85 | if (def->def_kind == DEF_PROGRAM) { | 85 | if (def->def_kind == DEF_PROGRAM) { | |
86 | emit_program(def); | 86 | emit_program(def); | |
87 | return; | 87 | return; | |
88 | } | 88 | } | |
89 | if (def->def_kind == DEF_TYPEDEF) { | 89 | if (def->def_kind == DEF_TYPEDEF) { | |
90 | /* now we need to handle declarations like struct typedef foo | 90 | /* now we need to handle declarations like struct typedef foo | |
91 | * foo; since we dont want this to be expanded into 2 calls to | 91 | * foo; since we dont want this to be expanded into 2 calls to | |
92 | * xdr_foo */ | 92 | * xdr_foo */ | |
93 | 93 | |||
94 | if (strcmp(def->def.ty.old_type, def->def_name) == 0) | 94 | if (strcmp(def->def.ty.old_type, def->def_name) == 0) | |
95 | return; | 95 | return; | |
96 | }; | 96 | }; | |
97 | 97 | |||
98 | print_header(def); | 98 | print_header(def); | |
99 | 99 | |||
100 | switch (def->def_kind) { | 100 | switch (def->def_kind) { | |
101 | case DEF_UNION: | 101 | case DEF_UNION: | |
102 | emit_union(def); | 102 | emit_union(def); | |
103 | break; | 103 | break; | |
104 | case DEF_ENUM: | 104 | case DEF_ENUM: | |
105 | emit_enum(def); | 105 | emit_enum(def); | |
106 | break; | 106 | break; | |
107 | case DEF_STRUCT: | 107 | case DEF_STRUCT: | |
108 | emit_struct(def); | 108 | emit_struct(def); | |
109 | break; | 109 | break; | |
110 | case DEF_TYPEDEF: | 110 | case DEF_TYPEDEF: | |
111 | emit_typedef(def); | 111 | emit_typedef(def); | |
112 | break; | 112 | break; | |
113 | case DEF_PROGRAM: | 113 | case DEF_PROGRAM: | |
114 | case DEF_CONST: | 114 | case DEF_CONST: | |
115 | errx(1, "Internal error at %s:%d: Case %d not handled", | 115 | errx(1, "Internal error at %s:%d: Case %d not handled", | |
116 | __FILE__, __LINE__, def->def_kind); | 116 | __FILE__, __LINE__, def->def_kind); | |
117 | break; | 117 | break; | |
118 | } | 118 | } | |
119 | print_trailer(); | 119 | print_trailer(); | |
120 | } | 120 | } | |
121 | 121 | |||
122 | static int | 122 | static int | |
123 | findtype(definition *def, const char *type) | 123 | findtype(definition *def, const char *type) | |
124 | { | 124 | { | |
125 | 125 | |||
126 | if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { | 126 | if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { | |
127 | return (0); | 127 | return (0); | |
128 | } else { | 128 | } else { | |
129 | return (streq(def->def_name, type)); | 129 | return (streq(def->def_name, type)); | |
130 | } | 130 | } | |
131 | } | 131 | } | |
132 | 132 | |||
133 | static int | 133 | static int | |
134 | undefined(const char *type) | 134 | undefined(const char *type) | |
135 | { | 135 | { | |
136 | definition *def; | 136 | definition *def; | |
137 | 137 | |||
138 | def = (definition *) FINDVAL(defined, type, findtype); | 138 | def = (definition *) FINDVAL(defined, type, findtype); | |
139 | 139 | |||
140 | 140 | |||
141 | return (def == NULL); | 141 | return (def == NULL); | |
142 | } | 142 | } | |
143 | 143 | |||
144 | static void | 144 | static void | |
145 | print_generic_header(const char *procname, int pointerp) | 145 | print_generic_header(const char *procname, int pointerp) | |
146 | { | 146 | { | |
147 | f_print(fout, "\n"); | 147 | f_print(fout, "\n"); | |
148 | f_print(fout, "bool_t\n"); | 148 | f_print(fout, "bool_t\n"); | |
149 | f_print(fout, "xdr_%s(", procname); | 149 | f_print(fout, "xdr_%s(", procname); | |
150 | f_print(fout, "XDR *xdrs, "); | 150 | f_print(fout, "XDR *xdrs, "); | |
151 | f_print(fout, "%s ", procname); | 151 | f_print(fout, "%s ", procname); | |
152 | if (pointerp) | 152 | if (pointerp) | |
153 | f_print(fout, "*"); | 153 | f_print(fout, "*"); | |
154 | f_print(fout, "objp)\n{\n"); | 154 | f_print(fout, "objp)\n{\n"); | |
155 | } | 155 | } | |
156 | 156 | |||
157 | static void | 157 | static void | |
158 | print_header(definition *def) | 158 | print_header(definition *def) | |
159 | { | 159 | { | |
160 | print_generic_header(def->def_name, | 160 | print_generic_header(def->def_name, | |
161 | def->def_kind != DEF_TYPEDEF || | 161 | def->def_kind != DEF_TYPEDEF || | |
162 | !isvectordef(def->def.ty.old_type, def->def.ty.rel)); | 162 | !isvectordef(def->def.ty.old_type, def->def.ty.rel)); | |
163 | } | 163 | } | |
164 | 164 | |||
165 | static void | 165 | static void | |
166 | print_prog_header(proc_list *plist) | 166 | print_prog_header(proc_list *plist) | |
167 | { | 167 | { | |
168 | print_generic_header(plist->args.argname, 1); | 168 | print_generic_header(plist->args.argname, 1); | |
169 | } | 169 | } | |
170 | 170 | |||
171 | static void | 171 | static void | |
172 | print_trailer(void) | 172 | print_trailer(void) | |
173 | { | 173 | { | |
174 | f_print(fout, "\treturn (TRUE);\n"); | 174 | f_print(fout, "\treturn (TRUE);\n"); | |
175 | f_print(fout, "}\n"); | 175 | f_print(fout, "}\n"); | |
176 | } | 176 | } | |
177 | 177 | |||
178 | 178 | |||
179 | static void | 179 | static void | |
180 | print_ifopen(int indent, const char *name) | 180 | print_ifopen(int indent, const char *name) | |
181 | { | 181 | { | |
182 | char _t_kludge[32]; | 182 | char _t_kludge[32]; | |
183 | /* | 183 | /* | |
184 | * XXX Solaris seems to strip the _t. No idea why. | 184 | * XXX Solaris seems to strip the _t. No idea why. | |
185 | */ | 185 | */ | |
186 | if (!strcmp(name, "rpcprog_t") || !strcmp(name, "rpcvers_t") || | 186 | if (!strcmp(name, "rpcprog_t") || !strcmp(name, "rpcvers_t") || | |
187 | !strcmp(name, "rpcproc_t") || !strcmp(name, "rpcprot_t") || | 187 | !strcmp(name, "rpcproc_t") || !strcmp(name, "rpcprot_t") || | |
188 | !strcmp(name, "rpcport_t") || !strcmp(name, "rpcpinline_t")) { | 188 | !strcmp(name, "rpcport_t") || !strcmp(name, "rpcpinline_t")) { | |
189 | strncpy(_t_kludge, name, strlen(name) - 2); | 189 | strncpy(_t_kludge, name, strlen(name) - 2); | |
190 | name = _t_kludge; | 190 | name = _t_kludge; | |
191 | } | 191 | } | |
192 | tabify(fout, indent); | 192 | tabify(fout, indent); | |
193 | f_print(fout, "if (!xdr_%s(xdrs", name); | 193 | f_print(fout, "if (!xdr_%s(xdrs", name); | |
194 | } | 194 | } | |
195 | 195 | |||
196 | static void | 196 | static void | |
197 | print_ifarg(const char *arg) | 197 | print_ifarg(const char *arg) | |
198 | { | 198 | { | |
199 | f_print(fout, ", %s", arg); | 199 | f_print(fout, ", %s", arg); | |
200 | } | 200 | } | |
201 | 201 | |||
202 | static void | 202 | static void | |
203 | print_ifsizeof(const char *prefix, const char *type) | 203 | print_ifsizeof(const char *prefix, const char *type) | |
204 | { | 204 | { | |
205 | if (streq(type, "bool")) { | 205 | if (streq(type, "bool")) { | |
206 | f_print(fout, ", (u_int)sizeof(bool_t), (xdrproc_t)xdr_bool"); | 206 | f_print(fout, ", (unsigned int)sizeof(bool_t), (xdrproc_t)xdr_bool"); | |
207 | } else { | 207 | } else { | |
208 | f_print(fout, ", (u_int)sizeof("); | 208 | f_print(fout, ", (unsigned int)sizeof("); | |
209 | if (undefined(type) && prefix) { | 209 | if (undefined(type) && prefix) { | |
210 | f_print(fout, "%s ", prefix); | 210 | f_print(fout, "%s ", prefix); | |
211 | } | 211 | } | |
212 | f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type); | 212 | f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type); | |
213 | } | 213 | } | |
214 | } | 214 | } | |
215 | 215 | |||
216 | static void | 216 | static void | |
217 | print_ifclose(int indent) | 217 | print_ifclose(int indent) | |
218 | { | 218 | { | |
219 | f_print(fout, "))\n"); | 219 | f_print(fout, "))\n"); | |
220 | tabify(fout, indent); | 220 | tabify(fout, indent); | |
221 | f_print(fout, "\treturn (FALSE);\n"); | 221 | f_print(fout, "\treturn (FALSE);\n"); | |
222 | } | 222 | } | |
223 | 223 | |||
224 | static void | 224 | static void | |
225 | print_ifstat(int indent, const char *prefix, const char *type, relation rel, | 225 | print_ifstat(int indent, const char *prefix, const char *type, relation rel, | |
226 | const char *amax, const char *objname, const char *name) | 226 | const char *amax, const char *objname, const char *name) | |
227 | { | 227 | { | |
228 | const char *alt = NULL; | 228 | const char *alt = NULL; | |
229 | 229 | |||
230 | switch (rel) { | 230 | switch (rel) { | |
231 | case REL_POINTER: | 231 | case REL_POINTER: | |
232 | print_ifopen(indent, "pointer"); | 232 | print_ifopen(indent, "pointer"); | |
233 | print_ifarg("(char **)(void *)"); | 233 | print_ifarg("(char **)(void *)"); | |
234 | f_print(fout, "%s", objname); | 234 | f_print(fout, "%s", objname); | |
235 | print_ifsizeof(prefix, type); | 235 | print_ifsizeof(prefix, type); | |
236 | break; | 236 | break; | |
237 | case REL_VECTOR: | 237 | case REL_VECTOR: | |
238 | if (streq(type, "string")) { | 238 | if (streq(type, "string")) { | |
239 | alt = "string"; | 239 | alt = "string"; | |
240 | } else | 240 | } else | |
241 | if (streq(type, "opaque")) { | 241 | if (streq(type, "opaque")) { | |
242 | alt = "opaque"; | 242 | alt = "opaque"; | |
243 | } | 243 | } | |
244 | if (alt) { | 244 | if (alt) { | |
245 | print_ifopen(indent, alt); | 245 | print_ifopen(indent, alt); | |
246 | print_ifarg(objname); | 246 | print_ifarg(objname); | |
247 | } else { | 247 | } else { | |
248 | print_ifopen(indent, "vector"); | 248 | print_ifopen(indent, "vector"); | |
249 | print_ifarg("(char *)(void *)"); | 249 | print_ifarg("(char *)(void *)"); | |
250 | f_print(fout, "%s", objname); | 250 | f_print(fout, "%s", objname); | |
251 | } | 251 | } | |
252 | print_ifarg(amax); | 252 | print_ifarg(amax); | |
253 | if (!alt) { | 253 | if (!alt) { | |
254 | print_ifsizeof(prefix, type); | 254 | print_ifsizeof(prefix, type); | |
255 | } | 255 | } | |
256 | break; | 256 | break; | |
257 | case REL_ARRAY: | 257 | case REL_ARRAY: | |
258 | if (streq(type, "string")) { | 258 | if (streq(type, "string")) { | |
259 | alt = "string"; | 259 | alt = "string"; | |
260 | } else | 260 | } else | |
261 | if (streq(type, "opaque")) { | 261 | if (streq(type, "opaque")) { | |
262 | alt = "bytes"; | 262 | alt = "bytes"; | |
263 | } | 263 | } | |
264 | if (streq(type, "string")) { | 264 | if (streq(type, "string")) { | |
265 | print_ifopen(indent, alt); | 265 | print_ifopen(indent, alt); | |
266 | print_ifarg(objname); | 266 | print_ifarg(objname); | |
267 | } else { | 267 | } else { | |
268 | if (alt) { | 268 | if (alt) { | |
269 | print_ifopen(indent, alt); | 269 | print_ifopen(indent, alt); | |
270 | } else { | 270 | } else { | |
271 | print_ifopen(indent, "array"); | 271 | print_ifopen(indent, "array"); | |
272 | } | 272 | } | |
273 | print_ifarg("(char **)(void *)"); | 273 | print_ifarg("(char **)(void *)"); | |
274 | if (*objname == '&') { | 274 | if (*objname == '&') { | |
275 | f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", | 275 | f_print(fout, "%s.%s_val, (unsigned int *)%s.%s_len", | |
276 | objname, name, objname, name); | 276 | objname, name, objname, name); | |
277 | } else { | 277 | } else { | |
278 | f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", | 278 | f_print(fout, "&%s->%s_val, (unsigned int *)&%s->%s_len", | |
279 | objname, name, objname, name); | 279 | objname, name, objname, name); | |
280 | } | 280 | } | |
281 | } | 281 | } | |
282 | print_ifarg(amax); | 282 | print_ifarg(amax); | |
283 | if (!alt) { | 283 | if (!alt) { | |
284 | print_ifsizeof(prefix, type); | 284 | print_ifsizeof(prefix, type); | |
285 | } | 285 | } | |
286 | break; | 286 | break; | |
287 | case REL_ALIAS: | 287 | case REL_ALIAS: | |
288 | print_ifopen(indent, type); | 288 | print_ifopen(indent, type); | |
289 | print_ifarg(objname); | 289 | print_ifarg(objname); | |
290 | break; | 290 | break; | |
291 | } | 291 | } | |
292 | print_ifclose(indent); | 292 | print_ifclose(indent); | |
293 | } | 293 | } | |
294 | /* ARGSUSED */ | 294 | /* ARGSUSED */ | |
295 | static void | 295 | static void | |
296 | emit_enum(definition *def) | 296 | emit_enum(definition *def) | |
297 | { | 297 | { | |
298 | tabify(fout, 1); | 298 | tabify(fout, 1); | |
299 | f_print(fout, "{\n"); | 299 | f_print(fout, "{\n"); | |
300 | tabify(fout, 2); | 300 | tabify(fout, 2); | |
301 | f_print(fout, "enum_t et = (enum_t)*objp;\n"); | 301 | f_print(fout, "enum_t et = (enum_t)*objp;\n"); | |
302 | print_ifopen(2, "enum"); | 302 | print_ifopen(2, "enum"); | |
303 | print_ifarg("&et"); | 303 | print_ifarg("&et"); | |
304 | print_ifclose(2); | 304 | print_ifclose(2); | |
305 | tabify(fout, 2); | 305 | tabify(fout, 2); | |
306 | f_print(fout, "*objp = (%s)et;\n", def->def_name); | 306 | f_print(fout, "*objp = (%s)et;\n", def->def_name); | |
307 | tabify(fout, 1); | 307 | tabify(fout, 1); | |
308 | f_print(fout, "}\n"); | 308 | f_print(fout, "}\n"); | |
309 | } | 309 | } | |
310 | 310 | |||
311 | static void | 311 | static void | |
312 | emit_program(definition *def) | 312 | emit_program(definition *def) | |
313 | { | 313 | { | |
314 | decl_list *dl; | 314 | decl_list *dl; | |
315 | version_list *vlist; | 315 | version_list *vlist; | |
316 | proc_list *plist; | 316 | proc_list *plist; | |
317 | 317 | |||
318 | for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) | 318 | for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) | |
319 | for (plist = vlist->procs; plist != NULL; plist = plist->next) { | 319 | for (plist = vlist->procs; plist != NULL; plist = plist->next) { | |
320 | if (!newstyle || plist->arg_num < 2) | 320 | if (!newstyle || plist->arg_num < 2) | |
321 | continue; /* old style, or single | 321 | continue; /* old style, or single | |
322 | * argument */ | 322 | * argument */ | |
323 | print_prog_header(plist); | 323 | print_prog_header(plist); | |
324 | for (dl = plist->args.decls; dl != NULL; | 324 | for (dl = plist->args.decls; dl != NULL; | |
325 | dl = dl->next) | 325 | dl = dl->next) | |
326 | print_stat(1, &dl->decl); | 326 | print_stat(1, &dl->decl); | |
327 | print_trailer(); | 327 | print_trailer(); | |
328 | } | 328 | } | |
329 | } | 329 | } | |
330 | 330 | |||
331 | 331 | |||
332 | static void | 332 | static void | |
333 | emit_union(definition *def) | 333 | emit_union(definition *def) | |
334 | { | 334 | { | |
335 | declaration *dflt; | 335 | declaration *dflt; | |
336 | case_list *cl; | 336 | case_list *cl; | |
337 | declaration *cs; | 337 | declaration *cs; | |
338 | char *object; | 338 | char *object; | |
339 | static const char vecformat[] = "objp->%s_u.%s"; | 339 | static const char vecformat[] = "objp->%s_u.%s"; | |
340 | static const char format[] = "&objp->%s_u.%s"; | 340 | static const char format[] = "&objp->%s_u.%s"; | |
341 | 341 | |||
342 | f_print(fout, "\n"); | 342 | f_print(fout, "\n"); | |
343 | print_stat(1, &def->def.un.enum_decl); | 343 | print_stat(1, &def->def.un.enum_decl); | |
344 | f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); | 344 | f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); | |
345 | for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { | 345 | for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { | |
346 | f_print(fout, "\tcase %s:\n", cl->case_name); | 346 | f_print(fout, "\tcase %s:\n", cl->case_name); | |
347 | if (cl->contflag == 1) /* a continued case statement */ | 347 | if (cl->contflag == 1) /* a continued case statement */ | |
348 | continue; | 348 | continue; | |
349 | cs = &cl->case_decl; | 349 | cs = &cl->case_decl; | |
350 | if (!streq(cs->type, "void")) { | 350 | if (!streq(cs->type, "void")) { | |
351 | object = alloc(strlen(def->def_name) + strlen(format) + | 351 | object = alloc(strlen(def->def_name) + strlen(format) + | |
352 | strlen(cs->name) + 1); | 352 | strlen(cs->name) + 1); | |
353 | if (isvectordef(cs->type, cs->rel)) { | 353 | if (isvectordef(cs->type, cs->rel)) { | |
354 | s_print(object, vecformat, def->def_name, | 354 | s_print(object, vecformat, def->def_name, | |
355 | cs->name); | 355 | cs->name); | |
356 | } else { | 356 | } else { | |
357 | s_print(object, format, def->def_name, | 357 | s_print(object, format, def->def_name, | |
358 | cs->name); | 358 | cs->name); | |
359 | } | 359 | } | |
360 | print_ifstat(2, cs->prefix, cs->type, cs->rel, | 360 | print_ifstat(2, cs->prefix, cs->type, cs->rel, | |
361 | cs->array_max, object, cs->name); | 361 | cs->array_max, object, cs->name); | |
362 | free(object); | 362 | free(object); | |
363 | } | 363 | } | |
364 | f_print(fout, "\t\tbreak;\n"); | 364 | f_print(fout, "\t\tbreak;\n"); | |
365 | } | 365 | } | |
366 | dflt = def->def.un.default_decl; | 366 | dflt = def->def.un.default_decl; | |
367 | f_print(fout, "\tdefault:\n"); | 367 | f_print(fout, "\tdefault:\n"); | |
368 | if (dflt != NULL) { | 368 | if (dflt != NULL) { | |
369 | if (!streq(dflt->type, "void")) { | 369 | if (!streq(dflt->type, "void")) { | |
370 | object = alloc(strlen(def->def_name) + strlen(format) + | 370 | object = alloc(strlen(def->def_name) + strlen(format) + | |
371 | strlen(dflt->name) + 1); | 371 | strlen(dflt->name) + 1); | |
372 | if (isvectordef(dflt->type, dflt->rel)) { | 372 | if (isvectordef(dflt->type, dflt->rel)) { | |
373 | s_print(object, vecformat, def->def_name, | 373 | s_print(object, vecformat, def->def_name, | |
374 | dflt->name); | 374 | dflt->name); | |
375 | } else { | 375 | } else { | |
376 | s_print(object, format, def->def_name, | 376 | s_print(object, format, def->def_name, | |
377 | dflt->name); | 377 | dflt->name); | |
378 | } | 378 | } | |
379 | print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, | 379 | print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, | |
380 | dflt->array_max, object, dflt->name); | 380 | dflt->array_max, object, dflt->name); | |
381 | free(object); | 381 | free(object); | |
382 | } | 382 | } | |
383 | f_print(fout, "\t\tbreak;\n"); | 383 | f_print(fout, "\t\tbreak;\n"); | |
384 | } else { | 384 | } else { | |
385 | f_print(fout, "\t\treturn (FALSE);\n"); | 385 | f_print(fout, "\t\treturn (FALSE);\n"); | |
386 | } | 386 | } | |
387 | 387 | |||
388 | f_print(fout, "\t}\n"); | 388 | f_print(fout, "\t}\n"); | |
389 | } | 389 | } | |
390 | 390 | |||
391 | static void | 391 | static void | |
392 | emit_struct(definition *def) | 392 | emit_struct(definition *def) | |
393 | { | 393 | { | |
394 | decl_list *dl; | 394 | decl_list *dl; | |
395 | int i, j, size, flag; | 395 | int i, j, size, flag; | |
396 | decl_list *cur = NULL, *psav; | 396 | decl_list *cur = NULL, *psav; | |
397 | bas_type *ptr; | 397 | bas_type *ptr; | |
398 | char *sizestr; | 398 | char *sizestr; | |
399 | const char *plus; | 399 | const char *plus; | |
400 | char ptemp[256]; | 400 | char ptemp[256]; | |
401 | int can_inline; | 401 | int can_inline; | |
402 | 402 | |||
403 | 403 | |||
404 | if (doinline == 0) { | 404 | if (doinline == 0) { | |
405 | f_print(fout, "\n"); | 405 | f_print(fout, "\n"); | |
406 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | 406 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | |
407 | print_stat(1, &dl->decl); | 407 | print_stat(1, &dl->decl); | |
408 | return; | 408 | return; | |
409 | } | 409 | } | |
410 | size = 0; | 410 | size = 0; | |
411 | can_inline = 0; | 411 | can_inline = 0; | |
412 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | 412 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | |
413 | if ((dl->decl.prefix == NULL) && | 413 | if ((dl->decl.prefix == NULL) && | |
414 | ((ptr = find_type(dl->decl.type)) != NULL) && | 414 | ((ptr = find_type(dl->decl.type)) != NULL) && | |
415 | ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { | 415 | ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { | |
416 | 416 | |||
417 | if (dl->decl.rel == REL_ALIAS) | 417 | if (dl->decl.rel == REL_ALIAS) | |
418 | size += ptr->length; | 418 | size += ptr->length; | |
419 | else { | 419 | else { | |
420 | can_inline = 1; | 420 | can_inline = 1; | |
421 | break; /* can be inlined */ | 421 | break; /* can be inlined */ | |
422 | }; | 422 | }; | |
423 | } else { | 423 | } else { | |
424 | if (size >= doinline) { | 424 | if (size >= doinline) { | |
425 | can_inline = 1; | 425 | can_inline = 1; | |
426 | break; /* can be inlined */ | 426 | break; /* can be inlined */ | |
427 | } | 427 | } | |
428 | size = 0; | 428 | size = 0; | |
429 | } | 429 | } | |
430 | if (size > doinline) | 430 | if (size > doinline) | |
431 | can_inline = 1; | 431 | can_inline = 1; | |
432 | 432 | |||
433 | if (can_inline == 0) { /* can not inline, drop back to old mode */ | 433 | if (can_inline == 0) { /* can not inline, drop back to old mode */ | |
434 | f_print(fout, "\n"); | 434 | f_print(fout, "\n"); | |
435 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | 435 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | |
436 | print_stat(1, &dl->decl); | 436 | print_stat(1, &dl->decl); | |
437 | return; | 437 | return; | |
438 | }; | 438 | }; | |
439 | 439 | |||
440 | /* May cause lint to complain. but ... */ | 440 | /* May cause lint to complain. but ... */ | |
441 | f_print(fout, "\tint32_t *buf;\n"); | 441 | f_print(fout, "\tint32_t *buf;\n"); | |
442 | 442 | |||
443 | flag = PUT; | 443 | flag = PUT; | |
444 | f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); | 444 | f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); | |
445 | 445 | |||
446 | for (j = 0; j < 2; j++) { | 446 | for (j = 0; j < 2; j++) { | |
447 | i = 0; | 447 | i = 0; | |
448 | size = 0; | 448 | size = 0; | |
449 | sizestr = NULL; | 449 | sizestr = NULL; | |
450 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */ | 450 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */ | |
451 | 451 | |||
452 | /* now walk down the list and check for basic types */ | 452 | /* now walk down the list and check for basic types */ | |
453 | if ((dl->decl.prefix == NULL) && ((ptr = find_type(dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { | 453 | if ((dl->decl.prefix == NULL) && ((ptr = find_type(dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { | |
454 | if (i == 0) | 454 | if (i == 0) | |
455 | cur = dl; | 455 | cur = dl; | |
456 | i++; | 456 | i++; | |
457 | 457 | |||
458 | if (dl->decl.rel == REL_ALIAS) | 458 | if (dl->decl.rel == REL_ALIAS) | |
459 | size += ptr->length; | 459 | size += ptr->length; | |
460 | else { | 460 | else { | |
461 | /* this is required to handle arrays */ | 461 | /* this is required to handle arrays */ | |
462 | 462 | |||
463 | if (sizestr == NULL) | 463 | if (sizestr == NULL) | |
464 | plus = ""; | 464 | plus = ""; | |
465 | else | 465 | else | |
466 | plus = " + "; | 466 | plus = " + "; | |
467 | 467 | |||
468 | if (ptr->length != 1) | 468 | if (ptr->length != 1) | |
469 | s_print(ptemp, "%s%s * %d", plus, dl->decl.array_max, ptr->length); | 469 | s_print(ptemp, "%s%s * %d", plus, dl->decl.array_max, ptr->length); | |
470 | else | 470 | else | |
471 | s_print(ptemp, "%s%s", plus, dl->decl.array_max); | 471 | s_print(ptemp, "%s%s", plus, dl->decl.array_max); | |
472 | 472 | |||
473 | /* now concatenate to sizestr !!!! */ | 473 | /* now concatenate to sizestr !!!! */ | |
474 | if (sizestr == NULL) | 474 | if (sizestr == NULL) | |
475 | sizestr = strdup(ptemp); | 475 | sizestr = strdup(ptemp); | |
476 | else { | 476 | else { | |
477 | char *nsizestr; | 477 | char *nsizestr; | |
478 | 478 | |||
479 | nsizestr = realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1); | 479 | nsizestr = realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1); | |
480 | if (nsizestr == NULL) { | 480 | if (nsizestr == NULL) { | |
481 | err(EXIT_FAILURE, "realloc"); | 481 | err(EXIT_FAILURE, "realloc"); | |
482 | } | 482 | } | |
483 | sizestr = nsizestr; | 483 | sizestr = nsizestr; | |
484 | sizestr = strcat(sizestr, ptemp); /* build up length of | 484 | sizestr = strcat(sizestr, ptemp); /* build up length of | |
485 | * array */ | 485 | * array */ | |
486 | 486 | |||
487 | } | 487 | } | |
488 | } | 488 | } | |
489 | 489 | |||
490 | } else { | 490 | } else { | |
491 | if (i > 0) { | 491 | if (i > 0) { | |
492 | if (sizestr == NULL && size < doinline) { | 492 | if (sizestr == NULL && size < doinline) { | |
493 | /* don't expand into inline | 493 | /* don't expand into inline | |
494 | * code if size < doinline */ | 494 | * code if size < doinline */ | |
495 | while (cur != dl) { | 495 | while (cur != dl) { | |
496 | print_stat(2, &cur->decl); | 496 | print_stat(2, &cur->decl); | |
497 | cur = cur->next; | 497 | cur = cur->next; | |
498 | } | 498 | } | |
499 | } else { | 499 | } else { | |
500 | 500 | |||
501 | 501 | |||
502 | 502 | |||
503 | /* were already looking at a | 503 | /* were already looking at a | |
504 | * xdr_inlineable structure */ | 504 | * xdr_inlineable structure */ | |
505 | if (sizestr == NULL) | 505 | if (sizestr == NULL) | |
506 | f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);\n", | 506 | f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);\n", | |
507 | size); | 507 | size); | |
508 | else | 508 | else | |
509 | if (size == 0) | 509 | if (size == 0) | |
510 | f_print(fout, | 510 | f_print(fout, | |
511 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);\n", | 511 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);\n", | |
512 | sizestr); | 512 | sizestr); | |
513 | else | 513 | else | |
514 | f_print(fout, | 514 | f_print(fout, | |
515 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s) * BYTES_PER_XDR_UNIT);\n", | 515 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s) * BYTES_PER_XDR_UNIT);\n", | |
516 | size, sizestr); | 516 | size, sizestr); | |
517 | 517 | |||
518 | f_print(fout, "\t\tif (buf == NULL) {\n"); | 518 | f_print(fout, "\t\tif (buf == NULL) {\n"); | |
519 | 519 | |||
520 | psav = cur; | 520 | psav = cur; | |
521 | while (cur != dl) { | 521 | while (cur != dl) { | |
522 | print_stat(3, &cur->decl); | 522 | print_stat(3, &cur->decl); | |
523 | cur = cur->next; | 523 | cur = cur->next; | |
524 | } | 524 | } | |
525 | 525 | |||
526 | f_print(fout, "\t\t} else {\n"); | 526 | f_print(fout, "\t\t} else {\n"); | |
527 | 527 | |||
528 | cur = psav; | 528 | cur = psav; | |
529 | while (cur != dl) { | 529 | while (cur != dl) { | |
530 | emit_inline(&cur->decl, flag); | 530 | emit_inline(&cur->decl, flag); | |
531 | cur = cur->next; | 531 | cur = cur->next; | |
532 | } | 532 | } | |
533 | 533 | |||
534 | f_print(fout, "\t\t}\n"); | 534 | f_print(fout, "\t\t}\n"); | |
535 | } | 535 | } | |
536 | } | 536 | } | |
537 | size = 0; | 537 | size = 0; | |
538 | i = 0; | 538 | i = 0; | |
539 | if (sizestr) { | 539 | if (sizestr) { | |
540 | free(sizestr); | 540 | free(sizestr); | |
541 | sizestr = NULL; | 541 | sizestr = NULL; | |
542 | } | 542 | } | |
543 | print_stat(2, &dl->decl); | 543 | print_stat(2, &dl->decl); | |
544 | } | 544 | } | |
545 | 545 | |||
546 | } | 546 | } | |
547 | if (i > 0) { | 547 | if (i > 0) { | |
548 | if (sizestr == NULL && size < doinline) { | 548 | if (sizestr == NULL && size < doinline) { | |
549 | /* don't expand into inline code if size < | 549 | /* don't expand into inline code if size < | |
550 | * doinline */ | 550 | * doinline */ | |
551 | while (cur != dl) { | 551 | while (cur != dl) { | |
552 | print_stat(2, &cur->decl); | 552 | print_stat(2, &cur->decl); | |
553 | cur = cur->next; | 553 | cur = cur->next; | |
554 | } | 554 | } | |
555 | } else { | 555 | } else { | |
556 | 556 | |||
557 | /* were already looking at a xdr_inlineable | 557 | /* were already looking at a xdr_inlineable | |
558 | * structure */ | 558 | * structure */ | |
559 | if (sizestr == NULL) | 559 | if (sizestr == NULL) | |
560 | f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);\n", | 560 | f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);\n", | |
561 | size); | 561 | size); | |
562 | else | 562 | else | |
563 | if (size == 0) | 563 | if (size == 0) | |
564 | f_print(fout, | 564 | f_print(fout, | |
565 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);\n", | 565 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);\n", | |
566 | sizestr); | 566 | sizestr); | |
567 | else | 567 | else | |
568 | f_print(fout, | 568 | f_print(fout, | |
569 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s) * BYTES_PER_XDR_UNIT);\n", | 569 | "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s) * BYTES_PER_XDR_UNIT);\n", | |
570 | size, sizestr); | 570 | size, sizestr); | |
571 | 571 | |||
572 | f_print(fout, "\t\tif (buf == NULL) {\n"); | 572 | f_print(fout, "\t\tif (buf == NULL) {\n"); | |
573 | 573 | |||
574 | psav = cur; | 574 | psav = cur; | |
575 | while (cur != NULL) { | 575 | while (cur != NULL) { | |
576 | print_stat(3, &cur->decl); | 576 | print_stat(3, &cur->decl); | |
577 | cur = cur->next; | 577 | cur = cur->next; | |
578 | } | 578 | } | |
579 | f_print(fout, "\t\t} else {\n"); | 579 | f_print(fout, "\t\t} else {\n"); | |
580 | 580 | |||
581 | cur = psav; | 581 | cur = psav; | |
582 | while (cur != dl) { | 582 | while (cur != dl) { | |
583 | emit_inline(&cur->decl, flag); | 583 | emit_inline(&cur->decl, flag); | |
584 | cur = cur->next; | 584 | cur = cur->next; | |
585 | } | 585 | } | |
586 | 586 | |||
587 | f_print(fout, "\t\t}\n"); | 587 | f_print(fout, "\t\t}\n"); | |
588 | 588 | |||
589 | } | 589 | } | |
590 | } | 590 | } | |
591 | if (flag == PUT) { | 591 | if (flag == PUT) { | |
592 | flag = GET; | 592 | flag = GET; | |
593 | f_print(fout, "\t} else if (xdrs->x_op == XDR_DECODE) {\n"); | 593 | f_print(fout, "\t} else if (xdrs->x_op == XDR_DECODE) {\n"); | |
594 | } | 594 | } | |
595 | } | 595 | } | |
596 | 596 | |||
597 | f_print(fout, "\t} else {\n"); | 597 | f_print(fout, "\t} else {\n"); | |
598 | 598 | |||
599 | /* now take care of XDR_FREE case */ | 599 | /* now take care of XDR_FREE case */ | |
600 | 600 | |||
601 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | 601 | for (dl = def->def.st.decls; dl != NULL; dl = dl->next) | |
602 | print_stat(2, &dl->decl); | 602 | print_stat(2, &dl->decl); | |
603 | 603 | |||
604 | f_print(fout, "\t}\n"); | 604 | f_print(fout, "\t}\n"); | |
605 | } | 605 | } | |
606 | 606 | |||
607 | static void | 607 | static void | |
608 | emit_typedef(definition *def) | 608 | emit_typedef(definition *def) | |
609 | { | 609 | { | |
610 | const char *prefix = def->def.ty.old_prefix; | 610 | const char *prefix = def->def.ty.old_prefix; | |
611 | const char *type = def->def.ty.old_type; | 611 | const char *type = def->def.ty.old_type; | |
612 | const char *amax = def->def.ty.array_max; | 612 | const char *amax = def->def.ty.array_max; | |
613 | relation rel = def->def.ty.rel; | 613 | relation rel = def->def.ty.rel; | |
614 | 614 | |||
615 | f_print(fout, "\n"); | 615 | f_print(fout, "\n"); | |
616 | print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); | 616 | print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); | |
617 | } | 617 | } | |
618 | 618 | |||
619 | static void | 619 | static void | |
620 | print_stat(int indent, declaration *dec) | 620 | print_stat(int indent, declaration *dec) | |
621 | { | 621 | { | |
622 | const char *prefix = dec->prefix; | 622 | const char *prefix = dec->prefix; | |
623 | const char *type = dec->type; | 623 | const char *type = dec->type; | |
624 | const char *amax = dec->array_max; | 624 | const char *amax = dec->array_max; | |
625 | relation rel = dec->rel; | 625 | relation rel = dec->rel; | |
626 | char name[256]; | 626 | char name[256]; | |
627 | 627 | |||
628 | if (isvectordef(type, rel)) { | 628 | if (isvectordef(type, rel)) { | |
629 | s_print(name, "objp->%s", dec->name); | 629 | s_print(name, "objp->%s", dec->name); | |
630 | } else { | 630 | } else { | |
631 | s_print(name, "&objp->%s", dec->name); | 631 | s_print(name, "&objp->%s", dec->name); | |
632 | } | 632 | } | |
633 | print_ifstat(indent, prefix, type, rel, amax, name, dec->name); | 633 | print_ifstat(indent, prefix, type, rel, amax, name, dec->name); | |
634 | } | 634 | } | |
635 | 635 | |||
636 | 636 | |||
637 | void | 637 | void | |
638 | emit_inline(declaration *decl, int flag) | 638 | emit_inline(declaration *decl, int flag) | |
639 | { | 639 | { | |
640 | 640 | |||
641 | /*check whether an array or not */ | 641 | /*check whether an array or not */ | |
642 | 642 | |||
643 | switch (decl->rel) { | 643 | switch (decl->rel) { | |
644 | case REL_ALIAS: | 644 | case REL_ALIAS: | |
645 | emit_single_in_line(decl, flag, REL_ALIAS); | 645 | emit_single_in_line(decl, flag, REL_ALIAS); | |
646 | break; | 646 | break; | |
647 | case REL_VECTOR: | 647 | case REL_VECTOR: | |
648 | f_print(fout, "\t\t\t{\n"); | 648 | f_print(fout, "\t\t\t{\n"); | |
649 | f_print(fout, "\t\t\t\tint i;\n"); | 649 | f_print(fout, "\t\t\t\tint i;\n"); | |
650 | f_print(fout, "\t\t\t\t%s *genp;\n", decl->type); | 650 | f_print(fout, "\t\t\t\t%s *genp;\n", decl->type); | |
651 | f_print(fout, "\n"); | 651 | f_print(fout, "\n"); | |
652 | f_print(fout, "\t\t\t\tfor (i = 0, genp = objp->%s;\n", | 652 | f_print(fout, "\t\t\t\tfor (i = 0, genp = objp->%s;\n", | |
653 | decl->name); | 653 | decl->name); | |
654 | f_print(fout, "\t\t\t\t i < %s; i++) {\n\t\t", | 654 | f_print(fout, "\t\t\t\t i < %s; i++) {\n\t\t", | |
655 | decl->array_max); | 655 | decl->array_max); | |
656 | emit_single_in_line(decl, flag, REL_VECTOR); | 656 | emit_single_in_line(decl, flag, REL_VECTOR); | |
657 | f_print(fout, "\t\t\t\t}\n\t\t\t}\n"); | 657 | f_print(fout, "\t\t\t\t}\n\t\t\t}\n"); | |
658 | break; | 658 | break; | |
659 | case REL_ARRAY: | 659 | case REL_ARRAY: | |
660 | case REL_POINTER: | 660 | case REL_POINTER: | |
661 | errx(1, "Internal error at %s:%d: Case %d not handled", | 661 | errx(1, "Internal error at %s:%d: Case %d not handled", | |
662 | __FILE__, __LINE__, decl->rel); | 662 | __FILE__, __LINE__, decl->rel); | |
663 | } | 663 | } | |
664 | } | 664 | } | |
665 | 665 | |||
666 | void | 666 | void | |
667 | emit_single_in_line(declaration *decl, int flag, relation rel) | 667 | emit_single_in_line(declaration *decl, int flag, relation rel) | |
668 | { | 668 | { | |
669 | const char *upp_case; | 669 | const char *upp_case; | |
670 | char *freeable; | 670 | char *freeable; | |
671 | int freed = 0; | 671 | int freed = 0; | |
672 | 672 | |||
673 | if (flag == PUT) | 673 | if (flag == PUT) | |
674 | f_print(fout, "\t\t\tIXDR_PUT_"); | 674 | f_print(fout, "\t\t\tIXDR_PUT_"); | |
675 | else | 675 | else | |
676 | if (rel == REL_ALIAS) | 676 | if (rel == REL_ALIAS) | |
677 | f_print(fout, "\t\t\tobjp->%s = IXDR_GET_", decl->name); | 677 | f_print(fout, "\t\t\tobjp->%s = IXDR_GET_", decl->name); | |
678 | else | 678 | else | |
679 | f_print(fout, "\t\t\t*genp++ = IXDR_GET_"); | 679 | f_print(fout, "\t\t\t*genp++ = IXDR_GET_"); | |
680 | 680 | |||
681 | upp_case = freeable = upcase(decl->type); | 681 | upp_case = freeable = upcase(decl->type); | |
682 | 682 | |||
683 | /* hack - XX */ | 683 | /* hack - XX */ | |
684 | if (strcmp(upp_case, "INT") == 0) { | 684 | if (strcmp(upp_case, "INT") == 0) { | |
685 | free(freeable); | 685 | free(freeable); | |
686 | freed = 1; | 686 | freed = 1; | |
687 | upp_case = "INT32"; | 687 | upp_case = "INT32"; | |
688 | } else if (strcmp(upp_case, "U_INT") == 0) { | 688 | } else if (strcmp(upp_case, "U_INT") == 0) { | |
689 | free(freeable); | 689 | free(freeable); | |
690 | freed = 1; | 690 | freed = 1; | |
691 | upp_case = "U_INT32"; | 691 | upp_case = "U_INT32"; | |
692 | } | 692 | } | |
693 | if (flag == PUT) { | 693 | if (flag == PUT) { | |
694 | if (rel == REL_ALIAS) | 694 | if (rel == REL_ALIAS) | |
695 | f_print(fout, "%s(buf, objp->%s);\n", upp_case, decl->name); | 695 | f_print(fout, "%s(buf, objp->%s);\n", upp_case, decl->name); | |
696 | else | 696 | else | |
697 | f_print(fout, "%s(buf, *genp++);\n", upp_case); | 697 | f_print(fout, "%s(buf, *genp++);\n", upp_case); | |
698 | 698 | |||
699 | } else | 699 | } else | |
700 | f_print(fout, "%s(buf);\n", upp_case); | 700 | f_print(fout, "%s(buf);\n", upp_case); | |
701 | if (!freed) | 701 | if (!freed) | |
702 | free(freeable); | 702 | free(freeable); | |
703 | 703 | |||
704 | } | 704 | } | |
705 | 705 | |||
706 | 706 | |||
707 | char * | 707 | char * | |
708 | upcase(const char *str) | 708 | upcase(const char *str) | |
709 | { | 709 | { | |
710 | char *ptr, *hptr; | 710 | char *ptr, *hptr; | |
711 | 711 | |||
712 | 712 | |||
713 | ptr = malloc(strlen(str) + 1); | 713 | ptr = malloc(strlen(str) + 1); | |
714 | if (ptr == NULL) { | 714 | if (ptr == NULL) { | |
715 | errx(EXIT_FAILURE, "Out of memory"); | 715 | errx(EXIT_FAILURE, "Out of memory"); | |
716 | } | 716 | } | |
717 | 717 | |||
718 | hptr = ptr; | 718 | hptr = ptr; | |
719 | while (*str != '\0') | 719 | while (*str != '\0') | |
720 | *ptr++ = toupper((unsigned char)*str++); | 720 | *ptr++ = toupper((unsigned char)*str++); | |
721 | 721 | |||
722 | *ptr = '\0'; | 722 | *ptr = '\0'; | |
723 | return (hptr); | 723 | return (hptr); | |
724 | 724 | |||
725 | } | 725 | } |
--- src/usr.bin/rpcgen/rpc_hout.c 2015/09/20 15:45:07 1.24
+++ src/usr.bin/rpcgen/rpc_hout.c 2016/01/23 02:33:09 1.25
@@ -1,543 +1,543 @@ | @@ -1,543 +1,543 @@ | |||
1 | /* $NetBSD: rpc_hout.c,v 1.24 2015/09/20 15:45:07 kamil Exp $ */ | 1 | /* $NetBSD: rpc_hout.c,v 1.25 2016/01/23 02:33:09 dholland Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
4 | * unrestricted use provided that this legend is included on all tape | 4 | * unrestricted use provided that this legend is included on all tape | |
5 | * media and as a part of the software program in whole or part. Users | 5 | * media and as a part of the software program in whole or part. Users | |
6 | * may copy or modify Sun RPC without charge, but are not authorized | 6 | * may copy or modify Sun RPC without charge, but are not authorized | |
7 | * to license or distribute it to anyone else except as part of a product or | 7 | * to license or distribute it to anyone else except as part of a product or | |
8 | * program developed by the user or with the express written consent of | 8 | * program developed by the user or with the express written consent of | |
9 | * Sun Microsystems, Inc. | 9 | * Sun Microsystems, Inc. | |
10 | * | 10 | * | |
11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
14 | * | 14 | * | |
15 | * Sun RPC is provided with no support and without any obligation on the | 15 | * Sun RPC is provided with no support and without any obligation on the | |
16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
17 | * modification or enhancement. | 17 | * modification or enhancement. | |
18 | * | 18 | * | |
19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
21 | * OR ANY PART THEREOF. | 21 | * OR ANY PART THEREOF. | |
22 | * | 22 | * | |
23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
24 | * or profits or other special, indirect and consequential damages, even if | 24 | * or profits or other special, indirect and consequential damages, even if | |
25 | * Sun has been advised of the possibility of such damages. | 25 | * Sun has been advised of the possibility of such damages. | |
26 | * | 26 | * | |
27 | * Sun Microsystems, Inc. | 27 | * Sun Microsystems, Inc. | |
28 | * 2550 Garcia Avenue | 28 | * 2550 Garcia Avenue | |
29 | * Mountain View, California 94043 | 29 | * Mountain View, California 94043 | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(lint) | 37 | #if defined(__RCSID) && !defined(lint) | |
38 | #if 0 | 38 | #if 0 | |
39 | static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI"; | 39 | static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI"; | |
40 | #else | 40 | #else | |
41 | __RCSID("$NetBSD: rpc_hout.c,v 1.24 2015/09/20 15:45:07 kamil Exp $"); | 41 | __RCSID("$NetBSD: rpc_hout.c,v 1.25 2016/01/23 02:33:09 dholland Exp $"); | |
42 | #endif | 42 | #endif | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | /* | 45 | /* | |
46 | * rpc_hout.c, Header file outputter for the RPC protocol compiler | 46 | * rpc_hout.c, Header file outputter for the RPC protocol compiler | |
47 | */ | 47 | */ | |
48 | #include <ctype.h> | 48 | #include <ctype.h> | |
49 | #include <err.h> | 49 | #include <err.h> | |
50 | #include <stdio.h> | 50 | #include <stdio.h> | |
51 | #include "rpc_scan.h" | 51 | #include "rpc_scan.h" | |
52 | #include "rpc_parse.h" | 52 | #include "rpc_parse.h" | |
53 | #include "rpc_util.h" | 53 | #include "rpc_util.h" | |
54 | 54 | |||
55 | static void pconstdef(definition *); | 55 | static void pconstdef(definition *); | |
56 | static void pargdef(definition *); | 56 | static void pargdef(definition *); | |
57 | static void pstructdef(definition *); | 57 | static void pstructdef(definition *); | |
58 | static void puniondef(definition *); | 58 | static void puniondef(definition *); | |
59 | static void pdefine(const char *, const char *); | 59 | static void pdefine(const char *, const char *); | |
60 | static void puldefine(const char *, const char *); | 60 | static void puldefine(const char *, const char *); | |
61 | static int define_printed(proc_list *, version_list *); | 61 | static int define_printed(proc_list *, version_list *); | |
62 | static void pprogramdef(definition *); | 62 | static void pprogramdef(definition *); | |
63 | static void penumdef(definition *); | 63 | static void penumdef(definition *); | |
64 | static void ptypedef(definition *); | 64 | static void ptypedef(definition *); | |
65 | static int undefined2(const char *, const char *); | 65 | static int undefined2(const char *, const char *); | |
66 | static void cplusplusstart(void); | 66 | static void cplusplusstart(void); | |
67 | static void cplusplusend(void); | 67 | static void cplusplusend(void); | |
68 | 68 | |||
69 | /* | 69 | /* | |
70 | * Print the C-version of an xdr definition | 70 | * Print the C-version of an xdr definition | |
71 | */ | 71 | */ | |
72 | void | 72 | void | |
73 | print_datadef(definition *def) | 73 | print_datadef(definition *def) | |
74 | { | 74 | { | |
75 | 75 | |||
76 | if (def->def_kind == DEF_PROGRAM) /* handle data only */ | 76 | if (def->def_kind == DEF_PROGRAM) /* handle data only */ | |
77 | return; | 77 | return; | |
78 | 78 | |||
79 | if (def->def_kind != DEF_CONST) { | 79 | if (def->def_kind != DEF_CONST) { | |
80 | f_print(fout, "\n"); | 80 | f_print(fout, "\n"); | |
81 | } | 81 | } | |
82 | switch (def->def_kind) { | 82 | switch (def->def_kind) { | |
83 | case DEF_STRUCT: | 83 | case DEF_STRUCT: | |
84 | pstructdef(def); | 84 | pstructdef(def); | |
85 | break; | 85 | break; | |
86 | case DEF_UNION: | 86 | case DEF_UNION: | |
87 | puniondef(def); | 87 | puniondef(def); | |
88 | break; | 88 | break; | |
89 | case DEF_ENUM: | 89 | case DEF_ENUM: | |
90 | penumdef(def); | 90 | penumdef(def); | |
91 | break; | 91 | break; | |
92 | case DEF_TYPEDEF: | 92 | case DEF_TYPEDEF: | |
93 | ptypedef(def); | 93 | ptypedef(def); | |
94 | break; | 94 | break; | |
95 | case DEF_PROGRAM: | 95 | case DEF_PROGRAM: | |
96 | pprogramdef(def); | 96 | pprogramdef(def); | |
97 | break; | 97 | break; | |
98 | case DEF_CONST: | 98 | case DEF_CONST: | |
99 | pconstdef(def); | 99 | pconstdef(def); | |
100 | break; | 100 | break; | |
101 | } | 101 | } | |
102 | } | 102 | } | |
103 | 103 | |||
104 | void | 104 | void | |
105 | print_progdef(definition *def) | 105 | print_progdef(definition *def) | |
106 | { | 106 | { | |
107 | switch (def->def_kind) { | 107 | switch (def->def_kind) { | |
108 | case DEF_PROGRAM: | 108 | case DEF_PROGRAM: | |
109 | f_print(fout, "\n"); | 109 | f_print(fout, "\n"); | |
110 | pprogramdef(def); | 110 | pprogramdef(def); | |
111 | break; | 111 | break; | |
112 | case DEF_CONST: | 112 | case DEF_CONST: | |
113 | case DEF_TYPEDEF: | 113 | case DEF_TYPEDEF: | |
114 | case DEF_ENUM: | 114 | case DEF_ENUM: | |
115 | case DEF_UNION: | 115 | case DEF_UNION: | |
116 | case DEF_STRUCT: | 116 | case DEF_STRUCT: | |
117 | break; | 117 | break; | |
118 | } | 118 | } | |
119 | } | 119 | } | |
120 | 120 | |||
121 | void | 121 | void | |
122 | print_funcdef(definition *def, int *did) | 122 | print_funcdef(definition *def, int *did) | |
123 | { | 123 | { | |
124 | switch (def->def_kind) { | 124 | switch (def->def_kind) { | |
125 | case DEF_PROGRAM: | 125 | case DEF_PROGRAM: | |
126 | case DEF_CONST: | 126 | case DEF_CONST: | |
127 | break; | 127 | break; | |
128 | case DEF_TYPEDEF: | 128 | case DEF_TYPEDEF: | |
129 | case DEF_ENUM: | 129 | case DEF_ENUM: | |
130 | case DEF_UNION: | 130 | case DEF_UNION: | |
131 | case DEF_STRUCT: | 131 | case DEF_STRUCT: | |
132 | if (!*did) { | 132 | if (!*did) { | |
133 | f_print(fout, "\n"); | 133 | f_print(fout, "\n"); | |
134 | cplusplusstart(); | 134 | cplusplusstart(); | |
135 | *did = 1; | 135 | *did = 1; | |
136 | } | 136 | } | |
137 | pxdrfuncdecl(def->def_name, | 137 | pxdrfuncdecl(def->def_name, | |
138 | def->def_kind != DEF_TYPEDEF || | 138 | def->def_kind != DEF_TYPEDEF || | |
139 | !isvectordef(def->def.ty.old_type, def->def.ty.rel)); | 139 | !isvectordef(def->def.ty.old_type, def->def.ty.rel)); | |
140 | break; | 140 | break; | |
141 | } | 141 | } | |
142 | } | 142 | } | |
143 | 143 | |||
144 | void | 144 | void | |
145 | print_funcend(int did) { | 145 | print_funcend(int did) { | |
146 | if (did) { | 146 | if (did) { | |
147 | cplusplusend(); | 147 | cplusplusend(); | |
148 | } | 148 | } | |
149 | } | 149 | } | |
150 | 150 | |||
151 | void | 151 | void | |
152 | pxdrfuncdecl(const char *name, int pointerp) | 152 | pxdrfuncdecl(const char *name, int pointerp) | |
153 | { | 153 | { | |
154 | 154 | |||
155 | f_print(fout, "bool_t xdr_%s(XDR *, %s%s);\n", name, | 155 | f_print(fout, "bool_t xdr_%s(XDR *, %s%s);\n", name, | |
156 | name, pointerp ? (" *") : ""); | 156 | name, pointerp ? (" *") : ""); | |
157 | } | 157 | } | |
158 | 158 | |||
159 | 159 | |||
160 | static void | 160 | static void | |
161 | pconstdef(definition *def) | 161 | pconstdef(definition *def) | |
162 | { | 162 | { | |
163 | pdefine(def->def_name, def->def.co); | 163 | pdefine(def->def_name, def->def.co); | |
164 | } | 164 | } | |
165 | 165 | |||
166 | /* print out the definitions for the arguments of functions in the | 166 | /* print out the definitions for the arguments of functions in the | |
167 | header file | 167 | header file | |
168 | */ | 168 | */ | |
169 | static void | 169 | static void | |
170 | pargdef(definition *def) | 170 | pargdef(definition *def) | |
171 | { | 171 | { | |
172 | decl_list *l; | 172 | decl_list *l; | |
173 | version_list *vers; | 173 | version_list *vers; | |
174 | char *name; | 174 | char *name; | |
175 | proc_list *plist; | 175 | proc_list *plist; | |
176 | int did; | 176 | int did; | |
177 | 177 | |||
178 | 178 | |||
179 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | 179 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | |
180 | for (plist = vers->procs; plist != NULL; plist = plist->next) { | 180 | for (plist = vers->procs; plist != NULL; plist = plist->next) { | |
181 | if (!newstyle || plist->arg_num < 2) { | 181 | if (!newstyle || plist->arg_num < 2) { | |
182 | continue; /* old style or single args */ | 182 | continue; /* old style or single args */ | |
183 | } | 183 | } | |
184 | name = plist->args.argname; | 184 | name = plist->args.argname; | |
185 | f_print(fout, "struct %s {\n", name); | 185 | f_print(fout, "struct %s {\n", name); | |
186 | for (l = plist->args.decls; | 186 | for (l = plist->args.decls; | |
187 | l != NULL; l = l->next) { | 187 | l != NULL; l = l->next) { | |
188 | pdeclaration(name, &l->decl, 1, ";\n"); | 188 | pdeclaration(name, &l->decl, 1, ";\n"); | |
189 | } | 189 | } | |
190 | f_print(fout, "};\n"); | 190 | f_print(fout, "};\n"); | |
191 | f_print(fout, "typedef struct %s %s;\n", name, name); | 191 | f_print(fout, "typedef struct %s %s;\n", name, name); | |
192 | } | 192 | } | |
193 | } | 193 | } | |
194 | did = 0; | 194 | did = 0; | |
195 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | 195 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | |
196 | for (plist = vers->procs; plist != NULL; plist = plist->next) { | 196 | for (plist = vers->procs; plist != NULL; plist = plist->next) { | |
197 | if (!newstyle || plist->arg_num < 2) { | 197 | if (!newstyle || plist->arg_num < 2) { | |
198 | continue; /* old style or single args */ | 198 | continue; /* old style or single args */ | |
199 | } | 199 | } | |
200 | 200 | |||
201 | if (!did) { | 201 | if (!did) { | |
202 | cplusplusstart(); | 202 | cplusplusstart(); | |
203 | did = 1; | 203 | did = 1; | |
204 | } | 204 | } | |
205 | pxdrfuncdecl(plist->args.argname, 1); | 205 | pxdrfuncdecl(plist->args.argname, 1); | |
206 | } | 206 | } | |
207 | } | 207 | } | |
208 | if (did) { | 208 | if (did) { | |
209 | cplusplusend(); | 209 | cplusplusend(); | |
210 | } | 210 | } | |
211 | 211 | |||
212 | } | 212 | } | |
213 | 213 | |||
214 | 214 | |||
215 | static void | 215 | static void | |
216 | pstructdef(definition *def) | 216 | pstructdef(definition *def) | |
217 | { | 217 | { | |
218 | decl_list *l; | 218 | decl_list *l; | |
219 | const char *name = def->def_name; | 219 | const char *name = def->def_name; | |
220 | 220 | |||
221 | f_print(fout, "struct %s {\n", name); | 221 | f_print(fout, "struct %s {\n", name); | |
222 | for (l = def->def.st.decls; l != NULL; l = l->next) { | 222 | for (l = def->def.st.decls; l != NULL; l = l->next) { | |
223 | pdeclaration(name, &l->decl, 1, ";\n"); | 223 | pdeclaration(name, &l->decl, 1, ";\n"); | |
224 | } | 224 | } | |
225 | f_print(fout, "};\n"); | 225 | f_print(fout, "};\n"); | |
226 | f_print(fout, "typedef struct %s %s;\n", name, name); | 226 | f_print(fout, "typedef struct %s %s;\n", name, name); | |
227 | } | 227 | } | |
228 | 228 | |||
229 | static void | 229 | static void | |
230 | puniondef(definition *def) | 230 | puniondef(definition *def) | |
231 | { | 231 | { | |
232 | case_list *l; | 232 | case_list *l; | |
233 | const char *name = def->def_name; | 233 | const char *name = def->def_name; | |
234 | declaration *decl; | 234 | declaration *decl; | |
235 | 235 | |||
236 | f_print(fout, "struct %s {\n", name); | 236 | f_print(fout, "struct %s {\n", name); | |
237 | decl = &def->def.un.enum_decl; | 237 | decl = &def->def.un.enum_decl; | |
238 | if (streq(decl->type, "bool")) { | 238 | if (streq(decl->type, "bool")) { | |
239 | f_print(fout, "\tbool_t %s;\n", decl->name); | 239 | f_print(fout, "\tbool_t %s;\n", decl->name); | |
240 | } else { | 240 | } else { | |
241 | f_print(fout, "\t%s %s;\n", decl->type, decl->name); | 241 | f_print(fout, "\t%s %s;\n", decl->type, decl->name); | |
242 | } | 242 | } | |
243 | f_print(fout, "\tunion {\n"); | 243 | f_print(fout, "\tunion {\n"); | |
244 | for (l = def->def.un.cases; l != NULL; l = l->next) { | 244 | for (l = def->def.un.cases; l != NULL; l = l->next) { | |
245 | if (l->contflag == 0) | 245 | if (l->contflag == 0) | |
246 | pdeclaration(name, &l->case_decl, 2, ";\n"); | 246 | pdeclaration(name, &l->case_decl, 2, ";\n"); | |
247 | } | 247 | } | |
248 | decl = def->def.un.default_decl; | 248 | decl = def->def.un.default_decl; | |
249 | if (decl && !streq(decl->type, "void")) { | 249 | if (decl && !streq(decl->type, "void")) { | |
250 | pdeclaration(name, decl, 2, ";\n"); | 250 | pdeclaration(name, decl, 2, ";\n"); | |
251 | } | 251 | } | |
252 | f_print(fout, "\t} %s_u;\n", name); | 252 | f_print(fout, "\t} %s_u;\n", name); | |
253 | f_print(fout, "};\n"); | 253 | f_print(fout, "};\n"); | |
254 | f_print(fout, "typedef struct %s %s;\n", name, name); | 254 | f_print(fout, "typedef struct %s %s;\n", name, name); | |
255 | } | 255 | } | |
256 | 256 | |||
257 | static void | 257 | static void | |
258 | pdefine(const char *name, const char *num) | 258 | pdefine(const char *name, const char *num) | |
259 | { | 259 | { | |
260 | f_print(fout, "#define %s %s\n", name, num); | 260 | f_print(fout, "#define %s %s\n", name, num); | |
261 | } | 261 | } | |
262 | 262 | |||
263 | static void | 263 | static void | |
264 | puldefine(const char *name, const char *num) | 264 | puldefine(const char *name, const char *num) | |
265 | { | 265 | { | |
266 | f_print(fout, "#define %s %s\n", name, num); | 266 | f_print(fout, "#define %s %s\n", name, num); | |
267 | } | 267 | } | |
268 | 268 | |||
269 | static int | 269 | static int | |
270 | define_printed(proc_list *stop, version_list *start) | 270 | define_printed(proc_list *stop, version_list *start) | |
271 | { | 271 | { | |
272 | version_list *vers; | 272 | version_list *vers; | |
273 | proc_list *proc; | 273 | proc_list *proc; | |
274 | 274 | |||
275 | for (vers = start; vers != NULL; vers = vers->next) { | 275 | for (vers = start; vers != NULL; vers = vers->next) { | |
276 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | 276 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | |
277 | if (proc == stop) { | 277 | if (proc == stop) { | |
278 | return (0); | 278 | return (0); | |
279 | } else | 279 | } else | |
280 | if (streq(proc->proc_name, stop->proc_name)) { | 280 | if (streq(proc->proc_name, stop->proc_name)) { | |
281 | return (1); | 281 | return (1); | |
282 | } | 282 | } | |
283 | } | 283 | } | |
284 | } | 284 | } | |
285 | errx(1, "Internal error at %s:%d: procedure not found", | 285 | errx(1, "Internal error at %s:%d: procedure not found", | |
286 | __FILE__, __LINE__); | 286 | __FILE__, __LINE__); | |
287 | /* NOTREACHED */ | 287 | /* NOTREACHED */ | |
288 | } | 288 | } | |
289 | 289 | |||
290 | static void | 290 | static void | |
291 | cplusplusstart(void) | 291 | cplusplusstart(void) | |
292 | { | 292 | { | |
293 | if (BSDflag) | 293 | if (BSDflag) | |
294 | f_print(fout, "__BEGIN_DECLS\n"); | 294 | f_print(fout, "__BEGIN_DECLS\n"); | |
295 | else | 295 | else | |
296 | f_print(fout, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); | 296 | f_print(fout, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); | |
297 | } | 297 | } | |
298 | 298 | |||
299 | static void | 299 | static void | |
300 | cplusplusend(void) | 300 | cplusplusend(void) | |
301 | { | 301 | { | |
302 | if (BSDflag) | 302 | if (BSDflag) | |
303 | f_print(fout, "__END_DECLS\n"); | 303 | f_print(fout, "__END_DECLS\n"); | |
304 | else | 304 | else | |
305 | f_print(fout, "#ifdef __cplusplus\n};\n#endif\n"); | 305 | f_print(fout, "#ifdef __cplusplus\n};\n#endif\n"); | |
306 | } | 306 | } | |
307 | 307 | |||
308 | static void | 308 | static void | |
309 | pprogramdef(definition *def) | 309 | pprogramdef(definition *def) | |
310 | { | 310 | { | |
311 | version_list *vers; | 311 | version_list *vers; | |
312 | proc_list *proc; | 312 | proc_list *proc; | |
313 | 313 | |||
314 | pargdef(def); | 314 | pargdef(def); | |
315 | 315 | |||
316 | puldefine(def->def_name, def->def.pr.prog_num); | 316 | puldefine(def->def_name, def->def.pr.prog_num); | |
317 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | 317 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | |
318 | if (tblflag) { | 318 | if (tblflag) { | |
319 | f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", | 319 | f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", | |
320 | locase(def->def_name), vers->vers_num); | 320 | locase(def->def_name), vers->vers_num); | |
321 | f_print(fout, "extern %s_%s_nproc;\n", | 321 | f_print(fout, "extern %s_%s_nproc;\n", | |
322 | locase(def->def_name), vers->vers_num); | 322 | locase(def->def_name), vers->vers_num); | |
323 | } | 323 | } | |
324 | puldefine(vers->vers_name, vers->vers_num); | 324 | puldefine(vers->vers_name, vers->vers_num); | |
325 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | 325 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | |
326 | if (!define_printed(proc, def->def.pr.versions)) { | 326 | if (!define_printed(proc, def->def.pr.versions)) { | |
327 | puldefine(proc->proc_name, proc->proc_num); | 327 | puldefine(proc->proc_name, proc->proc_num); | |
328 | } | 328 | } | |
329 | } | 329 | } | |
330 | } | 330 | } | |
331 | 331 | |||
332 | /* | 332 | /* | |
333 | * Print out 3 definitions, one for ANSI-C, another for C++, a | 333 | * Print out 3 definitions, one for ANSI-C, another for C++, a | |
334 | * third for old style C | 334 | * third for old style C | |
335 | */ | 335 | */ | |
336 | f_print(fout, "\n"); | 336 | f_print(fout, "\n"); | |
337 | cplusplusstart(); | 337 | cplusplusstart(); | |
338 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | 338 | for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | |
339 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | 339 | for (proc = vers->procs; proc != NULL; proc = proc->next) { | |
340 | pprocdef(proc, vers, "CLIENT *", 0); | 340 | pprocdef(proc, vers, "CLIENT *", 0); | |
341 | pprocdef(proc, vers, "struct svc_req *", 1); | 341 | pprocdef(proc, vers, "struct svc_req *", 1); | |
342 | } | 342 | } | |
343 | } | 343 | } | |
344 | cplusplusend(); | 344 | cplusplusend(); | |
345 | } | 345 | } | |
346 | 346 | |||
347 | void | 347 | void | |
348 | pprocdef(proc_list *proc, version_list *vp, const char *addargtype, | 348 | pprocdef(proc_list *proc, version_list *vp, const char *addargtype, | |
349 | int server_p) | 349 | int server_p) | |
350 | { | 350 | { | |
351 | decl_list *dl; | 351 | decl_list *dl; | |
352 | 352 | |||
353 | if (Mflag) { | 353 | if (Mflag) { | |
354 | if (server_p) | 354 | if (server_p) | |
355 | f_print(fout, "bool_t "); | 355 | f_print(fout, "bool_t "); | |
356 | else | 356 | else | |
357 | f_print(fout, "enum clnt_stat "); | 357 | f_print(fout, "enum clnt_stat "); | |
358 | } else { | 358 | } else { | |
359 | ptype(proc->res_prefix, proc->res_type, 1); | 359 | ptype(proc->res_prefix, proc->res_type, 1); | |
360 | f_print(fout, "*"); | 360 | f_print(fout, "*"); | |
361 | } | 361 | } | |
362 | if (server_p) | 362 | if (server_p) | |
363 | pvname_svc(proc->proc_name, vp->vers_num); | 363 | pvname_svc(proc->proc_name, vp->vers_num); | |
364 | else | 364 | else | |
365 | pvname(proc->proc_name, vp->vers_num); | 365 | pvname(proc->proc_name, vp->vers_num); | |
366 | 366 | |||
367 | f_print(fout, "("); | 367 | f_print(fout, "("); | |
368 | if (proc->arg_num < 2 && newstyle && | 368 | if (proc->arg_num < 2 && newstyle && | |
369 | streq(proc->args.decls->decl.type, "void")) { | 369 | streq(proc->args.decls->decl.type, "void")) { | |
370 | /* 0 argument in new style: do nothing */ | 370 | /* 0 argument in new style: do nothing */ | |
371 | } else { | 371 | } else { | |
372 | for (dl = proc->args.decls; dl != NULL; dl = dl->next) { | 372 | for (dl = proc->args.decls; dl != NULL; dl = dl->next) { | |
373 | ptype(dl->decl.prefix, dl->decl.type, 1); | 373 | ptype(dl->decl.prefix, dl->decl.type, 1); | |
374 | if (!newstyle) | 374 | if (!newstyle) | |
375 | f_print(fout, "*"); | 375 | f_print(fout, "*"); | |
376 | f_print(fout, ", "); | 376 | f_print(fout, ", "); | |
377 | } | 377 | } | |
378 | } | 378 | } | |
379 | if (Mflag) { | 379 | if (Mflag) { | |
380 | if (streq(proc->res_type, "void")) | 380 | if (streq(proc->res_type, "void")) | |
381 | f_print(fout, "char"); | 381 | f_print(fout, "char"); | |
382 | else | 382 | else | |
383 | ptype(proc->res_prefix, proc->res_type, 0); | 383 | ptype(proc->res_prefix, proc->res_type, 0); | |
384 | if (!isvectordef(proc->res_type, REL_ALIAS)) | 384 | if (!isvectordef(proc->res_type, REL_ALIAS)) | |
385 | f_print(fout, "*"); | 385 | f_print(fout, "*"); | |
386 | f_print(fout, ", "); | 386 | f_print(fout, ", "); | |
387 | } | 387 | } | |
388 | f_print(fout, "%s);\n", addargtype); | 388 | f_print(fout, "%s);\n", addargtype); | |
389 | } | 389 | } | |
390 | 390 | |||
391 | 391 | |||
392 | static void | 392 | static void | |
393 | penumdef(definition *def) | 393 | penumdef(definition *def) | |
394 | { | 394 | { | |
395 | const char *name = def->def_name; | 395 | const char *name = def->def_name; | |
396 | enumval_list *l; | 396 | enumval_list *l; | |
397 | const char *last = NULL; | 397 | const char *last = NULL; | |
398 | int count = 0; | 398 | int count = 0; | |
399 | const char *first = ""; | 399 | const char *first = ""; | |
400 | 400 | |||
401 | f_print(fout, "enum %s {\n", name); | 401 | f_print(fout, "enum %s {\n", name); | |
402 | for (l = def->def.en.vals; l != NULL; l = l->next) { | 402 | for (l = def->def.en.vals; l != NULL; l = l->next) { | |
403 | f_print(fout, "%s\t%s", first, l->name); | 403 | f_print(fout, "%s\t%s", first, l->name); | |
404 | if (l->assignment) { | 404 | if (l->assignment) { | |
405 | f_print(fout, " = %s", l->assignment); | 405 | f_print(fout, " = %s", l->assignment); | |
406 | last = l->assignment; | 406 | last = l->assignment; | |
407 | count = 1; | 407 | count = 1; | |
408 | } else { | 408 | } else { | |
409 | if (last == NULL) { | 409 | if (last == NULL) { | |
410 | f_print(fout, " = %d", count++); | 410 | f_print(fout, " = %d", count++); | |
411 | } else { | 411 | } else { | |
412 | f_print(fout, " = %s + %d", last, count++); | 412 | f_print(fout, " = %s + %d", last, count++); | |
413 | } | 413 | } | |
414 | } | 414 | } | |
415 | first = ",\n"; | 415 | first = ",\n"; | |
416 | } | 416 | } | |
417 | f_print(fout, "\n};\n"); | 417 | f_print(fout, "\n};\n"); | |
418 | f_print(fout, "typedef enum %s %s;\n", name, name); | 418 | f_print(fout, "typedef enum %s %s;\n", name, name); | |
419 | } | 419 | } | |
420 | 420 | |||
421 | static void | 421 | static void | |
422 | ptypedef(definition *def) | 422 | ptypedef(definition *def) | |
423 | { | 423 | { | |
424 | const char *name = def->def_name; | 424 | const char *name = def->def_name; | |
425 | const char *old = def->def.ty.old_type; | 425 | const char *old = def->def.ty.old_type; | |
426 | char prefix[8]; /* enough to contain "struct ", including NUL */ | 426 | char prefix[8]; /* enough to contain "struct ", including NUL */ | |
427 | relation rel = def->def.ty.rel; | 427 | relation rel = def->def.ty.rel; | |
428 | 428 | |||
429 | 429 | |||
430 | if (!streq(name, old)) { | 430 | if (!streq(name, old)) { | |
431 | if (streq(old, "string")) { | 431 | if (streq(old, "string")) { | |
432 | old = "char"; | 432 | old = "char"; | |
433 | rel = REL_POINTER; | 433 | rel = REL_POINTER; | |
434 | } else | 434 | } else | |
435 | if (streq(old, "opaque")) { | 435 | if (streq(old, "opaque")) { | |
436 | old = "char"; | 436 | old = "char"; | |
437 | } else | 437 | } else | |
438 | if (streq(old, "bool")) { | 438 | if (streq(old, "bool")) { | |
439 | old = "bool_t"; | 439 | old = "bool_t"; | |
440 | } | 440 | } | |
441 | if (undefined2(old, name) && def->def.ty.old_prefix) { | 441 | if (undefined2(old, name) && def->def.ty.old_prefix) { | |
442 | s_print(prefix, "%s ", def->def.ty.old_prefix); | 442 | s_print(prefix, "%s ", def->def.ty.old_prefix); | |
443 | } else { | 443 | } else { | |
444 | prefix[0] = 0; | 444 | prefix[0] = 0; | |
445 | } | 445 | } | |
446 | f_print(fout, "typedef "); | 446 | f_print(fout, "typedef "); | |
447 | switch (rel) { | 447 | switch (rel) { | |
448 | case REL_ARRAY: | 448 | case REL_ARRAY: | |
449 | f_print(fout, "struct {\n"); | 449 | f_print(fout, "struct {\n"); | |
450 | f_print(fout, "\tu_int %s_len;\n", name); | 450 | f_print(fout, "\tunsigned int %s_len;\n", name); | |
451 | f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); | 451 | f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); | |
452 | f_print(fout, "} %s", name); | 452 | f_print(fout, "} %s", name); | |
453 | break; | 453 | break; | |
454 | case REL_POINTER: | 454 | case REL_POINTER: | |
455 | f_print(fout, "%s%s *%s", prefix, old, name); | 455 | f_print(fout, "%s%s *%s", prefix, old, name); | |
456 | break; | 456 | break; | |
457 | case REL_VECTOR: | 457 | case REL_VECTOR: | |
458 | f_print(fout, "%s%s %s[%s]", prefix, old, name, | 458 | f_print(fout, "%s%s %s[%s]", prefix, old, name, | |
459 | def->def.ty.array_max); | 459 | def->def.ty.array_max); | |
460 | break; | 460 | break; | |
461 | case REL_ALIAS: | 461 | case REL_ALIAS: | |
462 | f_print(fout, "%s%s %s", prefix, old, name); | 462 | f_print(fout, "%s%s %s", prefix, old, name); | |
463 | break; | 463 | break; | |
464 | } | 464 | } | |
465 | f_print(fout, ";\n"); | 465 | f_print(fout, ";\n"); | |
466 | } | 466 | } | |
467 | } | 467 | } | |
468 | 468 | |||
469 | void | 469 | void | |
470 | pdeclaration(const char *name, declaration *dec, int tab, | 470 | pdeclaration(const char *name, declaration *dec, int tab, | |
471 | const char *separator) | 471 | const char *separator) | |
472 | { | 472 | { | |
473 | char buf[8]; /* enough to hold "struct ", include NUL */ | 473 | char buf[8]; /* enough to hold "struct ", include NUL */ | |
474 | const char *prefix; | 474 | const char *prefix; | |
475 | const char *type; | 475 | const char *type; | |
476 | 476 | |||
477 | if (streq(dec->type, "void")) { | 477 | if (streq(dec->type, "void")) { | |
478 | return; | 478 | return; | |
479 | } | 479 | } | |
480 | tabify(fout, tab); | 480 | tabify(fout, tab); | |
481 | if (streq(dec->type, name) && !dec->prefix) { | 481 | if (streq(dec->type, name) && !dec->prefix) { | |
482 | f_print(fout, "struct "); | 482 | f_print(fout, "struct "); | |
483 | } | 483 | } | |
484 | if (streq(dec->type, "string")) { | 484 | if (streq(dec->type, "string")) { | |
485 | f_print(fout, "char *%s", dec->name); | 485 | f_print(fout, "char *%s", dec->name); | |
486 | } else { | 486 | } else { | |
487 | prefix = ""; | 487 | prefix = ""; | |
488 | if (streq(dec->type, "bool")) { | 488 | if (streq(dec->type, "bool")) { | |
489 | type = "bool_t"; | 489 | type = "bool_t"; | |
490 | } else | 490 | } else | |
491 | if (streq(dec->type, "opaque")) { | 491 | if (streq(dec->type, "opaque")) { | |
492 | type = "char"; | 492 | type = "char"; | |
493 | } else { | 493 | } else { | |
494 | if (dec->prefix) { | 494 | if (dec->prefix) { | |
495 | s_print(buf, "%s ", dec->prefix); | 495 | s_print(buf, "%s ", dec->prefix); | |
496 | prefix = buf; | 496 | prefix = buf; | |
497 | } | 497 | } | |
498 | type = dec->type; | 498 | type = dec->type; | |
499 | } | 499 | } | |
500 | switch (dec->rel) { | 500 | switch (dec->rel) { | |
501 | case REL_ALIAS: | 501 | case REL_ALIAS: | |
502 | f_print(fout, "%s%s %s", prefix, type, dec->name); | 502 | f_print(fout, "%s%s %s", prefix, type, dec->name); | |
503 | break; | 503 | break; | |
504 | case REL_VECTOR: | 504 | case REL_VECTOR: | |
505 | f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, | 505 | f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, | |
506 | dec->array_max); | 506 | dec->array_max); | |
507 | break; | 507 | break; | |
508 | case REL_POINTER: | 508 | case REL_POINTER: | |
509 | f_print(fout, "%s%s *%s", prefix, type, dec->name); | 509 | f_print(fout, "%s%s *%s", prefix, type, dec->name); | |
510 | break; | 510 | break; | |
511 | case REL_ARRAY: | 511 | case REL_ARRAY: | |
512 | f_print(fout, "struct {\n"); | 512 | f_print(fout, "struct {\n"); | |
513 | tabify(fout, tab); | 513 | tabify(fout, tab); | |
514 | f_print(fout, "\tu_int %s_len;\n", dec->name); | 514 | f_print(fout, "\tunsigned int %s_len;\n", dec->name); | |
515 | tabify(fout, tab); | 515 | tabify(fout, tab); | |
516 | f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); | 516 | f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); | |
517 | tabify(fout, tab); | 517 | tabify(fout, tab); | |
518 | f_print(fout, "} %s", dec->name); | 518 | f_print(fout, "} %s", dec->name); | |
519 | break; | 519 | break; | |
520 | } | 520 | } | |
521 | } | 521 | } | |
522 | f_print(fout, "%s", separator); | 522 | f_print(fout, "%s", separator); | |
523 | } | 523 | } | |
524 | 524 | |||
525 | static int | 525 | static int | |
526 | undefined2(const char *type, const char *stop) | 526 | undefined2(const char *type, const char *stop) | |
527 | { | 527 | { | |
528 | list *l; | 528 | list *l; | |
529 | definition *def; | 529 | definition *def; | |
530 | 530 | |||
531 | for (l = defined; l != NULL; l = l->next) { | 531 | for (l = defined; l != NULL; l = l->next) { | |
532 | def = (definition *) l->val; | 532 | def = (definition *) l->val; | |
533 | if (def->def_kind != DEF_PROGRAM) { | 533 | if (def->def_kind != DEF_PROGRAM) { | |
534 | if (streq(def->def_name, stop)) { | 534 | if (streq(def->def_name, stop)) { | |
535 | return (1); | 535 | return (1); | |
536 | } else | 536 | } else | |
537 | if (streq(def->def_name, type)) { | 537 | if (streq(def->def_name, type)) { | |
538 | return (0); | 538 | return (0); | |
539 | } | 539 | } | |
540 | } | 540 | } | |
541 | } | 541 | } | |
542 | return (1); | 542 | return (1); | |
543 | } | 543 | } |
--- src/usr.bin/rpcgen/rpc_parse.c 2015/05/09 23:29:51 1.21
+++ src/usr.bin/rpcgen/rpc_parse.c 2016/01/23 02:33:09 1.22
@@ -1,618 +1,618 @@ | @@ -1,618 +1,618 @@ | |||
1 | /* $NetBSD: rpc_parse.c,v 1.21 2015/05/09 23:29:51 dholland Exp $ */ | 1 | /* $NetBSD: rpc_parse.c,v 1.22 2016/01/23 02:33:09 dholland Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
4 | * unrestricted use provided that this legend is included on all tape | 4 | * unrestricted use provided that this legend is included on all tape | |
5 | * media and as a part of the software program in whole or part. Users | 5 | * media and as a part of the software program in whole or part. Users | |
6 | * may copy or modify Sun RPC without charge, but are not authorized | 6 | * may copy or modify Sun RPC without charge, but are not authorized | |
7 | * to license or distribute it to anyone else except as part of a product or | 7 | * to license or distribute it to anyone else except as part of a product or | |
8 | * program developed by the user or with the express written consent of | 8 | * program developed by the user or with the express written consent of | |
9 | * Sun Microsystems, Inc. | 9 | * Sun Microsystems, Inc. | |
10 | * | 10 | * | |
11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
14 | * | 14 | * | |
15 | * Sun RPC is provided with no support and without any obligation on the | 15 | * Sun RPC is provided with no support and without any obligation on the | |
16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
17 | * modification or enhancement. | 17 | * modification or enhancement. | |
18 | * | 18 | * | |
19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
21 | * OR ANY PART THEREOF. | 21 | * OR ANY PART THEREOF. | |
22 | * | 22 | * | |
23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
24 | * or profits or other special, indirect and consequential damages, even if | 24 | * or profits or other special, indirect and consequential damages, even if | |
25 | * Sun has been advised of the possibility of such damages. | 25 | * Sun has been advised of the possibility of such damages. | |
26 | * | 26 | * | |
27 | * Sun Microsystems, Inc. | 27 | * Sun Microsystems, Inc. | |
28 | * 2550 Garcia Avenue | 28 | * 2550 Garcia Avenue | |
29 | * Mountain View, California 94043 | 29 | * Mountain View, California 94043 | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(lint) | 37 | #if defined(__RCSID) && !defined(lint) | |
38 | #if 0 | 38 | #if 0 | |
39 | static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI"; | 39 | static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI"; | |
40 | #else | 40 | #else | |
41 | __RCSID("$NetBSD: rpc_parse.c,v 1.21 2015/05/09 23:29:51 dholland Exp $"); | 41 | __RCSID("$NetBSD: rpc_parse.c,v 1.22 2016/01/23 02:33:09 dholland Exp $"); | |
42 | #endif | 42 | #endif | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | /* | 45 | /* | |
46 | * rpc_parse.c, Parser for the RPC protocol compiler | 46 | * rpc_parse.c, Parser for the RPC protocol compiler | |
47 | * Copyright (C) 1987 Sun Microsystems, Inc. | 47 | * Copyright (C) 1987 Sun Microsystems, Inc. | |
48 | */ | 48 | */ | |
49 | #include <stdio.h> | 49 | #include <stdio.h> | |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> | |
51 | #include <string.h> | 51 | #include <string.h> | |
52 | #include "rpc/types.h" | 52 | #include "rpc/types.h" | |
53 | #include "rpc_scan.h" | 53 | #include "rpc_scan.h" | |
54 | #include "rpc_parse.h" | 54 | #include "rpc_parse.h" | |
55 | #include "rpc_util.h" | 55 | #include "rpc_util.h" | |
56 | 56 | |||
57 | #define ARGNAME "arg" | 57 | #define ARGNAME "arg" | |
58 | 58 | |||
59 | static void isdefined(definition *); | 59 | static void isdefined(definition *); | |
60 | static void def_struct(definition *); | 60 | static void def_struct(definition *); | |
61 | static void def_program(definition *); | 61 | static void def_program(definition *); | |
62 | static void def_enum(definition *); | 62 | static void def_enum(definition *); | |
63 | static void def_const(definition *); | 63 | static void def_const(definition *); | |
64 | static void def_union(definition *); | 64 | static void def_union(definition *); | |
65 | static void check_type_name(const char *, int); | 65 | static void check_type_name(const char *, int); | |
66 | static void def_typedef(definition *); | 66 | static void def_typedef(definition *); | |
67 | static void get_declaration(declaration *, defkind); | 67 | static void get_declaration(declaration *, defkind); | |
68 | static void get_prog_declaration(declaration *, defkind, int); | 68 | static void get_prog_declaration(declaration *, defkind, int); | |
69 | static void get_type(const char **, const char **, defkind); | 69 | static void get_type(const char **, const char **, defkind); | |
70 | static void unsigned_dec(const char **); | 70 | static void unsigned_dec(const char **); | |
71 | 71 | |||
72 | /* | 72 | /* | |
73 | * return the next definition you see | 73 | * return the next definition you see | |
74 | */ | 74 | */ | |
75 | definition * | 75 | definition * | |
76 | get_definition(void) | 76 | get_definition(void) | |
77 | { | 77 | { | |
78 | definition *defp; | 78 | definition *defp; | |
79 | token tok; | 79 | token tok; | |
80 | 80 | |||
81 | defp = ALLOC(definition); | 81 | defp = ALLOC(definition); | |
82 | get_token(&tok); | 82 | get_token(&tok); | |
83 | switch (tok.kind) { | 83 | switch (tok.kind) { | |
84 | case TOK_STRUCT: | 84 | case TOK_STRUCT: | |
85 | def_struct(defp); | 85 | def_struct(defp); | |
86 | break; | 86 | break; | |
87 | case TOK_UNION: | 87 | case TOK_UNION: | |
88 | def_union(defp); | 88 | def_union(defp); | |
89 | break; | 89 | break; | |
90 | case TOK_TYPEDEF: | 90 | case TOK_TYPEDEF: | |
91 | def_typedef(defp); | 91 | def_typedef(defp); | |
92 | break; | 92 | break; | |
93 | case TOK_ENUM: | 93 | case TOK_ENUM: | |
94 | def_enum(defp); | 94 | def_enum(defp); | |
95 | break; | 95 | break; | |
96 | case TOK_PROGRAM: | 96 | case TOK_PROGRAM: | |
97 | def_program(defp); | 97 | def_program(defp); | |
98 | break; | 98 | break; | |
99 | case TOK_CONST: | 99 | case TOK_CONST: | |
100 | def_const(defp); | 100 | def_const(defp); | |
101 | break; | 101 | break; | |
102 | case TOK_EOF: | 102 | case TOK_EOF: | |
103 | free(defp); | 103 | free(defp); | |
104 | return (NULL); | 104 | return (NULL); | |
105 | default: | 105 | default: | |
106 | error("Expected definition keyword"); | 106 | error("Expected definition keyword"); | |
107 | } | 107 | } | |
108 | scan(TOK_SEMICOLON, &tok); | 108 | scan(TOK_SEMICOLON, &tok); | |
109 | isdefined(defp); | 109 | isdefined(defp); | |
110 | return (defp); | 110 | return (defp); | |
111 | } | 111 | } | |
112 | 112 | |||
113 | static void | 113 | static void | |
114 | isdefined(definition *defp) | 114 | isdefined(definition *defp) | |
115 | { | 115 | { | |
116 | STOREVAL(&defined, defp); | 116 | STOREVAL(&defined, defp); | |
117 | } | 117 | } | |
118 | 118 | |||
119 | static void | 119 | static void | |
120 | def_struct(definition *defp) | 120 | def_struct(definition *defp) | |
121 | { | 121 | { | |
122 | token tok; | 122 | token tok; | |
123 | declaration dec; | 123 | declaration dec; | |
124 | decl_list *decls; | 124 | decl_list *decls; | |
125 | decl_list **tailp; | 125 | decl_list **tailp; | |
126 | 126 | |||
127 | defp->def_kind = DEF_STRUCT; | 127 | defp->def_kind = DEF_STRUCT; | |
128 | 128 | |||
129 | scan(TOK_IDENT, &tok); | 129 | scan(TOK_IDENT, &tok); | |
130 | defp->def_name = tok.str; | 130 | defp->def_name = tok.str; | |
131 | scan(TOK_LBRACE, &tok); | 131 | scan(TOK_LBRACE, &tok); | |
132 | tailp = &defp->def.st.decls; | 132 | tailp = &defp->def.st.decls; | |
133 | do { | 133 | do { | |
134 | get_declaration(&dec, DEF_STRUCT); | 134 | get_declaration(&dec, DEF_STRUCT); | |
135 | decls = ALLOC(decl_list); | 135 | decls = ALLOC(decl_list); | |
136 | decls->decl = dec; | 136 | decls->decl = dec; | |
137 | *tailp = decls; | 137 | *tailp = decls; | |
138 | tailp = &decls->next; | 138 | tailp = &decls->next; | |
139 | scan(TOK_SEMICOLON, &tok); | 139 | scan(TOK_SEMICOLON, &tok); | |
140 | peek(&tok); | 140 | peek(&tok); | |
141 | } while (tok.kind != TOK_RBRACE); | 141 | } while (tok.kind != TOK_RBRACE); | |
142 | get_token(&tok); | 142 | get_token(&tok); | |
143 | *tailp = NULL; | 143 | *tailp = NULL; | |
144 | } | 144 | } | |
145 | 145 | |||
146 | static void | 146 | static void | |
147 | def_program(definition *defp) | 147 | def_program(definition *defp) | |
148 | { | 148 | { | |
149 | token tok; | 149 | token tok; | |
150 | declaration dec; | 150 | declaration dec; | |
151 | decl_list *decls; | 151 | decl_list *decls; | |
152 | decl_list **tailp; | 152 | decl_list **tailp; | |
153 | version_list *vlist; | 153 | version_list *vlist; | |
154 | version_list **vtailp; | 154 | version_list **vtailp; | |
155 | proc_list *plist; | 155 | proc_list *plist; | |
156 | proc_list **ptailp; | 156 | proc_list **ptailp; | |
157 | int num_args; | 157 | int num_args; | |
158 | bool_t isvoid = FALSE; /* whether first argument is void */ | 158 | bool_t isvoid = FALSE; /* whether first argument is void */ | |
159 | defp->def_kind = DEF_PROGRAM; | 159 | defp->def_kind = DEF_PROGRAM; | |
160 | scan(TOK_IDENT, &tok); | 160 | scan(TOK_IDENT, &tok); | |
161 | defp->def_name = tok.str; | 161 | defp->def_name = tok.str; | |
162 | scan(TOK_LBRACE, &tok); | 162 | scan(TOK_LBRACE, &tok); | |
163 | vtailp = &defp->def.pr.versions; | 163 | vtailp = &defp->def.pr.versions; | |
164 | tailp = &defp->def.st.decls; | 164 | tailp = &defp->def.st.decls; | |
165 | scan(TOK_VERSION, &tok); | 165 | scan(TOK_VERSION, &tok); | |
166 | do { | 166 | do { | |
167 | scan(TOK_IDENT, &tok); | 167 | scan(TOK_IDENT, &tok); | |
168 | vlist = ALLOC(version_list); | 168 | vlist = ALLOC(version_list); | |
169 | vlist->vers_name = tok.str; | 169 | vlist->vers_name = tok.str; | |
170 | scan(TOK_LBRACE, &tok); | 170 | scan(TOK_LBRACE, &tok); | |
171 | ptailp = &vlist->procs; | 171 | ptailp = &vlist->procs; | |
172 | do { | 172 | do { | |
173 | /* get result type */ | 173 | /* get result type */ | |
174 | plist = ALLOC(proc_list); | 174 | plist = ALLOC(proc_list); | |
175 | get_type(&plist->res_prefix, &plist->res_type, | 175 | get_type(&plist->res_prefix, &plist->res_type, | |
176 | DEF_PROGRAM); | 176 | DEF_PROGRAM); | |
177 | if (streq(plist->res_type, "opaque")) { | 177 | if (streq(plist->res_type, "opaque")) { | |
178 | error("Illegal result type"); | 178 | error("Illegal result type"); | |
179 | } | 179 | } | |
180 | scan(TOK_IDENT, &tok); | 180 | scan(TOK_IDENT, &tok); | |
181 | plist->proc_name = tok.str; | 181 | plist->proc_name = tok.str; | |
182 | scan(TOK_LPAREN, &tok); | 182 | scan(TOK_LPAREN, &tok); | |
183 | /* get args - first one */ | 183 | /* get args - first one */ | |
184 | num_args = 1; | 184 | num_args = 1; | |
185 | isvoid = FALSE; | 185 | isvoid = FALSE; | |
186 | /* type of DEF_PROGRAM in the first | 186 | /* type of DEF_PROGRAM in the first | |
187 | * get_prog_declaration and DEF_STURCT in the next | 187 | * get_prog_declaration and DEF_STURCT in the next | |
188 | * allows void as argument if it is the only argument */ | 188 | * allows void as argument if it is the only argument */ | |
189 | get_prog_declaration(&dec, DEF_PROGRAM, num_args); | 189 | get_prog_declaration(&dec, DEF_PROGRAM, num_args); | |
190 | if (streq(dec.type, "void")) | 190 | if (streq(dec.type, "void")) | |
191 | isvoid = TRUE; | 191 | isvoid = TRUE; | |
192 | decls = ALLOC(decl_list); | 192 | decls = ALLOC(decl_list); | |
193 | plist->args.decls = decls; | 193 | plist->args.decls = decls; | |
194 | decls->decl = dec; | 194 | decls->decl = dec; | |
195 | tailp = &decls->next; | 195 | tailp = &decls->next; | |
196 | /* get args */ | 196 | /* get args */ | |
197 | while (peekscan(TOK_COMMA, &tok)) { | 197 | while (peekscan(TOK_COMMA, &tok)) { | |
198 | num_args++; | 198 | num_args++; | |
199 | get_prog_declaration(&dec, DEF_STRUCT, | 199 | get_prog_declaration(&dec, DEF_STRUCT, | |
200 | num_args); | 200 | num_args); | |
201 | decls = ALLOC(decl_list); | 201 | decls = ALLOC(decl_list); | |
202 | decls->decl = dec; | 202 | decls->decl = dec; | |
203 | *tailp = decls; | 203 | *tailp = decls; | |
204 | if (streq(dec.type, "void")) | 204 | if (streq(dec.type, "void")) | |
205 | isvoid = TRUE; | 205 | isvoid = TRUE; | |
206 | tailp = &decls->next; | 206 | tailp = &decls->next; | |
207 | } | 207 | } | |
208 | /* multiple arguments are only allowed in newstyle */ | 208 | /* multiple arguments are only allowed in newstyle */ | |
209 | if (!newstyle && num_args > 1) { | 209 | if (!newstyle && num_args > 1) { | |
210 | error("Only one argument is allowed"); | 210 | error("Only one argument is allowed"); | |
211 | } | 211 | } | |
212 | if (isvoid && num_args > 1) { | 212 | if (isvoid && num_args > 1) { | |
213 | error("Illegal use of void in program definition"); | 213 | error("Illegal use of void in program definition"); | |
214 | } | 214 | } | |
215 | *tailp = NULL; | 215 | *tailp = NULL; | |
216 | scan(TOK_RPAREN, &tok); | 216 | scan(TOK_RPAREN, &tok); | |
217 | scan(TOK_EQUAL, &tok); | 217 | scan(TOK_EQUAL, &tok); | |
218 | scan_num(&tok); | 218 | scan_num(&tok); | |
219 | scan(TOK_SEMICOLON, &tok); | 219 | scan(TOK_SEMICOLON, &tok); | |
220 | plist->proc_num = tok.str; | 220 | plist->proc_num = tok.str; | |
221 | plist->arg_num = num_args; | 221 | plist->arg_num = num_args; | |
222 | *ptailp = plist; | 222 | *ptailp = plist; | |
223 | ptailp = &plist->next; | 223 | ptailp = &plist->next; | |
224 | peek(&tok); | 224 | peek(&tok); | |
225 | } while (tok.kind != TOK_RBRACE); | 225 | } while (tok.kind != TOK_RBRACE); | |
226 | *ptailp = NULL; | 226 | *ptailp = NULL; | |
227 | *vtailp = vlist; | 227 | *vtailp = vlist; | |
228 | vtailp = &vlist->next; | 228 | vtailp = &vlist->next; | |
229 | scan(TOK_RBRACE, &tok); | 229 | scan(TOK_RBRACE, &tok); | |
230 | scan(TOK_EQUAL, &tok); | 230 | scan(TOK_EQUAL, &tok); | |
231 | scan_num(&tok); | 231 | scan_num(&tok); | |
232 | vlist->vers_num = tok.str; | 232 | vlist->vers_num = tok.str; | |
233 | /* make the argument structure name for each arg */ | 233 | /* make the argument structure name for each arg */ | |
234 | for (plist = vlist->procs; plist != NULL; | 234 | for (plist = vlist->procs; plist != NULL; | |
235 | plist = plist->next) { | 235 | plist = plist->next) { | |
236 | plist->args.argname = make_argname(plist->proc_name, | 236 | plist->args.argname = make_argname(plist->proc_name, | |
237 | vlist->vers_num); | 237 | vlist->vers_num); | |
238 | /* free the memory ?? */ | 238 | /* free the memory ?? */ | |
239 | } | 239 | } | |
240 | scan(TOK_SEMICOLON, &tok); | 240 | scan(TOK_SEMICOLON, &tok); | |
241 | scan2(TOK_VERSION, TOK_RBRACE, &tok); | 241 | scan2(TOK_VERSION, TOK_RBRACE, &tok); | |
242 | } while (tok.kind == TOK_VERSION); | 242 | } while (tok.kind == TOK_VERSION); | |
243 | scan(TOK_EQUAL, &tok); | 243 | scan(TOK_EQUAL, &tok); | |
244 | scan_num(&tok); | 244 | scan_num(&tok); | |
245 | defp->def.pr.prog_num = tok.str; | 245 | defp->def.pr.prog_num = tok.str; | |
246 | *vtailp = NULL; | 246 | *vtailp = NULL; | |
247 | } | 247 | } | |
248 | 248 | |||
249 | 249 | |||
250 | static void | 250 | static void | |
251 | def_enum(definition *defp) | 251 | def_enum(definition *defp) | |
252 | { | 252 | { | |
253 | token tok; | 253 | token tok; | |
254 | enumval_list *elist; | 254 | enumval_list *elist; | |
255 | enumval_list **tailp; | 255 | enumval_list **tailp; | |
256 | 256 | |||
257 | defp->def_kind = DEF_ENUM; | 257 | defp->def_kind = DEF_ENUM; | |
258 | scan(TOK_IDENT, &tok); | 258 | scan(TOK_IDENT, &tok); | |
259 | defp->def_name = tok.str; | 259 | defp->def_name = tok.str; | |
260 | scan(TOK_LBRACE, &tok); | 260 | scan(TOK_LBRACE, &tok); | |
261 | tailp = &defp->def.en.vals; | 261 | tailp = &defp->def.en.vals; | |
262 | do { | 262 | do { | |
263 | scan(TOK_IDENT, &tok); | 263 | scan(TOK_IDENT, &tok); | |
264 | elist = ALLOC(enumval_list); | 264 | elist = ALLOC(enumval_list); | |
265 | elist->name = tok.str; | 265 | elist->name = tok.str; | |
266 | elist->assignment = NULL; | 266 | elist->assignment = NULL; | |
267 | scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok); | 267 | scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok); | |
268 | if (tok.kind == TOK_EQUAL) { | 268 | if (tok.kind == TOK_EQUAL) { | |
269 | scan_num(&tok); | 269 | scan_num(&tok); | |
270 | elist->assignment = tok.str; | 270 | elist->assignment = tok.str; | |
271 | scan2(TOK_COMMA, TOK_RBRACE, &tok); | 271 | scan2(TOK_COMMA, TOK_RBRACE, &tok); | |
272 | } | 272 | } | |
273 | *tailp = elist; | 273 | *tailp = elist; | |
274 | tailp = &elist->next; | 274 | tailp = &elist->next; | |
275 | } while (tok.kind != TOK_RBRACE); | 275 | } while (tok.kind != TOK_RBRACE); | |
276 | *tailp = NULL; | 276 | *tailp = NULL; | |
277 | } | 277 | } | |
278 | 278 | |||
279 | static void | 279 | static void | |
280 | def_const(definition *defp) | 280 | def_const(definition *defp) | |
281 | { | 281 | { | |
282 | token tok; | 282 | token tok; | |
283 | 283 | |||
284 | defp->def_kind = DEF_CONST; | 284 | defp->def_kind = DEF_CONST; | |
285 | scan(TOK_IDENT, &tok); | 285 | scan(TOK_IDENT, &tok); | |
286 | defp->def_name = tok.str; | 286 | defp->def_name = tok.str; | |
287 | scan(TOK_EQUAL, &tok); | 287 | scan(TOK_EQUAL, &tok); | |
288 | scan2(TOK_IDENT, TOK_STRCONST, &tok); | 288 | scan2(TOK_IDENT, TOK_STRCONST, &tok); | |
289 | defp->def.co = tok.str; | 289 | defp->def.co = tok.str; | |
290 | } | 290 | } | |
291 | 291 | |||
292 | static void | 292 | static void | |
293 | def_union(definition *defp) | 293 | def_union(definition *defp) | |
294 | { | 294 | { | |
295 | token tok; | 295 | token tok; | |
296 | declaration dec; | 296 | declaration dec; | |
297 | case_list *cases; | 297 | case_list *cases; | |
298 | case_list **tailp; | 298 | case_list **tailp; | |
299 | 299 | |||
300 | defp->def_kind = DEF_UNION; | 300 | defp->def_kind = DEF_UNION; | |
301 | scan(TOK_IDENT, &tok); | 301 | scan(TOK_IDENT, &tok); | |
302 | defp->def_name = tok.str; | 302 | defp->def_name = tok.str; | |
303 | scan(TOK_SWITCH, &tok); | 303 | scan(TOK_SWITCH, &tok); | |
304 | scan(TOK_LPAREN, &tok); | 304 | scan(TOK_LPAREN, &tok); | |
305 | get_declaration(&dec, DEF_UNION); | 305 | get_declaration(&dec, DEF_UNION); | |
306 | defp->def.un.enum_decl = dec; | 306 | defp->def.un.enum_decl = dec; | |
307 | tailp = &defp->def.un.cases; | 307 | tailp = &defp->def.un.cases; | |
308 | scan(TOK_RPAREN, &tok); | 308 | scan(TOK_RPAREN, &tok); | |
309 | scan(TOK_LBRACE, &tok); | 309 | scan(TOK_LBRACE, &tok); | |
310 | scan(TOK_CASE, &tok); | 310 | scan(TOK_CASE, &tok); | |
311 | while (tok.kind == TOK_CASE) { | 311 | while (tok.kind == TOK_CASE) { | |
312 | scan2(TOK_IDENT, TOK_CHARCONST, &tok); | 312 | scan2(TOK_IDENT, TOK_CHARCONST, &tok); | |
313 | cases = ALLOC(case_list); | 313 | cases = ALLOC(case_list); | |
314 | cases->case_name = tok.str; | 314 | cases->case_name = tok.str; | |
315 | scan(TOK_COLON, &tok); | 315 | scan(TOK_COLON, &tok); | |
316 | /* now peek at next token */ | 316 | /* now peek at next token */ | |
317 | if (peekscan(TOK_CASE, &tok)) { | 317 | if (peekscan(TOK_CASE, &tok)) { | |
318 | 318 | |||
319 | do { | 319 | do { | |
320 | scan2(TOK_IDENT, TOK_CHARCONST, &tok); | 320 | scan2(TOK_IDENT, TOK_CHARCONST, &tok); | |
321 | cases->contflag = 1; /* continued case | 321 | cases->contflag = 1; /* continued case | |
322 | * statement */ | 322 | * statement */ | |
323 | *tailp = cases; | 323 | *tailp = cases; | |
324 | tailp = &cases->next; | 324 | tailp = &cases->next; | |
325 | cases = ALLOC(case_list); | 325 | cases = ALLOC(case_list); | |
326 | cases->case_name = tok.str; | 326 | cases->case_name = tok.str; | |
327 | scan(TOK_COLON, &tok); | 327 | scan(TOK_COLON, &tok); | |
328 | 328 | |||
329 | } while (peekscan(TOK_CASE, &tok)); | 329 | } while (peekscan(TOK_CASE, &tok)); | |
330 | } | 330 | } | |
331 | get_declaration(&dec, DEF_UNION); | 331 | get_declaration(&dec, DEF_UNION); | |
332 | cases->case_decl = dec; | 332 | cases->case_decl = dec; | |
333 | cases->contflag = 0; /* no continued case statement */ | 333 | cases->contflag = 0; /* no continued case statement */ | |
334 | *tailp = cases; | 334 | *tailp = cases; | |
335 | tailp = &cases->next; | 335 | tailp = &cases->next; | |
336 | scan(TOK_SEMICOLON, &tok); | 336 | scan(TOK_SEMICOLON, &tok); | |
337 | 337 | |||
338 | scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok); | 338 | scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok); | |
339 | } | 339 | } | |
340 | *tailp = NULL; | 340 | *tailp = NULL; | |
341 | if (tok.kind == TOK_DEFAULT) { | 341 | if (tok.kind == TOK_DEFAULT) { | |
342 | scan(TOK_COLON, &tok); | 342 | scan(TOK_COLON, &tok); | |
343 | get_declaration(&dec, DEF_UNION); | 343 | get_declaration(&dec, DEF_UNION); | |
344 | defp->def.un.default_decl = ALLOC(declaration); | 344 | defp->def.un.default_decl = ALLOC(declaration); | |
345 | *defp->def.un.default_decl = dec; | 345 | *defp->def.un.default_decl = dec; | |
346 | scan(TOK_SEMICOLON, &tok); | 346 | scan(TOK_SEMICOLON, &tok); | |
347 | scan(TOK_RBRACE, &tok); | 347 | scan(TOK_RBRACE, &tok); | |
348 | } else { | 348 | } else { | |
349 | defp->def.un.default_decl = NULL; | 349 | defp->def.un.default_decl = NULL; | |
350 | } | 350 | } | |
351 | } | 351 | } | |
352 | 352 | |||
353 | static const char *const reserved_words[] = { | 353 | static const char *const reserved_words[] = { | |
354 | "array", | 354 | "array", | |
355 | "bytes", | 355 | "bytes", | |
356 | "destroy", | 356 | "destroy", | |
357 | "free", | 357 | "free", | |
358 | "getpos", | 358 | "getpos", | |
359 | "inline", | 359 | "inline", | |
360 | "pointer", | 360 | "pointer", | |
361 | "reference", | 361 | "reference", | |
362 | "setpos", | 362 | "setpos", | |
363 | "sizeof", | 363 | "sizeof", | |
364 | "union", | 364 | "union", | |
365 | "vector", | 365 | "vector", | |
366 | NULL | 366 | NULL | |
367 | }; | 367 | }; | |
368 | 368 | |||
369 | static const char *const reserved_types[] = { | 369 | static const char *const reserved_types[] = { | |
370 | "opaque", | 370 | "opaque", | |
371 | "string", | 371 | "string", | |
372 | NULL | 372 | NULL | |
373 | }; | 373 | }; | |
374 | /* check that the given name is not one that would eventually result in | 374 | /* check that the given name is not one that would eventually result in | |
375 | xdr routines that would conflict with internal XDR routines. */ | 375 | xdr routines that would conflict with internal XDR routines. */ | |
376 | static void | 376 | static void | |
377 | check_type_name(const char *name, int new_type) | 377 | check_type_name(const char *name, int new_type) | |
378 | { | 378 | { | |
379 | int i; | 379 | int i; | |
380 | 380 | |||
381 | for (i = 0; reserved_words[i] != NULL; i++) { | 381 | for (i = 0; reserved_words[i] != NULL; i++) { | |
382 | if (strcmp(name, reserved_words[i]) == 0) { | 382 | if (strcmp(name, reserved_words[i]) == 0) { | |
383 | error("Illegal (reserved) name '%s' in type definition", name); | 383 | error("Illegal (reserved) name '%s' in type definition", name); | |
384 | } | 384 | } | |
385 | } | 385 | } | |
386 | if (new_type) { | 386 | if (new_type) { | |
387 | for (i = 0; reserved_types[i] != NULL; i++) { | 387 | for (i = 0; reserved_types[i] != NULL; i++) { | |
388 | if (strcmp(name, reserved_types[i]) == 0) { | 388 | if (strcmp(name, reserved_types[i]) == 0) { | |
389 | error("Illegal (reserved) name '%s' in type definition", name); | 389 | error("Illegal (reserved) name '%s' in type definition", name); | |
390 | } | 390 | } | |
391 | } | 391 | } | |
392 | } | 392 | } | |
393 | } | 393 | } | |
394 | 394 | |||
395 | static void | 395 | static void | |
396 | def_typedef(definition *defp) | 396 | def_typedef(definition *defp) | |
397 | { | 397 | { | |
398 | declaration dec; | 398 | declaration dec; | |
399 | 399 | |||
400 | defp->def_kind = DEF_TYPEDEF; | 400 | defp->def_kind = DEF_TYPEDEF; | |
401 | get_declaration(&dec, DEF_TYPEDEF); | 401 | get_declaration(&dec, DEF_TYPEDEF); | |
402 | defp->def_name = dec.name; | 402 | defp->def_name = dec.name; | |
403 | check_type_name(dec.name, 1); | 403 | check_type_name(dec.name, 1); | |
404 | defp->def.ty.old_prefix = dec.prefix; | 404 | defp->def.ty.old_prefix = dec.prefix; | |
405 | defp->def.ty.old_type = dec.type; | 405 | defp->def.ty.old_type = dec.type; | |
406 | defp->def.ty.rel = dec.rel; | 406 | defp->def.ty.rel = dec.rel; | |
407 | defp->def.ty.array_max = dec.array_max; | 407 | defp->def.ty.array_max = dec.array_max; | |
408 | } | 408 | } | |
409 | 409 | |||
410 | static void | 410 | static void | |
411 | get_declaration(declaration *dec, defkind dkind) | 411 | get_declaration(declaration *dec, defkind dkind) | |
412 | { | 412 | { | |
413 | token tok; | 413 | token tok; | |
414 | 414 | |||
415 | get_type(&dec->prefix, &dec->type, dkind); | 415 | get_type(&dec->prefix, &dec->type, dkind); | |
416 | dec->rel = REL_ALIAS; | 416 | dec->rel = REL_ALIAS; | |
417 | if (streq(dec->type, "void")) { | 417 | if (streq(dec->type, "void")) { | |
418 | return; | 418 | return; | |
419 | } | 419 | } | |
420 | check_type_name(dec->type, 0); | 420 | check_type_name(dec->type, 0); | |
421 | 421 | |||
422 | scan2(TOK_STAR, TOK_IDENT, &tok); | 422 | scan2(TOK_STAR, TOK_IDENT, &tok); | |
423 | if (tok.kind == TOK_STAR) { | 423 | if (tok.kind == TOK_STAR) { | |
424 | dec->rel = REL_POINTER; | 424 | dec->rel = REL_POINTER; | |
425 | scan(TOK_IDENT, &tok); | 425 | scan(TOK_IDENT, &tok); | |
426 | } | 426 | } | |
427 | dec->name = tok.str; | 427 | dec->name = tok.str; | |
428 | if (peekscan(TOK_LBRACKET, &tok)) { | 428 | if (peekscan(TOK_LBRACKET, &tok)) { | |
429 | if (dec->rel == REL_POINTER) { | 429 | if (dec->rel == REL_POINTER) { | |
430 | error("No array-of-pointer declarations -- use typedef"); | 430 | error("No array-of-pointer declarations -- use typedef"); | |
431 | } | 431 | } | |
432 | dec->rel = REL_VECTOR; | 432 | dec->rel = REL_VECTOR; | |
433 | scan_num(&tok); | 433 | scan_num(&tok); | |
434 | dec->array_max = tok.str; | 434 | dec->array_max = tok.str; | |
435 | scan(TOK_RBRACKET, &tok); | 435 | scan(TOK_RBRACKET, &tok); | |
436 | } else | 436 | } else | |
437 | if (peekscan(TOK_LANGLE, &tok)) { | 437 | if (peekscan(TOK_LANGLE, &tok)) { | |
438 | if (dec->rel == REL_POINTER) { | 438 | if (dec->rel == REL_POINTER) { | |
439 | error("No array-of-pointer declarations -- use typedef"); | 439 | error("No array-of-pointer declarations -- use typedef"); | |
440 | } | 440 | } | |
441 | dec->rel = REL_ARRAY; | 441 | dec->rel = REL_ARRAY; | |
442 | if (peekscan(TOK_RANGLE, &tok)) { | 442 | if (peekscan(TOK_RANGLE, &tok)) { | |
443 | dec->array_max = "(u_int)~0"; | 443 | dec->array_max = "(unsigned int)~0"; | |
444 | /* unspecified size, use * max */ | 444 | /* unspecified size, use * max */ | |
445 | } else { | 445 | } else { | |
446 | scan_num(&tok); | 446 | scan_num(&tok); | |
447 | dec->array_max = tok.str; | 447 | dec->array_max = tok.str; | |
448 | scan(TOK_RANGLE, &tok); | 448 | scan(TOK_RANGLE, &tok); | |
449 | } | 449 | } | |
450 | } | 450 | } | |
451 | if (streq(dec->type, "opaque")) { | 451 | if (streq(dec->type, "opaque")) { | |
452 | if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) { | 452 | if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) { | |
453 | error("Array declaration expected"); | 453 | error("Array declaration expected"); | |
454 | } | 454 | } | |
455 | } else | 455 | } else | |
456 | if (streq(dec->type, "string")) { | 456 | if (streq(dec->type, "string")) { | |
457 | if (dec->rel != REL_ARRAY) { | 457 | if (dec->rel != REL_ARRAY) { | |
458 | error("Variable-length array declaration expected"); | 458 | error("Variable-length array declaration expected"); | |
459 | } | 459 | } | |
460 | } | 460 | } | |
461 | } | 461 | } | |
462 | 462 | |||
463 | static void | 463 | static void | |
464 | get_prog_declaration(declaration *dec, defkind dkind, int num /* arg number */) | 464 | get_prog_declaration(declaration *dec, defkind dkind, int num /* arg number */) | |
465 | { | 465 | { | |
466 | token tok; | 466 | token tok; | |
467 | char name[255]; /* argument name */ | 467 | char name[255]; /* argument name */ | |
468 | 468 | |||
469 | if (dkind == DEF_PROGRAM) { | 469 | if (dkind == DEF_PROGRAM) { | |
470 | peek(&tok); | 470 | peek(&tok); | |
471 | if (tok.kind == TOK_RPAREN) { /* no arguments */ | 471 | if (tok.kind == TOK_RPAREN) { /* no arguments */ | |
472 | dec->rel = REL_ALIAS; | 472 | dec->rel = REL_ALIAS; | |
473 | dec->type = "void"; | 473 | dec->type = "void"; | |
474 | dec->prefix = NULL; | 474 | dec->prefix = NULL; | |
475 | dec->name = NULL; | 475 | dec->name = NULL; | |
476 | return; | 476 | return; | |
477 | } | 477 | } | |
478 | } | 478 | } | |
479 | get_type(&dec->prefix, &dec->type, dkind); | 479 | get_type(&dec->prefix, &dec->type, dkind); | |
480 | dec->rel = REL_ALIAS; | 480 | dec->rel = REL_ALIAS; | |
481 | if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ | 481 | if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ | |
482 | strcpy(name, tok.str); | 482 | strcpy(name, tok.str); | |
483 | else | 483 | else | |
484 | sprintf(name, "%s%d", ARGNAME, num); /* default name of | 484 | sprintf(name, "%s%d", ARGNAME, num); /* default name of | |
485 | * argument */ | 485 | * argument */ | |
486 | 486 | |||
487 | dec->name = strdup(name); | 487 | dec->name = strdup(name); | |
488 | 488 | |||
489 | if (streq(dec->type, "void")) { | 489 | if (streq(dec->type, "void")) { | |
490 | return; | 490 | return; | |
491 | } | 491 | } | |
492 | if (streq(dec->type, "opaque")) { | 492 | if (streq(dec->type, "opaque")) { | |
493 | error("Opaque -- illegal argument type"); | 493 | error("Opaque -- illegal argument type"); | |
494 | } | 494 | } | |
495 | if (peekscan(TOK_STAR, &tok)) { | 495 | if (peekscan(TOK_STAR, &tok)) { | |
496 | if (streq(dec->type, "string")) { | 496 | if (streq(dec->type, "string")) { | |
497 | error("Pointer to string not allowed in program arguments\n"); | 497 | error("Pointer to string not allowed in program arguments\n"); | |
498 | } | 498 | } | |
499 | dec->rel = REL_POINTER; | 499 | dec->rel = REL_POINTER; | |
500 | if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ | 500 | if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ | |
501 | dec->name = strdup(tok.str); | 501 | dec->name = strdup(tok.str); | |
502 | } | 502 | } | |
503 | if (peekscan(TOK_LANGLE, &tok)) { | 503 | if (peekscan(TOK_LANGLE, &tok)) { | |
504 | if (!streq(dec->type, "string")) { | 504 | if (!streq(dec->type, "string")) { | |
505 | error("Arrays cannot be declared as arguments to procedures -- use typedef"); | 505 | error("Arrays cannot be declared as arguments to procedures -- use typedef"); | |
506 | } | 506 | } | |
507 | dec->rel = REL_ARRAY; | 507 | dec->rel = REL_ARRAY; | |
508 | if (peekscan(TOK_RANGLE, &tok)) { | 508 | if (peekscan(TOK_RANGLE, &tok)) { | |
509 | dec->array_max = "(u_int)~0"; | 509 | dec->array_max = "(unsigned int)~0"; | |
510 | /* unspecified size, use max */ | 510 | /* unspecified size, use max */ | |
511 | } else { | 511 | } else { | |
512 | scan_num(&tok); | 512 | scan_num(&tok); | |
513 | dec->array_max = tok.str; | 513 | dec->array_max = tok.str; | |
514 | scan(TOK_RANGLE, &tok); | 514 | scan(TOK_RANGLE, &tok); | |
515 | } | 515 | } | |
516 | } | 516 | } | |
517 | if (streq(dec->type, "string")) { | 517 | if (streq(dec->type, "string")) { | |
518 | if (dec->rel != REL_ARRAY) { /* .x specifies just string as | 518 | if (dec->rel != REL_ARRAY) { /* .x specifies just string as | |
519 | * type of argument - make it | 519 | * type of argument - make it | |
520 | * string<> */ | 520 | * string<> */ | |
521 | dec->rel = REL_ARRAY; | 521 | dec->rel = REL_ARRAY; | |
522 | dec->array_max = "(u_int)~0"; | 522 | dec->array_max = "(unsigned int)~0"; | |
523 | /* unspecified size, use max */ | 523 | /* unspecified size, use max */ | |
524 | } | 524 | } | |
525 | } | 525 | } | |
526 | } | 526 | } | |
527 | 527 | |||
528 | 528 | |||
529 | 529 | |||
530 | static void | 530 | static void | |
531 | get_type(const char **prefixp, const char **typep, defkind dkind) | 531 | get_type(const char **prefixp, const char **typep, defkind dkind) | |
532 | { | 532 | { | |
533 | token tok; | 533 | token tok; | |
534 | 534 | |||
535 | *prefixp = NULL; | 535 | *prefixp = NULL; | |
536 | get_token(&tok); | 536 | get_token(&tok); | |
537 | switch (tok.kind) { | 537 | switch (tok.kind) { | |
538 | case TOK_IDENT: | 538 | case TOK_IDENT: | |
539 | *typep = tok.str; | 539 | *typep = tok.str; | |
540 | break; | 540 | break; | |
541 | case TOK_STRUCT: | 541 | case TOK_STRUCT: | |
542 | case TOK_ENUM: | 542 | case TOK_ENUM: | |
543 | case TOK_UNION: | 543 | case TOK_UNION: | |
544 | *prefixp = tok.str; | 544 | *prefixp = tok.str; | |
545 | scan(TOK_IDENT, &tok); | 545 | scan(TOK_IDENT, &tok); | |
546 | *typep = tok.str; | 546 | *typep = tok.str; | |
547 | break; | 547 | break; | |
548 | case TOK_UNSIGNED: | 548 | case TOK_UNSIGNED: | |
549 | unsigned_dec(typep); | 549 | unsigned_dec(typep); | |
550 | break; | 550 | break; | |
551 | case TOK_SHORT: | 551 | case TOK_SHORT: | |
552 | *typep = "short"; | 552 | *typep = "short"; | |
553 | (void) peekscan(TOK_INT, &tok); | 553 | (void) peekscan(TOK_INT, &tok); | |
554 | break; | 554 | break; | |
555 | case TOK_LONG: | 555 | case TOK_LONG: | |
556 | *typep = "long"; | 556 | *typep = "long"; | |
557 | (void) peekscan(TOK_INT, &tok); | 557 | (void) peekscan(TOK_INT, &tok); | |
558 | break; | 558 | break; | |
559 | case TOK_HYPER: | 559 | case TOK_HYPER: | |
560 | *typep = "longlong_t"; | 560 | *typep = "longlong_t"; | |
561 | (void) peekscan(TOK_INT, &tok); | 561 | (void) peekscan(TOK_INT, &tok); | |
562 | break; | 562 | break; | |
563 | case TOK_VOID: | 563 | case TOK_VOID: | |
564 | if (dkind != DEF_UNION && dkind != DEF_PROGRAM) { | 564 | if (dkind != DEF_UNION && dkind != DEF_PROGRAM) { | |
565 | error("Void is allowed only inside union and program definitions with one argument"); | 565 | error("Void is allowed only inside union and program definitions with one argument"); | |
566 | } | 566 | } | |
567 | *typep = tok.str; | 567 | *typep = tok.str; | |
568 | break; | 568 | break; | |
569 | case TOK_STRING: | 569 | case TOK_STRING: | |
570 | case TOK_OPAQUE: | 570 | case TOK_OPAQUE: | |
571 | case TOK_CHAR: | 571 | case TOK_CHAR: | |
572 | case TOK_INT: | 572 | case TOK_INT: | |
573 | case TOK_FLOAT: | 573 | case TOK_FLOAT: | |
574 | case TOK_DOUBLE: | 574 | case TOK_DOUBLE: | |
575 | case TOK_BOOL: | 575 | case TOK_BOOL: | |
576 | case TOK_QUAD: | 576 | case TOK_QUAD: | |
577 | *typep = tok.str; | 577 | *typep = tok.str; | |
578 | break; | 578 | break; | |
579 | default: | 579 | default: | |
580 | error("Type specifier expected"); | 580 | error("Type specifier expected"); | |
581 | } | 581 | } | |
582 | } | 582 | } | |
583 | 583 | |||
584 | static void | 584 | static void | |
585 | unsigned_dec(const char **typep) | 585 | unsigned_dec(const char **typep) | |
586 | { | 586 | { | |
587 | token tok; | 587 | token tok; | |
588 | 588 | |||
589 | peek(&tok); | 589 | peek(&tok); | |
590 | switch (tok.kind) { | 590 | switch (tok.kind) { | |
591 | case TOK_CHAR: | 591 | case TOK_CHAR: | |
592 | get_token(&tok); | 592 | get_token(&tok); | |
593 | *typep = "u_char"; | 593 | *typep = "u_char"; | |
594 | break; | 594 | break; | |
595 | case TOK_SHORT: | 595 | case TOK_SHORT: | |
596 | get_token(&tok); | 596 | get_token(&tok); | |
597 | *typep = "u_short"; | 597 | *typep = "u_short"; | |
598 | (void) peekscan(TOK_INT, &tok); | 598 | (void) peekscan(TOK_INT, &tok); | |
599 | break; | 599 | break; | |
600 | case TOK_LONG: | 600 | case TOK_LONG: | |
601 | get_token(&tok); | 601 | get_token(&tok); | |
602 | *typep = "u_long"; | 602 | *typep = "u_long"; | |
603 | (void) peekscan(TOK_INT, &tok); | 603 | (void) peekscan(TOK_INT, &tok); | |
604 | break; | 604 | break; | |
605 | case TOK_HYPER: | 605 | case TOK_HYPER: | |
606 | get_token(&tok); | 606 | get_token(&tok); | |
607 | *typep = "u_longlong_t"; | 607 | *typep = "u_longlong_t"; | |
608 | (void) peekscan(TOK_INT, &tok); | 608 | (void) peekscan(TOK_INT, &tok); | |
609 | break; | 609 | break; | |
610 | case TOK_INT: | 610 | case TOK_INT: | |
611 | get_token(&tok); | 611 | get_token(&tok); | |
612 | *typep = "u_int"; | 612 | *typep = "u_int"; | |
613 | break; | 613 | break; | |
614 | default: | 614 | default: | |
615 | *typep = "u_int"; | 615 | *typep = "u_int"; | |
616 | break; | 616 | break; | |
617 | } | 617 | } | |
618 | } | 618 | } |
--- src/usr.bin/rpcgen/rpc_tblout.c 2013/12/15 00:40:17 1.14
+++ src/usr.bin/rpcgen/rpc_tblout.c 2016/01/23 02:33:09 1.15
@@ -1,181 +1,181 @@ | @@ -1,181 +1,181 @@ | |||
1 | /* $NetBSD: rpc_tblout.c,v 1.14 2013/12/15 00:40:17 christos Exp $ */ | 1 | /* $NetBSD: rpc_tblout.c,v 1.15 2016/01/23 02:33:09 dholland Exp $ */ | |
2 | /* | 2 | /* | |
3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
4 | * unrestricted use provided that this legend is included on all tape | 4 | * unrestricted use provided that this legend is included on all tape | |
5 | * media and as a part of the software program in whole or part. Users | 5 | * media and as a part of the software program in whole or part. Users | |
6 | * may copy or modify Sun RPC without charge, but are not authorized | 6 | * may copy or modify Sun RPC without charge, but are not authorized | |
7 | * to license or distribute it to anyone else except as part of a product or | 7 | * to license or distribute it to anyone else except as part of a product or | |
8 | * program developed by the user or with the express written consent of | 8 | * program developed by the user or with the express written consent of | |
9 | * Sun Microsystems, Inc. | 9 | * Sun Microsystems, Inc. | |
10 | * | 10 | * | |
11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
14 | * | 14 | * | |
15 | * Sun RPC is provided with no support and without any obligation on the | 15 | * Sun RPC is provided with no support and without any obligation on the | |
16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
17 | * modification or enhancement. | 17 | * modification or enhancement. | |
18 | * | 18 | * | |
19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
21 | * OR ANY PART THEREOF. | 21 | * OR ANY PART THEREOF. | |
22 | * | 22 | * | |
23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
24 | * or profits or other special, indirect and consequential damages, even if | 24 | * or profits or other special, indirect and consequential damages, even if | |
25 | * Sun has been advised of the possibility of such damages. | 25 | * Sun has been advised of the possibility of such damages. | |
26 | * | 26 | * | |
27 | * Sun Microsystems, Inc. | 27 | * Sun Microsystems, Inc. | |
28 | * 2550 Garcia Avenue | 28 | * 2550 Garcia Avenue | |
29 | * Mountain View, California 94043 | 29 | * Mountain View, California 94043 | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(lint) | 37 | #if defined(__RCSID) && !defined(lint) | |
38 | #if 0 | 38 | #if 0 | |
39 | static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; | 39 | static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; | |
40 | #else | 40 | #else | |
41 | __RCSID("$NetBSD: rpc_tblout.c,v 1.14 2013/12/15 00:40:17 christos Exp $"); | 41 | __RCSID("$NetBSD: rpc_tblout.c,v 1.15 2016/01/23 02:33:09 dholland Exp $"); | |
42 | #endif | 42 | #endif | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | /* | 45 | /* | |
46 | * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler | 46 | * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler | |
47 | */ | 47 | */ | |
48 | #include <stdio.h> | 48 | #include <stdio.h> | |
49 | #include <string.h> | 49 | #include <string.h> | |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> | |
51 | #include "rpc_scan.h" | 51 | #include "rpc_scan.h" | |
52 | #include "rpc_parse.h" | 52 | #include "rpc_parse.h" | |
53 | #include "rpc_util.h" | 53 | #include "rpc_util.h" | |
54 | 54 | |||
55 | #define TABSIZE 8 | 55 | #define TABSIZE 8 | |
56 | #define TABCOUNT 5 | 56 | #define TABCOUNT 5 | |
57 | #define TABSTOP (TABSIZE*TABCOUNT) | 57 | #define TABSTOP (TABSIZE*TABCOUNT) | |
58 | 58 | |||
59 | static char tabstr[TABCOUNT + 1] = "\t\t\t\t\t"; | 59 | static char tabstr[TABCOUNT + 1] = "\t\t\t\t\t"; | |
60 | 60 | |||
61 | static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; | 61 | static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; | |
62 | static const char tbl_end[] = "};\n"; | 62 | static const char tbl_end[] = "};\n"; | |
63 | 63 | |||
64 | static const char null_entry[] = "\t(char *(*)())0,\n\ | 64 | static const char null_entry[] = "\t(char *(*)())0,\n\ | |
65 | \t(xdrproc_t)xdr_void,\t\t0,\n\ | 65 | \t(xdrproc_t)xdr_void,\t\t0,\n\ | |
66 | \t(xdrproc_t)xdr_void,\t\t0,\n"; | 66 | \t(xdrproc_t)xdr_void,\t\t0,\n"; | |
67 | 67 | |||
68 | static const char tbl_nproc[] = | 68 | static const char tbl_nproc[] = | |
69 | "u_int %s_nproc =\n\t(u_int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n"; | 69 | "unsigned int %s_nproc =\n\t(unsigned int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n"; | |
70 | 70 | |||
71 | static void write_table(definition *); | 71 | static void write_table(definition *); | |
72 | static void printit(const char *, const char *); | 72 | static void printit(const char *, const char *); | |
73 | 73 | |||
74 | void | 74 | void | |
75 | write_tables(void) | 75 | write_tables(void) | |
76 | { | 76 | { | |
77 | list *l; | 77 | list *l; | |
78 | definition *def; | 78 | definition *def; | |
79 | 79 | |||
80 | f_print(fout, "\n"); | 80 | f_print(fout, "\n"); | |
81 | for (l = defined; l != NULL; l = l->next) { | 81 | for (l = defined; l != NULL; l = l->next) { | |
82 | def = (definition *) l->val; | 82 | def = (definition *) l->val; | |
83 | if (def->def_kind == DEF_PROGRAM) { | 83 | if (def->def_kind == DEF_PROGRAM) { | |
84 | write_table(def); | 84 | write_table(def); | |
85 | } | 85 | } | |
86 | } | 86 | } | |
87 | } | 87 | } | |
88 | 88 | |||
89 | static void | 89 | static void | |
90 | write_table(definition *def) | 90 | write_table(definition *def) | |
91 | { | 91 | { | |
92 | version_list *vp; | 92 | version_list *vp; | |
93 | proc_list *proc; | 93 | proc_list *proc; | |
94 | int current; | 94 | int current; | |
95 | int expected; | 95 | int expected; | |
96 | char progvers[100]; | 96 | char progvers[100]; | |
97 | int warning; | 97 | int warning; | |
98 | 98 | |||
99 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { | 99 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { | |
100 | warning = 0; | 100 | warning = 0; | |
101 | s_print(progvers, "%s_%s", | 101 | s_print(progvers, "%s_%s", | |
102 | locase(def->def_name), vp->vers_num); | 102 | locase(def->def_name), vp->vers_num); | |
103 | /* print the table header */ | 103 | /* print the table header */ | |
104 | f_print(fout, tbl_hdr, progvers); | 104 | f_print(fout, tbl_hdr, progvers); | |
105 | 105 | |||
106 | if (nullproc(vp->procs)) { | 106 | if (nullproc(vp->procs)) { | |
107 | expected = 0; | 107 | expected = 0; | |
108 | } else { | 108 | } else { | |
109 | expected = 1; | 109 | expected = 1; | |
110 | f_print(fout, null_entry); | 110 | f_print(fout, null_entry); | |
111 | } | 111 | } | |
112 | for (proc = vp->procs; proc != NULL; proc = proc->next) { | 112 | for (proc = vp->procs; proc != NULL; proc = proc->next) { | |
113 | if (expected != 0) | 113 | if (expected != 0) | |
114 | f_print(fout, "\n"); | 114 | f_print(fout, "\n"); | |
115 | current = atoi(proc->proc_num); | 115 | current = atoi(proc->proc_num); | |
116 | if (current != expected++) { | 116 | if (current != expected++) { | |
117 | f_print(fout, | 117 | f_print(fout, | |
118 | "/*\n * WARNING: table out of order\n */\n\n"); | 118 | "/*\n * WARNING: table out of order\n */\n\n"); | |
119 | if (warning == 0) { | 119 | if (warning == 0) { | |
120 | f_print(stderr, | 120 | f_print(stderr, | |
121 | "WARNING %s table is out of order\n", | 121 | "WARNING %s table is out of order\n", | |
122 | progvers); | 122 | progvers); | |
123 | warning = 1; | 123 | warning = 1; | |
124 | nonfatalerrors = 1; | 124 | nonfatalerrors = 1; | |
125 | } | 125 | } | |
126 | expected = current + 1; | 126 | expected = current + 1; | |
127 | } | 127 | } | |
128 | f_print(fout, "\t(char *(*)())RPCGEN_ACTION("); | 128 | f_print(fout, "\t(char *(*)())RPCGEN_ACTION("); | |
129 | 129 | |||
130 | /* routine to invoke */ | 130 | /* routine to invoke */ | |
131 | if (!newstyle) | 131 | if (!newstyle) | |
132 | pvname_svc(proc->proc_name, vp->vers_num); | 132 | pvname_svc(proc->proc_name, vp->vers_num); | |
133 | else { | 133 | else { | |
134 | if (newstyle) | 134 | if (newstyle) | |
135 | f_print(fout, "_"); /* calls internal func */ | 135 | f_print(fout, "_"); /* calls internal func */ | |
136 | pvname(proc->proc_name, vp->vers_num); | 136 | pvname(proc->proc_name, vp->vers_num); | |
137 | } | 137 | } | |
138 | f_print(fout, "),\n"); | 138 | f_print(fout, "),\n"); | |
139 | 139 | |||
140 | /* argument info */ | 140 | /* argument info */ | |
141 | if (proc->arg_num > 1) | 141 | if (proc->arg_num > 1) | |
142 | printit(NULL, proc->args.argname); | 142 | printit(NULL, proc->args.argname); | |
143 | else | 143 | else | |
144 | /* do we have to do something special for | 144 | /* do we have to do something special for | |
145 | * newstyle */ | 145 | * newstyle */ | |
146 | printit(proc->args.decls->decl.prefix, | 146 | printit(proc->args.decls->decl.prefix, | |
147 | proc->args.decls->decl.type); | 147 | proc->args.decls->decl.type); | |
148 | /* result info */ | 148 | /* result info */ | |
149 | printit(proc->res_prefix, proc->res_type); | 149 | printit(proc->res_prefix, proc->res_type); | |
150 | } | 150 | } | |
151 | 151 | |||
152 | /* print the table trailer */ | 152 | /* print the table trailer */ | |
153 | f_print(fout, tbl_end); | 153 | f_print(fout, tbl_end); | |
154 | f_print(fout, tbl_nproc, progvers, progvers, progvers); | 154 | f_print(fout, tbl_nproc, progvers, progvers, progvers); | |
155 | } | 155 | } | |
156 | } | 156 | } | |
157 | 157 | |||
158 | static void | 158 | static void | |
159 | printit(const char *prefix, const char *type) | 159 | printit(const char *prefix, const char *type) | |
160 | { | 160 | { | |
161 | int len; | 161 | int len; | |
162 | int tabs; | 162 | int tabs; | |
163 | 163 | |||
164 | 164 | |||
165 | len = fprintf(fout, "\txdr_%s,", stringfix(type)); | 165 | len = fprintf(fout, "\txdr_%s,", stringfix(type)); | |
166 | /* account for leading tab expansion */ | 166 | /* account for leading tab expansion */ | |
167 | len += TABSIZE - 1; | 167 | len += TABSIZE - 1; | |
168 | /* round up to tabs required */ | 168 | /* round up to tabs required */ | |
169 | tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE; | 169 | tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE; | |
170 | f_print(fout, "%s", &tabstr[TABCOUNT - tabs]); | 170 | f_print(fout, "%s", &tabstr[TABCOUNT - tabs]); | |
171 | 171 | |||
172 | if (streq(type, "void")) { | 172 | if (streq(type, "void")) { | |
173 | f_print(fout, "0"); | 173 | f_print(fout, "0"); | |
174 | } else { | 174 | } else { | |
175 | f_print(fout, "(u_int)sizeof("); | 175 | f_print(fout, "(unsigned int)sizeof("); | |
176 | /* XXX: should "follow" be 1 ??? */ | 176 | /* XXX: should "follow" be 1 ??? */ | |
177 | ptype(prefix, type, 0); | 177 | ptype(prefix, type, 0); | |
178 | f_print(fout, ")"); | 178 | f_print(fout, ")"); | |
179 | } | 179 | } | |
180 | f_print(fout, ",\n"); | 180 | f_print(fout, ",\n"); | |
181 | } | 181 | } |