home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devtools / rpcgen / rpc_cout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  16.2 KB  |  741 lines

  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 or with the express written consent of
  8.  * Sun Microsystems, Inc.
  9.  *
  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.
  13.  *
  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.
  17.  *
  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.
  21.  *
  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.
  25.  *
  26.  * Sun Microsystems, Inc.
  27.  * 2550 Garcia Avenue
  28.  * Mountain View, California  94043
  29.  */
  30.  
  31. #ifndef lint
  32. static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI";
  33. #endif
  34.  
  35. /*
  36.  * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 
  37.  */
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include "rpc_parse.h"
  41. #include "rpc_util.h"
  42.  
  43. #ifdef amigados
  44. #include <ctype.h>
  45. #undef  toupper
  46. #endif
  47.  
  48. #ifdef __STDC__
  49. #include "rpc_scan.h"
  50. #include "protos.h"
  51.  
  52. void emit ( definition *def );
  53. static int findtype ( definition *def , char *type );
  54. static int undefined ( char *type );
  55. static void print_generic_header ( char *procname , int pointerp );
  56. static void print_header ( definition *def );
  57. static void print_prog_header ( proc_list *plist );
  58. static void print_trailer ( void );
  59. static void print_ifopen ( int indent , char *name );
  60. static void print_ifarg ( char *arg );
  61. static void print_ifsizeof ( char *prefix , char *type );
  62. static void print_ifclose ( int indent );
  63. static void print_ifstat ( int indent , char *prefix , char *type , relation rel , char *amax , char *objname , char *name );
  64. static void emit_enum ( definition *def );
  65. static void emit_program ( definition *def );
  66. static void emit_union ( definition *def );
  67. static void emit_struct ( definition *def );
  68. static void emit_typedef ( definition *def );
  69. static void print_stat ( int indent , declaration *dec );
  70. void emit_inline ( declaration *decl , int flag );
  71. void emit_single_in_line ( declaration *decl , int flag , relation rel );
  72. char *upcase ( char *str );
  73. #endif
  74.  
  75. /*
  76.  * Emit the C-routine for the given definition 
  77.  */
  78. void
  79. emit(definition *def)
  80. {
  81.     if (def->def_kind == DEF_CONST) {
  82.         return;
  83.     }
  84.     if (def->def_kind == DEF_PROGRAM) {
  85.         emit_program(def);
  86.         return;
  87.     }
  88.     if(def->def_kind == DEF_TYPEDEF)
  89.       {
  90.       /* now we need to handle declarations like 
  91.    struct typedef foo foo; 
  92.    since we dont want this to be expanded into 2 calls to xdr_foo */
  93.  
  94.      if(strcmp(def->def.ty.old_type,def->def_name)==0)
  95.       return;
  96.       };
  97.  
  98.     print_header(def);
  99.     switch (def->def_kind) {
  100.     case DEF_UNION:
  101.         emit_union(def);
  102.         break;
  103.     case DEF_ENUM:
  104.         emit_enum(def);
  105.         break;
  106.     case DEF_STRUCT:
  107.         emit_struct(def);
  108.         break;
  109.     case DEF_TYPEDEF:
  110.         emit_typedef(def);
  111.         break;
  112.     }
  113.     print_trailer();
  114. }
  115.  
  116. static int
  117. findtype(definition *def, char *type)
  118. {
  119.  
  120.     if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
  121.         return (0);
  122.     } else {
  123.         return (streq(def->def_name, type));
  124.     }
  125. }
  126.  
  127. static int
  128. undefined(char *type)
  129. {
  130.     definition *def;
  131.  
  132.     def = (definition *) FINDVAL(defined, type, findtype);
  133.  
  134.     
  135.     return (def == NULL);
  136. }
  137.  
  138. static void 
  139. print_generic_header(char* procname, int pointerp)
  140. {
  141.     f_print(fout, "\n");
  142. #ifdef amigados
  143.     f_print(fout, "bool_t XDRFUN\n");
  144. #else
  145.     f_print(fout, "bool_t\n");
  146. #endif
  147.     if (Cflag) {
  148.        f_print(fout, "xdr_%s(", procname);
  149.        f_print(fout, "XDR *xdrs, ");
  150.        f_print(fout, "%s ", procname);
  151.        if( pointerp )
  152.          f_print(fout, "*");
  153.        f_print(fout, "objp)\n{\n\n");
  154.     } else {
  155.       f_print(fout, "xdr_%s(xdrs, objp)\n", procname);
  156.       f_print(fout, "\tXDR *xdrs;\n");
  157.       f_print(fout, "\t%s ", procname);
  158.       if( pointerp )
  159.         f_print(fout, "*");
  160.       f_print(fout, "objp;\n{\n\n");
  161.     }
  162. }
  163.  
  164. static void
  165. print_header(definition *def)
  166. {
  167. #ifndef amigados
  168.   decl_list *dl;
  169.   bas_type *ptr;
  170.   int i;
  171. #endif
  172.  
  173.   print_generic_header( def->def_name,
  174.                def->def_kind != DEF_TYPEDEF ||
  175.                !isvectordef(def->def.ty.old_type, def->def.ty.rel));
  176.  
  177.   /* Now add Inline support */
  178.  
  179.  
  180.   if(inline == 0 )
  181.     return;
  182.   /*May cause lint to complain. but  ... */
  183. f_print(fout, "\t register long *buf;\n\n");
  184.  
  185. }
  186.  
  187. static void
  188. print_prog_header(proc_list *plist)
  189. {
  190.   print_generic_header( plist->args.argname, 1 );
  191. }
  192.  
  193. static void
  194. print_trailer(void)
  195. {
  196.     f_print(fout, "\treturn (TRUE);\n");
  197.     f_print(fout, "}\n");
  198. }
  199.  
  200. static void
  201. print_ifopen(int indent, char *name)
  202. {
  203.     tabify(fout, indent);
  204.     f_print(fout, " if (!xdr_%s(xdrs", name);
  205. }
  206.  
  207. static void
  208. print_ifarg(char *arg)
  209. {
  210.     f_print(fout, ", %s", arg);
  211. }
  212.  
  213. static void
  214. print_ifsizeof(char *prefix, char *type)
  215. {
  216.     if (streq(type, "bool")) {
  217.         f_print(fout, ", sizeof(bool_t), (xdrproc_t)xdr_bool");
  218.     } else {
  219.         f_print(fout, ", sizeof(");
  220.         if (undefined(type) && prefix) {
  221.             f_print(fout, "%s ", prefix);
  222.         }
  223.         f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type);
  224.     }
  225. }
  226.  
  227. static void
  228. print_ifclose(int indent)
  229. {
  230.     f_print(fout, ")) {\n");
  231.     tabify(fout, indent);
  232.     f_print(fout, "\t return (FALSE);\n");
  233.     tabify(fout, indent);
  234.     f_print(fout, " }\n");
  235. }
  236.  
  237. static void
  238. print_ifstat(int indent,
  239.          char *prefix,
  240.          char *type,
  241.          relation rel,
  242.          char *amax,
  243.          char *objname,
  244.          char *name)
  245. {
  246.     char *alt = NULL;
  247.  
  248.     switch (rel) {
  249.     case REL_POINTER:
  250.         print_ifopen(indent, "pointer");
  251.         print_ifarg("(char **)");
  252.         f_print(fout, "%s", objname);
  253.         print_ifsizeof(prefix, type);
  254.         break;
  255.     case REL_VECTOR:
  256.         if (streq(type, "string")) {
  257.             alt = "string";
  258.         } else if (streq(type, "opaque")) {
  259.             alt = "opaque";
  260.         }
  261.         if (alt) {
  262.             print_ifopen(indent, alt);
  263.             print_ifarg(objname);
  264.         } else {
  265.             print_ifopen(indent, "vector");
  266.             print_ifarg("(char *)");
  267.             f_print(fout, "%s", objname);
  268.         }
  269.         print_ifarg(amax);
  270.         if (!alt) {
  271.             print_ifsizeof(prefix, type);
  272.         }
  273.         break;
  274.     case REL_ARRAY:
  275.         if (streq(type, "string")) {
  276.             alt = "string";
  277.         } else if (streq(type, "opaque")) {
  278.             alt = "bytes";
  279.         }
  280.         if (streq(type, "string")) {
  281.             print_ifopen(indent, alt);
  282.             print_ifarg(objname);
  283.         } else {
  284.             if (alt) {
  285.                 print_ifopen(indent, alt);
  286.             } else {
  287.                 print_ifopen(indent, "array");
  288.             }
  289.             print_ifarg("(char **)");
  290.             if (*objname == '&') {
  291.                 f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
  292.                     objname, name, objname, name);
  293.             } else {
  294.                 f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
  295.                     objname, name, objname, name);
  296.             }
  297.         }
  298.         print_ifarg(amax);
  299.         if (!alt) {
  300.             print_ifsizeof(prefix, type);
  301.         }
  302.         break;
  303.     case REL_ALIAS:
  304.         print_ifopen(indent, type);
  305.         print_ifarg(objname);
  306.         break;
  307.     }
  308.     print_ifclose(indent);
  309. }
  310.  
  311. /* ARGSUSED */
  312. static void
  313. emit_enum(definition *def)
  314. {
  315.     print_ifopen(1, "enum");
  316.     print_ifarg("(enum_t *)objp");
  317.     print_ifclose(1);
  318. }
  319.  
  320. static void
  321. emit_program(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 void
  341. emit_union(definition *def)
  342. {
  343.   declaration *dflt;
  344.   case_list *cl;
  345.   declaration *cs;
  346.   char *object;
  347.   char *vecformat = "objp->%s_u.%s";
  348.   char *format = "&objp->%s_u.%s";
  349.  
  350.   print_stat(1,&def->def.un.enum_decl);
  351.   f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
  352.   for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
  353.  
  354.     f_print(fout, "\tcase %s:\n", cl->case_name);
  355.     if(cl->contflag == 1)    /* a continued case statement */
  356.       continue;
  357.     cs = &cl->case_decl;
  358.     if (!streq(cs->type, "void")) {
  359.       object = alloc(strlen(def->def_name) + strlen(format) +
  360.              strlen(cs->name) + 1);
  361.       if (isvectordef (cs->type, cs->rel)) {
  362.     s_print(object, vecformat, def->def_name, 
  363.         cs->name);
  364.       } else {
  365.     s_print(object, format, def->def_name, 
  366.         cs->name);
  367.       }
  368.       print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
  369.            object, cs->name);
  370.       free(object);
  371.     }
  372.     f_print(fout, "\t\tbreak;\n");
  373.   }
  374.   dflt = def->def.un.default_decl;
  375.   if (dflt != NULL) {
  376.     if (!streq(dflt->type, "void")) {
  377.       f_print(fout, "\tdefault:\n");
  378.       object = alloc(strlen(def->def_name) + strlen(format) +
  379.              strlen(dflt->name) + 1);
  380.       if (isvectordef (dflt->type, dflt->rel)) {
  381.     s_print(object, vecformat, def->def_name, 
  382.         dflt->name);
  383.       } else {
  384.     s_print(object, format, def->def_name, 
  385.         dflt->name);
  386.       }
  387.  
  388.       print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
  389.            dflt->array_max, object, dflt->name);
  390.       free(object);
  391.       f_print(fout, "\t\tbreak;\n");
  392.     }
  393. #if defined(linux) || defined(amigados)
  394.     else {
  395.       f_print(fout, "\tdefault:\n");
  396.       f_print(fout, "\t\tbreak;\n");
  397.     }
  398. #endif
  399.   } else {
  400.     f_print(fout, "\tdefault:\n");
  401.     f_print(fout, "\t\treturn (FALSE);\n");
  402.   }
  403.  
  404.   f_print(fout, "\t}\n");
  405. }
  406.  
  407. static void
  408. emit_struct(definition *def)
  409. {
  410.     decl_list *dl;
  411.     int i,j,size,flag;
  412.     decl_list *cur,*psav;
  413.     bas_type *ptr;
  414.     char *sizestr,*plus;
  415.     char ptemp[256];
  416.     int can_inline;
  417.  
  418.  
  419.     if(inline  == 0)    {
  420.         for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 
  421.             print_stat(1,&dl->decl);
  422.     }
  423.     
  424.     else    {
  425.         
  426.         for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 
  427.             if(dl->decl.rel == REL_VECTOR){
  428.                 f_print(fout,"\t int i;\n");
  429.                 break;
  430.             }
  431.  
  432.         size=0;can_inline=0;
  433.         for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 
  434.             if((dl->decl.prefix == NULL) && ((ptr=find_type(dl->decl.type))!= NULL) &&          ((dl->decl.rel == REL_ALIAS)||(dl->decl.rel == REL_VECTOR))){
  435.                 
  436.                 if(dl->decl.rel == REL_ALIAS) 
  437.                     size+=ptr->length;
  438.                 else {
  439.                     can_inline=1;
  440.                     break; /* can be inlined */
  441.                 };
  442.             }
  443.             else {
  444.                 if(size >= inline){
  445.                     can_inline=1;
  446.                     break; /* can be inlined */
  447.                 }
  448.                 size=0;
  449.             }
  450.         if(size > inline)
  451.             can_inline=1;
  452.  
  453.         if(can_inline == 0){ /* can not inline, drop back to old mode */
  454.             for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 
  455.                 print_stat(1,&dl->decl);
  456.             return;
  457.         };
  458.  
  459.  
  460.             
  461.  
  462.         flag=PUT;
  463.         for(j=0; j<2; j++){
  464.  
  465.             if(flag == PUT)
  466.                 f_print(fout,"\n\t if (xdrs->x_op == XDR_ENCODE) {\n");
  467.             else
  468.                 f_print(fout,"\n \t return (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n");
  469.  
  470.  
  471.             i=0;
  472.             size=0;
  473.             sizestr=NULL;
  474.             for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */
  475.  
  476.                 /* now walk down the list and check for basic types */
  477.                 if((dl->decl.prefix == NULL) && ((ptr=find_type(dl->decl.type))!= NULL) &&          ((dl->decl.rel == REL_ALIAS)||(dl->decl.rel == REL_VECTOR))){
  478.                     if(i ==0 ) 
  479.                         cur=dl;
  480.                     i++;
  481.  
  482.                     if(dl->decl.rel == REL_ALIAS) 
  483.                         size+=ptr->length;
  484.                     else {
  485.                         /* this is required to handle arrays */
  486.             
  487.                         if(sizestr == NULL)
  488.                             plus = " ";
  489.                         else
  490.                             plus = "+";
  491.  
  492.                         if(ptr->length != 1)
  493.                             s_print(ptemp," %s %s * %d",plus,dl->decl.array_max,ptr->length);
  494.                         else
  495.                             s_print(ptemp," %s %s ",plus,dl->decl.array_max);
  496.  
  497.                         /*now concatenate to sizestr !!!! */
  498.                         if (sizestr == NULL)
  499.                             sizestr=strdup(ptemp);
  500.                         else{
  501.                             sizestr=realloc(sizestr,strlen(sizestr)+strlen(ptemp)+1);
  502.                             if(sizestr == NULL){
  503.  
  504.                                 f_print(stderr, "Fatal error : no memory \n");
  505.                                 crash();
  506.                             };
  507.                             sizestr=strcat(sizestr,ptemp); /*build up length of array */
  508.             
  509.                         }
  510.                     }
  511.  
  512.                 }
  513.                 else{
  514.                     if(i > 0 )
  515.                         if(sizestr == NULL && size < inline){    
  516.                             /* don't expand into inline code if size < inline */
  517.                             while(cur != dl){
  518.                                 print_stat(1,&cur->decl);
  519.                                 cur=cur->next;
  520.                             } 
  521.                         }
  522.                         else{
  523.  
  524.  
  525.  
  526.                             /* were already looking at a xdr_inlineable structure */
  527.                             if(sizestr == NULL)
  528.                                 f_print(fout,"\t buf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
  529.                                     size);
  530.                             else
  531.                                 if(size == 0)
  532.                                     f_print(fout,
  533.                                         "\t buf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
  534.                                         sizestr);
  535.                                 else
  536.                                     f_print(fout,
  537.                                         "\t buf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
  538.                                         size,sizestr);
  539.             
  540.                             f_print(fout,"\n\t   if (buf == NULL) {\n");
  541.  
  542.                             psav=cur;
  543.                             while(cur != dl){
  544.                                 print_stat(2,&cur->decl);
  545.                                 cur=cur->next;
  546.                             }
  547.  
  548.                             f_print(fout,"\n\t  }\n\t  else {\n");
  549.         
  550.                             cur=psav;
  551.                             while(cur != dl){
  552.                                 emit_inline(&cur->decl,flag);
  553.                                 cur=cur->next;
  554.                             }
  555.  
  556.                             f_print(fout,"\t  }\n");
  557.                         }
  558.                     size=0;i=0;sizestr=NULL;
  559.                     print_stat(1,&dl->decl);
  560.                 }
  561.         
  562.             }
  563.             if(i > 0 )
  564.                 if(sizestr == NULL && size < inline){
  565.                     /* don't expand into inline code if size < inline */
  566.                     while(cur != dl){
  567.                         print_stat(1,&cur->decl);
  568.                         cur=cur->next;
  569.                     } 
  570.                 }
  571.                 else{
  572.  
  573.                     /* were already looking at a xdr_inlineable structure */
  574.                     if(sizestr == NULL)
  575.                         f_print(fout,"\t\tbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
  576.                             size);
  577.                     else
  578.                         if(size == 0)
  579.                             f_print(fout,
  580.                                 "\t\tbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
  581.                                 sizestr);
  582.                         else
  583.                             f_print(fout,
  584.                                 "\t\tbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
  585.                                 size,sizestr);
  586.             
  587.                     f_print(fout,"\n\t\tif (buf == NULL) {\n");
  588.  
  589.                     psav=cur;
  590.                     while(cur != NULL){
  591.                         print_stat(2,&cur->decl);
  592.                         cur=cur->next;
  593.                     }
  594.                     f_print(fout,"\n\t  }\n\t  else {\n");
  595.         
  596.                     cur=psav;
  597.                     while(cur != dl){
  598.                         emit_inline(&cur->decl,flag);
  599.                         cur=cur->next;
  600.                     }
  601.  
  602.                     f_print(fout,"\t  }\n");
  603.  
  604.                 }
  605.             flag=GET;
  606.         }
  607.         f_print(fout,"\t return(TRUE);\n\t}\n\n");
  608.   
  609.         /* now take care of XDR_FREE case */
  610.  
  611.         for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 
  612.             print_stat(1,&dl->decl);
  613.     }    
  614. }
  615.  
  616.  
  617.  
  618.  
  619. static void
  620. emit_typedef(definition *def)
  621. {
  622.     char *prefix = def->def.ty.old_prefix;
  623.     char *type = def->def.ty.old_type;
  624.     char *amax = def->def.ty.array_max;
  625.     relation rel = def->def.ty.rel;
  626.  
  627.  
  628.       print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
  629. }
  630.  
  631. static void
  632. print_stat(int indent, declaration *dec)
  633. {
  634.     char *prefix = dec->prefix;
  635.     char *type = dec->type;
  636.     char *amax = dec->array_max;
  637.     relation rel = dec->rel;
  638.     char name[256];
  639.  
  640.     if (isvectordef(type, rel)) {
  641.         s_print(name, "objp->%s", dec->name);
  642.     } else {
  643.         s_print(name, "&objp->%s", dec->name);
  644.     }
  645.     print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
  646. }
  647.  
  648.  
  649. char *upcase ();
  650.  
  651. void
  652. emit_inline(declaration *decl, int flag)
  653. {
  654.  
  655. /*check whether an array or not */
  656.  
  657. switch(decl->rel)
  658.   {
  659.  case  REL_ALIAS :
  660.   emit_single_in_line(decl,flag,REL_ALIAS);
  661.   break;
  662.  case REL_VECTOR :
  663.    f_print(fout,"\t\t{ register %s *genp; \n",decl->type);
  664.    f_print(fout,"\t\t  for ( i = 0,genp=objp->%s;\n \t\t\ti < %s; i++){\n\t\t",
  665.        decl->name,decl->array_max);
  666.   emit_single_in_line(decl,flag,REL_VECTOR);
  667.     f_print(fout,"\t\t   }\n\t\t };\n");
  668.  
  669.   }
  670. }
  671.  
  672. void 
  673. emit_single_in_line(declaration *decl, int flag, relation rel)
  674. {
  675.     char *upp_case;
  676.     int freed=0;
  677.  
  678.  
  679.  
  680.     if(flag == PUT)
  681.         f_print(fout,"\t\t IXDR_PUT_");
  682.     else    
  683.         if(rel== REL_ALIAS)
  684.             f_print(fout,"\t\t objp->%s = IXDR_GET_",decl->name);
  685.         else
  686.             f_print(fout,"\t\t *genp++ = IXDR_GET_");
  687.  
  688.     upp_case=upcase(decl->type);
  689.  
  690.     /* hack  - XX */
  691.     if(strcmp(upp_case,"INT") == 0)
  692.     {
  693.         free(upp_case);
  694.         freed=1;
  695.         upp_case="LONG";
  696.     }
  697.  
  698.     if(strcmp(upp_case,"U_INT") == 0)
  699.     {
  700.         free(upp_case);
  701.         freed=1;
  702.         upp_case="U_LONG";
  703.     }
  704.  
  705.  
  706.     if(flag == PUT) 
  707.         if(rel== REL_ALIAS)
  708.             f_print(fout,"%s(buf,objp->%s);\n",upp_case,decl->name);
  709.         else
  710.             f_print(fout,"%s(buf,*genp++);\n",upp_case);
  711.  
  712.     else
  713.         f_print(fout,"%s(buf);\n",upp_case);
  714.     if(!freed)
  715.         free(upp_case);
  716.  
  717. }
  718.  
  719.  
  720. char * upcase(str)
  721. char *str;
  722. {
  723. char *ptr,*hptr;
  724.  
  725.  
  726. ptr =  (char * )malloc(strlen(str));
  727. if(ptr == (char * ) NULL)
  728.   {
  729.     f_print(stderr,"malloc failed \n");
  730.     exit(1);
  731.   };
  732.  
  733. hptr=ptr;
  734. while (*str != '\0')
  735.     *ptr++=toupper(*str++);
  736.  
  737. *ptr='\0';
  738. return(hptr);
  739.   
  740. }
  741.