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

Diff for /src/usr.bin/rpcgen/rpc_hout.c between version 1.7 and 1.8

version 1.7, 2001/11/24 19:17:47 version 1.8, 2001/11/24 19:19:59
Line 43 
Line 43 
 #include "rpc_parse.h"  #include "rpc_parse.h"
 #include "rpc_util.h"  #include "rpc_util.h"
   
 static void pconstdef __P((definition *));  static pconstdef __P((definition *));
 static void pargdef __P((definition *));  static pargdef __P((definition *));
 static void pstructdef __P((definition *));  static pstructdef __P((definition *));
 static void puniondef __P((definition *));  static puniondef __P((definition *));
 static void pprogramdef __P((definition *));  static pprogramdef __P((definition *));
 static void penumdef __P((definition *));  static penumdef __P((definition *));
 static void ptypedef __P((definition *));  static ptypedef __P((definition *));
 static void pdefine __P((char *, char *));  static pdefine __P((char *, char *));
 static void puldefine __P((char *, char *));  static puldefine __P((char *, char *));
 static int define_printed __P((proc_list *, version_list *));  static define_printed __P((proc_list *, version_list *));
 static int undefined2 __P((char *, char *));  static undefined2 __P((char *, char *));
 static void parglist __P((proc_list *, char *));  static parglist __P((proc_list *, char *));
 void pxdrfuncdecl(char *, int);  
 void pprocdef(proc_list *, version_list *, char *, int, int);  
 void pdeclaration(char *, declaration *, int, char *);  
   
 /*  /*
  * Print the C-version of an xdr definition   * Print the C-version of an xdr definition
Line 67 
Line 64 
         definition *def;          definition *def;
 {  {
   
         if (def->def_kind == DEF_PROGRAM)  /* handle data only */          if (def->def_kind == DEF_PROGRAM )  /* handle data only */
                 return;                  return;
   
         if (def->def_kind != DEF_CONST)          if (def->def_kind != DEF_CONST) {
                 f_print(fout, "\n");                  f_print(fout, "\n");
           }
         switch (def->def_kind) {          switch (def->def_kind) {
         case DEF_STRUCT:          case DEF_STRUCT:
                 pstructdef(def);                  pstructdef(def);
Line 93 
Line 91 
                 break;                  break;
         }          }
         if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {          if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) {
                 pxdrfuncdecl( def->def_name,            pxdrfuncdecl( 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));
   
         }          }
 }  }
   
