[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.11 and 1.12

version 1.11, 2002/02/16 21:27:51 version 1.12, 2002/06/01 01:40:38
Line 135 
Line 135 
         char    *procname;          char    *procname;
         int     pointerp;          int     pointerp;
 {  {
         f_print(fout, "\n");          fprintf(fout, "\n");
         f_print(fout, "bool_t\n");          fprintf(fout, "bool_t\n");
         if (Cflag) {          if (Cflag) {
                 f_print(fout, "xdr_%s(", procname);                  fprintf(fout, "xdr_%s(", procname);
                 f_print(fout, "XDR *xdrs, ");                  fprintf(fout, "XDR *xdrs, ");
                 f_print(fout, "%s ", procname);                  fprintf(fout, "%s ", procname);
                 if (pointerp)                  if (pointerp)
                         f_print(fout, "*");                          fprintf(fout, "*");
                 f_print(fout, "objp)\n{\n");                  fprintf(fout, "objp)\n{\n");
         } else {          } else {
                 f_print(fout, "xdr_%s(xdrs, objp)\n", procname);                  fprintf(fout, "xdr_%s(xdrs, objp)\n", procname);
                 f_print(fout, "\tXDR *xdrs;\n");                  fprintf(fout, "\tXDR *xdrs;\n");
                 f_print(fout, "\t%s ", procname);                  fprintf(fout, "\t%s ", procname);
                 if (pointerp)                  if (pointerp)
                         f_print(fout, "*");                          fprintf(fout, "*");
                 f_print(fout, "objp;\n{\n");                  fprintf(fout, "objp;\n{\n");
         }          }
 }  }
   
Line 167 
Line 167 
         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");          fprintf(fout, "\tint32_t *buf;\n\n");
 }  }
   
 static void  static void
Line 180 
Line 180 
 static void  static void
 print_trailer()  print_trailer()
 {  {
         f_print(fout, "\treturn (TRUE);\n");          fprintf(fout, "\treturn (TRUE);\n");
         f_print(fout, "}\n");          fprintf(fout, "}\n");
 }  }
   
 static void  static void
Line 190 
Line 190 
         char   *name;          char   *name;
 {  {
         tabify(fout, indent);          tabify(fout, indent);
         f_print(fout, "if (!xdr_%s(xdrs", name);          fprintf(fout, "if (!xdr_%s(xdrs", name);
 }  }
   
 static void  static void
 print_ifarg(arg)  print_ifarg(arg)
         char   *arg;          char   *arg;
 {  {
         f_print(fout, ", %s", arg);          fprintf(fout, ", %s", arg);
 }  }
   
 static void  static void
Line 206 
Line 206 
         char   *type;          char   *type;
 {  {
         if (streq(type, "bool")) {          if (streq(type, "bool")) {
                 f_print(fout, ", sizeof(bool_t), (xdrproc_t)xdr_bool");                  fprintf(fout, ", sizeof(bool_t), (xdrproc_t)xdr_bool");
         } else {          } else {
                 f_print(fout, ", sizeof(");                  fprintf(fout, ", sizeof(");
                 if (undefined(type) && prefix) {                  if (undefined(type) && prefix) {
                         f_print(fout, "%s ", prefix);                          fprintf(fout, "%s ", prefix);
                 }                  }
                 f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type);                  fprintf(fout, "%s), (xdrproc_t)xdr_%s", type, type);
         }          }
 }  }
   
Line 220 
Line 220 
 print_ifclose(indent)  print_ifclose(indent)
         int     indent;          int     indent;
 {  {
         f_print(fout, ")) {\n");          fprintf(fout, ")) {\n");
         tabify(fout, indent);          tabify(fout, indent);
         f_print(fout, "\treturn (FALSE);\n");          fprintf(fout, "\treturn (FALSE);\n");
         tabify(fout, indent);          tabify(fout, indent);
         f_print(fout, "}\n");          fprintf(fout, "}\n");
 }  }
   
 static void  static void
Line 243 
Line 243 
         case REL_POINTER:          case REL_POINTER:
                 print_ifopen(indent, "pointer");                  print_ifopen(indent, "pointer");
                 print_ifarg("(char **)");                  print_ifarg("(char **)");
                 f_print(fout, "%s", objname);                  fprintf(fout, "%s", objname);
                 print_ifsizeof(prefix, type);                  print_ifsizeof(prefix, type);
                 break;                  break;
         case REL_VECTOR:          case REL_VECTOR:
