home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / preproc / pmain.c < prev    next >
C/C++ Source or Header  |  2002-01-18  |  5KB  |  206 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 || 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 || ... */
  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 UNIX || VMS
  52. static char *ostr = "+CPD:I:U:o:";
  53. static char *options =
  54.    "[-C] [-P] [-Dname[=[text]]] [-Uname] [-Ipath] [-ofile] [files]";
  55. #endif                    /* UNIX || VMS */
  56.  
  57. /*
  58.  * End of operating-system specific code.
  59.  */
  60.  
  61. extern line_cntrl;
  62.  
  63. /*
  64.  * getopt() variables
  65.  */
  66. extern int optind;        /* index into parent argv vector */
  67. extern int optopt;        /* character checked for validity */
  68. extern char *optarg;        /* argument associated with option */
  69.  
  70. int main(argc, argv)
  71. int argc;
  72. char **argv;
  73.    {
  74.    int c;
  75.    char *opt_lst;
  76.    char **opt_args;
  77.    int nopts;
  78.    FILE *out_file;
  79.  
  80.    /*
  81.     * By default, keep the image of white space, but replace each comment
  82.     *  by a space. By default, output #line directives.
  83.     */
  84.    whsp_image = NoComment;
  85.    line_cntrl = 1;
  86.  
  87.    /*
  88.     * The number of options that must be passed on to other phases
  89.     *  of the preprocessor are at most as large as the entire option
  90.     *  list.
  91.     */
  92.    opt_lst = alloc(argc);
  93.    opt_args = alloc(argc * sizeof (char *));
  94.    nopts = 0;
  95.    out_file = stdout;
  96.  
  97.    /*
  98.     * Process options.
  99.     */
  100.    while ((c = getopt(argc, argv, ostr)) != EOF)
  101.       switch (c) {
  102.          case 'C':  /* -C - retan comments */
  103.             whsp_image = FullImage;
  104.             break;
  105.           case 'P': /* -P - do not output #line directives */
  106.             line_cntrl = 0;
  107.             break;
  108.          case 'D': /* -D<id><definition> - predefine an identifier */
  109.          case 'I': /* -I<path> - location to search for standard header files */
  110.          case 'U': /* -U<id> - undefine predefined identifier */
  111.  
  112. /*
  113.  * The following code is operating-system dependent [@pmain.02]. Accept
  114.  *  system specific options.
  115.  */
  116.  
  117. #if PORT
  118.    /* may need something */
  119. Deliberate Syntax Error
  120. #endif                    /* PORT */
  121.  
  122. #if AMIGA || MACINTOSH
  123.    /* may need something */
  124. Deliberate Syntax Error
  125. #endif                    /* AMIGA || ... */
  126.  
  127. #if MSDOS
  128. #if MICROSOFT
  129.          case 'A':
  130.          case 'J':
  131.          case 'Z':
  132. #endif                    /* MICROSOFT */
  133.  
  134. #if ZTC_386
  135.          case 'm':
  136.          case 'A':
  137.          case 'u':
  138.          case 'J':
  139.          case 'W':
  140.          case 'f':
  141.          case '2':
  142.          case '3':
  143.          case '4':
  144. #endif                    /* ZTC_386 */
  145.  
  146. #if TURBO || BORLAND_286 || BORLAND_386
  147.          case 'm':
  148.          case 'p':
  149. #endif                    /* TURBO || BORLAND_286 ... */
  150.  
  151. #if HIGHC_386 || INTEL_386 || WATCOM
  152.    /* something is needed */
  153. #endif                    /* HIGHC_386 || INTEL_386 || ... */
  154. #endif                    /* MSDOS */
  155.  
  156. #if UNIX || VMS
  157.    /* nothing is needed */
  158. #endif                    /* UNIX || VMS */
  159.  
  160. /*
  161.  * End of operating-system specific code.
  162.  */
  163.  
  164.             opt_lst[nopts] = c;
  165.             opt_args[nopts] = optarg;
  166.             ++nopts;
  167.             break;
  168.          case 'o': /* -o<file> - write output to this file */
  169.             out_file = fopen(optarg, "w");
  170.             if (out_file == NULL)
  171.                err2("cannot open output file ", optarg);
  172.             break;
  173.          default:
  174.             show_usage();
  175.          }
  176.  
  177.    opt_lst[nopts] = '\0';
  178.  
  179.    /*
  180.     * Scan file name arguments. If there are none, process standard input,
  181.     *  indicated by the name "-".
  182.     */
  183.    if (optind == argc) {
  184.       init_preproc("-", opt_lst, opt_args);
  185.       output(out_file);
  186.       }
  187.    else {
  188.       while (optind < argc)  {
  189.          init_preproc(argv[optind], opt_lst, opt_args);
  190.          output(out_file);
  191.          optind++;
  192.          }
  193.       }
  194.  
  195.    return EXIT_SUCCESS;
  196.    }
  197.  
  198. /*
  199.  * Print an error message if called incorrectly.
  200.  */
  201. void show_usage()
  202.    {
  203.    fprintf(stderr, "usage: %s %s\n", progname, options);
  204.    exit(EXIT_FAILURE);
  205.    }
  206.