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

Diff for /src/usr.bin/rpcgen/rpc_main.c between version 1.14 and 1.15

version 1.14, 2002/06/01 01:40:38 version 1.15, 2002/07/05 05:39:42
Line 41 
Line 41 
   
 #define RPCGEN_VERSION  "199506"/* This program's version (year & month) */  #define RPCGEN_VERSION  "199506"/* This program's version (year & month) */
   
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <string.h>  
 #include <sys/types.h>  #include <sys/types.h>
 #ifdef __TURBOC__  
 #define MAXPATHLEN      80  
 #include <process.h>  
 #include <dir.h>  
 #else  
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/file.h>  #include <sys/file.h>
 #endif  #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <unistd.h>
   #include <stdlib.h>
   #include <ctype.h>
 #include <sys/stat.h>  #include <sys/stat.h>
 #include "rpc_parse.h"  #include "rpc_parse.h"
 #include "rpc_util.h"  #include "rpc_util.h"
Line 130 
Line 127 
 static char    *dos_cppfile = NULL;  static char    *dos_cppfile = NULL;
 #endif  #endif
   
 static c_output(char *, char *, int, char *);  static void c_output(char *, char *, int, char *);
 static h_output(char *, char *, int, char *);  static void h_output(char *, char *, int, char *);
 static s_output(int, char **, char *, char *, int, char *, int, int);  static void s_output(int, char **, char *, char *, int, char *, int, int);
 static l_output(char *, char *, int, char *);  static void l_output(char *, char *, int, char *);
 static t_output(char *, char *, int, char *);  static void t_output(char *, char *, int, char *);
 static svc_output(char *, char *, int, char *);  static void svc_output(char *, char *, int, char *);
 static clnt_output(char *, char *, int, char *);  static void clnt_output(char *, char *, int, char *);
 static do_registers(int, char **);  static int do_registers(int, char **);
 static void addarg(char *);  static void addarg(char *);
 static void putarg(int, char *);  static void putarg(int, char *);
 static void clear_args(void);  static void clear_args(void);
 static void checkfiles(char *, char *);  static void checkfiles(char *, char *);
 static int parseargs(int, char **, struct commandline *);  static int parseargs(int, char **, struct commandline *);
 static usage(void);  static void usage(void);
   void c_initialize(void);
   
   
 int  int
 main(argc, argv)  main(argc, argv)
         int argc;          int argc;
Line 234 
Line 231 
                 file++;                  file++;
   
         res = alloc(strlen(file) + strlen(ext) + 1);          res = alloc(strlen(file) + strlen(ext) + 1);
         if (res == NULL)          if (res == NULL) {
                 abort();                  fprintf(stderr, "could not allocate memory\n");
                   exit(1);
           }
         p = strrchr(file, '.');          p = strrchr(file, '.');
         if (p == NULL)          if (p == NULL)
                 p = file + strlen(file);                  p = file + strlen(file);
Line 272 
Line 271 
   
 }  }
   
 static  static void
 add_warning()  add_warning()
 {  {
         fprintf(fout, "/*\n");          fprintf(fout, "/*\n");
Line 282 
Line 281 
 }  }
   
 /* clear list of arguments */  /* clear list of arguments */
 static void  static void
 clear_args()  clear_args()
 {  {
         int             i;          int             i;
Line 292 
Line 291 
 }  }
   
 /* make sure that a CPP exists */  /* make sure that a CPP exists */
 static void  static void
 find_cpp()  find_cpp()
 {  {
         struct stat     buf;          struct stat     buf;
Line 317 
Line 316 
 /*  /*
  * Open input file with given define for C-preprocessor   * Open input file with given define for C-preprocessor
  */   */
 static  static void
 open_input(infile, define)  open_input(infile, define)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 416 
Line 415 
         NULL          NULL
 };  };
   
 static int  static int
 check_nettype(name, list_to_check)  check_nettype(name, list_to_check)
         char           *name;          char           *name;
         char           *list_to_check[];          char           *list_to_check[];
Line 434 
Line 433 
  * Compile into an XDR routine output file   * Compile into an XDR routine output file
  */   */
   
 static  static void
 c_output(infile, define, extend, outfile)  c_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 458 