Line 259 
Line 259 
                 } else {                  } else {
                         print_ifopen(indent, "vector");                          print_ifopen(indent, "vector");
                         print_ifarg("(char *)");                          print_ifarg("(char *)");
                         f_print(fout, "%s", objname);                          fprintf(fout, "%s", objname);
                 }                  }
                 print_ifarg(amax);                  print_ifarg(amax);
                 if (!alt) {                  if (!alt) {
Line 284 
Line 284 
                         }                          }
                         print_ifarg("(char **)");                          print_ifarg("(char **)");
                         if (*objname == '&') {                          if (*objname == '&') {
                                 f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",                                  fprintf(fout, "%s.%s_val, (u_int *)%s.%s_len",
                                     objname, name, objname, name);                                      objname, name, objname, name);
                         } else {                          } else {
                                 f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",                                  fprintf(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
                                     objname, name, objname, name);                                      objname, name, objname, name);
                         }                          }
                 }                  }
Line 347 
Line 347 
         char   *format = "&objp->%s_u.%s";          char   *format = "&objp->%s_u.%s";
   
         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);          fprintf(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);                  fprintf(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;
                 cs = &cl->case_decl;                  cs = &cl->case_decl;
Line 357 
Line 357 
                         object = alloc(strlen(def->def_name) + strlen(format) +                          object = alloc(strlen(def->def_name) + strlen(format) +
                             strlen(cs->name) + 1);                              strlen(cs->name) + 1);
                         if (isvectordef(cs->type, cs->rel)) {                          if (isvectordef(cs->type, cs->rel)) {
                                 s_print(object, vecformat, def->def_name,                                  sprintf(object, vecformat, def->def_name,
                                     cs->name);                                      cs->name);
                         } else {                          } else {
                                 s_print(object, format, def->def_name,                                  sprintf(object, format, def->def_name,
                                     cs->name);                                      cs->name);
                         }                          }
                         print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,                          print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
                             object, cs->name);                              object, cs->name);
                         free(object);                          free(object);
                 }                  }
                 f_print(fout, "\t\tbreak;\n");                  fprintf(fout, "\t\tbreak;\n");
         }          }
         dflt = def->def.un.default_decl;          dflt = def->def.un.default_decl;
         if (dflt != NULL) {          if (dflt != NULL) {
                 if (!streq(dflt->type, "void")) {                  if (!streq(dflt->type, "void")) {
                         f_print(fout, "\tdefault:\n");                          fprintf(fout, "\tdefault:\n");
                         object = alloc(strlen(def->def_name) + strlen(format) +                          object = alloc(strlen(def->def_name) + strlen(format) +
                             strlen(dflt->name) + 1);                              strlen(dflt->name) + 1);
                         if (isvectordef(dflt->type, dflt->rel)) {                          if (isvectordef(dflt->type, dflt->rel)) {
                                 s_print(object, vecformat, def->def_name,                                  sprintf(object, vecformat, def->def_name,
                                     dflt->name);                                      dflt->name);
                         } else {                          } else {
                                 s_print(object, format, def->def_name,                                  sprintf(object, format, def->def_name,
                                     dflt->name);                                      dflt->name);
                         }                          }
   
                         print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,                          print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
                             dflt->array_max, object, dflt->name);                              dflt->array_max, object, dflt->name);
                         free(object);                          free(object);
                         f_print(fout, "\t\tbreak;\n");                          fprintf(fout, "\t\tbreak;\n");
                 }                  }
         } else {          } else {
                 f_print(fout, "\tdefault:\n");                  fprintf(fout, "\tdefault:\n");
                 f_print(fout, "\t\treturn (FALSE);\n");                  fprintf(fout, "\t\treturn (FALSE);\n");
         }          }
   
         f_print(fout, "\t}\n");          fprintf(fout, "\t}\n");
 }  }
   
 static void  static void
Line 415 
Line 415 
         }          }
         for (dl = def->def.st.decls; dl != NULL; dl = dl->next)          for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
                 if (dl->decl.rel == REL_VECTOR) {                  if (dl->decl.rel == REL_VECTOR) {
                         f_print(fout, "\tint i;\n");                          fprintf(fout, "\tint i;\n");
                         break;                          break;
                 }                  }
         size = 0;          size = 0;
Line 449 
Line 449 
         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");                          fprintf(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");                          fprintf(fout, "\t\treturn (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n");
   
                 i = 0;                  i = 0;
                 size = 0;                  size = 0;
