1 /* @(#)rpc_cout.c 1.1 87/11/04 3.9 RPCSRC */
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
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
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
33 * Copyright (C) 1987, Sun Microsystems, Inc.
35 #include <afs/param.h>
36 #include <afsconfig.h>
46 #include "rpc_parse.h"
50 static print_header();
51 static print_trailer();
56 static emit_typedef();
60 * Emit the C-routine for the given definition
66 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
70 switch (def->def_kind) {
92 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
95 return (streq(def->def_name, type));
105 def = (definition *) FINDVAL(defined, type, findtype);
106 return (def == NULL);
115 f_print(fout, "bool_t\n");
116 f_print(fout, "xdr_%s(xdrs, objp)\n", def->def_name);
117 f_print(fout, "\tXDR *xdrs;\n");
118 f_print(fout, "\t%s ", def->def_name);
119 if (def->def_kind != DEF_TYPEDEF ||
120 !isvectordef(def->def.ty.old_type, def->def.ty.rel)) {
123 f_print(fout, "objp;\n");
124 f_print(fout, "{\n");
130 f_print(fout, "\treturn (TRUE);\n");
131 f_print(fout, "}\n");
137 print_ifopen(indent, name)
141 tabify(fout, indent);
142 f_print(fout, "if (!xdr_%s(xdrs", name);
150 f_print(fout, ", %s", arg);
155 print_ifsizeof(prefix, type)
159 if (streq(type, "bool")) {
160 f_print(fout, ", sizeof(bool_t), xdr_bool");
162 f_print(fout, ", sizeof(");
163 if (undefined(type) && prefix) {
164 f_print(fout, "%s ", prefix);
166 f_print(fout, "%s), xdr_%s", type, type);
171 print_ifclose(indent)
174 f_print(fout, ")) {\n");
175 tabify(fout, indent);
176 f_print(fout, "\treturn (FALSE);\n");
177 tabify(fout, indent);
178 f_print(fout, "}\n");
184 f_print(fout, "\n\n");
188 print_ifstat(indent, prefix, type, rel, amax, objname, name)
201 print_ifopen(indent, "pointer");
202 print_ifarg("(char **)");
203 f_print(fout, "%s", objname);
204 print_ifsizeof(prefix, type);
207 if (streq(type, "string")) {
209 } else if (streq(type, "opaque")) {
213 print_ifopen(indent, alt);
214 print_ifarg(objname);
216 print_ifopen(indent, "vector");
217 print_ifarg("(char *)");
218 f_print(fout, "%s", objname);
222 print_ifsizeof(prefix, type);
226 if (streq(type, "string")) {
228 } else if (streq(type, "opaque")) {
231 if (streq(type, "string")) {
232 print_ifopen(indent, alt);
233 print_ifarg(objname);
236 print_ifopen(indent, alt);
238 print_ifopen(indent, "array");
240 print_ifarg("(char **)");
241 if (*objname == '&') {
242 f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
243 objname, name, objname, name);
245 f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
246 objname, name, objname, name);
251 print_ifsizeof(prefix, type);
255 print_ifopen(indent, type);
256 print_ifarg(objname);
259 print_ifclose(indent);
268 print_ifopen(1, "enum");
269 print_ifarg("(enum_t *)objp");
282 char *format = "&objp->%s_u.%s";
284 print_stat(&def->def.un.enum_decl);
285 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
286 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
288 f_print(fout, "\tcase %s:\n", cl->case_name);
289 if (!streq(cs->type, "void")) {
290 object = alloc(strlen(def->def_name) + strlen(format) +
291 strlen(cs->name) + 1);
292 s_print(object, format, def->def_name, cs->name);
293 print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
297 f_print(fout, "\t\tbreak;\n");
299 dflt = def->def.un.default_decl;
301 if (!streq(dflt->type, "void")) {
302 f_print(fout, "\tdefault:\n");
303 object = alloc(strlen(def->def_name) + strlen(format) +
304 strlen(dflt->name) + 1);
305 s_print(object, format, def->def_name, dflt->name);
306 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
307 dflt->array_max, object, dflt->name);
309 f_print(fout, "\t\tbreak;\n");
312 f_print(fout, "\tdefault:\n");
313 f_print(fout, "\t\treturn (FALSE);\n");
315 f_print(fout, "\t}\n");
326 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) {
327 print_stat(&dl->decl);
338 char *prefix = def->def.ty.old_prefix;
339 char *type = def->def.ty.old_type;
340 char *amax = def->def.ty.array_max;
341 relation rel = def->def.ty.rel;
343 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
354 char *prefix = dec->prefix;
355 char *type = dec->type;
356 char *amax = dec->array_max;
357 relation rel = dec->rel;
360 if (isvectordef(type, rel)) {
361 s_print(name, "objp->%s", dec->name);
363 s_print(name, "&objp->%s", dec->name);
365 print_ifstat(1, prefix, type, rel, amax, name, dec->name);
368 extern proc1_list *Proc_list;
369 extern int PerProcCounter;
379 s_print(prefix, "%s ", dec->prefix);
382 f_print(fout, "\ntypedef ");
385 f_print(fout, "struct %s {\n", dec->name);
386 f_print(fout, "\tu_int %s_len;\n", dec->name);
387 f_print(fout, "\t%s%s *%s_val;\n", prefix, dec->type, dec->name);
388 f_print(fout, "} %s", dec->name);
391 f_print(fout, ";\n");
392 f_print(fout, "bool_t xdr_%s();\n", dec->name);
404 f_print(fout, "bool_t\n");
405 f_print(fout, "xdr_%s(xdrs, objp)\n", dec->name);
406 f_print(fout, "\tXDR *xdrs;\n");
407 f_print(fout, "\t%s *objp;\n", dec->name);
408 f_print(fout, "{\n");
409 print_ifstat(1, dec->prefix, dec->type, dec->rel, dec->array_max, "objp", dec->name);
416 print_rxifopen(typename)
419 sprintf(Proc_list->code, "xdr_%s(&z_xdrs", typename);
420 sprintf(Proc_list->scode, "xdr_%s(z_xdrs", typename);
425 print_rxifarg(amp, arg, costant)
430 char code[100], scode[100];
432 sprintf(code, ", %s%s", amp, arg);
434 sprintf(scode, ", %s", arg);
436 sprintf(scode, ", &%s", arg);
437 strcat(Proc_list->code, code);
438 strcat(Proc_list->scode, scode);
443 print_rxifsizeof(prefix, type)
448 if (streq(type, "bool")) {
449 strcat(Proc_list->code, ", sizeof(bool_t), xdr_bool");
450 strcat(Proc_list->scode, ", sizeof(bool_t), xdr_bool");
452 strcat(Proc_list->code, ", sizeof(");
453 strcat(Proc_list->scode, ", sizeof(");
454 if (undefined(type) && prefix) {
455 sprintf(name, "%s ", prefix);
456 strcat(Proc_list->code, name);
457 strcat(Proc_list->scode, name);
459 sprintf(name, "%s), xdr_%s", type, type);
460 strcat(Proc_list->code, name);
461 strcat(Proc_list->scode, name);
469 char *prefix = dec->prefix;
470 char *type = dec->type;
471 char *amax = dec->array_max;
472 relation rel = dec->rel;
473 char *name = dec->name;
476 char *objname, *amp="";
478 if (rel == REL_POINTER)
479 Proc_list->pl.param_flag |= INDIRECT_PARAM;
482 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
484 objname = Proc_list->pl.param_name;
487 print_rxifopen(type);
488 print_rxifarg(amp, objname, 0);
490 print_rxifopen("pointer");
491 print_rxifarg(amp, "(char **)", 1);
492 sprintf(temp, "%s", objname);
493 strcat(Proc_list->code, temp);
494 strcat(Proc_list->scode, temp);
495 print_rxifsizeof(prefix, type);
499 if (streq(type, "string")) {
501 } else if (streq(type, "opaque")) {
506 print_rxifarg(amp, objname, 0);
508 print_rxifopen("vector");
509 print_rxifarg(amp, "(char *)", 0);
510 sprintf(temp, "%s", objname);
511 strcat(Proc_list->code, temp);
512 strcat(Proc_list->scode, temp);
514 print_rxifarg("", amax, 1);
516 print_rxifsizeof(prefix, type);
520 if (streq(type, "string")) {
522 } else if (streq(type, "opaque")) {
525 if (streq(type, "string")) {
527 if ((Proc_list->pl.param_kind == DEF_OUTPARAM) ||
528 (Proc_list->pl.param_kind == DEF_INOUTPARAM)) {
529 Proc_list->pl.param_flag |= OUT_STRING;
530 print_rxifarg("", objname, 0);
532 print_rxifarg("&", objname, 0);
533 /* print_rxifarg(amp, objname, 0); */
534 print_rxifarg("", amax, 1);
536 print_rxifsizeof(prefix, type);
539 char typecontents[100];
543 strcpy(temp, dec->name);
544 strcpy(typecontents, dec->name);
545 strcat(typecontents, " *");
546 strcpy(Proc_list->pl.param_type, typecontents);
547 sprintf(typecontents, "%s_%d", Proc_list->pl.param_name, ++PerProcCounter);
548 strcpy(Proc_list->pl.param_name, typecontents);
549 Proc_list->pl.param_flag |= FREETHIS_PARAM;
550 print_rxifopen(temp);
551 print_rxifarg(amp, name, 0);
557 print_rxifopen("array");
559 print_rxifarg(amp, "(char **)", 1);
560 if (*objname == '&') {
561 sprintf(temp, "%s.%s_val, (u_int *)%s.%s_len",
562 objname, name, objname, name);
564 sprintf(temp, "&%s->%s_val, (u_int *)&%s->%s_len",
565 objname, name, objname, name);
567 strcat(Proc_list->code, temp);
568 strcat(Proc_list->scode, temp);
570 print_rxifarg("", amax, 1);
572 print_rxifsizeof(prefix, type);
577 print_rxifopen(type);
578 print_rxifarg(amp, objname, 0);
581 strcat(Proc_list->code, ")");
582 strcat(Proc_list->scode, ")");