home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / preproc / pmain.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  5KB  |  217 lines

  1. #include "::preproc:preproc.h"
  2. #include "::preproc:pproto.h"
  3.  
  4. char *progname = "pp";
  5.  
  6. /*
  7.  * The following code is operating-system dependent [@pmain.01]. Establish
  8.  *  command-line options.
  9.  */
  10.  
  11. #if PORT
  12. static char *ostr = "CPD:I:U:o:";
  13. static char *options = 
  14.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  15.    /* may need more options */
  16. Deliberate Syntax Error
  17. #endif                    /* PORT */
  18.  
  19. #if AMIGA || ATARI_ST || MACINTOSH
  20. static char *ostr = "CPD:I:U:o:";
  21. static char *options = 
  22.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  23.    /* may need more options */
  24. Deliberate Syntax Error
  25. #endif                    /* AMIGA || ATARI_ST || ... */
  26.  
  27. #if MSDOS
  28. #if MICROSOFT || INTEL_386 || HIGHC_386 || WATCOM
  29.    /* this really isn't right for anything but Microsoft */
  30. static char *ostr = "CPD:I:U:o:A:Z:J";
  31. static char *options = 
  32.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile]\n    \
  33. [-A(S|C|M|L|H)] [-Za] [-J] [files]";
  34. #endif                    /* MICROSOFT || INTEL_386 || ...  */
  35.  
  36. #if ZTC_386 
  37. static char *ostr = "CPD:I:U:o:m:AuJWf234";
  38. static char *options = 
  39.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath[;path...]] [-ofile]\n    \
  40. [-m(t|s|c|m|l|v|r|p|x|z)] [-A] [-u] [-J] [-W] [-f] [-(2|3|4)] [files]";
  41. #endif                    /* ZTC_386 */
  42.  
  43. #if TURBO || BORLAND_286 || BORLAND_386 
  44. static char *ostr = "CPD:I:U:o:m:p";
  45. static char *options = 
  46.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile]\n    \
  47. [-m(t|s|m|c|l|h)] [-p] [files]";
  48. #endif                    /* TURBO || BORLAND_286 ... */
  49. #endif                    /* MSDOS */
  50.  
  51. #if VM || MVS
  52. static char *ostr = "CPD:I:U:o:";
  53. static char *options =
  54.    "<-C> <-P> <-Dname<=<text>>> <-Uname> <-Ipath> <-ofile> <files>";
  55.    /* ??? may need more options */
  56. #endif                                  /* VM || MVS */
  57.  
  58. #if UNIX || VMS
  59. static char *ostr = "CPD:I:U:o:";
  60. static char *options = 
  61.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  62. #endif                    /* UNIX || VMS */
  63.  
  64. /*
  65.  * End of operating-system specific code.
  66.  */
  67.  
  68. extern line_cntrl;
  69.  
  70. /*
  71.  * getopt() variables
  72.  */
  73. extern int optindex;        /* index into parent argv vector */
  74. extern int optopt;        /* character checked for validity */
  75. extern char *optarg;        /* argument associated with option */
  76.  
  77. int main(argc, argv)
  78. int argc;
  79. char **argv;
  80.    {
  81.    int c;
  82.    char *opt_lst;
  83.    char **opt_args;
  84.    int nopts;
  85.    FILE *out_file;
  86.  
  87.    /*
  88.     * By default, keep the image of white space, but replace each comment
  89.     *  by a space. By default, output #line directives.
  90.     */
  91.    whsp_image = NoComment;
  92.    line_cntrl = 1;
  93.  
  94.    /*
  95.     * The number of options that must be passed on to other phases
  96.     *  of the preprocessor are at most as large as the entire option
  97.     *  list.
  98.     */
  99.    opt_lst = (char *)alloc((unsigned int)argc);
  100.    opt_args = (char **)alloc((unsigned int)((sizeof (char *)) * argc));
  101.    nopts = 0;
  102.    out_file = stdout;
  103.  
  104.    /*
  105.     * Process options.
  106.     */
  107.    while ((c = getopt(argc, argv, ostr)) != EOF)
  108.       switch (c) {
  109.          case 'C':  /* -C - retan comments */
  110.             whsp_image = FullImage;
  111.             break;
  112.           case 'P': /* -P - do not output #line directives */
  113.             line_cntrl = 0;
  114.             break;
  115.          case 'D': /* -D<id><definition> - predefine an identifier */
  116.          case 'I': /* -I<path> - location to search for standard header files */ 
  117.          case 'U': /* -U<id> - undefine predefined identifier */
  118.  
  119. /*
  120.  * The following code is operating-system dependent [@pmain.02]. Accept
  121.  *  system specific options.
  122.  */
  123.  
  124. #if PORT
  125.    /* may need something */
  126. Deliberate Syntax Error
  127. #endif                    /* PORT */
  128.  
  129. #if AMIGA || ATARI_ST || MACINTOSH
  130.    /* may need something */
  131. Deliberate Syntax Error
  132. #endif                    /* AMIGA || ATARI_ST || ... */
  133.  
  134. #if MSDOS
  135. #if MICROSOFT
  136.          case 'A':
  137.          case 'J':
  138.          case 'Z':
  139. #endif                    /* MICROSOFT */
  140.  
  141. #if ZTC_386
  142.          case 'm':
  143.          case 'A':
  144.          case 'u':
  145.          case 'J':
  146.          case 'W':
  147.          case 'f':
  148.          case '2':
  149.          case '3':
  150.          case '4':
  151. #endif                    /* ZTC_386 */
  152.  
  153. #if TURBO || BORLAND_286 || BORLAND_386 
  154.          case 'm':
  155.          case 'p':
  156. #endif                    /* TURBO || BORLAND_286 ... */
  157.  
  158. #if HIGHC_386 || INTEL_386 || WATCOM
  159.    /* something is needed */
  160. #endif                    /* HIGHC_386 || INTEL_386 || ... */
  161. #endif                    /* MSDOS */
  162.  
  163. #if MVS || VM
  164.    /* ??? we'll see */
  165. #endif                    /* MVS || VM */
  166.  
  167. #if UNIX || VMS
  168.    /* nothing is needed */
  169. #endif                    /* UNIX || VMS */
  170.  
  171. /*
  172.  * End of operating-system specific code.
  173.  */
  174.  
  175.             opt_lst[nopts] = c;
  176.             opt_args[nopts] = optarg;
  177.             ++nopts;
  178.             break;
  179.          case 'o': /* -o<file> - write output to this file */
  180.             out_file = fopen(optarg, "w");
  181.             if (out_file == NULL)
  182.                err2("cannot open output file ", optarg);
  183.             break;
  184.          default:
  185.             show_usage();
  186.          }
  187.  
  188.    opt_lst[nopts] = '\0';
  189.  
  190.    /*
  191.     * Scan file name arguments. If there are none, process standard input,
  192.     *  indicated by the name "-".
  193.     */
  194.    if (optindex == argc) {
  195.       init_preproc("-", opt_lst, opt_args);
  196.       output(out_file);
  197.       }
  198.    else {
  199.       while (optindex < argc)  {
  200.          init_preproc(argv[optindex], opt_lst, opt_args);
  201.          output(out_file);
  202.          optindex++;
  203.          }
  204.       }
  205.  
  206.    return NormalExit;
  207.    }
  208.  
  209. /*
  210.  * Print an error message if called incorrectly.
  211.  */
  212. novalue show_usage()
  213.    {
  214.    fprintf(stderr, "usage: %s %s\n", progname, options);
  215.    exit(ErrorExit);
  216.    }
  217.