home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Bison.sit.hqx / Bison / Source / getargs.c < prev    next >
Text File  |  1992-08-21  |  3KB  |  142 lines

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