From e2aaf4c4f98afe4b15ea297d8b0b2b0e210f6fc4 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 27 Jun 2002 12:19:20 +0000 Subject: [PATCH] * src/options.h, src/options.c: Remove. * src/getargs.c (short_options, long_options): New. --- ChangeLog | 5 ++ src/Makefile.am | 1 - src/getargs.c | 61 +++++++++++++++++-- src/options.c | 152 ------------------------------------------------ src/options.h | 61 ------------------- src/reader.c | 1 - 6 files changed, 61 insertions(+), 220 deletions(-) delete mode 100644 src/options.c delete mode 100644 src/options.h diff --git a/ChangeLog b/ChangeLog index f38f8b9d..d3536bd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-06-27 Akim Demaille + + * src/options.h, src/options.c: Remove. + * src/getargs.c (short_options, long_options): New. + 2002-06-27 Akim Demaille * data/bison.simple, data/bison.c++: Rename as... diff --git a/src/Makefile.am b/src/Makefile.am index c7100589..fabfdf0a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,7 +49,6 @@ bison_SOURCES = \ main.c \ muscle_tab.c muscle_tab.h \ nullable.c nullable.h \ - options.c options.h \ output.c output.h \ parse-gram.h parse-gram.y \ print.c print.h \ diff --git a/src/getargs.c b/src/getargs.c index 5789152a..0cec1a03 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -24,7 +24,6 @@ #include "argmatch.h" #include "complain.h" #include "getargs.h" -#include "options.h" #include "files.h" int debug_flag = 0; @@ -186,6 +185,61 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ | Process the options. | `----------------------*/ +/* Shorts options. */ +const char *short_options = "yvegdhr:ltknVo:b:p:S:"; + +static struct option const long_options[] = +{ + /* Operation modes. */ + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'V' }, + + /* Parser. */ + { "name-prefix", required_argument, 0, 'p' }, + { "include", required_argument, 0, 'I' }, + + /* Output. */ + { "file-prefix", required_argument, 0, 'b' }, + { "output", required_argument, 0, 'o' }, + { "output-file", required_argument, 0, 'o' }, + { "graph", optional_argument, 0, 'g' }, + { "report", required_argument, 0, 'r' }, + { "verbose", no_argument, 0, 'v' }, + + /* Hidden. */ + { "trace", no_argument, &trace_flag, 1 }, + + /* FIXME: semantic parsers will output an `include' of an + output file: be sure that the naem included is indeed the name of + the output file. */ /* FIXME Should we activate this options ? + */ + { "output", required_argument, 0, 'o' }, + { "file-prefix", required_argument, 0, 'b' }, + { "name-prefix", required_argument, 0, 'p' }, + + /* + * Percent and command line declarations. + */ + + /* Output. */ + { "defines", optional_argument, 0, 'd' }, + + /* Operation modes. */ + { "fixed-output-files", no_argument, 0, 'y' }, + { "yacc", no_argument, 0, 'y' }, + + /* Parser. */ + { "debug", no_argument, 0, 't' }, + { "locations", no_argument, &locations_flag, 1 }, + { "no-lines", no_argument, 0, 'l' }, + { "no-parser", no_argument, 0, 'n' }, + { "raw", no_argument, 0, 0 }, + { "skeleton", required_argument, 0, 'S' }, + { "token-table", no_argument, 0, 'k' }, + + {0, 0, 0, 0} +}; + /* Under DOS, there is no difference on the case. This can be troublesome when looking for `.tab' etc. */ #ifdef MSDOS @@ -199,8 +253,7 @@ getargs (int argc, char *argv[]) { int c; - struct option *longopts = long_option_table_new (); - while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != EOF) + while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != EOF) switch (c) { case 0: @@ -282,8 +335,6 @@ getargs (int argc, char *argv[]) exit (1); } - free (longopts); - if (optind == argc) { fprintf (stderr, _("%s: no grammar file given\n"), program_name); diff --git a/src/options.c b/src/options.c deleted file mode 100644 index f8f5301e..00000000 --- a/src/options.c +++ /dev/null @@ -1,152 +0,0 @@ -/* Concentrate all options use in bison, - Copyright 2001, 2002 Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include "system.h" -#include "getopt.h" -#include "files.h" -#include "getargs.h" -#include "symtab.h" -#include "gram.h" -#include "output.h" -#include "options.h" - -/* Shorts options. */ -const char *shortopts = "yvegdhr:ltknVo:b:p:S:"; - -/* A CLI option only. - Arguments is the policy: `no', `optional', `required'. - OptionChar is the value given to the Var if the latter is specified. */ -#undef OPTN -#define OPTN(OptionString, Arguments, Var, Token, OptionChar) \ - { opt_cmd_line, \ - (OptionString), (Arguments##_argument), (Var), (Token), (OptionChar) }, - -/* A directive only. */ -#undef DRTV -#define DRTV(DirectiveString, Arguments, Var, Token) \ - { opt_percent, \ - (DirectiveString), (Arguments##_argument), (Var), (Token), (0) }, - -/* An option activated both by a directive and an CLI option. */ -#undef BOTH -#define BOTH(String, Arguments, Var, Token, OptionChar) \ - { opt_both, \ - (String), (Arguments##_argument), (Var), (Token), (OptionChar) }, - - -const struct option_table_s option_table[] = -{ - /* - * Command line. - */ - - /* Operation modes. */ - OPTN ("help", no, 0, 0, 'h') - OPTN ("version", no, 0, 0, 'V') - - /* Parser. */ - OPTN ("name-prefix", required, 0, 0, 'p') - OPTN ("include", required, 0, 0, 'I') - - /* Output. */ - OPTN ("file-prefix", required, 0, 0, 'b') - OPTN ("output", required, 0, 0, 'o') - OPTN ("output-file", required, 0, 0, 'o') - OPTN ("graph", optional, 0, 0, 'g') - OPTN ("report", required, 0, 0, 'r') - OPTN ("verbose", no, 0, 0, 'v') - - /* Hidden. */ - OPTN ("trace", no, &trace_flag, 0, 1) - - /* FIXME: semantic parsers will output an `include' of an - output file: be sure that the naem included is indeed the name of - the output file. */ /* FIXME Should we activate this options ? - */ - OPTN ("output", required, &spec_outfile, 0, 'o') - OPTN ("file-prefix", required, &spec_file_prefix, 0, 'b') - OPTN ("name-prefix", required, &spec_name_prefix, 0, 'p') - - /* - * Percent and command line declarations. - */ - - /* Output. */ - OPTN ("defines", optional, &defines_flag, 0, 'd') - - /* Operation modes. */ - OPTN ("fixed-output-files", no, &yacc_flag, 0, 'y') - OPTN ("yacc", no, &yacc_flag, 0, 'y') - - /* Parser. */ - OPTN ("debug", no, &debug_flag, 0, 't') - OPTN ("locations", no, &locations_flag, 0, 1) - OPTN ("no-lines", no, &no_lines_flag, 0, 'l') - OPTN ("no-parser", no, &no_parser_flag, 0, 'n') - OPTN ("raw", no, 0, 0, 0) - OPTN ("skeleton", required, 0, 0, 'S') - OPTN ("token-table", no, &token_table_flag, 0, 'k') - - {0, 0, 0, 0, 0, 0} -}; - - -/*--------------------------------------------------------. -| Create the longoptions structure from the option_table, | -| for the getopt file. | -`--------------------------------------------------------*/ - -struct option * -long_option_table_new () -{ - struct option *res = NULL; - int i = 0; - int j = 0; - int number_options; - - for (number_options = 0; option_table[i].name; i++) - if (option_table[i].access == opt_cmd_line - || option_table[i].access == opt_both) - ++number_options; - - res = XMALLOC (struct option, number_options + 1); - for (i = 0; option_table[i].name; i++) - if (option_table[i].access == opt_cmd_line - || option_table[i].access == opt_both) - { - res[j].name = option_table[i].name; - res[j].has_arg = option_table[i].has_arg; - /* When a getopt_long option has an associated variable - (member FLAG), then it is set of the VAL member value. In - other words, we cannot expect getopt_long to store the - argument if we also want a short option. */ - if (res[j].has_arg == optional_argument) - res[j].flag = NULL; - else - res[j].flag = option_table[i].flag; - res[j++].val = option_table[i].val; - } - res[number_options].name = NULL; - res[number_options].has_arg = 0; - res[number_options].flag = NULL; - res[number_options].val = 0; - - return res; -} diff --git a/src/options.h b/src/options.h deleted file mode 100644 index b4beb43c..00000000 --- a/src/options.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Concentrate all options use in bison, - Copyright 2001, 2002 Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef OPTIONS_H_ -# define OPTIONS_H_ - -/* opt_access_t and struct option_table_struct need to be declare - here, for the parse_percent_token function in lex.c. */ - -/* Option accessibility. */ -typedef enum opt_access_e -{ - opt_cmd_line = 1, - opt_percent, - opt_both -} opt_access_t; - -/* This is the general struct, which contains user's options from - command line or in grammar with percent flag. */ -struct option_table_s -{ - /* Set the accessibility. */ - opt_access_t access; - /* This name is used for long option et percent directives. */ - const char *name; - /* Use for command line. */ - int has_arg; - /* An optional lvalue to be set. */ - void *flag; - /* A retval action returns the code. */ - int ret_val; - /* The short option value, frequently a letter. */ - int val; -}; - -extern const char *shortopts; - -/* Table which contain all options. */ -extern const struct option_table_s option_table[]; - -/* Return a malloc'd list of the options for getopt_long. */ -struct option *long_option_table_new PARAMS ((void)); - -#endif /* !OPTIONS_H_ */ diff --git a/src/reader.c b/src/reader.c index b80adfd6..c0702eb0 100644 --- a/src/reader.c +++ b/src/reader.c @@ -27,7 +27,6 @@ #include "files.h" #include "symtab.h" #include "symlist.h" -#include "options.h" #include "gram.h" #include "complain.h" #include "output.h" -- 2.45.2