GETARGS.C 3.0 KB

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