home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnubison.zip / getargs.c < prev    next >
C/C++ Source or Header  |  1996-06-20  |  4KB  |  177 lines

  1. /* Parse command line arguments for bison,
  2.    Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "getopt.h"
  23. #include "system.h"
  24. #include "files.h"
  25.  
  26. int verboseflag;
  27. int definesflag;
  28. int debugflag;
  29. int nolinesflag;
  30. int noparserflag = 0;
  31. int toknumflag = 0;
  32. int rawtoknumflag = 0;
  33. char *spec_name_prefix; /* for -p.  */
  34. char *spec_file_prefix; /* for -b. */
  35. extern int fixed_outfiles;/* for -y */
  36.   
  37. extern char *program_name;
  38. extern char *version_string;
  39.  
  40. extern void warns();    /* main.c */
  41.  
  42. struct option longopts[] =
  43. {
  44.   {"debug", 0, &debugflag, 1},
  45.   {"defines", 0, &definesflag, 1},
  46.   {"file-prefix", 1, 0, 'b'},
  47.   {"fixed-output-files", 0, &fixed_outfiles, 1},
  48.   {"help", 0, 0, 'h'},
  49.   {"name-prefix", 1, 0, 'p'}, /* was 'a';  apparently unused -wjh */
  50.   {"no-lines", 0, &nolinesflag, 1},
  51.   {"no-parser", 0, &noparserflag, 1},
  52.   {"output", 1, 0, 'o'},
  53.   {"output-file", 1, 0, 'o'},
  54.   {"raw", 0, &rawtoknumflag, 1},
  55.   {"token-table", 0, &toknumflag, 1},
  56.   {"verbose", 0, &verboseflag, 1},
  57.   {"version", 0, 0, 'V'},
  58.   {"yacc", 0, &fixed_outfiles, 1},
  59.   {0, 0, 0, 0}
  60. };
  61.  
  62. void
  63. usage (stream)
  64.      FILE *stream;
  65. {
  66.   extern char *version_string;
  67.   fprintf (stream, "\n%s\n", version_string);
  68.   fprintf (stream, "\
  69. Usage: %s [-dhklntvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
  70.        [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
  71.        [--verbose] [--version] [--help] [--yacc]\n\
  72.        [--no-parser] [--token-table]\n\
  73.        [--file-prefix=prefix] [--name-prefix=prefix]\n\
  74.        [--output=outfile] grammar-file\n",
  75.        program_name);
  76. }
  77.  
  78. void
  79. getargs(argc, argv)
  80.      int argc;
  81.      char *argv[];
  82. {
  83.   register int c;
  84.  
  85.   verboseflag = 0;
  86.   definesflag = 0;
  87.   debugflag = 0;
  88.   noparserflag = 0;
  89.   rawtoknumflag = 0;
  90.   toknumflag = 0;
  91.   fixed_outfiles = 0;
  92.  
  93.   if ( argc == 1 )
  94.   {
  95.     usage(stdout);
  96.     exit(0);
  97.   }
  98.  
  99.   while ((c = getopt_long (argc, argv, "yvdhrltknVo:b:p:", longopts, (int *)0))
  100.      != EOF)
  101.     {
  102.       switch (c)
  103.     {
  104.     case 0:
  105.       /* Certain long options cause getopt_long to return 0.  */
  106.       break;
  107.  
  108.     case 'y':
  109.       fixed_outfiles = 1;
  110.       break;
  111.       
  112.     case 'h':
  113.       usage (stdout);
  114.       exit (0);
  115.  
  116.     case 'V':
  117.       printf ("\n%s", version_string);
  118.       exit (0);
  119.       
  120.     case 'v':
  121.       verboseflag = 1;
  122.       break;
  123.       
  124.     case 'd':
  125.       definesflag = 1;
  126.       break;
  127.       
  128.     case 'l':
  129.       nolinesflag = 1;
  130.       break;
  131.       
  132.     case 'k':
  133.       toknumflag = 1;
  134.       break;
  135.  
  136.     case 'r':
  137.       rawtoknumflag = 1;
  138.       break;
  139.       
  140.     case 'n':
  141.       noparserflag = 1;
  142.       break;
  143.       
  144.     case 't':
  145.       debugflag = 1;
  146.       break;
  147.       
  148.     case 'o':
  149.       spec_outfile = optarg;
  150.       break;
  151.       
  152.     case 'b':
  153.       spec_file_prefix = optarg;
  154.       break;
  155.       
  156.     case 'p':
  157.       spec_name_prefix = optarg;
  158.       break;
  159.       
  160.     default:
  161.       usage (stderr);
  162.       exit (1);
  163.     }
  164.     }
  165.  
  166.   if (optind == argc)
  167.     {
  168.       fprintf(stderr, "%s: no grammar file given\n", program_name);
  169.       exit(1);
  170.     }
  171.   if (optind < argc - 1)
  172.     fprintf(stderr, "%s: extra arguments ignored after '%s'\n", 
  173.         program_name, argv[optind]);
  174.  
  175.   infile = argv[optind];
  176. }
  177.