Line 109 
Line 108 
                 f_print(fout, "\n");                  f_print(fout, "\n");
                 pprogramdef(def);                  pprogramdef(def);
                 break;                  break;
         }                }
 }  }
   
 void  pxdrfuncdecl( name, pointerp )
 pxdrfuncdecl(name, pointerp)  char* name;
         char *name;  int pointerp;
         int pointerp;  
 {  {
   
         f_print(fout,"#ifdef __cplusplus\n");    f_print(fout,"#ifdef __cplusplus\n");
         f_print(fout, "extern \"C\" bool_t xdr_%s(XDR *, %s%s);\n",      f_print(fout, "extern \"C\" bool_t xdr_%s(XDR *, %s%s);\n",
             name, name, pointerp ? ("*") : "");          name,
         f_print(fout,"#elif defined(__STDC__)\n");          name, pointerp ? ("*") : "");
         f_print(fout, "extern  bool_t xdr_%s(XDR *, %s%s);\n",    f_print(fout,"#elif defined(__STDC__)\n");
             name, name, pointerp ? ("*") : "");      f_print(fout, "extern  bool_t xdr_%s(XDR *, %s%s);\n",
         f_print(fout,"#else /* Old Style C */\n");          name,
         f_print(fout, "bool_t xdr_%s();\n", name);          name, pointerp ? ("*") : "");
         f_print(fout,"#endif /* Old Style C */\n\n");    f_print(fout,"#else /* Old Style C */\n");
       f_print(fout, "bool_t xdr_%s();\n", name);
     f_print(fout,"#endif /* Old Style C */\n\n");
 }  }
   
   
 static void  static
 pconstdef(def)  pconstdef(def)
         definition *def;          definition *def;
 {  {
Line 140 
Line 140 
 /* print out the definitions for the arguments of functions in the  /* print out the definitions for the arguments of functions in the
    header file     header file
 */  */
 static void  static
 pargdef(def)  pargdef(def)
         definition *def;          definition *def;
 {  {
Line 149 
Line 149 
         char *name;          char *name;
         proc_list *plist;          proc_list *plist;
   
   
         for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {          for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
                 for(plist = vers->procs; plist != NULL;                          for(plist = vers->procs; plist != NULL;
                     plist = plist->next) {                              plist = plist->next) {
                         if (!newstyle || plist->arg_num < 2) {  
                                 continue; /* old style or single args */                                  if (!newstyle || plist->arg_num < 2) {
                                           continue; /* old style or single args */
                                   }
                                   name = plist->args.argname;
                                   f_print(fout, "struct %s {\n", name);
                                   for (l = plist->args.decls;
                                        l != NULL; l = l->next) {
                                           pdeclaration(name, &l->decl, 1, ";\n" );
                                   }
                                   f_print(fout, "};\n");
                                   f_print(fout, "typedef struct %s %s;\n", name, name);
                                   pxdrfuncdecl( name,NULL );
                                   f_print( fout, "\n" );
                         }                          }
                         name = plist->args.argname;  
                         f_print(fout, "struct %s {\n", name);  
                         for (l = plist->args.decls;  
                              l != NULL; l = l->next) {  
                                 pdeclaration(name, &l->decl, 1, ";\n");  
                         }  
                         f_print(fout, "};\n");  
                         f_print(fout, "typedef struct %s %s;\n", name, name);  
                         pxdrfuncdecl(name, NULL);  
                         f_print(fout, "\n");  
                 }                  }
         }  
 }  }
   
 static void  
   static
 pstructdef(def)  pstructdef(def)
         definition *def;          definition *def;
 {  {
         char *name = def->def_name;  
         decl_list *l;          decl_list *l;
           char *name = def->def_name;
   
         f_print(fout, "struct %s {\n", name);          f_print(fout, "struct %s {\n", name);
         for (l = def->def.st.decls; l != NULL; l = l->next)          for (l = def->def.st.decls; l != NULL; l = l->next) {
                 pdeclaration(name, &l->decl, 1, ";\n");                  pdeclaration(name, &l->decl, 1, ";\n");
           }
         f_print(fout, "};\n");          f_print(fout, "};\n");
         f_print(fout, "typedef struct %s %s;\n", name, name);          f_print(fout, "typedef struct %s %s;\n", name, name);
 }  }
   
 static void  static
 puniondef(def)  puniondef(def)
         definition *def;          definition *def;
 {  {
Line 200 
Line 205 
         }          }
         f_print(fout, "\tunion {\n");          f_print(fout, "\tunion {\n");
         for (l = def->def.un.cases; l != NULL; l = l->next) {          for (l = def->def.un.cases; l != NULL; l = l->next) {
           if (l->contflag == 0)            if(l->contflag == 0)
                 pdeclaration(name, &l->case_decl, 2, ";\n");                  pdeclaration(name, &l->case_decl, 2, ";\n" );
         }          }
         decl = def->def.un.default_decl;          decl = def->def.un.default_decl;
         if (decl && !streq(decl->type, "void")) {          if (decl && !streq(decl->type, "void")) {
                 pdeclaration(name, decl, 2, ";\n");                  pdeclaration(name, decl, 2, ";\n" );
         }          }
         f_print(fout, "\t} %s_u;\n", name);          f_print(fout, "\t} %s_u;\n", name);
         f_print(fout, "};\n");          f_print(fout, "};\n");
         f_print(fout, "typedef struct %s %s;\n", name, name);          f_print(fout, "typedef struct %s %s;\n", name, name);
 }  }
   
 static void  static
 pdefine(name, num)  pdefine(name, num)
         char *name;          char *name;
         char *num;          char *num;
Line 220 
Line 225 
         f_print(fout, "#define %s %s\n", name, num);          f_print(fout, "#define %s %s\n", name, num);
 }  }
   
 static void  static
 puldefine(name, num)  puldefine(name, num)
         char *name;          char *name;
         char *num;          char *num;