Line 457 
         } else          } else
                 fprintf(fout, "#include <rpc/rpc.h>\n");                  fprintf(fout, "#include <rpc/rpc.h>\n");
         tell = ftell(fout);          tell = ftell(fout);
         while (def = get_definition()) {          while ((def = get_definition())) {
                 emit(def);                  emit(def);
         }          }
         if (extend && tell == ftell(fout)) {          if (extend && tell == ftell(fout)) {
Line 467 
Line 466 
 }  }
   
   
 c_initialize()  void
   c_initialize(void)
 {  {
   
         /* add all the starting basic types */          /* add all the starting basic types */
Line 492 
Line 492 
 };\n";  };\n";
   
   
 char           *  char *
 generate_guard(pathname)  generate_guard(pathname)
         char           *pathname;          char           *pathname;
 {  {
Line 501 
Line 501 
         filename = strrchr(pathname, '/');      /* find last component */          filename = strrchr(pathname, '/');      /* find last component */
         filename = ((filename == 0) ? pathname : filename + 1);          filename = ((filename == 0) ? pathname : filename + 1);
         guard = strdup(filename);          guard = strdup(filename);
           if (guard == NULL) {
                   fprintf(stderr, "out of memory while processing %s\n", filename);
                   crash();
           }
   
         /* convert to upper case */          /* convert to upper case */
         tmp = guard;          tmp = guard;
         while (*tmp) {          while (*tmp) {
Line 517 
Line 522 
  * Compile into an XDR header file   * Compile into an XDR header file
  */   */
   
 static  static void
 h_output(infile, define, extend, outfile)  h_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 544 
Line 549 
   
         tell = ftell(fout);          tell = ftell(fout);
         /* print data definitions */          /* print data definitions */
         while (def = get_definition()) {          while ((def = get_definition())) {
                 print_datadef(def);                  print_datadef(def);
         }          }
   
Line 566 
Line 571 
 /*  /*
  * Compile into an RPC service   * Compile into an RPC service
  */   */
 static  static void
 s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)  s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
         int             argc;          int             argc;
         char           *argv[];          char           *argv[];
Line 632 
Line 637 
         if ((netflag || pmflag) && tirpcflag) {          if ((netflag || pmflag) && tirpcflag) {
                 fprintf(fout, "#include <netconfig.h>\n");                  fprintf(fout, "#include <netconfig.h>\n");
         }          }
         if ( /* timerflag && */ tirpcflag)          if (/* timerflag && */ tirpcflag)
                 fprintf(fout, "#include <sys/resource.h> /* rlimit */\n");                  fprintf(fout, "#include <sys/resource.h> /* rlimit */\n");
         if (logflag || inetdflag || pmflag) {          if (logflag || inetdflag || pmflag) {
                 fprintf(fout, "#include <syslog.h>\n");                  fprintf(fout, "#include <syslog.h>\n");
Line 644 
Line 649 
         fprintf(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");          fprintf(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
         if (timerflag)          if (timerflag)
                 fprintf(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);                  fprintf(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);
         while (def = get_definition()) {          while ((def = get_definition())) {
                 foundprogram |= (def->def_kind == DEF_PROGRAM);                  foundprogram |= (def->def_kind == DEF_PROGRAM);
         }          }
         if (extend && !foundprogram) {          if (extend && !foundprogram) {
Line 667 
Line 672 
 /*  /*
  * generate client side stubs   * generate client side stubs
  */   */
 static  static void
 l_output(infile, define, extend, outfile)  l_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 690 
Line 695 
                 free(include);                  free(include);
         } else          } else
                 fprintf(fout, "#include <rpc/rpc.h>\n");                  fprintf(fout, "#include <rpc/rpc.h>\n");
         while (def = get_definition())          while ((def = get_definition()))
                 foundprogram |= (def->def_kind == DEF_PROGRAM);                  foundprogram |= (def->def_kind == DEF_PROGRAM);
   
         if (extend && !foundprogram) {          if (extend && !foundprogram) {
Line 703 
Line 708 
 /*  /*
  * generate the dispatch table   * generate the dispatch table
  */   */
 static  static void
 t_output(infile, define, extend, outfile)  t_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 718 
Line 723 
         outfilename = extend ? extendfile(infile, outfile) : outfile;          outfilename = extend ? extendfile(infile, outfile) : outfile;
         open_output(infile, outfilename);          open_output(infile, outfilename);
         add_warning();          add_warning();
         while (def = get_definition())          while ((def = get_definition()))
                 foundprogram |= (def->def_kind == DEF_PROGRAM);                  foundprogram |= (def->def_kind == DEF_PROGRAM);
   
         if (extend && !foundprogram) {          if (extend && !foundprogram) {
Line 729 
Line 734 
 }  }
   
 /* sample routine for the server template */  /* sample routine for the server template */
 static  static void
 svc_output(infile, define, extend, outfile)  svc_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 756 
Line 761 
                 fprintf(fout, "#include <rpc/rpc.h>\n");                  fprintf(fout, "#include <rpc/rpc.h>\n");
   
         tell = ftell(fout);          tell = ftell(fout);
         while (def = get_definition())          while ((def = get_definition()))
                 write_sample_svc(def);                  write_sample_svc(def);
   
         if (extend && tell == ftell(fout))          if (extend && tell == ftell(fout))
Line 765 
Line 770 
   
   
 /* sample main routine for client */  /* sample main routine for client */
 static  static void
 clnt_output(infile, define, extend, outfile)  clnt_output(infile, define, extend, outfile)
         char           *infile;          char           *infile;
         char           *define;          char           *define;
Line 794 
Line 799 
         } else          } else
                 fprintf(fout, "#include <rpc/rpc.h>\n");                  fprintf(fout, "#include <rpc/rpc.h>\n");
         tell = ftell(fout);          tell = ftell(fout);
         while (def = get_definition())          while ((def = get_definition()))
                 has_program += write_sample_clnt(def);                  has_program += write_sample_clnt(def);
   
         if (has_program)          if (has_program)
Line 808 
Line 813 
  * Perform registrations for service output   * Perform registrations for service output
  * Return 0 if failed; 1 otherwise.   * Return 0 if failed; 1 otherwise.
  */   */
 static  static int
 int  
 do_registers(argc, argv)  do_registers(argc, argv)
         int             argc;          int             argc;
         char           *argv[];          char           *argv[];
Line 952 
Line 956 
                                 case 'l':                                  case 'l':
                                 case 'm':                                  case 'm':
                                 case 't':                                  case 't':
                                         if (flag[c])                                          if (flag[(unsigned char)c])
                                                 return (0);                                                  return (0);
                                         flag[c] = 1;                                          flag[(unsigned char)c] = 1;
                                         break;                                          break;
                                 case 'S':                                  case 'S':
                                         /*                                          /*
Line 970 
Line 974 
                                         else                                          else
                                                 return (0);                                                  return (0);
   
                                         if (flag[c])                                          if (flag[(unsigned char)c])
                                                 return (0);                                                  return (0);
                                         flag[c] = 1;                                          flag[(unsigned char)c] = 1;
                                         break;                                          break;
                                 case 'C':       /* ANSI C syntax */                                  case 'C':       /* ANSI C syntax */
                                         Cflag = 1;                                          Cflag = 1;
Line 1014 
Line 1018 
                                         if (argv[i][j - 1] != '-' ||                                          if (argv[i][j - 1] != '-' ||
                                             argv[i][j + 1] != 0)                                              argv[i][j + 1] != 0)
                                                 return (0);                                                  return (0);
                                         flag[c] = 1;                                          flag[(unsigned char)c] = 1;
                                         if (++i == argc)                                          if (++i == argc)
                                                 return (0);                                                  return (0);
                                         if (c == 's') {                                          if (c == 's') {
Line 1097 
Line 1101 
         return (1);          return (1);
 }  }
   
 static  static void
 usage()  usage(void)
 {  {
         fprintf(stderr, "usage: %s [-abACILNT] [-Dname[=value]] [-i lines] "          fprintf(stderr, "usage: %s [-abACILNT] [-Dname[=value]] [-i lines] "
             "[-K seconds] infile\n", cmdname);              "[-K seconds] infile\n", cmdname);

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15