0
|
1 |
/*********************************************************************
|
|
2 |
* RPC for the Windows NT Operating System
|
|
3 |
* 1993 by Martin F. Gergeleit
|
|
4 |
* Users may use, copy or modify Sun RPC for the Windows NT Operating
|
|
5 |
* System according to the Sun copyright below.
|
|
6 |
*
|
|
7 |
* RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
|
|
8 |
* WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
|
|
9 |
* USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
|
|
10 |
*********************************************************************/
|
|
11 |
|
|
12 |
/* @(#)rpc_hout.c 2.1 88/08/01 4.0 RPCSRC */
|
|
13 |
/*
|
|
14 |
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
|
15 |
* unrestricted use provided that this legend is included on all tape
|
|
16 |
* media and as a part of the software program in whole or part. Users
|
|
17 |
* may copy or modify Sun RPC without charge, but are not authorized
|
|
18 |
* to license or distribute it to anyone else except as part of a product or
|
|
19 |
* program developed by the user.
|
|
20 |
*
|
|
21 |
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
|
22 |
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
|
23 |
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
|
24 |
*
|
|
25 |
* Sun RPC is provided with no support and without any obligation on the
|
|
26 |
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
|
27 |
* modification or enhancement.
|
|
28 |
*
|
|
29 |
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
|
30 |
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
|
31 |
* OR ANY PART THEREOF.
|
|
32 |
*
|
|
33 |
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
|
34 |
* or profits or other special, indirect and consequential damages, even if
|
|
35 |
* Sun has been advised of the possibility of such damages.
|
|
36 |
*
|
|
37 |
* Sun Microsystems, Inc.
|
|
38 |
* 2550 Garcia Avenue
|
|
39 |
* Mountain View, California 94043
|
|
40 |
*/
|
|
41 |
//#ifndef lint
|
|
42 |
//static char sccsid[] = "@(#)rpc_hout.c 1.6 87/07/28 (C) 1987 SMI";
|
|
43 |
//#endif
|
|
44 |
|
|
45 |
/*
|
|
46 |
* rpc_hout.c, Header file outputter for the RPC protocol compiler
|
|
47 |
* Copyright (C) 1987, Sun Microsystems, Inc.
|
|
48 |
*/
|
|
49 |
#include <stdio.h>
|
|
50 |
#include <stdlib.h>
|
|
51 |
#include <ctype.h>
|
|
52 |
#include "rpc_util.h"
|
|
53 |
#include "rpc_pars.h"
|
|
54 |
#include "ae_component_rpc.h"
|
|
55 |
|
|
56 |
/* prototypes */
|
|
57 |
static void pdefine( char *name, char *num );
|
|
58 |
static void pdeclaration( char *name, declaration *dec, int tab );
|
|
59 |
void pprocdef( proc_list *proc, version_list *vp );
|
|
60 |
static int undefined2( char *type, char *stop );
|
|
61 |
|
|
62 |
/* implementation */
|
|
63 |
static void
|
|
64 |
pconstdef(def)
|
|
65 |
definition *def;
|
|
66 |
{
|
|
67 |
pdefine(def->def_name, def->def.co);
|
|
68 |
}
|
|
69 |
|
|
70 |
static void
|
|
71 |
pstructdef(def)
|
|
72 |
definition *def;
|
|
73 |
{
|
|
74 |
decl_list *l;
|
|
75 |
char *name = def->def_name;
|
|
76 |
|
|
77 |
f_print(fout, "struct %s {\n", name);
|
|
78 |
for (l = def->def.st.decls; l != NULL; l = l->next) {
|
|
79 |
pdeclaration(name, &l->decl, 1);
|
|
80 |
}
|
|
81 |
f_print(fout, "};\n");
|
|
82 |
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
83 |
}
|
|
84 |
|
|
85 |
static void
|
|
86 |
puniondef(def)
|
|
87 |
definition *def;
|
|
88 |
{
|
|
89 |
case_list *l;
|
|
90 |
char *name = def->def_name;
|
|
91 |
declaration *decl;
|
|
92 |
|
|
93 |
f_print(fout, "struct %s {\n", name);
|
|
94 |
decl = &def->def.un.enum_decl;
|
|
95 |
if (streq(decl->type, "bool")) {
|
|
96 |
f_print(fout, "\tbool_t %s;\n", decl->name);
|
|
97 |
} else {
|
|
98 |
f_print(fout, "\t%s %s;\n", decl->type, decl->name);
|
|
99 |
}
|
|
100 |
f_print(fout, "\tunion {\n");
|
|
101 |
for (l = def->def.un.cases; l != NULL; l = l->next) {
|
|
102 |
pdeclaration(name, &l->case_decl, 2);
|
|
103 |
}
|
|
104 |
decl = def->def.un.default_decl;
|
|
105 |
if (decl && !streq(decl->type, "void")) {
|
|
106 |
pdeclaration(name, decl, 2);
|
|
107 |
}
|
|
108 |
f_print(fout, "\t} %s_u;\n", name);
|
|
109 |
f_print(fout, "};\n");
|
|
110 |
f_print(fout, "typedef struct %s %s;\n", name, name);
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
static void
|
|
116 |
pdefine(name, num)
|
|
117 |
char *name;
|
|
118 |
char *num;
|
|
119 |
{
|
|
120 |
f_print(fout, "#define %s %s\n", name, num);
|
|
121 |
}
|
|
122 |
|
|
123 |
static void
|
|
124 |
puldefine(name, num)
|
|
125 |
char *name;
|
|
126 |
char *num;
|
|
127 |
{
|
|
128 |
f_print(fout, "#define %s ((u_long)%s)\n", name, num);
|
|
129 |
}
|
|
130 |
|
|
131 |
static int
|
|
132 |
define_printed(stop, start)
|
|
133 |
proc_list *stop;
|
|
134 |
version_list *start;
|
|
135 |
{
|
|
136 |
version_list *vers;
|
|
137 |
proc_list *proc;
|
|
138 |
|
|
139 |
for (vers = start; vers != NULL; vers = vers->next) {
|
|
140 |
for (proc = vers->procs; proc != NULL; proc = proc->next) {
|
|
141 |
if (proc == stop) {
|
|
142 |
return (0);
|
|
143 |
} else if (streq(proc->proc_name, stop->proc_name)) {
|
|
144 |
return (1);
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|
|
148 |
abort();
|
|
149 |
/* NOTREACHED */
|
|
150 |
}
|
|
151 |
|
|
152 |
|
|
153 |
static void
|
|
154 |
pprogramdef(def)
|
|
155 |
definition *def;
|
|
156 |
{
|
|
157 |
version_list *vers;
|
|
158 |
proc_list *proc;
|
|
159 |
|
|
160 |
puldefine(def->def_name, def->def.pr.prog_num);
|
|
161 |
for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
|
|
162 |
puldefine(vers->vers_name, vers->vers_num);
|
|
163 |
for (proc = vers->procs; proc != NULL; proc = proc->next) {
|
|
164 |
if (!define_printed(proc, def->def.pr.versions)) {
|
|
165 |
puldefine(proc->proc_name, proc->proc_num);
|
|
166 |
}
|
|
167 |
pprocdef(proc, vers);
|
|
168 |
}
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
void
|
|
173 |
pprocdef(proc, vp)
|
|
174 |
proc_list *proc;
|
|
175 |
version_list *vp;
|
|
176 |
{
|
|
177 |
f_print(fout, "#ifdef __cplusplus\nextern \"C\" {\n");
|
|
178 |
|
|
179 |
f_print(fout, "extern ");
|
|
180 |
if (proc->res_prefix) {
|
|
181 |
if (streq(proc->res_prefix, "enum")) {
|
|
182 |
f_print(fout, "enum ");
|
|
183 |
} else {
|
|
184 |
f_print(fout, "struct ");
|
|
185 |
}
|
|
186 |
}
|
|
187 |
if (streq(proc->res_type, "bool")) {
|
|
188 |
f_print(fout, "bool_t *");
|
|
189 |
} else if (streq(proc->res_type, "string")) {
|
|
190 |
f_print(fout, "char **");
|
|
191 |
} else {
|
|
192 |
f_print(fout, "%s *", fixtype(proc->res_type));
|
|
193 |
}
|
|
194 |
pvname(proc->proc_name, vp->vers_num);
|
|
195 |
|
|
196 |
// AE -- modified to make it print out the correct headers
|
|
197 |
{
|
|
198 |
// f_print(fout, "(...);\n}\n#else\n");
|
|
199 |
f_print(fout, "( " );
|
|
200 |
|
|
201 |
|
|
202 |
if (streq(proc->arg_type, "bool")) {
|
|
203 |
f_print(fout, "bool_t *");
|
|
204 |
} else if (streq(proc->arg_type, "string")) {
|
|
205 |
f_print(fout, "char **");
|
|
206 |
} else {
|
|
207 |
f_print(fout, "%s *", fixtype(proc->arg_type));
|
|
208 |
}
|
|
209 |
|
|
210 |
f_print(fout, " arg, CLIENT *cl ");
|
|
211 |
f_print(fout, ");\n}\n#else\n" );
|
|
212 |
}
|
|
213 |
|
|
214 |
f_print(fout, "extern ");
|
|
215 |
if (proc->res_prefix) {
|
|
216 |
if (streq(proc->res_prefix, "enum")) {
|
|
217 |
f_print(fout, "enum ");
|
|
218 |
} else {
|
|
219 |
f_print(fout, "struct ");
|
|
220 |
}
|
|
221 |
}
|
|
222 |
if (streq(proc->res_type, "bool")) {
|
|
223 |
f_print(fout, "bool_t *");
|
|
224 |
} else if (streq(proc->res_type, "string")) {
|
|
225 |
f_print(fout, "char **");
|
|
226 |
} else {
|
|
227 |
f_print(fout, "%s *", fixtype(proc->res_type));
|
|
228 |
}
|
|
229 |
pvname(proc->proc_name, vp->vers_num);
|
|
230 |
f_print(fout, "();\n#endif /* __cplusplus */\n");
|
|
231 |
|
|
232 |
}
|
|
233 |
|
|
234 |
static void
|
|
235 |
penumdef(def)
|
|
236 |
definition *def;
|
|
237 |
{
|
|
238 |
char *name = def->def_name;
|
|
239 |
enumval_list *l;
|
|
240 |
char *last = NULL;
|
|
241 |
int count = 0;
|
|
242 |
|
|
243 |
f_print(fout, "enum %s {\n", name);
|
|
244 |
for (l = def->def.en.vals; l != NULL; l = l->next) {
|
|
245 |
f_print(fout, "\t%s", l->name);
|
|
246 |
if (l->assignment) {
|
|
247 |
f_print(fout, " = %s", l->assignment);
|
|
248 |
last = l->assignment;
|
|
249 |
count = 1;
|
|
250 |
} else {
|
|
251 |
if (last == NULL) {
|
|
252 |
f_print(fout, " = %d", count++);
|
|
253 |
} else {
|
|
254 |
f_print(fout, " = %s + %d", last, count++);
|
|
255 |
}
|
|
256 |
}
|
|
257 |
f_print(fout, ",\n");
|
|
258 |
}
|
|
259 |
f_print(fout, "};\n");
|
|
260 |
f_print(fout, "typedef enum %s %s;\n", name, name);
|
|
261 |
}
|
|
262 |
|
|
263 |
static void
|
|
264 |
ptypedef(def)
|
|
265 |
definition *def;
|
|
266 |
{
|
|
267 |
char *name = def->def_name;
|
|
268 |
char *old = def->def.ty.old_type;
|
|
269 |
char prefix[8]; /* enough to contain "struct ", including NUL */
|
|
270 |
relation rel = def->def.ty.rel;
|
|
271 |
|
|
272 |
|
|
273 |
if (!streq(name, old)) {
|
|
274 |
if (streq(old, "string")) {
|
|
275 |
old = "char";
|
|
276 |
rel = REL_POINTER;
|
|
277 |
} else if (streq(old, "opaque")) {
|
|
278 |
old = "char";
|
|
279 |
} else if (streq(old, "bool")) {
|
|
280 |
old = "bool_t";
|
|
281 |
}
|
|
282 |
if (undefined2(old, name) && def->def.ty.old_prefix) {
|
|
283 |
s_print(prefix, "%s ", def->def.ty.old_prefix);
|
|
284 |
} else {
|
|
285 |
prefix[0] = 0;
|
|
286 |
}
|
|
287 |
f_print(fout, "typedef ");
|
|
288 |
switch (rel) {
|
|
289 |
case REL_ARRAY:
|
|
290 |
f_print(fout, "struct {\n");
|
|
291 |
f_print(fout, "\tu_int %s_len;\n", name);
|
|
292 |
f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
|
|
293 |
f_print(fout, "} %s", name);
|
|
294 |
break;
|
|
295 |
case REL_POINTER:
|
|
296 |
f_print(fout, "%s%s *%s", prefix, old, name);
|
|
297 |
break;
|
|
298 |
case REL_VECTOR:
|
|
299 |
f_print(fout, "%s%s %s[%s]", prefix, old, name,
|
|
300 |
def->def.ty.array_max);
|
|
301 |
break;
|
|
302 |
case REL_ALIAS:
|
|
303 |
f_print(fout, "%s%s %s", prefix, old, name);
|
|
304 |
break;
|
|
305 |
}
|
|
306 |
f_print(fout, ";\n");
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
static void
|
|
312 |
pdeclaration(name, dec, tab)
|
|
313 |
char *name;
|
|
314 |
declaration *dec;
|
|
315 |
int tab;
|
|
316 |
{
|
|
317 |
char buf[8]; /* enough to hold "struct ", include NUL */
|
|
318 |
char *prefix;
|
|
319 |
char *type;
|
|
320 |
|
|
321 |
if (streq(dec->type, "void")) {
|
|
322 |
return;
|
|
323 |
}
|
|
324 |
tabify(fout, tab);
|
|
325 |
if (streq(dec->type, name) && !dec->prefix) {
|
|
326 |
f_print(fout, "struct ");
|
|
327 |
}
|
|
328 |
if (streq(dec->type, "string")) {
|
|
329 |
f_print(fout, "char *%s", dec->name);
|
|
330 |
} else {
|
|
331 |
prefix = "";
|
|
332 |
if (streq(dec->type, "bool")) {
|
|
333 |
type = "bool_t";
|
|
334 |
} else if (streq(dec->type, "opaque")) {
|
|
335 |
type = "char";
|
|
336 |
} else {
|
|
337 |
if (dec->prefix) {
|
|
338 |
s_print(buf, "%s ", dec->prefix);
|
|
339 |
prefix = buf;
|
|
340 |
}
|
|
341 |
type = dec->type;
|
|
342 |
}
|
|
343 |
switch (dec->rel) {
|
|
344 |
case REL_ALIAS:
|
|
345 |
f_print(fout, "%s%s %s", prefix, type, dec->name);
|
|
346 |
break;
|
|
347 |
case REL_VECTOR:
|
|
348 |
f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
|
|
349 |
dec->array_max);
|
|
350 |
break;
|
|
351 |
case REL_POINTER:
|
|
352 |
f_print(fout, "%s%s *%s", prefix, type, dec->name);
|
|
353 |
break;
|
|
354 |
case REL_ARRAY:
|
|
355 |
f_print(fout, "struct {\n");
|
|
356 |
tabify(fout, tab);
|
|
357 |
f_print(fout, "\tu_int %s_len;\n", dec->name);
|
|
358 |
tabify(fout, tab);
|
|
359 |
f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
|
|
360 |
tabify(fout, tab);
|
|
361 |
f_print(fout, "} %s", dec->name);
|
|
362 |
break;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
f_print(fout, ";\n");
|
|
366 |
}
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
static int
|
|
371 |
undefined2(type, stop)
|
|
372 |
char *type;
|
|
373 |
char *stop;
|
|
374 |
{
|
|
375 |
list *l;
|
|
376 |
definition *def;
|
|
377 |
|
|
378 |
for (l = defined; l != NULL; l = l->next) {
|
|
379 |
def = (definition *) l->val;
|
|
380 |
if (def->def_kind != DEF_PROGRAM) {
|
|
381 |
if (streq(def->def_name, stop)) {
|
|
382 |
return (1);
|
|
383 |
} else if (streq(def->def_name, type)) {
|
|
384 |
return (0);
|
|
385 |
}
|
|
386 |
}
|
|
387 |
}
|
|
388 |
return (1);
|
|
389 |
}
|
|
390 |
|
|
391 |
/*
|
|
392 |
* Print the C-version of an xdr definition
|
|
393 |
*/
|
|
394 |
void
|
|
395 |
print_datadef(def)
|
|
396 |
definition *def;
|
|
397 |
{
|
|
398 |
if (def->def_kind != DEF_CONST) {
|
|
399 |
f_print(fout, "\n");
|
|
400 |
}
|
|
401 |
switch (def->def_kind) {
|
|
402 |
case DEF_STRUCT:
|
|
403 |
pstructdef(def);
|
|
404 |
break;
|
|
405 |
case DEF_UNION:
|
|
406 |
puniondef(def);
|
|
407 |
break;
|
|
408 |
case DEF_ENUM:
|
|
409 |
penumdef(def);
|
|
410 |
break;
|
|
411 |
case DEF_TYPEDEF:
|
|
412 |
ptypedef(def);
|
|
413 |
break;
|
|
414 |
case DEF_PROGRAM:
|
|
415 |
pprogramdef(def);
|
|
416 |
break;
|
|
417 |
case DEF_CONST:
|
|
418 |
pconstdef(def);
|
|
419 |
break;
|
|
420 |
}
|
|
421 |
if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
|
|
422 |
f_print(fout, "#ifdef __cplusplus\nextern \"C\" {\n");
|
|
423 |
f_print(fout, "bool_t xdr_%s(...);\n", ae_extend_custom_types(def->def_name));
|
|
424 |
f_print(fout, "}\n#else\n");
|
|
425 |
f_print(fout, "bool_t xdr_%s();\n", ae_extend_custom_types(def->def_name));
|
|
426 |
f_print(fout, "#endif\n");
|
|
427 |
}
|
|
428 |
if (def->def_kind != DEF_CONST) {
|
|
429 |
f_print(fout, "\n");
|
|
430 |
}
|
|
431 |
}
|