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 <afsconfig.h>
36 #include <afs/param.h>
50 #include "rpc_parse.h"
52 static print_header();
53 static print_trailer();
58 static emit_typedef();
62 * Emit the C-routine for the given definition
68 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
72 switch (def->def_kind) {
94 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
97 return (streq(def->def_name, type));
107 def = (definition *) FINDVAL(defined, type, findtype);
108 return (def == NULL);
117 f_print(fout, "bool_t\n");
118 f_print(fout, "xdr_%s(xdrs, objp)\n", def->def_name);
119 f_print(fout, "\tXDR *xdrs;\n");
120 f_print(fout, "\t%s ", def->def_name);
121 if (def->def_kind != DEF_TYPEDEF ||
122 !isvectordef(def->def.ty.old_type, def->def.ty.rel)) {
125 f_print(fout, "objp;\n");
126 f_print(fout, "{\n");
132 f_print(fout, "\treturn (TRUE);\n");
133 f_print(fout, "}\n");
139 print_ifopen(indent, name)
143 tabify(fout, indent);
144 f_print(fout, "if (!xdr_%s(xdrs", name);
152 f_print(fout, ", %s", arg);
157 print_ifsizeof(prefix, type)
161 if (streq(type, "bool")) {
162 f_print(fout, ", sizeof(bool_t), xdr_bool");
164 f_print(fout, ", sizeof(");
165 if (undefined(type) && prefix) {
166 f_print(fout, "%s ", prefix);
168 f_print(fout, "%s), xdr_%s", type, type);
173 print_ifclose(indent)
176 f_print(fout, ")) {\n");
177 tabify(fout, indent);
178 f_print(fout, "\treturn (FALSE);\n");
179 tabify(fout, indent);
180 f_print(fout, "}\n");
186 f_print(fout, "\n\n");
190 print_ifstat(indent, prefix, type, rel, amax, objname, name)
203 print_ifopen(indent, "pointer");
204 print_ifarg("(char **)");
205 f_print(fout, "%s", objname);
206 print_ifsizeof(prefix, type);
209 if (streq(type, "string")) {
211 } else if (streq(type, "opaque")) {
215 print_ifopen(indent, alt);
216 print_ifarg(objname);
218 print_ifopen(indent, "vector");
219 print_ifarg("(char *)");
220 f_print(fout, "%s", objname);
224 print_ifsizeof(prefix, type);
228 if (streq(type, "string")) {
230 } else if (streq(type, "opaque")) {
233 if (streq(type, "string")) {
234 print_ifopen(indent, alt);
235 print_ifarg(objname);
238 print_ifopen(indent, alt);
240 print_ifopen(indent, "array");
242 print_ifarg("(char **)");
243 if (*objname == '&') {
244 f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
245 objname, name, objname, name);
247 f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
248 objname, name, objname, name);
253 print_ifsizeof(prefix, type);
257 print_ifopen(indent, type);
258 print_ifarg(objname);
261 print_ifclose(indent);
270 print_ifopen(1, "enum");
271 print_ifarg("(enum_t *)objp");
284 char *format = "&objp->%s_u.%s";
286 print_stat(&def->def.un.enum_decl);
287 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
288 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
290 f_print(fout, "\tcase %s:\n", cl->case_name);
291 if (!streq(cs->type, "void")) {
292 object = alloc(strlen(def->def_name) + strlen(format) +
293 strlen(cs->name) + 1);
294 s_print(object, format, def->def_name, cs->name);
295 print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
299 f_print(fout, "\t\tbreak;\n");
301 dflt = def->def.un.default_decl;
303 if (!streq(dflt->type, "void")) {
304 f_print(fout, "\tdefault:\n");
305 object = alloc(strlen(def->def_name) + strlen(format) +
306 strlen(dflt->name) + 1);
307 s_print(object, format, def->def_name, dflt->name);
308 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
309 dflt->array_max, object, dflt->name);
311 f_print(fout, "\t\tbreak;\n");
314 f_print(fout, "\tdefault:\n");
315 f_print(fout, "\t\treturn (FALSE);\n");
317 f_print(fout, "\t}\n");
328 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) {
329 print_stat(&dl->decl);
340 char *prefix = def->def.ty.old_prefix;
341 char *type = def->def.ty.old_type;
342 char *amax = def->def.ty.array_max;
343 relation rel = def->def.ty.rel;
345 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
356 char *prefix = dec->prefix;
357 char *type = dec->type;
358 char *amax = dec->array_max;
359 relation rel = dec->rel;
362 if (isvectordef(type, rel)) {
363 s_print(name, "objp->%s", dec->name);
365 s_print(name, "&objp->%s", dec->name);
367 print_ifstat(1, prefix, type, rel, amax, name, dec->name);
370 extern proc1_list *Proc_list;
371 extern int PerProcCounter;
381 s_print(prefix, "%s ", dec->prefix);
384 f_print(fout, "\ntypedef ");
387 f_print(fout, "struct %s {\n", dec->name);
388 f_print(fout, "\tu_int %s_len;\n", dec->name);
389 f_print(fout, "\t%s%s *%s_val;\n", prefix, dec->type, dec->name);
390 f_print(fout, "} %s", dec->name);
393 f_print(fout, ";\n");
394 f_print(fout, "bool_t xdr_%s();\n", dec->name);
406 f_print(fout, "bool_t\n");
407 f_print(fout, "xdr_%s(xdrs, objp)\n", dec->name);
408 f_print(fout, "\tXDR *xdrs;\n");
409 f_print(fout, "\t%s *objp;\n", dec->name);
410 f_print(fout, "{\n");
411 print_ifstat(1, dec->prefix, dec->type, dec->rel, dec->array_max, "objp", dec->name);
418 print_rxifopen(typename)
421 sprintf(Proc_list->code, "xdr_%s(&z_xdrs", typename);
422 sprintf(Proc_list->scode, "xdr_%s(z_xdrs", typename);
427 print_rxifarg(amp, arg, costant)
432 char code[100], scode[100];
434 sprintf(code, ", %s%s", amp, arg);
436 sprintf(scode, ", %s", arg);
438 sprintf(scode, ", &%s", arg);
439 strcat(Proc_list->code, code);
440 strcat(Proc_list->scode, scode);
445 print_rxifsizeof(prefix, type)
450 if (streq(type, "bool")) {
451 strcat(Proc_list->code, ", sizeof(bool_t), xdr_bool");
452 strcat(Proc_list->scode, ", sizeof(bool_t), xdr_bool");
454 strcat(Proc_list->code, ", sizeof(");
455 strcat(Proc_list->scode, ", sizeof(");
456 if (undefined(type) && prefix) {
457 sprintf(name, "%s ", prefix);
458 strcat(Proc_list->code, name);
459 strcat(Proc_list->scode, name);
461 sprintf(name, "%s), xdr_%s", type, type);
462 strcat(Proc_list->code, name);
463 strcat(Proc_list->scode, name);
471 char *prefix = dec->prefix;
472 char *type = dec->type;
473 char *amax = dec->array_max;
474 relation rel = dec->rel;
475 char *name = dec->name;
478 char *objname, *amp="";
480 if (rel == REL_POINTER)
481 Proc_list->pl.param_flag |= INDIRECT_PARAM;
484 Proc_list->pl.param_flag &= ~INDIRECT_PARAM;
486 objname = Proc_list->pl.param_name;
489 print_rxifopen(type);
490 print_rxifarg(amp, objname, 0);
492 print_rxifopen("pointer");
493 print_rxifarg(amp, "(char **)", 1);
494 sprintf(temp, "%s", objname);
495 strcat(Proc_list->code, temp);
496 strcat(Proc_list->scode, temp);
497 print_rxifsizeof(prefix, type);
501 if (streq(type, "string")) {
503 } else if (streq(type, "opaque")) {
508 print_rxifarg(amp, objname, 0);
510 print_rxifopen("vector");
511 print_rxifarg(amp, "(char *)", 0);
512 sprintf(temp, "%s", objname);
513 strcat(Proc_list->code, temp);
514 strcat(Proc_list->scode, temp);
516 print_rxifarg("", amax, 1);
518 print_rxifsizeof(prefix, type);
522 if (streq(type, "string")) {
524 } else if (streq(type, "opaque")) {
527 if (streq(type, "string")) {
529 if ((Proc_list->pl.param_kind == DEF_OUTPARAM) ||
530 (Proc_list->pl.param_kind == DEF_INOUTPARAM)) {
531 Proc_list->pl.param_flag |= OUT_STRING;
532 print_rxifarg("", objname, 0);
534 print_rxifarg("&", objname, 0);
535 /* print_rxifarg(amp, objname, 0); */
536 print_rxifarg("", amax, 1);
538 print_rxifsizeof(prefix, type);
541 char typecontents[100];
545 strcpy(temp, dec->name);
546 strcpy(typecontents, dec->name);
547 strcat(typecontents, " *");
548 strcpy(Proc_list->pl.param_type, typecontents);
549 sprintf(typecontents, "%s_%d", Proc_list->pl.param_name, ++PerProcCounter);
550 strcpy(Proc_list->pl.param_name, typecontents);
551 Proc_list->pl.param_flag |= FREETHIS_PARAM;
552 print_rxifopen(temp);
553 print_rxifarg(amp, name, 0);
559 print_rxifopen("array");
561 print_rxifarg(amp, "(char **)", 1);
562 if (*objname == '&') {
563 sprintf(temp, "%s.%s_val, (u_int *)%s.%s_len",
564 objname, name, objname, name);
566 sprintf(temp, "&%s->%s_val, (u_int *)&%s->%s_len",
567 objname, name, objname, name);
569 strcat(Proc_list->code, temp);
570 strcat(Proc_list->scode, temp);
572 print_rxifarg("", amax, 1);
574 print_rxifsizeof(prefix, type);
579 print_rxifopen(type);
580 print_rxifarg(amp, objname, 0);
583 strcat(Proc_list->code, ")");
584 strcat(Proc_list->scode, ")");