1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 /* 29 * University Copyright- Copyright (c) 1982, 1986, 1988 30 * The Regents of the University of California 31 * All Rights Reserved 32 * 33 * University Acknowledgment- Portions of this document are derived from 34 * software developed by the University of California, Berkeley, and its 35 * contributors. 36 */ 37 38 #pragma ident "%Z%%M% %I% %E% SMI" 39 40 /* 41 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 42 */ 43 #include <stdio.h> 44 #include <string.h> 45 #include "rpc_parse.h" 46 #include "rpc_util.h" 47 48 /* 49 * Emit the C-routine for the given definition 50 */ 51 void 52 emit(def) 53 definition *def; 54 { 55 if (def->def_kind == DEF_CONST) { 56 return; 57 } 58 if (def->def_kind == DEF_PROGRAM) { 59 emit_program(def); 60 return; 61 } 62 if (def->def_kind == DEF_TYPEDEF) { 63 /* 64 * now we need to handle declarations like 65 * struct typedef foo foo; 66 * since we dont want this to be expanded into 2 calls 67 * to xdr_foo 68 */ 69 70 if (strcmp(def->def.ty.old_type, def->def_name) == 0) 71 return; 72 }; 73 print_header(def); 74 switch (def->def_kind) { 75 case DEF_UNION: 76 emit_union(def); 77 break; 78 case DEF_ENUM: 79 emit_enum(def); 80 break; 81 case DEF_STRUCT: 82 emit_struct(def); 83 break; 84 case DEF_TYPEDEF: 85 emit_typedef(def); 86 break; 87 } 88 print_trailer(); 89 } 90 91 static 92 findtype(def, type) 93 definition *def; 94 char *type; 95 { 96 97 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { 98 return (0); 99 } else { 100 return (streq(def->def_name, type)); 101 } 102 } 103 104 static 105 undefined(type) 106 char *type; 107 { 108 definition *def; 109 110 def = (definition *) FINDVAL(defined, type, findtype); 111 return (def == NULL); 112 } 113 114 115 static 116 print_generic_header(procname, pointerp) 117 char *procname; 118 int pointerp; 119 { 120 f_print(fout, "\n"); 121 f_print(fout, "bool_t\n"); 122 if (Cflag) { 123 f_print(fout, "xdr_%s(", procname); 124 f_print(fout, "register XDR *xdrs, "); 125 f_print(fout, "%s ", procname); 126 if (pointerp) 127 f_print(fout, "*"); 128 f_print(fout, "objp)\n{\n\n"); 129 } else { 130 f_print(fout, "xdr_%s(xdrs, objp)\n", procname); 131 f_print(fout, "\tregister XDR *xdrs;\n"); 132 f_print(fout, "\t%s ", procname); 133 if (pointerp) 134 f_print(fout, "*"); 135 f_print(fout, "objp;\n{\n\n"); 136 } 137 } 138 139 static 140 print_header(def) 141 definition *def; 142 { 143 144 decl_list *dl; 145 bas_type *ptr; 146 int i; 147 148 print_generic_header(def->def_name, 149 def->def_kind != DEF_TYPEDEF || 150 !isvectordef(def->def.ty.old_type, 151 def->def.ty.rel)); 152 /* Now add Inline support */ 153 154 if (inlinelen == 0) 155 return; 156 /* May cause lint to complain. but ... */ 157 f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n"); 158 f_print(fout, "\tregister int *buf;\n"); 159 f_print(fout, "#else\n"); 160 f_print(fout, "\tregister long *buf;\n"); 161 f_print(fout, "#endif\n\n"); 162 } 163 164 static 165 print_prog_header(plist) 166 proc_list *plist; 167 { 168 print_generic_header(plist->args.argname, 1); 169 } 170 171 static 172 print_trailer() 173 { 174 f_print(fout, "\treturn (TRUE);\n"); 175 f_print(fout, "}\n"); 176 } 177 178 179 static 180 print_ifopen(indent, name) 181 int indent; 182 char *name; 183 { 184 tabify(fout, indent); 185 if (streq(name, "rpcprog_t") || 186 streq(name, "rpcvers_t") || 187 streq(name, "rpcproc_t") || 188 streq(name, "rpcprot_t") || 189 streq(name, "rpcport_t")) 190 strtok(name, "_"); 191 f_print(fout, "if (!xdr_%s(xdrs", name); 192 } 193 194 static 195 print_ifarg(arg) 196 char *arg; 197 { 198 f_print(fout, ", %s", arg); 199 } 200 201 static 202 print_ifsizeof(indent, prefix, type) 203 int indent; 204 char *prefix; 205 char *type; 206 { 207 if (indent) { 208 f_print(fout, ",\n"); 209 tabify(fout, indent); 210 } else { 211 f_print(fout, ", "); 212 } 213 if (streq(type, "bool")) { 214 f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); 215 } else { 216 f_print(fout, "sizeof ("); 217 if (undefined(type) && prefix) { 218 f_print(fout, "%s ", prefix); 219 } 220 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type); 221 } 222 } 223 224 static 225 print_ifclose(indent) 226 int indent; 227 { 228 f_print(fout, "))\n"); 229 tabify(fout, indent); 230 f_print(fout, "\treturn (FALSE);\n"); 231 } 232 233 static 234 print_ifstat(indent, prefix, type, rel, amax, objname, name) 235 int indent; 236 char *prefix; 237 char *type; 238 relation rel; 239 char *amax; 240 char *objname; 241 char *name; 242 { 243 char *alt = NULL; 244 245 switch (rel) { 246 case REL_POINTER: 247 print_ifopen(indent, "pointer"); 248 print_ifarg("(char **)"); 249 f_print(fout, "%s", objname); 250 print_ifsizeof(0, prefix, type); 251 break; 252 case REL_VECTOR: 253 if (streq(type, "string")) { 254 alt = "string"; 255 } else if (streq(type, "opaque")) { 256 alt = "opaque"; 257 } 258 if (alt) { 259 print_ifopen(indent, alt); 260 print_ifarg(objname); 261 } else { 262 print_ifopen(indent, "vector"); 263 print_ifarg("(char *)"); 264 f_print(fout, "%s", objname); 265 } 266 print_ifarg(amax); 267 if (!alt) { 268 print_ifsizeof(indent + 1, prefix, type); 269 } 270 break; 271 case REL_ARRAY: 272 if (streq(type, "string")) { 273 alt = "string"; 274 } else if (streq(type, "opaque")) { 275 alt = "bytes"; 276 } 277 if (streq(type, "string")) { 278 print_ifopen(indent, alt); 279 print_ifarg(objname); 280 } else { 281 if (alt) { 282 print_ifopen(indent, alt); 283 } else { 284 print_ifopen(indent, "array"); 285 } 286 print_ifarg("(char **)"); 287 if (*objname == '&') { 288 f_print(fout, "%s.%s_val, (u_int *) %s.%s_len", 289 objname, name, objname, name); 290 } else { 291 f_print(fout, 292 "&%s->%s_val, (u_int *) &%s->%s_len", 293 objname, name, objname, name); 294 } 295 } 296 print_ifarg(amax); 297 if (!alt) { 298 print_ifsizeof(indent + 1, prefix, type); 299 } 300 break; 301 case REL_ALIAS: 302 print_ifopen(indent, type); 303 print_ifarg(objname); 304 break; 305 } 306 print_ifclose(indent); 307 } 308 309 /* ARGSUSED */ 310 static 311 emit_enum(def) 312 definition *def; 313 { 314 print_ifopen(1, "enum"); 315 print_ifarg("(enum_t *)objp"); 316 print_ifclose(1); 317 } 318 319 static 320 emit_program(def) 321 definition *def; 322 { 323 decl_list *dl; 324 version_list *vlist; 325 proc_list *plist; 326 327 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) 328 for (plist = vlist->procs; plist != NULL; plist = plist->next) { 329 if (!newstyle || plist->arg_num < 2) 330 continue; /* old style, or single argument */ 331 print_prog_header(plist); 332 for (dl = plist->args.decls; dl != NULL; 333 dl = dl->next) 334 print_stat(1, &dl->decl); 335 print_trailer(); 336 } 337 } 338 339 340 static 341 emit_union(def) 342 definition *def; 343 { 344 declaration *dflt; 345 case_list *cl; 346 declaration *cs; 347 char *object; 348 char *vecformat = "objp->%s_u.%s"; 349 char *format = "&objp->%s_u.%s"; 350 351 print_stat(1, &def->def.un.enum_decl); 352 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); 353 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { 354 355 f_print(fout, "\tcase %s:\n", cl->case_name); 356 if (cl->contflag == 1) /* a continued case statement */ 357 continue; 358 cs = &cl->case_decl; 359 if (!streq(cs->type, "void")) { 360 object = alloc(strlen(def->def_name) + strlen(format) + 361 strlen(cs->name) + 1); 362 if (isvectordef(cs->type, cs->rel)) { 363 s_print(object, vecformat, def->def_name, 364 cs->name); 365 } else { 366 s_print(object, format, def->def_name, 367 cs->name); 368 } 369 print_ifstat(2, cs->prefix, cs->type, cs->rel, 370 cs->array_max, object, cs->name); 371 free(object); 372 } 373 f_print(fout, "\t\tbreak;\n"); 374 } 375 dflt = def->def.un.default_decl; 376 if (dflt != NULL) { 377 if (!streq(dflt->type, "void")) { 378 f_print(fout, "\tdefault:\n"); 379 object = alloc(strlen(def->def_name) + strlen(format) + 380 strlen(dflt->name) + 1); 381 if (isvectordef(dflt->type, dflt->rel)) { 382 s_print(object, vecformat, def->def_name, 383 dflt->name); 384 } else { 385 s_print(object, format, def->def_name, 386 dflt->name); 387 } 388 389 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, 390 dflt->array_max, object, dflt->name); 391 free(object); 392 f_print(fout, "\t\tbreak;\n"); 393 } 394 } else { 395 f_print(fout, "\tdefault:\n"); 396 f_print(fout, "\t\treturn (FALSE);\n"); 397 } 398 399 f_print(fout, "\t}\n"); 400 } 401 402 static void 403 expand_inline(int indent, const char *sizestr, 404 int size, int flag, decl_list *dl, decl_list *cur) 405 { 406 decl_list *psav; 407 408 /* 409 * were already looking at a xdr_inlineable structure 410 */ 411 tabify(fout, indent + 1); 412 if (sizestr == NULL) 413 f_print(fout, 414 "buf = XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);", 415 size); 416 else if (size == 0) 417 f_print(fout, 418 "buf = XDR_INLINE(xdrs, (%s) * BYTES_PER_XDR_UNIT);", 419 sizestr); 420 else 421 f_print(fout, 422 "buf = XDR_INLINE(xdrs, (%d + (%s)) " 423 "* BYTES_PER_XDR_UNIT);", size, sizestr); 424 425 f_print(fout, "\n"); 426 tabify(fout, indent + 1); 427 f_print(fout, "if (buf == NULL) {\n"); 428 429 psav = cur; 430 while (cur != dl) { 431 print_stat(indent + 2, 432 &cur->decl); 433 cur = cur->next; 434 } 435 436 tabify(fout, indent+1); 437 f_print(fout, "} else {\n"); 438 439 f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n"); 440 cur = psav; 441 while (cur != dl) { 442 emit_inline64(indent + 2, &cur->decl, flag); 443 cur = cur->next; 444 } 445 f_print(fout, "#else\n"); 446 cur = psav; 447 while (cur != dl) { 448 emit_inline(indent + 2, &cur->decl, flag); 449 cur = cur->next; 450 } 451 f_print(fout, "#endif\n"); 452 453 tabify(fout, indent + 1); 454 f_print(fout, "}\n"); 455 } 456 457 /* 458 * An inline type is a base type (interger type) or a vector of base types. 459 */ 460 static int 461 inline_type(declaration *dc, int *size) 462 { 463 bas_type *ptr; 464 465 *size = 0; 466 467 if (dc->prefix == NULL && 468 (dc->rel == REL_ALIAS || dc->rel == REL_VECTOR)) { 469 ptr = find_type(dc->type); 470 if (ptr != NULL) { 471 *size = ptr->length; 472 return (1); 473 } 474 } 475 476 return (0); 477 } 478 479 static char * 480 arraysize(char *sz, declaration *dc, int elsize) 481 { 482 int len; 483 int elsz = elsize; 484 int digits; 485 int slen = 0; 486 char *plus = ""; 487 char *tmp; 488 489 /* 490 * Calculate the size of a string to hold the size of all arrays 491 * to be inlined. 492 * 493 * We have the string representation of the total size that has already 494 * been seen. (Null if this is the first array). 495 * We have the string representation of array max from the declaration, 496 * optionally the plus string, " + ", if this is not the first array, 497 * and the number of digits for the element size for this declaration. 498 */ 499 if (sz != NULL) { 500 plus = " + "; 501 slen = strlen(sz); 502 } 503 504 /* Calculate the number of digits to hold the element size */ 505 for (digits = 1; elsz >= 10; digits++) 506 elsz /= 10; 507 508 /* 509 * If elsize != 1 the allocate 3 extra bytes for the times 510 * string, " * ", the "()" below, and the digits. One extra 511 * for the trailing NULL 512 */ 513 len = strlen(dc->array_max) + (elsize == 1 ? 0 : digits + 5) + 1; 514 tmp = realloc(sz, slen + len + strlen(plus)); 515 if (tmp == NULL) { 516 f_print(stderr, "Fatal error : no memory\n"); 517 crash(); 518 } 519 520 if (elsize == 1) 521 s_print(tmp + slen, "%s%s", plus, dc->array_max); 522 else 523 s_print(tmp + slen, "%s(%s) * %d", plus, dc->array_max, elsize); 524 525 return (tmp); 526 } 527 528 static void 529 inline_struct(decl_list *dl, decl_list *last, int flag, int indent) 530 { 531 int size, tsize; 532 decl_list *cur, *psav; 533 char *sizestr, *plus; 534 char ptemp[256]; 535 536 cur = NULL; 537 tsize = 0; 538 sizestr = NULL; 539 for (; dl != last; dl = dl->next) { 540 if (inline_type(&dl->decl, &size)) { 541 if (cur == NULL) 542 cur = dl; 543 544 if (dl->decl.rel == REL_ALIAS) 545 tsize += size; 546 else { 547 /* this code is required to handle arrays */ 548 sizestr = arraysize(sizestr, &dl->decl, size); 549 } 550 } else { 551 if (cur != NULL) 552 if (sizestr == NULL && tsize < inlinelen) { 553 /* 554 * don't expand into inline code 555 * if tsize < inlinelen 556 */ 557 while (cur != dl) { 558 print_stat(indent + 1, 559 &cur->decl); 560 cur = cur->next; 561 } 562 } else { 563 expand_inline(indent, sizestr, 564 tsize, flag, dl, cur); 565 } 566 tsize = 0; 567 cur = NULL; 568 sizestr = NULL; 569 print_stat(indent + 1, &dl->decl); 570 } 571 } 572 573 if (cur != NULL) 574 if (sizestr == NULL && tsize < inlinelen) { 575 /* don't expand into inline code if tsize < inlinelen */ 576 while (cur != dl) { 577 print_stat(indent + 1, &cur->decl); 578 cur = cur->next; 579 } 580 } else { 581 expand_inline(indent, sizestr, tsize, flag, dl, cur); 582 } 583 } 584 585 /* 586 * Check if we can inline this structure. While we are at it check if the 587 * declaration list has any vectors defined of "basic" types. 588 */ 589 static int 590 check_inline(decl_list *dl, int inlinelen, int *have_vector) 591 { 592 int tsize = 0; 593 int size; 594 int doinline = 0; 595 596 *have_vector = 0; 597 if (inlinelen == 0) 598 return (0); 599 600 for (; dl != NULL; dl = dl->next) { 601 if (inline_type(&dl->decl, &size)) { 602 if (dl->decl.rel == REL_VECTOR) { 603 *have_vector = 1; 604 doinline = 1; 605 break; 606 } else { 607 tsize += size; 608 if (tsize >= inlinelen) 609 doinline = 1; 610 } 611 } else { 612 tsize = 0; 613 } 614 } 615 616 return (doinline); 617 } 618 619 620 static void 621 emit_struct_tail_recursion(definition *defp, int can_inline) 622 { 623 int indent = 3; 624 struct_def *sp = &defp->def.st; 625 decl_list *dl; 626 627 628 f_print(fout, "\t%s *tmp_%s;\n", 629 defp->def_name, defp->def_name); 630 631 f_print(fout, "\tbool_t more_data = TRUE;\n"); 632 f_print(fout, "\tbool_t first_objp = TRUE;\n\n"); 633 634 f_print(fout, "\n\tif (xdrs->x_op == XDR_DECODE) {\n"); 635 f_print(fout, "\n\t\twhile (more_data) {\n"); 636 f_print(fout, "\n\t\t\tvoid bzero();\n\n"); 637 638 if (can_inline) 639 inline_struct(sp->decls, sp->tail, GET, indent); 640 else 641 for (dl = sp->decls; dl != NULL && dl != sp->tail; 642 dl = dl->next) 643 print_stat(indent, &dl->decl); 644 645 f_print(fout, "\t\t\tif (!xdr_bool(xdrs, " 646 "&more_data))\n\t\t\t\treturn (FALSE);\n"); 647 648 f_print(fout, "\n\t\t\tif (!more_data) {\n"); 649 f_print(fout, "\t\t\t\tobjp->%s = NULL;\n", sp->tail->decl.name); 650 f_print(fout, "\t\t\t\tbreak;\n"); 651 f_print(fout, "\t\t\t}\n\n"); 652 f_print(fout, "\t\t\tif (objp->%s == NULL) {\n", sp->tail->decl.name); 653 f_print(fout, "\t\t\t\tobjp->%s = " 654 "(%s *)\n\t\t\t\t\tmem_alloc(sizeof (%s));\n", 655 sp->tail->decl.name, defp->def_name, defp->def_name); 656 657 f_print(fout, "\t\t\t\tif (objp->%s == NULL)\n" 658 "\t\t\t\t\treturn (FALSE);\n", sp->tail->decl.name); 659 f_print(fout, "\t\t\t\tbzero(objp->%s, sizeof (%s));\n", 660 sp->tail->decl.name, defp->def_name); 661 f_print(fout, "\t\t\t}\n"); 662 f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name); 663 f_print(fout, "\t\t}\n"); 664 665 f_print(fout, "\n\t} else if (xdrs->x_op == XDR_ENCODE) {\n"); 666 f_print(fout, "\n\t\twhile (more_data) {\n"); 667 668 if (can_inline) 669 inline_struct(sp->decls, sp->tail, PUT, indent); 670 else 671 for (dl = sp->decls; dl != NULL && dl != sp->tail; 672 dl = dl->next) 673 print_stat(indent, &dl->decl); 674 675 f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name); 676 f_print(fout, "\t\t\tif (objp == NULL)\n"); 677 f_print(fout, "\t\t\t\tmore_data = FALSE;\n"); 678 679 f_print(fout, "\t\t\tif (!xdr_bool(xdrs, &more_data))\n" 680 "\t\t\t\treturn (FALSE);\n"); 681 682 f_print(fout, "\t\t}\n"); 683 684 f_print(fout, "\n\t} else {\n"); 685 f_print(fout, "\n\t\twhile (more_data) {\n"); 686 687 for (dl = sp->decls; dl != NULL && dl != sp->tail; dl = dl->next) 688 print_stat(indent, &dl->decl); 689 690 f_print(fout, "\t\t\ttmp_%s = objp;\n", defp->def_name); 691 f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name); 692 693 f_print(fout, "\t\t\tif (objp == NULL)\n"); 694 f_print(fout, "\t\t\t\tmore_data = FALSE;\n"); 695 696 f_print(fout, "\t\t\tif (!first_objp)\n"); 697 698 f_print(fout, "\t\t\t\tmem_free(tmp_%s, sizeof (%s));\n", 699 defp->def_name, defp->def_name); 700 701 f_print(fout, "\t\t\telse\n\t\t\t\tfirst_objp = FALSE;\n\t\t}\n"); 702 703 f_print(fout, "\n\t}\n"); 704 } 705 706 static 707 emit_struct(def) 708 definition *def; 709 { 710 decl_list *dl = def->def.st.decls; 711 int can_inline, have_vector; 712 713 714 can_inline = check_inline(dl, inlinelen, &have_vector); 715 if (have_vector) 716 f_print(fout, "\tint i;\n"); 717 718 719 if (rflag && def->def.st.self_pointer) { 720 /* Handle tail recursion elimination */ 721 emit_struct_tail_recursion(def, can_inline); 722 return; 723 } 724 725 726 if (can_inline) { 727 f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); 728 inline_struct(dl, NULL, PUT, 1); 729 730 f_print(fout, "\t\treturn (TRUE);\n\t}" 731 " else if (xdrs->x_op == XDR_DECODE) {\n"); 732 733 inline_struct(dl, NULL, GET, 1); 734 f_print(fout, "\t\treturn (TRUE);\n\t}\n\n"); 735 } 736 737 /* now take care of XDR_FREE inline case or the non-inline cases */ 738 739 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 740 print_stat(1, &dl->decl); 741 742 } 743 744 static 745 emit_typedef(def) 746 definition *def; 747 { 748 char *prefix = def->def.ty.old_prefix; 749 char *type = def->def.ty.old_type; 750 char *amax = def->def.ty.array_max; 751 relation rel = def->def.ty.rel; 752 753 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); 754 } 755 756 static 757 print_stat(indent, dec) 758 int indent; 759 declaration *dec; 760 { 761 char *prefix = dec->prefix; 762 char *type = dec->type; 763 char *amax = dec->array_max; 764 relation rel = dec->rel; 765 char name[256]; 766 767 if (isvectordef(type, rel)) { 768 s_print(name, "objp->%s", dec->name); 769 } else { 770 s_print(name, "&objp->%s", dec->name); 771 } 772 print_ifstat(indent, prefix, type, rel, amax, name, dec->name); 773 } 774 775 776 char *upcase(); 777 778 emit_inline(indent, decl, flag) 779 int indent; 780 declaration *decl; 781 int flag; 782 { 783 switch (decl->rel) { 784 case REL_ALIAS : 785 emit_single_in_line(indent, decl, flag, REL_ALIAS); 786 break; 787 case REL_VECTOR : 788 tabify(fout, indent); 789 f_print(fout, "{\n"); 790 tabify(fout, indent + 1); 791 f_print(fout, "register %s *genp;\n\n", decl->type); 792 tabify(fout, indent + 1); 793 f_print(fout, 794 "for (i = 0, genp = objp->%s;\n", decl->name); 795 tabify(fout, indent + 2); 796 f_print(fout, "i < %s; i++) {\n", decl->array_max); 797 emit_single_in_line(indent + 2, decl, flag, REL_VECTOR); 798 tabify(fout, indent + 1); 799 f_print(fout, "}\n"); 800 tabify(fout, indent); 801 f_print(fout, "}\n"); 802 } 803 } 804 805 emit_inline64(indent, decl, flag) 806 int indent; 807 declaration *decl; 808 int flag; 809 { 810 switch (decl->rel) { 811 case REL_ALIAS : 812 emit_single_in_line64(indent, decl, flag, REL_ALIAS); 813 break; 814 case REL_VECTOR : 815 tabify(fout, indent); 816 f_print(fout, "{\n"); 817 tabify(fout, indent + 1); 818 f_print(fout, "register %s *genp;\n\n", decl->type); 819 tabify(fout, indent + 1); 820 f_print(fout, 821 "for (i = 0, genp = objp->%s;\n", decl->name); 822 tabify(fout, indent + 2); 823 f_print(fout, "i < %s; i++) {\n", decl->array_max); 824 emit_single_in_line64(indent + 2, decl, flag, REL_VECTOR); 825 tabify(fout, indent + 1); 826 f_print(fout, "}\n"); 827 tabify(fout, indent); 828 f_print(fout, "}\n"); 829 } 830 } 831 832 emit_single_in_line(indent, decl, flag, rel) 833 int indent; 834 declaration *decl; 835 int flag; 836 relation rel; 837 { 838 char *upp_case; 839 int freed = 0; 840 841 tabify(fout, indent); 842 if (flag == PUT) 843 f_print(fout, "IXDR_PUT_"); 844 else 845 if (rel == REL_ALIAS) 846 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 847 else 848 f_print(fout, "*genp++ = IXDR_GET_"); 849 850 upp_case = upcase(decl->type); 851 852 /* hack - XX */ 853 if (strcmp(upp_case, "INT") == 0) 854 { 855 free(upp_case); 856 freed = 1; 857 upp_case = "LONG"; 858 } 859 if ((strcmp(upp_case, "U_INT") == 0) || 860 (strcmp(upp_case, "RPCPROG") == 0) || 861 (strcmp(upp_case, "RPCVERS") == 0) || 862 (strcmp(upp_case, "RPCPROC") == 0) || 863 (strcmp(upp_case, "RPCPROT") == 0) || 864 (strcmp(upp_case, "RPCPORT") == 0)) 865 { 866 free(upp_case); 867 freed = 1; 868 upp_case = "U_LONG"; 869 } 870 871 if (flag == PUT) 872 if (rel == REL_ALIAS) 873 f_print(fout, 874 "%s(buf, objp->%s);\n", upp_case, decl->name); 875 else 876 f_print(fout, "%s(buf, *genp++);\n", upp_case); 877 878 else 879 f_print(fout, "%s(buf);\n", upp_case); 880 if (!freed) 881 free(upp_case); 882 } 883 884 emit_single_in_line64(indent, decl, flag, rel) 885 int indent; 886 declaration *decl; 887 int flag; 888 relation rel; 889 { 890 char *upp_case; 891 int freed = 0; 892 893 tabify(fout, indent); 894 if (flag == PUT) 895 f_print(fout, "IXDR_PUT_"); 896 else 897 if (rel == REL_ALIAS) 898 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 899 else 900 f_print(fout, "*genp++ = IXDR_GET_"); 901 902 upp_case = upcase(decl->type); 903 904 /* hack - XX */ 905 if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0)) 906 { 907 free(upp_case); 908 freed = 1; 909 upp_case = "INT32"; 910 } 911 if ((strcmp(upp_case, "U_INT") == 0) || 912 (strcmp(upp_case, "U_LONG") == 0) || 913 (strcmp(upp_case, "RPCPROG") == 0) || 914 (strcmp(upp_case, "RPCVERS") == 0) || 915 (strcmp(upp_case, "RPCPROC") == 0) || 916 (strcmp(upp_case, "RPCPROT") == 0) || 917 (strcmp(upp_case, "RPCPORT") == 0)) 918 { 919 free(upp_case); 920 freed = 1; 921 upp_case = "U_INT32"; 922 } 923 924 if (flag == PUT) 925 if (rel == REL_ALIAS) 926 f_print(fout, 927 "%s(buf, objp->%s);\n", upp_case, decl->name); 928 else 929 f_print(fout, "%s(buf, *genp++);\n", upp_case); 930 931 else 932 f_print(fout, "%s(buf);\n", upp_case); 933 if (!freed) 934 free(upp_case); 935 } 936 937 char * 938 upcase(str) 939 char *str; 940 { 941 char *ptr, *hptr; 942 943 ptr = (char *)malloc(strlen(str)+1); 944 if (ptr == (char *)NULL) 945 { 946 f_print(stderr, "malloc failed\n"); 947 exit(1); 948 }; 949 950 hptr = ptr; 951 while (*str != '\0') 952 *ptr++ = toupper(*str++); 953 954 *ptr = '\0'; 955 return (hptr); 956 } 957