Line 477 
Line 477 
                                                 plus = "+";                                                  plus = "+";
   
                                         if (ptr->length != 1)                                          if (ptr->length != 1)
                                                 s_print(ptemp, " %s %s * %d", plus, dl->decl.array_max, ptr->length);                                                  snprintf(ptemp, sizeof ptemp,
                                                       " %s %s * %d", plus,
                                                       dl->decl.array_max,
                                                       ptr->length);
                                         else                                          else
                                                 s_print(ptemp, " %s %s ", plus, dl->decl.array_max);                                                  snprintf(ptemp, sizeof ptemp,
                                                       " %s %s ", plus,
                                                       dl->decl.array_max);
   
                                         /* now concatenate to sizestr !!!! */                                          /* now concatenate to sizestr !!!! */
                                         if (sizestr == NULL)                                          if (sizestr == NULL)
Line 487 
Line 492 
                                         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");                                                          fprintf(stderr, "Fatal error : no memory\n");
                                                         crash();                                                          crash();
                                                 }                                                  }
                                                 sizestr = strcat(sizestr, ptemp);       /* build up length of                                                  sizestr = strcat(sizestr, ptemp);       /* build up length of
Line 509 
Line 514 
                                                 /* were already looking at a                                                  /* were already looking at a
                                                  * xdr_inlineable structure */                                                   * xdr_inlineable structure */
                                                 if (sizestr == NULL)                                                  if (sizestr == NULL)
                                                         f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",                                                          fprintf(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",
                                                             size);                                                              size);
                                                 else                                                  else
                                                         if (size == 0)                                                          if (size == 0)
                                                                 f_print(fout,                                                                  fprintf(fout,
                                                                     "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);",                                                                      "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);",
                                                                     sizestr);                                                                      sizestr);
                                                         else                                                          else
                                                                 f_print(fout,                                                                  fprintf(fout,
                                                                     "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s)* BYTES_PER_XDR_UNIT);",                                                                      "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s)* BYTES_PER_XDR_UNIT);",
                                                                     size, sizestr);                                                                      size, sizestr);
   
                                                 f_print(fout, "\n\t\tif (buf == NULL) {\n");                                                  fprintf(fout, "\n\t\tif (buf == NULL) {\n");
   
                                                 psav = cur;                                                  psav = cur;
                                                 while (cur != dl) {                                                  while (cur != dl) {
Line 529 
Line 534 
                                                         cur = cur->next;                                                          cur = cur->next;
                                                 }                                                  }
   
                                                 f_print(fout, "\t\t} else {\n");                                                  fprintf(fout, "\t\t} else {\n");
   
                                                 cur = psav;                                                  cur = psav;
                                                 while (cur != dl) {                                                  while (cur != dl) {
Line 537 
Line 542 
                                                         cur = cur->next;                                                          cur = cur->next;
                                                 }                                                  }
   
                                                 f_print(fout, "\t\t}\n");                                                  fprintf(fout, "\t\t}\n");
                                         }                                          }
                                 }                                  }
                                 size = 0;                                  size = 0;
Line 559 
Line 564 
                                 /* were already looking at a xdr_inlineable                                  /* were already looking at a xdr_inlineable
                                  * structure */                                   * structure */
                                 if (sizestr == NULL)                                  if (sizestr == NULL)
                                         f_print(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",                                          fprintf(fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",
                                             size);                                              size);
                                 else                                  else
                                         if (size == 0)                                          if (size == 0)
                                                 f_print(fout,                                                  fprintf(fout,
                                                     "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);",                                                      "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, %s * BYTES_PER_XDR_UNIT);",
                                                     sizestr);                                                      sizestr);
                                         else                                          else
                                                 f_print(fout,                                                  fprintf(fout,
                                                     "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s)* BYTES_PER_XDR_UNIT);",                                                      "\t\tbuf = (int32_t *)XDR_INLINE(xdrs, (%d + %s)* BYTES_PER_XDR_UNIT);",
                                                     size, sizestr);                                                      size, sizestr);
   
                                 f_print(fout, "\n\t\tif (buf == NULL) {\n");                                  fprintf(fout, "\n\t\tif (buf == NULL) {\n");
   
                                 psav = cur;                                  psav = cur;
                                 while (cur != NULL) {                                  while (cur != NULL) {
                                         print_stat(3, &cur->decl);                                          print_stat(3, &cur->decl);
                                         cur = cur->next;                                          cur = cur->next;
                                 }                                  }
                                 f_print(fout, "\t\t} else {\n");                                  fprintf(fout, "\t\t} else {\n");
   
                                 cur = psav;                                  cur = psav;
                                 while (cur != dl) {                                  while (cur != dl) {
Line 586 
Line 591 
                                         cur = cur->next;                                          cur = cur->next;
                                 }                                  }
   
                                 f_print(fout, "\t\t}\n");                                  fprintf(fout, "\t\t}\n");
   
                         }                          }
                 }                  }
                 flag = GET;                  flag = GET;
         }          }
         f_print(fout, "\t\treturn (TRUE);\n\t}\n\n");          fprintf(fout, "\t\treturn (TRUE);\n\t}\n\n");
   
         /* now take care of XDR_FREE case */          /* now take care of XDR_FREE case */
   
