[BACK]Return to rpc_cout.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rpcgen

Diff for /src/usr.bin/rpcgen/rpc_cout.c between version 1.8 and 1.9

version 1.8, 2001/11/24 19:17:47 version 1.9, 2001/11/24 19:19:59
Line 41 
Line 41 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <ctype.h>  
 #include "rpc_parse.h"  #include "rpc_parse.h"
 #include "rpc_util.h"  #include "rpc_util.h"
   
 static int findtype __P((definition *, char *));  static findtype __P((definition *, char *));
 static int undefined __P((char *));  static undefined __P((char *));
 static void print_generic_header __P((char *, int));  static print_generic_header __P((char *, int));
 static void print_header __P((definition *));  static print_header __P((definition *));
 static void print_prog_header __P((proc_list *));  static print_prog_header __P((proc_list *));
 static void print_trailer __P((void));  static print_trailer __P((void));
 static void print_ifopen __P((int, char *));  static print_ifopen __P((int, char *));
 static void print_ifarg __P((char *));  static print_ifarg __P((char *));
 static void print_ifsizeof __P((char *, char *));  static print_ifsizeof __P((char *, char *));
 static void print_ifclose __P((int));  static print_ifclose __P((int));
 static void print_ifstat __P((int, char *, char *, relation, char *, char *, char *));  static print_ifstat __P((int, char *, char *, relation, char *, char *, char *));
 static void emit_num __P((definition *));  static emit_num __P((definition *));
 static void emit_program __P((definition *));  static emit_program __P((definition *));
 static void emit_enum __P((definition *));  static emit_enum __P((definition *));
 static void emit_union __P((definition *));  static emit_union __P((definition *));
 static void emit_struct __P((definition *));  static emit_struct __P((definition *));
 static void emit_typedef __P((definition *));  static emit_typedef __P((definition *));
 static void print_stat __P((int, declaration *));  static print_stat __P((int, declaration *));
 void emit_inline __P((declaration *, int));  
 void emit_single_in_line __P((declaration *, int, relation));  
   
   
 /*  /*
  * Emit the C-routine for the given definition   * Emit the C-routine for the given definition
  */   */
Line 107 
Line 105 
         print_trailer();          print_trailer();
 }  }
   
 static int  static
 findtype(def, type)  findtype(def, type)
         definition *def;          definition *def;
         char    *type;          char   *type;
 {  {
   
         if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {          if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
Line 120 
Line 118 
         }          }
 }  }
   
 static int  static
 undefined(type)  undefined(type)
         char    *type;          char   *type;
 {  {
         definition *def;          definition *def;
   
         def = (definition *) FINDVAL(defined, type, findtype);          def = (definition *) FINDVAL(defined, type, findtype);
   
   
         return (def == NULL);          return (def == NULL);
 }  }
   
 static void  static
 print_generic_header(procname, pointerp)  print_generic_header(procname, pointerp)
         char    *procname;          char   *procname;
         int     pointerp;          int     pointerp;
 {  {
         f_print(fout, "\n");          f_print(fout, "\n");
         f_print(fout, "bool_t\n");          f_print(fout, "bool_t\n");
Line 154 
Line 154 
         }          }
 }  }
   
 static void  static
 print_header(def)  print_header(def)
         definition *def;          definition *def;
 {  {
   
           decl_list *dl;
           bas_type *ptr;
           int     i;
   
   
         print_generic_header(def->def_name,          print_generic_header(def->def_name,
             def->def_kind != DEF_TYPEDEF ||              def->def_kind != DEF_TYPEDEF ||
             !isvectordef(def->def.ty.old_type, def->def.ty.rel));              !isvectordef(def->def.ty.old_type, def->def.ty.rel));
   
         /* Now add Inline support */          /* Now add Inline support */
   
   
         if (doinline == 0)          if (doinline == 0)
                 return;                  return;
         /* May cause lint to complain. but  ... */          /* May cause lint to complain. but  ... */
         f_print(fout, "\tint32_t *buf;\n\n");          f_print(fout, "\tint32_t *buf;\n\n");
   
 }  }
   
 static void  static
 print_prog_header(plist)  print_prog_header(plist)
         proc_list *plist;          proc_list *plist;
 {  {
         print_generic_header(plist->args.argname, 1);          print_generic_header(plist->args.argname, 1);
 }  }
   
 static void  static
 print_trailer()  print_trailer()
 {  {
         f_print(fout, "\treturn (TRUE);\n");          f_print(fout, "\treturn (TRUE);\n");
         f_print(fout, "}\n");          f_print(fout, "}\n");
 }  }
   
 static void  
   static
 print_ifopen(indent, name)  print_ifopen(indent, name)
         int     indent;          int     indent;
         char   *name;          char   *name;
