rpc_cout.c (149710) | rpc_cout.c (152398) |
---|---|
1/* 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. 8 * --- 21 unchanged lines hidden (view full) --- 30#if 0 31#ifndef lint 32#ident "@(#)rpc_cout.c 1.14 93/07/05 SMI" 33static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI"; 34#endif 35#endif 36 37#include <sys/cdefs.h> | 1/* 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. 8 * --- 21 unchanged lines hidden (view full) --- 30#if 0 31#ifndef lint 32#ident "@(#)rpc_cout.c 1.14 93/07/05 SMI" 33static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI"; 34#endif 35#endif 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_cout.c 149710 2005-09-02 10:32:05Z stefanf $"); | 38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_cout.c 152398 2005-11-13 21:17:24Z dwmalone $"); |
39 40/* 41 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 42 * Copyright (C) 1987, Sun Microsystems, Inc. 43 */ 44#include <ctype.h> 45#include <stdio.h> 46#include <string.h> --- 11 unchanged lines hidden (view full) --- 58static void emit_typedef( definition * ); 59static void emit_inline( int, declaration *, int ); 60static void emit_single_in_line( int, declaration *, int, relation ); 61 62/* 63 * Emit the C-routine for the given definition 64 */ 65void | 39 40/* 41 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 42 * Copyright (C) 1987, Sun Microsystems, Inc. 43 */ 44#include <ctype.h> 45#include <stdio.h> 46#include <string.h> --- 11 unchanged lines hidden (view full) --- 58static void emit_typedef( definition * ); 59static void emit_inline( int, declaration *, int ); 60static void emit_single_in_line( int, declaration *, int, relation ); 61 62/* 63 * Emit the C-routine for the given definition 64 */ 65void |
66emit(def) 67 definition *def; | 66emit(definition *def) |
68{ 69 if (def->def_kind == DEF_CONST) { 70 return; 71 } 72 if (def->def_kind == DEF_PROGRAM) { 73 emit_program(def); 74 return; 75 } --- 24 unchanged lines hidden (view full) --- 100 /* DEF_CONST and DEF_PROGRAM have already been handled */ 101 default: 102 break; 103 } 104 print_trailer(); 105} 106 107static int | 67{ 68 if (def->def_kind == DEF_CONST) { 69 return; 70 } 71 if (def->def_kind == DEF_PROGRAM) { 72 emit_program(def); 73 return; 74 } --- 24 unchanged lines hidden (view full) --- 99 /* DEF_CONST and DEF_PROGRAM have already been handled */ 100 default: 101 break; 102 } 103 print_trailer(); 104} 105 106static int |
108findtype(def, type) 109 definition *def; 110 char *type; | 107findtype(definition *def, const char *type) |
111{ 112 113 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { 114 return (0); 115 } else { 116 return (streq(def->def_name, type)); 117 } 118} 119 120static int | 108{ 109 110 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { 111 return (0); 112 } else { 113 return (streq(def->def_name, type)); 114 } 115} 116 117static int |
121undefined(type) 122 char *type; | 118undefined(const char *type) |
123{ 124 definition *def; 125 126 def = (definition *) FINDVAL(defined, type, findtype); 127 return (def == NULL); 128} 129 130 131static void | 119{ 120 definition *def; 121 122 def = (definition *) FINDVAL(defined, type, findtype); 123 return (def == NULL); 124} 125 126 127static void |
132print_generic_header(procname, pointerp) 133 char* procname; 134 int pointerp; | 128print_generic_header(const char *procname, int pointerp) |
135{ 136 f_print(fout, "\n"); 137 f_print(fout, "bool_t\n"); 138 f_print(fout, "xdr_%s(", procname); 139 f_print(fout, "XDR *xdrs, "); 140 f_print(fout, "%s ", procname); 141 if (pointerp) 142 f_print(fout, "*"); 143 f_print(fout, "objp)\n{\n\n"); 144} 145 146static void | 129{ 130 f_print(fout, "\n"); 131 f_print(fout, "bool_t\n"); 132 f_print(fout, "xdr_%s(", procname); 133 f_print(fout, "XDR *xdrs, "); 134 f_print(fout, "%s ", procname); 135 if (pointerp) 136 f_print(fout, "*"); 137 f_print(fout, "objp)\n{\n\n"); 138} 139 140static void |
147print_header(def) 148 definition *def; | 141print_header(definition *def) |
149{ 150 print_generic_header(def->def_name, 151 def->def_kind != DEF_TYPEDEF || 152 !isvectordef(def->def.ty.old_type, 153 def->def.ty.rel)); 154 /* Now add Inline support */ 155 156 if (inline_size == 0) 157 return; 158 /* May cause lint to complain. but ... */ 159 f_print(fout, "\tregister long *buf;\n\n"); 160} 161 162static void | 142{ 143 print_generic_header(def->def_name, 144 def->def_kind != DEF_TYPEDEF || 145 !isvectordef(def->def.ty.old_type, 146 def->def.ty.rel)); 147 /* Now add Inline support */ 148 149 if (inline_size == 0) 150 return; 151 /* May cause lint to complain. but ... */ 152 f_print(fout, "\tregister long *buf;\n\n"); 153} 154 155static void |
163print_prog_header(plist) 164 proc_list *plist; | 156print_prog_header(proc_list *plist) |
165{ 166 print_generic_header(plist->args.argname, 1); 167} 168 169static void | 157{ 158 print_generic_header(plist->args.argname, 1); 159} 160 161static void |
170print_trailer() | 162print_trailer(void) |
171{ 172 f_print(fout, "\treturn (TRUE);\n"); 173 f_print(fout, "}\n"); 174} 175 176 177static void | 163{ 164 f_print(fout, "\treturn (TRUE);\n"); 165 f_print(fout, "}\n"); 166} 167 168 169static void |
178print_ifopen(indent, name) 179 int indent; 180 char *name; | 170print_ifopen(int indent, const char *name) |
181{ 182 tabify(fout, indent); 183 f_print(fout, "if (!xdr_%s(xdrs", name); 184} 185 186static void | 171{ 172 tabify(fout, indent); 173 f_print(fout, "if (!xdr_%s(xdrs", name); 174} 175 176static void |
187print_ifarg(arg) 188 char *arg; | 177print_ifarg(const char *arg) |
189{ 190 f_print(fout, ", %s", arg); 191} 192 193static void | 178{ 179 f_print(fout, ", %s", arg); 180} 181 182static void |
194print_ifsizeof(indent, prefix, type) 195 int indent; 196 char *prefix; 197 char *type; | 183print_ifsizeof(int indent, const char *prefix, const char *type) |
198{ 199 if (indent) { 200 f_print(fout, ",\n"); 201 tabify(fout, indent); 202 } else { 203 f_print(fout, ", "); 204 } 205 if (streq(type, "bool")) { 206 f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); 207 } else { 208 f_print(fout, "sizeof ("); 209 if (undefined(type) && prefix) { 210 f_print(fout, "%s ", prefix); 211 } 212 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type); 213 } 214} 215 216static void | 184{ 185 if (indent) { 186 f_print(fout, ",\n"); 187 tabify(fout, indent); 188 } else { 189 f_print(fout, ", "); 190 } 191 if (streq(type, "bool")) { 192 f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); 193 } else { 194 f_print(fout, "sizeof ("); 195 if (undefined(type) && prefix) { 196 f_print(fout, "%s ", prefix); 197 } 198 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type); 199 } 200} 201 202static void |
217print_ifclose(indent) 218 int indent; | 203print_ifclose(int indent) |
219{ 220 f_print(fout, "))\n"); 221 tabify(fout, indent); 222 f_print(fout, "\treturn (FALSE);\n"); 223} 224 225static void | 204{ 205 f_print(fout, "))\n"); 206 tabify(fout, indent); 207 f_print(fout, "\treturn (FALSE);\n"); 208} 209 210static void |
226print_ifstat(indent, prefix, type, rel, amax, objname, name) 227 int indent; 228 char *prefix; 229 char *type; 230 relation rel; 231 char *amax; 232 char *objname; 233 char *name; | 211print_ifstat(int indent, const char *prefix, const char *type, relation rel, 212 const char *amax, const char *objname, const char *name) |
234{ | 213{ |
235 char *alt = NULL; | 214 const char *alt = NULL; |
236 237 switch (rel) { 238 case REL_POINTER: 239 print_ifopen(indent, "pointer"); 240 print_ifarg("(char **)"); 241 f_print(fout, "%s", objname); 242 print_ifsizeof(0, prefix, type); 243 break; --- 51 unchanged lines hidden (view full) --- 295 print_ifarg(objname); 296 break; 297 } 298 print_ifclose(indent); 299} 300 301/* ARGSUSED */ 302static void | 215 216 switch (rel) { 217 case REL_POINTER: 218 print_ifopen(indent, "pointer"); 219 print_ifarg("(char **)"); 220 f_print(fout, "%s", objname); 221 print_ifsizeof(0, prefix, type); 222 break; --- 51 unchanged lines hidden (view full) --- 274 print_ifarg(objname); 275 break; 276 } 277 print_ifclose(indent); 278} 279 280/* ARGSUSED */ 281static void |
303emit_enum(def) 304 definition *def; | 282emit_enum(definition *def __unused) |
305{ 306 print_ifopen(1, "enum"); 307 print_ifarg("(enum_t *)objp"); 308 print_ifclose(1); 309} 310 311static void | 283{ 284 print_ifopen(1, "enum"); 285 print_ifarg("(enum_t *)objp"); 286 print_ifclose(1); 287} 288 289static void |
312emit_program(def) 313 definition *def; | 290emit_program(definition *def) |
314{ 315 decl_list *dl; 316 version_list *vlist; 317 proc_list *plist; 318 319 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) 320 for (plist = vlist->procs; plist != NULL; plist = plist->next) { 321 if (!newstyle || plist->arg_num < 2) 322 continue; /* old style, or single argument */ 323 print_prog_header(plist); 324 for (dl = plist->args.decls; dl != NULL; 325 dl = dl->next) 326 print_stat(1, &dl->decl); 327 print_trailer(); 328 } 329} 330 331 332static void | 291{ 292 decl_list *dl; 293 version_list *vlist; 294 proc_list *plist; 295 296 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) 297 for (plist = vlist->procs; plist != NULL; plist = plist->next) { 298 if (!newstyle || plist->arg_num < 2) 299 continue; /* old style, or single argument */ 300 print_prog_header(plist); 301 for (dl = plist->args.decls; dl != NULL; 302 dl = dl->next) 303 print_stat(1, &dl->decl); 304 print_trailer(); 305 } 306} 307 308 309static void |
333emit_union(def) 334 definition *def; | 310emit_union(definition *def) |
335{ 336 declaration *dflt; 337 case_list *cl; 338 declaration *cs; 339 char *object; | 311{ 312 declaration *dflt; 313 case_list *cl; 314 declaration *cs; 315 char *object; |
340 char *vecformat = "objp->%s_u.%s"; 341 char *format = "&objp->%s_u.%s"; | 316 const char *vecformat = "objp->%s_u.%s"; 317 const char *format = "&objp->%s_u.%s"; |
342 343 print_stat(1, &def->def.un.enum_decl); 344 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); 345 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { 346 347 f_print(fout, "\tcase %s:\n", cl->case_name); 348 if (cl->contflag == 1) /* a continued case statement */ 349 continue; --- 40 unchanged lines hidden (view full) --- 390 f_print(fout, "\tdefault:\n"); 391 f_print(fout, "\t\treturn (FALSE);\n"); 392 } 393 394 f_print(fout, "\t}\n"); 395} 396 397static void | 318 319 print_stat(1, &def->def.un.enum_decl); 320 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); 321 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { 322 323 f_print(fout, "\tcase %s:\n", cl->case_name); 324 if (cl->contflag == 1) /* a continued case statement */ 325 continue; --- 40 unchanged lines hidden (view full) --- 366 f_print(fout, "\tdefault:\n"); 367 f_print(fout, "\t\treturn (FALSE);\n"); 368 } 369 370 f_print(fout, "\t}\n"); 371} 372 373static void |
398inline_struct(def, flag) 399definition *def; 400int flag; | 374inline_struct(definition *def, int flag) |
401{ 402 decl_list *dl; 403 int i, size; 404 decl_list *cur, *psav; 405 bas_type *ptr; | 375{ 376 decl_list *dl; 377 int i, size; 378 decl_list *cur, *psav; 379 bas_type *ptr; |
406 char *sizestr, *plus; | 380 char *sizestr; 381 const char *plus; |
407 char ptemp[256]; 408 int indent = 1; 409 410 cur = NULL; 411 if (flag == PUT) 412 f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); 413 else 414 f_print(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); --- 134 unchanged lines hidden (view full) --- 549 cur = cur->next; 550 } 551 f_print(fout, "\t\t}\n"); 552 } 553 } 554} 555 556static void | 382 char ptemp[256]; 383 int indent = 1; 384 385 cur = NULL; 386 if (flag == PUT) 387 f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n"); 388 else 389 f_print(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); --- 134 unchanged lines hidden (view full) --- 524 cur = cur->next; 525 } 526 f_print(fout, "\t\t}\n"); 527 } 528 } 529} 530 531static void |
557emit_struct(def) 558 definition *def; | 532emit_struct(definition *def) |
559{ 560 decl_list *dl; 561 int j, size, flag; 562 bas_type *ptr; 563 int can_inline; 564 565 if (inline_size == 0) { 566 /* No xdr_inlining at all */ --- 52 unchanged lines hidden (view full) --- 619 /* now take care of XDR_FREE case */ 620 621 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 622 print_stat(1, &dl->decl); 623 624} 625 626static void | 533{ 534 decl_list *dl; 535 int j, size, flag; 536 bas_type *ptr; 537 int can_inline; 538 539 if (inline_size == 0) { 540 /* No xdr_inlining at all */ --- 52 unchanged lines hidden (view full) --- 593 /* now take care of XDR_FREE case */ 594 595 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 596 print_stat(1, &dl->decl); 597 598} 599 600static void |
627emit_typedef(def) 628 definition *def; | 601emit_typedef(definition *def) |
629{ | 602{ |
630 char *prefix = def->def.ty.old_prefix; 631 char *type = def->def.ty.old_type; 632 char *amax = def->def.ty.array_max; | 603 const char *prefix = def->def.ty.old_prefix; 604 const char *type = def->def.ty.old_type; 605 const char *amax = def->def.ty.array_max; |
633 relation rel = def->def.ty.rel; 634 635 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); 636} 637 638static void | 606 relation rel = def->def.ty.rel; 607 608 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); 609} 610 611static void |
639print_stat(indent, dec) 640 int indent; 641 declaration *dec; | 612print_stat(int indent, declaration *dec) |
642{ | 613{ |
643 char *prefix = dec->prefix; 644 char *type = dec->type; 645 char *amax = dec->array_max; | 614 const char *prefix = dec->prefix; 615 const char *type = dec->type; 616 const char *amax = dec->array_max; |
646 relation rel = dec->rel; 647 char name[256]; 648 649 if (isvectordef(type, rel)) { 650 s_print(name, "objp->%s", dec->name); 651 } else { 652 s_print(name, "&objp->%s", dec->name); 653 } 654 print_ifstat(indent, prefix, type, rel, amax, name, dec->name); 655} 656 657 | 617 relation rel = dec->rel; 618 char name[256]; 619 620 if (isvectordef(type, rel)) { 621 s_print(name, "objp->%s", dec->name); 622 } else { 623 s_print(name, "&objp->%s", dec->name); 624 } 625 print_ifstat(indent, prefix, type, rel, amax, name, dec->name); 626} 627 628 |
658char *upcase (); | 629char *upcase(const char *); |
659 660static void | 630 631static void |
661emit_inline(indent, decl, flag) 662int indent; 663declaration *decl; 664int flag; | 632emit_inline(int indent, declaration *decl, int flag) |
665{ 666 switch (decl->rel) { 667 case REL_ALIAS : 668 emit_single_in_line(indent, decl, flag, REL_ALIAS); 669 break; 670 case REL_VECTOR : 671 tabify(fout, indent); 672 f_print(fout, "{\n"); --- 11 unchanged lines hidden (view full) --- 684 f_print(fout, "}\n"); 685 break; 686 default: 687 break; 688 } 689} 690 691static void | 633{ 634 switch (decl->rel) { 635 case REL_ALIAS : 636 emit_single_in_line(indent, decl, flag, REL_ALIAS); 637 break; 638 case REL_VECTOR : 639 tabify(fout, indent); 640 f_print(fout, "{\n"); --- 11 unchanged lines hidden (view full) --- 652 f_print(fout, "}\n"); 653 break; 654 default: 655 break; 656 } 657} 658 659static void |
692emit_single_in_line(indent, decl, flag, rel) 693int indent; 694declaration *decl; 695int flag; 696relation rel; | 660emit_single_in_line(int indent, declaration *decl, int flag, relation rel) |
697{ 698 char *upp_case; | 661{ 662 char *upp_case; |
699 int freed = 0; | |
700 701 tabify(fout, indent); 702 if (flag == PUT) 703 f_print(fout, "IXDR_PUT_"); 704 else 705 if (rel == REL_ALIAS) 706 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 707 else 708 f_print(fout, "*genp++ = IXDR_GET_"); 709 710 upp_case = upcase(decl->type); 711 712 /* hack - XX */ 713 if (strcmp(upp_case, "INT") == 0) 714 { 715 free(upp_case); | 663 664 tabify(fout, indent); 665 if (flag == PUT) 666 f_print(fout, "IXDR_PUT_"); 667 else 668 if (rel == REL_ALIAS) 669 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 670 else 671 f_print(fout, "*genp++ = IXDR_GET_"); 672 673 upp_case = upcase(decl->type); 674 675 /* hack - XX */ 676 if (strcmp(upp_case, "INT") == 0) 677 { 678 free(upp_case); |
716 freed = 1; 717 upp_case = "LONG"; | 679 upp_case = strdup("LONG"); |
718 } 719 720 if (strcmp(upp_case, "U_INT") == 0) 721 { 722 free(upp_case); | 680 } 681 682 if (strcmp(upp_case, "U_INT") == 0) 683 { 684 free(upp_case); |
723 freed = 1; 724 upp_case = "U_LONG"; | 685 upp_case = strdup("U_LONG"); |
725 } 726 if (flag == PUT) 727 if (rel == REL_ALIAS) 728 f_print(fout, 729 "%s(buf, objp->%s);\n", upp_case, decl->name); 730 else 731 f_print(fout, "%s(buf, *genp++);\n", upp_case); 732 733 else 734 f_print(fout, "%s(buf);\n", upp_case); | 686 } 687 if (flag == PUT) 688 if (rel == REL_ALIAS) 689 f_print(fout, 690 "%s(buf, objp->%s);\n", upp_case, decl->name); 691 else 692 f_print(fout, "%s(buf, *genp++);\n", upp_case); 693 694 else 695 f_print(fout, "%s(buf);\n", upp_case); |
735 if (!freed) 736 free(upp_case); | 696 free(upp_case); |
737} 738 | 697} 698 |
739char *upcase(str) 740char *str; | 699char * 700upcase(const char *str) |
741{ 742 char *ptr, *hptr; 743 744 ptr = (char *)xmalloc(strlen(str)+1); 745 746 hptr = ptr; 747 while (*str != '\0') 748 *ptr++ = toupper(*str++); 749 750 *ptr = '\0'; 751 return (hptr); 752} | 701{ 702 char *ptr, *hptr; 703 704 ptr = (char *)xmalloc(strlen(str)+1); 705 706 hptr = ptr; 707 while (*str != '\0') 708 *ptr++ = toupper(*str++); 709 710 *ptr = '\0'; 711 return (hptr); 712} |