getargs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 char *program_name;
  27. extern char *version_string;
  28. extern void fatal();
  29. struct option longopts[] =
  30. {
  31. {"debug", 0, &debugflag, 1},
  32. {"defines", 0, &definesflag, 1},
  33. {"file-prefix", 1, 0, 'b'},
  34. {"fixed-output-files", 0, &fixed_outfiles, 1},
  35. {"help", 0, 0, 'h'},
  36. {"name-prefix", 1, 0, 'a'},
  37. {"no-lines", 0, &nolinesflag, 1},
  38. {"output", 1, 0, 'o'},
  39. {"output-file", 1, 0, 'o'},
  40. {"verbose", 0, &verboseflag, 1},
  41. {"version", 0, 0, 'V'},
  42. {"yacc", 0, &fixed_outfiles, 1},
  43. {0, 0, 0, 0}
  44. };
  45. void
  46. usage (stream)
  47. FILE *stream;
  48. {
  49. fprintf (stream, "\
  50. Usage: %s [-dhltvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
  51. [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
  52. [--verbose] [--version] [--help] [--yacc]\n\
  53. [--file-prefix=prefix] [--name-prefix=prefix]\n\
  54. [--output=outfile] grammar-file\n",
  55. program_name);
  56. }
  57. void
  58. getargs(argc, argv)
  59. int argc;
  60. char *argv[];
  61. {
  62. register int c;
  63. verboseflag = 0;
  64. definesflag = 0;
  65. debugflag = 0;
  66. fixed_outfiles = 0;
  67. while ((c = getopt_long (argc, argv, "yvdhltVo:b:p:", longopts, (int *)0))
  68. != EOF)
  69. {
  70. switch (c)
  71. {
  72. case 0:
  73. /* Certain long options cause getopt_long to return 0. */
  74. break;
  75. case 'y':
  76. fixed_outfiles = 1;
  77. break;
  78. case 'h':
  79. usage (stdout);
  80. exit (0);
  81. case 'V':
  82. printf ("%s", version_string);
  83. exit (0);
  84. case 'v':
  85. verboseflag = 1;
  86. break;
  87. case 'd':
  88. definesflag = 1;
  89. break;
  90. case 'l':
  91. nolinesflag = 1;
  92. break;
  93. case 't':
  94. debugflag = 1;
  95. break;
  96. case 'o':
  97. spec_outfile = optarg;
  98. break;
  99. case 'b':
  100. spec_file_prefix = optarg;
  101. break;
  102. case 'p':
  103. spec_name_prefix = optarg;
  104. break;
  105. default:
  106. usage (stderr);
  107. exit (1);
  108. }
  109. }
  110. if (optind == argc)
  111. {
  112. fprintf(stderr, "%s: no grammar file given\n", program_name);
  113. exit(1);
  114. }
  115. if (optind < argc - 1)
  116. fprintf(stderr, "%s: warning: extra arguments ignored\n", program_name);
  117. infile = argv[optind];
  118. }