Line 193 
Line 202 
         f_print(fout, "if (!xdr_%s(xdrs", name);          f_print(fout, "if (!xdr_%s(xdrs", name);
 }  }
   
 static void  static
 print_ifarg(arg)  print_ifarg(arg)
         char   *arg;          char   *arg;
 {  {
         f_print(fout, ", %s", arg);          f_print(fout, ", %s", arg);
 }  }
   
 static void  static
 print_ifsizeof(prefix, type)  print_ifsizeof(prefix, type)
         char   *prefix;          char   *prefix;
         char   *type;          char   *type;
Line 216 
Line 225 
         }          }
 }  }
   
 static void  static
 print_ifclose(indent)  print_ifclose(indent)
         int     indent;          int     indent;
 {  {
Line 227 
Line 236 
         f_print(fout, "}\n");          f_print(fout, "}\n");
 }  }
   
 static void  static
 print_ifstat(indent, prefix, type, rel, amax, objname, name)  print_ifstat(indent, prefix, type, rel, amax, objname, name)
         int     indent;          int     indent;
         char   *prefix;          char   *prefix;
Line 305 
Line 314 
 }  }
   
 /* ARGSUSED */  /* ARGSUSED */
 static void  static
 emit_enum(def)  emit_enum(def)
         definition *def;          definition *def;
 {  {
Line 314 
Line 323 
         print_ifclose(1);          print_ifclose(1);
 }  }
   
 static void  static
 emit_program(def)  emit_program(def)
         definition *def;          definition *def;
 {  {
Line 335 
Line 344 
                 }                  }
 }  }
   
 static void  
   static
 emit_union(def)  emit_union(def)
         definition *def;          definition *def;
 {  {
Line 349 
Line 359 
         print_stat(1, &def->def.un.enum_decl);          print_stat(1, &def->def.un.enum_decl);
         f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);          f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
         for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {          for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
   
                 f_print(fout, "\tcase %s:\n", cl->case_name);                  f_print(fout, "\tcase %s:\n", cl->case_name);
                 if (cl->contflag == 1)  /* a continued case statement */                  if (cl->contflag == 1)  /* a continued case statement */
                         continue;                          continue;
Line 396 
Line 407 
         f_print(fout, "\t}\n");          f_print(fout, "\t}\n");
 }  }
   
 static void  static
 emit_struct(def)  emit_struct(def)
         definition *def;          definition *def;
 {  {
Line 408 
Line 419 
         char    ptemp[256];          char    ptemp[256];
         int     can_inline;          int     can_inline;
   
   
         if (doinline == 0) {          if (doinline == 0) {
                 for (dl = def->def.st.decls; dl != NULL; dl = dl->next)                  for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
                         print_stat(1, &dl->decl);                          print_stat(1, &dl->decl);
Line 424 
Line 436 
                 if ((dl->decl.prefix == NULL) &&                  if ((dl->decl.prefix == NULL) &&
                     ((ptr = find_type(dl->decl.type)) != NULL) &&                      ((ptr = find_type(dl->decl.type)) != NULL) &&
                     ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) {                      ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) {
   
                         if (dl->decl.rel == REL_ALIAS)                          if (dl->decl.rel == REL_ALIAS)
                                 size += ptr->length;                                  size += ptr->length;
                         else {                          else {
Line 446 
Line 459 
                 return;                  return;
         }          }
   
   
   
   
         flag = PUT;          flag = PUT;
         for (j = 0; j < 2; j++) {          for (j = 0; j < 2; j++) {
   
                 if (flag == PUT)                  if (flag == PUT)
                         f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n");                          f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n");
                 else                  else
                         f_print(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n");                          f_print(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n");
   
   
                 i = 0;                  i = 0;
                 size = 0;                  size = 0;
                 sizestr = NULL;                  sizestr = NULL;
Line 485 
Line 503 
                                         else {                                          else {
                                                 sizestr = (char *)realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1);                                                  sizestr = (char *)realloc(sizestr, strlen(sizestr) + strlen(ptemp) + 1);
                                                 if (sizestr == NULL) {                                                  if (sizestr == NULL) {
   
                                                         f_print(stderr, "Fatal error : no memory\n");                                                          f_print(stderr, "Fatal error : no memory\n");
                                                         crash();                                                          crash();
                                                 }                                                  }
Line 495 
Line 514 
                                 }                                  }
   
                         } else {                          } else {
                                 if (i > 0) {                                  if (i > 0)
                                         if (sizestr == NULL && size < doinline) {                                          if (sizestr == NULL && size < doinline) {
                                                 /* don't expand into inline                                                  /* don't expand into inline
                                                  * code if size < doinline */                                                   * code if size < doinline */
Line 504 
Line 523 
                                                         cur = cur->next;                                                          cur = cur->next;
                                                 }                                                  }
                                         } else {                                          } else {
   
   
   
                                                 /* were already looking at a                                                  /* were already looking at a
                                                  * xdr_inlineable structure */                                                   * xdr_inlineable structure */
                                                 if (sizestr == NULL)                                                  if (sizestr == NULL)
Line 537 
Line 559 
   
                                                 f_print(fout, "\t\t}\n");                                                  f_print(fout, "\t\t}\n");
                                         }                                          }
                                 }  
                                 size = 0;                                  size = 0;
                                 i = 0;                                  i = 0;
                                 sizestr = NULL;                                  sizestr = NULL;
Line 545 
Line 566 
                         }                          }
   
                 }                  }
                 if (i > 0) {                  if (i > 0)
                         if (sizestr == NULL && size < doinline) {                          if (sizestr == NULL && size < doinline) {
                                 /* don't expand into inline code if size <                                  /* don't expand into inline code if size <
                                  * doinline */                                   * doinline */
Line 554 
Line 575 
                                         cur = cur->next;                                          cur = cur->next;
                                 }                                  }
                         } else {                          } else {
   
                                 /* were already looking at a xdr_inlineable                                  /* were already looking at a xdr_inlineable
                                  * structure */                                   * structure */
                                 if (sizestr == NULL)                                  if (sizestr == NULL)
Line 588 
Line 610 
   
                         }                          }
                 flag = GET;                  flag = GET;
                 }  
         }          }
         f_print(fout, "\t\treturn (TRUE);\n\t}\n\n");          f_print(fout, "\t\treturn (TRUE);\n\t}\n\n");
   