Line 228 
Line 233 
         f_print(fout, "#define %s ((u_long)%s)\n", name, num);          f_print(fout, "#define %s ((u_long)%s)\n", name, num);
 }  }
   
 static int  static
 define_printed(stop, start)  define_printed(stop, start)
         proc_list *stop;          proc_list *stop;
         version_list *start;          version_list *start;
Line 249 
Line 254 
         /* NOTREACHED */          /* NOTREACHED */
 }  }
   
 static void  static
 pprogramdef(def)  pprogramdef(def)
         definition *def;          definition *def;
 {  {
Line 257 
Line 262 
         proc_list *proc;          proc_list *proc;
         int i;          int i;
         char *ext;          char *ext;
   
         pargdef(def);          pargdef(def);
   
         puldefine(def->def_name, def->def.pr.prog_num);          puldefine(def->def_name, def->def.pr.prog_num);
         for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {          for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
                 if (tblflag) {                  if (tblflag) {
                         f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n",                          f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n",
                             locase(def->def_name), vers->vers_num);                                  locase(def->def_name), vers->vers_num);
                         f_print(fout, "extern %s_%s_nproc;\n",                          f_print(fout, "extern %s_%s_nproc;\n",
                             locase(def->def_name), vers->vers_num);                                  locase(def->def_name), vers->vers_num);
                 }                  }
                 puldefine(vers->vers_name, vers->vers_num);                  puldefine(vers->vers_name, vers->vers_num);
   
Line 274 
Line 279 
                  * Print out 3 definitions, one for ANSI-C, another for C++,                   * Print out 3 definitions, one for ANSI-C, another for C++,
                  * a third for old style C                   * a third for old style C
                  */                   */
                 for(i=0; i<3; i++) {  
                         if (i==0) {                  for(i=0;i<3;i++){
                           if(i==0){
                                 f_print(fout,"\n#ifdef __cplusplus\n");                                  f_print(fout,"\n#ifdef __cplusplus\n");
                                 ext = "extern \"C\" ";                                  ext="extern \"C\" ";
                         } else if (i==1) {                          }else if ( i== 1){
                                 f_print(fout,"\n#elif defined(__STDC__)\n");                                  f_print(fout,"\n#elif defined(__STDC__)\n");
                                 ext = "extern  ";                                  ext="extern  "  ;
                         } else {                          }else{
                                 f_print(fout,"\n#else /* Old Style C */\n");                                  f_print(fout,"\n#else /* Old Style C */\n");
                                 ext = "extern  ";                                  ext="extern  ";
                         }                          }
   
   
                         for (proc = vers->procs; proc != NULL; proc = proc->next) {                          for (proc = vers->procs; proc != NULL; proc = proc->next) {
                                 if (!define_printed(proc, def->def.pr.versions))                                  if (!define_printed(proc, def->def.pr.versions)) {
                                         puldefine(proc->proc_name, proc->proc_num);                                          puldefine(proc->proc_name, proc->proc_num);
                                   }
                                 f_print(fout,"%s",ext);                                  f_print(fout,"%s",ext);
                                 pprocdef(proc, vers, "CLIENT *", 0,i);                                  pprocdef(proc, vers, "CLIENT *", 0,i);
                                 f_print(fout,"%s",ext);                                  f_print(fout,"%s",ext);
                                 pprocdef(proc, vers, "struct svc_req *", 1,i);                                  pprocdef(proc, vers, "struct svc_req *", 1,i);
   
                         }                          }
   
                 }                  }
                 f_print(fout,"#endif /* Old Style C */\n");                  f_print(fout,"#endif /* Old Style C */\n");
         }          }
 }  }
   
 void  
 pprocdef(proc, vp, addargtype, server_p,mode)  pprocdef(proc, vp, addargtype, server_p,mode)
         proc_list *proc;          proc_list *proc;
         version_list *vp;          version_list *vp;
         char *addargtype;          char* addargtype;
         int server_p;          int server_p;
         int mode;          int mode;
 {  {
   
         ptype(proc->res_prefix, proc->res_type, 1);          ptype( proc->res_prefix, proc->res_type, 1 );
         f_print(fout, "* ");          f_print( fout, "* " );
         if (server_p)          if( server_p )
                 pvname_svc(proc->proc_name, vp->vers_num);                  pvname_svc(proc->proc_name, vp->vers_num);
         else          else
                 pvname(proc->proc_name, vp->vers_num);                  pvname(proc->proc_name, vp->vers_num);
Line 318 
Line 327 
         /*          /*
          * mode  0 == cplusplus, mode  1 = ANSI-C, mode 2 = old style C           * mode  0 == cplusplus, mode  1 = ANSI-C, mode 2 = old style C
          */           */
         if (mode == 0 || mode == 1)          if(mode == 0 || mode ==1)
                 parglist(proc, addargtype);                  parglist( proc, addargtype );
         else          else
                 f_print(fout, "();\n");                  f_print(fout, "();\n");
 }  }
   
   
 /* print out argument list of procedure */  /* print out argument list of procedure */
 static void  static
 parglist(proc, addargtype)  parglist(proc, addargtype)
         proc_list *proc;          proc_list *proc;
         char *addargtype;          char* addargtype;
 {  {
         decl_list *dl;          decl_list *dl;
   
         f_print(fout,"(");          f_print(fout,"(");
   
         if (proc->arg_num < 2 && newstyle &&          if( proc->arg_num < 2 && newstyle &&
            streq(proc->args.decls->decl.type, "void")) {             streq( proc->args.decls->decl.type, "void")) {
                 /* 0 argument in new style:  do nothing */                  /* 0 argument in new style:  do nothing */
         } else {          } else {
                 for (dl = proc->args.decls; dl != NULL; dl = dl->next) {                  for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
                         ptype(dl->decl.prefix, dl->decl.type, 1);                          ptype( dl->decl.prefix, dl->decl.type, 1 );
                         if (!newstyle)                          if( !newstyle )
                                 f_print(fout, "*"); /* old style passes by reference */                                  f_print( fout, "*" ); /* old style passes by reference */
                         f_print(fout, ", ");  
                           f_print( fout, ", " );
                 }                  }
         }          }
   
         f_print(fout, "%s);\n", addargtype);          f_print(fout, "%s);\n", addargtype);
 }  }
   
 static void  static
 penumdef(def)  penumdef(def)
         definition *def;          definition *def;
 {  {
Line 380 
Line 392 
         f_print(fout, "typedef enum %s %s;\n", name, name);          f_print(fout, "typedef enum %s %s;\n", name, name);
 }  }
   
 static void  static
 ptypedef(def)  ptypedef(def)
         definition *def;          definition *def;
 {  {
Line 389 
Line 401 
         char prefix[8]; /* enough to contain "struct ", including NUL */          char prefix[8]; /* enough to contain "struct ", including NUL */
         relation rel = def->def.ty.rel;          relation rel = def->def.ty.rel;
   
   
         if (!streq(name, old)) {          if (!streq(name, old)) {
                 if (streq(old, "string")) {                  if (streq(old, "string")) {
                         old = "char";                          old = "char";
Line 426 
Line 439 
         }          }
 }  }
   
 void  
 pdeclaration(name, dec, tab, separator)  pdeclaration(name, dec, tab, separator)
         char *name;          char *name;
         declaration *dec;          declaration *dec;
Line 437 
Line 449 
         char *prefix;          char *prefix;
         char *type;          char *type;
   
         if (streq(dec->type, "void"))          if (streq(dec->type, "void")) {
                 return;                  return;
           }
         tabify(fout, tab);          tabify(fout, tab);
         if (streq(dec->type, name) && !dec->prefix) {          if (streq(dec->type, name) && !dec->prefix) {
                 f_print(fout, "struct ");                  f_print(fout, "struct ");
Line 480 
Line 493 
                         break;                          break;
                 }                  }
         }          }
         f_print(fout, separator);          f_print(fout, separator );
 }  }
   
 static int  static
 undefined2(type, stop)  undefined2(type, stop)
         char *type;          char *type;
         char *stop;          char *stop;

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