Line 624 
Line 629 
         char    name[256];          char    name[256];
   
         if (isvectordef(type, rel)) {          if (isvectordef(type, rel)) {
                 s_print(name, "objp->%s", dec->name);                  snprintf(name, sizeof name, "objp->%s", dec->name);
         } else {          } else {
                 s_print(name, "&objp->%s", dec->name);                  snprintf(name, sizeof name, "&objp->%s", dec->name);
         }          }
         print_ifstat(indent, prefix, type, rel, amax, name, dec->name);          print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
 }  }
Line 642 
Line 647 
   
         switch (decl->rel) {          switch (decl->rel) {
         case REL_ALIAS:          case REL_ALIAS:
                 f_print(fout, "\t");                  fprintf(fout, "\t");
                 emit_single_in_line(decl, flag, REL_ALIAS);                  emit_single_in_line(decl, flag, REL_ALIAS);
                 break;                  break;
         case REL_VECTOR:          case REL_VECTOR:
                 f_print(fout, "\t\t\t{\n\t\t\t\t%s *genp;\n\n", decl->type);                  fprintf(fout, "\t\t\t{\n\t\t\t\t%s *genp;\n\n", decl->type);
                 f_print(fout, "\t\t\t\tfor (i = 0, genp = objp->%s;\n\t\t\t\t    i < %s; i++) {\n\t\t\t",                  fprintf(fout, "\t\t\t\tfor (i = 0, genp = objp->%s;\n\t\t\t\t    i < %s; i++) {\n\t\t\t",
                     decl->name, decl->array_max);                      decl->name, decl->array_max);
                 emit_single_in_line(decl, flag, REL_VECTOR);                  emit_single_in_line(decl, flag, REL_VECTOR);
                 f_print(fout, "\t\t\t\t}\n\t\t\t}\n");                  fprintf(fout, "\t\t\t\t}\n\t\t\t}\n");
   
         }          }
 }  }
Line 665 
Line 670 
         int     freed = 0;          int     freed = 0;
   
         if (flag == PUT)          if (flag == PUT)
                 f_print(fout, "\t\tIXDR_PUT_");                  fprintf(fout, "\t\tIXDR_PUT_");
         else          else
                 if (rel == REL_ALIAS)                  if (rel == REL_ALIAS)
                         f_print(fout, "\t\tobjp->%s = IXDR_GET_", decl->name);                          fprintf(fout, "\t\tobjp->%s = IXDR_GET_", decl->name);
                 else                  else
                         f_print(fout, "\t\t*genp++ = IXDR_GET_");                          fprintf(fout, "\t\t*genp++ = IXDR_GET_");
   
         upp_case = upcase(decl->type);          upp_case = upcase(decl->type);
   
Line 687 
Line 692 
         }          }
         if (flag == PUT)          if (flag == PUT)
                 if (rel == REL_ALIAS)                  if (rel == REL_ALIAS)
                         f_print(fout, "%s(buf, objp->%s);\n", upp_case, decl->name);                          fprintf(fout, "%s(buf, objp->%s);\n", upp_case, decl->name);
                 else                  else
                         f_print(fout, "%s(buf, *genp++);\n", upp_case);                          fprintf(fout, "%s(buf, *genp++);\n", upp_case);
   
         else          else
                 f_print(fout, "%s(buf);\n", upp_case);                  fprintf(fout, "%s(buf);\n", upp_case);
         if (!freed)          if (!freed)
                 free(upp_case);                  free(upp_case);
 }  }
Line 705 
Line 710 
   
         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");                  fprintf(stderr, "malloc failed\n");
                 exit(1);                  exit(1);
         }          }
   

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12