home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / bison / getargs.c < prev    next >
C/C++ Source or Header  |  1990-07-01  |  4KB  |  155 lines

  1. /* Parse command line arguments for bison,
  2.    Copyright (C) 1984, 1986, 1989 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 1, 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 "system.h"
  23. #include "files.h"
  24.  
  25. int verboseflag;
  26. int definesflag;
  27. int debugflag;
  28. int nolinesflag;
  29. char *spec_name_prefix; /* For -a.  */
  30. char *spec_file_prefix; /* -b */
  31. extern int fixed_outfiles;/* JF */
  32. extern char *version_string;
  33.  
  34. extern int getopt();
  35. extern void fatal();
  36.  
  37. void
  38. getargs(argc, argv)
  39. int argc;
  40. char *argv[];
  41. {
  42.   register int c;
  43.   char *p = argv[0];
  44.   char *lastcomponent;
  45.  
  46.   extern int optind;
  47.   extern char *optarg;
  48.  
  49.   verboseflag = 0;
  50.   definesflag = 0;
  51.   debugflag = 0;
  52.   fixed_outfiles = 0;
  53.  
  54. #if 0 /* Let's avoid dependence on what name invoked with.
  55.      The file `yacc' can be a shell script that runs `bison -y'.  */
  56.   /* See if the program was invoked as "yacc".  */
  57.  
  58.   lastcomponent = p;
  59.   while (*p)
  60.     {
  61.       if (*p == '/')
  62.     lastcomponent = p + 1;
  63.       p++;
  64.     }
  65.   if (! strcmp (lastcomponent, "yacc"))
  66.     /* If so, pretend we have "-y" as argument.  */
  67.     fixed_outfiles = 1;
  68. #endif
  69.  
  70.   if ( argc == 1 )
  71.     usage(argv[0]);
  72.  
  73.   while ((c = getopt (argc, argv, "yvdlto:b:a:")) != EOF)
  74.     switch (c)
  75.       {
  76.       case 'y':
  77.     fixed_outfiles = 1;
  78.     break;
  79.  
  80.       case 'v':
  81.         if(optind && argv[optind] && !strcmp(argv[optind],"-version")) {
  82.  
  83.           printf("\n%s",version_string);
  84.       while(getopt(argc,argv,"ersion")!='n')
  85.        ;
  86.     } else
  87.       verboseflag = 1;
  88.     break;
  89.  
  90.       case 'd':
  91.     definesflag = 1;
  92.     break;
  93.  
  94.       case 'l':
  95.     nolinesflag = 1;
  96.     break;
  97.  
  98.       case 't':
  99.     debugflag = 1;
  100.     break;
  101.  
  102.       case 'o':
  103.     spec_outfile = optarg;
  104.     break;
  105.  
  106.       case 'b':
  107.     spec_file_prefix = optarg;
  108.     break;
  109.  
  110.       case 'a':
  111.     spec_name_prefix = optarg;
  112.     break;
  113.       }
  114.  
  115.   if (optind == argc)
  116.     fatal("grammar file not specified");
  117.   else
  118.     infile = argv[optind];
  119.  
  120.   if (optind < argc - 1)
  121.     fprintf(stderr, "bison: warning: extra arguments ignored\n");
  122. }
  123.  
  124.  
  125. usage(name)
  126. char *name;
  127. {
  128.   printf("\n%s", version_string);
  129.  
  130.   printf("\nUsage: %s [-dltvy] [-o file] file\n", name);
  131.  
  132.   printf("\n  -d       Produce a .tab.h file, similar to yacc's y.tab.h file."
  133.  
  134.          "\n  -l       Omit #line lines in the parser output file. Error mes-"
  135.          "\n           sages from the C compiler will then be associated with"
  136.          "\n           lines in the parser output file, instead of lines in"
  137.          "\n           the original grammar file.");
  138.  
  139.   printf("\n  -t       Turn on debugging. This option causes the bison output"
  140.          "\n           to have debugging code made available via the C pre-"
  141.          "\n           processor.  The external variable yydebug should be"
  142.          "\n           made non-zero to have the debugging code actually pro-"
  143.          "\n           duce output.");
  144.  
  145.   printf("\n  -v       Be verbose. Analogous to the same flag for yacc."
  146.  
  147.          "\n  -y       Use fixed output file names. I.e., force the output to"
  148.          "\n           be in files y.tab.c, y.tab.h, and so on. This is for"
  149.          "\n           full yacc compatibility."
  150.  
  151.          "\n  -o file  Define special output file name.\n");
  152.  
  153.   exit(1);
  154. }
  155.