[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.6 and 1.7

version 1.6, 2001/07/18 22:26:00 version 1.7, 2001/11/24 19:17:47
Line 43 
Line 43 
 #include "rpc_parse.h"  #include "rpc_parse.h"
 #include "rpc_util.h"  #include "rpc_util.h"
   
 static pconstdef __P((definition *));  static void pconstdef __P((definition *));
 static pargdef __P((definition *));  static void pargdef __P((definition *));
 static pstructdef __P((definition *));  static void pstructdef __P((definition *));
 static puniondef __P((definition *));  static void puniondef __P((definition *));
 static pprogramdef __P((definition *));  static void pprogramdef __P((definition *));
 static penumdef __P((definition *));  static void penumdef __P((definition *));
 static ptypedef __P((definition *));  static void ptypedef __P((definition *));
 static pdefine __P((char *, char *));  static void pdefine __P((char *, char *));
 static puldefine __P((char *, char *));  static void puldefine __P((char *, char *));
 static define_printed __P((proc_list *, version_list *));  static int define_printed __P((proc_list *, version_list *));
 static undefined2 __P((char *, char *));  static int undefined2 __P((char *, char *));
 static parglist __P((proc_list *, char *));  static void 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 64 
Line 67 
         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 91 
Line 93 
                 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 108 
Line 109 
                 f_print(fout, "\n");                  f_print(fout, "\n");
                 pprogramdef(def);                  pprogramdef(def);
                 break;                  break;
               }          }
 }  }
   
 pxdrfuncdecl( name, pointerp )  void
 char* name;  pxdrfuncdecl(name, pointerp)
 int pointerp;          char *name;
           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, name, pointerp ? ("*") : "");
         name, pointerp ? ("*") : "");          f_print(fout,"#elif defined(__STDC__)\n");
   f_print(fout,"#elif defined(__STDC__)\n");          f_print(fout, "extern  bool_t xdr_%s(XDR *, %s%s);\n",
     f_print(fout, "extern  bool_t xdr_%s(XDR *, %s%s);\n",              name, name, pointerp ? ("*") : "");
         name,          f_print(fout,"#else /* Old Style C */\n");
         name, pointerp ? ("*") : "");          f_print(fout, "bool_t xdr_%s();\n", name);
   f_print(fout,"#else /* Old Style C */\n");          f_print(fout,"#endif /* Old Style C */\n\n");
     f_print(fout, "bool_t xdr_%s();\n", name);  
   f_print(fout,"#endif /* Old Style C */\n\n");  
 }  }
   
   
 static  static void
 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  static void
 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) {
                                 if (!newstyle || plist->arg_num < 2) {                                  continue; /* old style or single args */
                                         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;
 {  {
         decl_list *l;  
         char *name = def->def_name;          char *name = def->def_name;
           decl_list *l;
   
         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  static void
 puniondef(def)  puniondef(def)
         definition *def;          definition *def;
 {  {
Line 205 
Line 200 
         }          }
         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  static void
 pdefine(name, num)  pdefine(name, num)
         char *name;          char *name;
         char *num;          char *num;
Line 225 
Line 220 
         f_print(fout, "#define %s %s\n", name, num);          f_print(fout, "#define %s %s\n", name, num);
 }  }
   
 static  static void
 puldefine(name, num)  puldefine(name, num)
         char *name;          char *name;
         char *num;          char *num;
Line 233 
Line 228 
         f_print(fout, "#define %s ((u_long)%s)\n", name, num);          f_print(fout, "#define %s ((u_long)%s)\n", name, num);
 }  }
   
 static  static int
 define_printed(stop, start)  define_printed(stop, start)
         proc_list *stop;          proc_list *stop;
         version_list *start;          version_list *start;
Line 254 
Line 249 
         /* NOTREACHED */          /* NOTREACHED */
 }  }
   
 static  static void
 pprogramdef(def)  pprogramdef(def)
         definition *def;          definition *def;
 {  {
Line 262 
Line 257 
         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 279 
Line 274 
                  * 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++) {
                 for(i=0;i<3;i++){                          if (i==0) {
                         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 327 
Line 318 
         /*          /*
          * 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  static void
 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  static void
 penumdef(def)  penumdef(def)
         definition *def;          definition *def;
 {  {
Line 392 
Line 380 
         f_print(fout, "typedef enum %s %s;\n", name, name);          f_print(fout, "typedef enum %s %s;\n", name, name);
 }  }
   
 static  static void
 ptypedef(def)  ptypedef(def)
         definition *def;          definition *def;
 {  {
Line 401 
Line 389 
         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 439 
Line 426 
         }          }
 }  }
   
   void
 pdeclaration(name, dec, tab, separator)  pdeclaration(name, dec, tab, separator)
         char *name;          char *name;
         declaration *dec;          declaration *dec;
Line 449 
Line 437 
         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 493 
Line 480 
                         break;                          break;
                 }                  }
         }          }
         f_print(fout, separator );          f_print(fout, separator);
 }  }
   
 static  static int
 undefined2(type, stop)  undefined2(type, stop)
         char *type;          char *type;
         char *stop;          char *stop;

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