home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 285_02 / getargs.c < prev    next >
Text File  |  1990-07-09  |  3KB  |  105 lines

  1. /* Parse command line arguments for bison,
  2.    Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  3.  
  4. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone
  6. for the consequences of using it or for whether it serves any
  7. particular purpose or works at all, unless he says so in writing.
  8. Refer to the BISON General Public License for full details.
  9.  
  10. Everyone is granted permission to copy, modify and redistribute BISON,
  11. but only under the conditions described in the BISON General Public
  12. License.  A copy of this license is supposed to have been given to you
  13. along with BISON so you can know your rights and responsibilities.  It
  14. should be in a file named COPYING.  Among other things, the copyright
  15. notice and this notice must be preserved on all copies.
  16.  
  17.  In other words, you are welcome to use, share and improve this program.
  18.  You are forbidden to forbid anyone else to use, share and improve
  19.  what you give them.   Help stamp out software-hoarding!  */
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "files.h"
  24. #include "bison.h"
  25. #include "getopt.h"
  26. #include "getargs.h"
  27.  
  28. int verboseflag;
  29. int definesflag;
  30. int debugflag;
  31. int nolinesflag;
  32. extern int fixed_outfiles; /* JF */
  33.  
  34.  
  35. void getargs(argc, argv)
  36. int argc;
  37. char *argv[];
  38. {
  39.   register int c;
  40.   char *p = argv[0];
  41.   char *lastcomponent;
  42.  
  43.   extern int optind;
  44.   extern char *optarg;
  45.  
  46.   verboseflag = 0;
  47.   definesflag = 0;
  48.   debugflag = 0;
  49.   fixed_outfiles = 0;
  50.   spec_outfile = "" ;
  51.  
  52.   /* See if the program was invoked as "yacc".  */
  53.  
  54.   lastcomponent = p;
  55.   while (*p)
  56.     {
  57.       if (*p == '/')
  58.     lastcomponent = p + 1;
  59.       p++;
  60.     }
  61.   if (! strcmp (lastcomponent, "yacc"))
  62.     /* If so, pretend we have "-y" as argument.  */
  63.     fixed_outfiles = 1;
  64.  
  65.   while ((c = getopt (argc, argv, "yvdlto:")) != EOF)
  66.     switch (c)
  67.       {
  68.       case 'y':
  69.     fixed_outfiles = 1;
  70.     break;
  71.  
  72.       case 'v':
  73.     verboseflag = 1;
  74.     break;
  75.  
  76.       case 'd':
  77.     definesflag = 1;
  78.     break;
  79.  
  80.       case 'l':
  81.     nolinesflag = 1;
  82.     break;
  83.  
  84.       case 't':
  85.     debugflag = 1;
  86.     break;
  87.  
  88.       case 'o':
  89.     spec_outfile = optarg;
  90.     break ;
  91.  
  92.       default:
  93.     break ;
  94.       }
  95.  
  96.   if (optind == argc)
  97.     fatal("grammar file not specified");
  98.   else
  99.     infile = argv[optind];
  100.  
  101.   if (optind < argc - 1)
  102.     fprintf(stderr, "bison: warning: extra arguments ignored\n");
  103. }
  104.  
  105.