2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI
32 #ident "@(#)rpc_hout.c 1.16 94/04/25 SMI"
35 * rpc_hout.c, Header file outputter for the RPC protocol compiler
36 * Copyright (C) 1987, Sun Microsystems, Inc.
40 #include "rpc_parse.h"
43 void storexdrfuncdecl __P(( char *, int ));
44 static void pconstdef __P(( definition * ));
45 static void pstructdef __P(( definition * ));
46 static void puniondef __P(( definition * ));
47 static void pprogramdef __P(( definition * ));
48 static void pstructdef __P(( definition * ));
49 static void penumdef __P(( definition * ));
50 static void ptypedef __P(( definition * ));
51 static void pdefine __P(( char *, char * ));
52 static int undefined2 __P(( char *, char * ));
53 static void parglist __P(( proc_list *, char * ));
54 static void pprocdef __P(( proc_list *, version_list *, char *, int, int ));
55 void pdeclaration __P(( char *, declaration *, int, char * ));
57 static char RESULT[] = "clnt_res";
61 * Print the C-version of an xdr definition
68 if (def->def_kind == DEF_PROGRAM) /* handle data only */
71 if (def->def_kind != DEF_CONST) {
74 switch (def->def_kind) {
94 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
95 storexdrfuncdecl(def->def_name,
96 def->def_kind != DEF_TYPEDEF ||
97 !isvectordef(def->def.ty.old_type,
107 switch (def->def_kind) {
116 /* store away enough information to allow the XDR functions to be spat
117 out at the end of the file */
120 storexdrfuncdecl(name, pointerp)
126 xdrptr = (xdrfunc *) malloc(sizeof (struct xdrfunc));
129 xdrptr->pointerp = pointerp;
132 if (xdrfunc_tail == NULL){
133 xdrfunc_head = xdrptr;
134 xdrfunc_tail = xdrptr;
136 xdrfunc_tail->next = xdrptr;
137 xdrfunc_tail = xdrptr;
144 print_xdr_func_def(name, pointerp, i)
150 f_print(fout, "extern bool_t xdr_%s();\n", name);
154 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
155 name, pointerp ? "*" : "");
165 pdefine(def->def_name, def->def.co);
168 /* print out the definitions for the arguments of functions in the
181 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
182 for (plist = vers->procs; plist != NULL;
183 plist = plist->next) {
185 if (!newstyle || plist->arg_num < 2) {
186 continue; /* old style or single args */
188 name = plist->args.argname;
189 f_print(fout, "struct %s {\n", name);
190 for (l = plist->args.decls;
191 l != NULL; l = l->next) {
192 pdeclaration(name, &l->decl, 1,
195 f_print(fout, "};\n");
196 f_print(fout, "typedef struct %s %s;\n",
198 storexdrfuncdecl(name, 1);
210 char *name = def->def_name;
212 f_print(fout, "struct %s {\n", name);
213 for (l = def->def.st.decls; l != NULL; l = l->next) {
214 pdeclaration(name, &l->decl, 1, ";\n");
216 f_print(fout, "};\n");
217 f_print(fout, "typedef struct %s %s;\n", name, name);
225 char *name = def->def_name;
228 f_print(fout, "struct %s {\n", name);
229 decl = &def->def.un.enum_decl;
230 if (streq(decl->type, "bool")) {
231 f_print(fout, "\tbool_t %s;\n", decl->name);
233 f_print(fout, "\t%s %s;\n", decl->type, decl->name);
235 f_print(fout, "\tunion {\n");
236 for (l = def->def.un.cases; l != NULL; l = l->next) {
237 if (l->contflag == 0)
238 pdeclaration(name, &l->case_decl, 2, ";\n");
240 decl = def->def.un.default_decl;
241 if (decl && !streq(decl->type, "void")) {
242 pdeclaration(name, decl, 2, ";\n");
244 f_print(fout, "\t} %s_u;\n", name);
245 f_print(fout, "};\n");
246 f_print(fout, "typedef struct %s %s;\n", name, name);
254 f_print(fout, "#define\t%s %s\n", name, num);
262 f_print(fout, "#define\t%s ((unsigned long)(%s))\n", name, num);
266 define_printed(stop, start)
273 for (vers = start; vers != NULL; vers = vers->next) {
274 for (proc = vers->procs; proc != NULL; proc = proc->next) {
277 } else if (streq(proc->proc_name, stop->proc_name)) {
287 pfreeprocdef(char * name, char *vers, int mode)
289 f_print(fout, "extern int ");
292 f_print(fout,"_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
294 f_print(fout,"_freeresult();\n");
310 puldefine(def->def_name, def->def.pr.prog_num);
311 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
314 "extern struct rpcgen_table %s_%s_table[];\n",
315 locase(def->def_name), vers->vers_num);
317 "extern %s_%s_nproc;\n",
318 locase(def->def_name), vers->vers_num);
320 puldefine(vers->vers_name, vers->vers_num);
323 * Print out 2 definitions, one for ANSI-C, another for
329 for (proc = vers->procs; proc != NULL;
331 if (!define_printed(proc,
332 def->def.pr.versions)) {
333 puldefine(proc->proc_name,
336 f_print(fout, "%s", ext);
337 pprocdef(proc, vers, NULL, 0, 2);
340 f_print(fout, "%s", ext);
341 pprocdef(proc, vers, NULL, 1, 2);
344 pfreeprocdef(def->def_name, vers->vers_num, 2);
347 for (i = 1; i < 3; i++){
349 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
352 f_print(fout, "\n#else /* K&R C */\n");
356 for (proc = vers->procs; proc != NULL;
358 if (!define_printed(proc,
359 def->def.pr.versions)) {
360 puldefine(proc->proc_name,
363 f_print(fout, "%s", ext);
364 pprocdef(proc, vers, "CLIENT *", 0, i);
365 f_print(fout, "%s", ext);
366 pprocdef(proc, vers, "struct svc_req *", 1, i);
368 pfreeprocdef(def->def_name, vers->vers_num, i);
370 f_print(fout, "#endif /* K&R C */\n");
376 pprocdef(proc, vp, addargtype, server_p, mode)
383 if (mtflag) {/* Print MT style stubs */
385 f_print(fout, "bool_t ");
387 f_print(fout, "enum clnt_stat ");
389 ptype(proc->res_prefix, proc->res_type, 1);
393 pvname_svc(proc->proc_name, vp->vers_num);
395 pvname(proc->proc_name, vp->vers_num);
398 * mode 1 = ANSI-C, mode 2 = K&R C
401 parglist(proc, addargtype);
403 f_print(fout, "();\n");
408 /* print out argument list of procedure */
410 parglist(proc, addargtype)
417 if (proc->arg_num < 2 && newstyle &&
418 streq(proc->args.decls->decl.type, "void")) {
419 /* 0 argument in new style: do nothing*/
422 for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
423 ptype(dl->decl.prefix, dl->decl.type, 1);
426 /* old style passes by reference */
432 ptype(proc->res_prefix, proc->res_type, 1);
433 f_print(fout, "*, ");
436 f_print(fout, "%s);\n", addargtype);
444 char *name = def->def_name;
449 f_print(fout, "enum %s {\n", name);
450 for (l = def->def.en.vals; l != NULL; l = l->next) {
451 f_print(fout, "\t%s", l->name);
453 f_print(fout, " = %s", l->assignment);
454 last = l->assignment;
458 f_print(fout, " = %d", count++);
460 f_print(fout, " = %s + %d", last, count++);
464 f_print(fout, ",\n");
468 f_print(fout, "};\n");
469 f_print(fout, "typedef enum %s %s;\n", name, name);
476 char *name = def->def_name;
477 char *old = def->def.ty.old_type;
478 char prefix[8]; /* enough to contain "struct ", including NUL */
479 relation rel = def->def.ty.rel;
482 if (!streq(name, old)) {
483 if (streq(old, "string")) {
486 } else if (streq(old, "opaque")) {
488 } else if (streq(old, "bool")) {
491 if (undefined2(old, name) && def->def.ty.old_prefix) {
492 s_print(prefix, "%s ", def->def.ty.old_prefix);
496 f_print(fout, "typedef ");
499 f_print(fout, "struct {\n");
500 f_print(fout, "\tu_int %s_len;\n", name);
501 f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
502 f_print(fout, "} %s", name);
505 f_print(fout, "%s%s *%s", prefix, old, name);
508 f_print(fout, "%s%s %s[%s]", prefix, old, name,
509 def->def.ty.array_max);
512 f_print(fout, "%s%s %s", prefix, old, name);
515 f_print(fout, ";\n");
520 pdeclaration(name, dec, tab, separator)
526 char buf[8]; /* enough to hold "struct ", include NUL */
530 if (streq(dec->type, "void")) {
534 if (streq(dec->type, name) && !dec->prefix) {
535 f_print(fout, "struct ");
537 if (streq(dec->type, "string")) {
538 f_print(fout, "char *%s", dec->name);
541 if (streq(dec->type, "bool")) {
543 } else if (streq(dec->type, "opaque")) {
547 s_print(buf, "%s ", dec->prefix);
554 f_print(fout, "%s%s %s", prefix, type, dec->name);
557 f_print(fout, "%s%s %s[%s]", prefix, type, dec->name,
561 f_print(fout, "%s%s *%s", prefix, type, dec->name);
564 f_print(fout, "struct {\n");
566 f_print(fout, "\tu_int %s_len;\n", dec->name);
569 "\t%s%s *%s_val;\n", prefix, type, dec->name);
571 f_print(fout, "} %s", dec->name);
575 f_print(fout, separator);
579 undefined2(type, stop)
586 for (l = defined; l != NULL; l = l->next) {
587 def = (definition *) l->val;
588 if (def->def_kind != DEF_PROGRAM) {
589 if (streq(def->def_name, stop)) {
591 } else if (streq(def->def_name, type)) {