Line 598 
Line 619 
                 print_stat(1, &dl->decl);                  print_stat(1, &dl->decl);
 }  }
   
 static void  static
 emit_typedef(def)  emit_typedef(def)
         definition *def;          definition *def;
 {  {
Line 607 
Line 628 
         char   *amax = def->def.ty.array_max;          char   *amax = def->def.ty.array_max;
         relation rel = def->def.ty.rel;          relation rel = def->def.ty.rel;
   
   
         print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);          print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
 }  }
   
 static void  static
 print_stat(indent, dec)  print_stat(indent, dec)
         declaration *dec;          declaration *dec;
         int     indent;          int     indent;
Line 629 
Line 651 
         print_ifstat(indent, prefix, type, rel, amax, name, dec->name);          print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
 }  }
   
   
 char   *upcase __P((char *));  char   *upcase __P((char *));
   
 void  
 emit_inline(decl, flag)  emit_inline(decl, flag)
         declaration *decl;          declaration *decl;
         int     flag;          int     flag;
 {  {
         /*check whether an array or not */  
   
   /*check whether an array or not */
   
         switch (decl->rel) {          switch (decl->rel) {
         case REL_ALIAS:          case REL_ALIAS:
                 f_print(fout, "\t");                  f_print(fout, "\t");
Line 653 
Line 677 
         }          }
 }  }
   
 void  
 emit_single_in_line(decl, flag, rel)  emit_single_in_line(decl, flag, rel)
         declaration *decl;          declaration *decl;
         int     flag;          int     flag;
Line 662 
Line 685 
         char   *upp_case;          char   *upp_case;
         int     freed = 0;          int     freed = 0;
   
   
   
         if (flag == PUT)          if (flag == PUT)
                 f_print(fout, "\t\tIXDR_PUT_");                  f_print(fout, "\t\tIXDR_PUT_");
         else          else
Line 693 
Line 718 
                 f_print(fout, "%s(buf);\n", upp_case);                  f_print(fout, "%s(buf);\n", upp_case);
         if (!freed)          if (!freed)
                 free(upp_case);                  free(upp_case);
   
 }  }
   
   
 char *  char *
 upcase(str)  upcase(str)
         char   *str;          char   *str;
 {  {
         char   *ptr, *hptr;          char   *ptr, *hptr;
   
   
         ptr = (char *) malloc(strlen(str)+1);          ptr = (char *) malloc(strlen(str)+1);
         if (ptr == (char *) NULL) {          if (ptr == (char *) NULL) {
                 f_print(stderr, "malloc failed\n");                  f_print(stderr, "malloc failed\n");
Line 713 
Line 741 
   
         *ptr = '\0';          *ptr = '\0';
         return (hptr);          return (hptr);
   
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9