Mercurial > hg > octave-lojdl
changeset 10195:b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 23 Jan 2010 12:42:48 -0500 |
parents | d4f813c3f5ed |
children | 69bb6e1e10d2 |
files | liboctave/ChangeLog liboctave/Makefile.am liboctave/oct-getopt.c liboctave/oct-getopt.h liboctave/prog-args.cc liboctave/prog-args.h src/ChangeLog src/octave.cc |
diffstat | 8 files changed, 67 insertions(+), 286 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,10 @@ +2010-01-23 John W. Eaton <jwe@octave.org> + + * Makefile.am (LIBOCTAVE_C_SOURCES): Remove oct-getopt.c from the list. + (LIBOCTAVE_CXX_SOURCES): Remove prog-args.c from the list. + (INCS): Remove prog-args.h and oct-getopt.h from the list. + * prog-args.cc, prog-args.h, oct-getopt.c, oct-getopt.h: Delete. + 2010-01-22 John W. Eaton <jwe@octave.org> * prog-args.h, prog-args.cc (prog_args::get_option,
--- a/liboctave/Makefile.am +++ b/liboctave/Makefile.am @@ -213,7 +213,6 @@ oct-cmplx.h \ oct-env.h \ oct-fftw.h \ - oct-getopt.h \ oct-group.h \ oct-inttypes.h \ oct-locbuf.h \ @@ -234,7 +233,6 @@ oct-uname.h \ pathlen.h \ pathsearch.h \ - prog-args.h \ randgamma.h \ randmtzig.h \ randpoisson.h \ @@ -437,7 +435,6 @@ oct-syscalls.cc \ oct-time.cc \ oct-uname.cc \ - prog-args.cc \ regex-match.cc \ sparse-sort.cc \ sparse-util.cc \ @@ -459,7 +456,6 @@ filemode.c \ lo-cieee.c \ lo-cutils.c \ - oct-getopt.c \ randgamma.c \ randmtzig.c \ randpoisson.c \
deleted file mode 100644 --- a/liboctave/oct-getopt.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - -Copyright (C) 2000, 2003, 2005, 2007 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "getopt.h" - -int -octave_getopt (int argc, char *const *argv, const char *optstring) -{ - return getopt (argc, argv, optstring); -} - -int -octave_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return getopt_long (argc, argv, options, long_options, opt_index); -}
deleted file mode 100644 --- a/liboctave/oct-getopt.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - -Copyright (C) 2000, 2005, 2007 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if !defined (octave_getopt_h) -#define octave_getopt_h 1 - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern int -octave_getopt (int, char *const *, const char *); - -extern int -octave_getopt_long (int, char *const *, const char *, - const struct option *, int *); - -extern char *optarg; - -extern int optind; - -#ifdef __cplusplus -} -#endif - -#endif
deleted file mode 100644 --- a/liboctave/prog-args.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - -Copyright (C) 1996, 1997, 1998, 2000, 2005, 2006, 2007 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "oct-getopt.h" - -#include "prog-args.h" - -int -prog_args::get_option (void) -{ - if (long_opts) - return ::octave_getopt_long - (xargc, xargv, short_opts, - reinterpret_cast<const struct option *> (long_opts), 0); - else - return ::octave_getopt (xargc, xargv, short_opts); -} - -const char * -prog_args::option_argument (void) -{ - return ::optarg; -} - -int -prog_args::option_index (void) -{ - return ::optind; -} - -// This is intended to communicate to getopt that it is supposed to -// start over on the next call, but it may not be portable. See the -// comments in getopt.c for more information. - -void -prog_args::init (void) -{ - ::optind = 0; -}
deleted file mode 100644 --- a/liboctave/prog-args.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - -Copyright (C) 1996, 1997, 2005, 2006, 2007 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if !defined (octave_prog_args_h) -#define octave_prog_args_h 1 - -struct -long_options -{ - const char *name; - int has_arg; - int *flag; - int val; -}; - -class -OCTAVE_API -prog_args -{ -public: - - // These values must match the corresponding defines in getopt.h. - enum option_argument - { - no_arg = 0, - required_arg = 1, - optional_arg = 2 - }; - - prog_args (int argc, char *const *argv, const char *s_opts, const - long_options* l_opts = 0) - : xargc (argc), xargv (argv), short_opts (s_opts), long_opts (l_opts) - { - init (); - } - - ~prog_args (void) { } - - int get_option (void); - - const char *option_argument (void); - - int option_index (void); - -private: - - // Number of args. - int xargc; - - // Program args. - char *const *xargv; - - // Single character options. - const char *short_opts; - - // Long options. - const long_options *long_opts; - - void init (void); - - prog_args (const prog_args&); - - prog_args& operator = (const prog_args&); -}; - -#endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-01-23 John W. Eaton <jwe@octave.org> + + * octave.cc (octave_main): Use getopt directly instead of using + the (mostly useless) prog_args wrapper class. + Include <getopt.h>, not "prog-args.h". + 2010-01-23 John W. Eaton <jwe@octave.org> * sighandlers.cc (user_abort): Also set debug_mode if Vdebugging.
--- a/src/octave.cc +++ b/src/octave.cc @@ -34,6 +34,8 @@ #include <iostream> +#include <getopt.h> + #include "cmd-edit.h" #include "f77-fcn.h" #include "file-ops.h" @@ -60,7 +62,6 @@ #include "toplev.h" #include "parse.h" #include "procstream.h" -#include "prog-args.h" #include "sighandlers.h" #include "sysdep.h" #include "ov.h" @@ -151,35 +152,35 @@ #define NO_WINDOW_SYSTEM_OPTION 12 #define PERSIST_OPTION 13 #define TRADITIONAL_OPTION 14 -long_options long_opts[] = +struct option long_opts[] = { - { "braindead", prog_args::no_arg, 0, TRADITIONAL_OPTION }, - { "debug", prog_args::no_arg, 0, 'd' }, - { "doc-cache-file", prog_args::required_arg, 0, DOC_CACHE_FILE_OPTION }, - { "echo-commands", prog_args::no_arg, 0, 'x' }, - { "eval", prog_args::required_arg, 0, EVAL_OPTION }, - { "exec-path", prog_args::required_arg, 0, EXEC_PATH_OPTION }, - { "help", prog_args::no_arg, 0, 'h' }, - { "image-path", prog_args::required_arg, 0, IMAGE_PATH_OPTION }, - { "info-file", prog_args::required_arg, 0, INFO_FILE_OPTION }, - { "info-program", prog_args::required_arg, 0, INFO_PROG_OPTION }, - { "interactive", prog_args::no_arg, 0, 'i' }, - { "line-editing", prog_args::no_arg, 0, LINE_EDITING_OPTION }, - { "no-history", prog_args::no_arg, 0, 'H' }, - { "no-init-file", prog_args::no_arg, 0, NO_INIT_FILE_OPTION }, - { "no-init-path", prog_args::no_arg, 0, NO_INIT_PATH_OPTION }, - { "no-line-editing", prog_args::no_arg, 0, NO_LINE_EDITING_OPTION }, - { "no-site-file", prog_args::no_arg, 0, NO_SITE_FILE_OPTION }, - { "no-window-system", prog_args::no_arg, 0, NO_WINDOW_SYSTEM_OPTION }, - { "norc", prog_args::no_arg, 0, 'f' }, - { "path", prog_args::required_arg, 0, 'p' }, - { "persist", prog_args::no_arg, 0, PERSIST_OPTION }, - { "quiet", prog_args::no_arg, 0, 'q' }, - { "silent", prog_args::no_arg, 0, 'q' }, - { "traditional", prog_args::no_arg, 0, TRADITIONAL_OPTION }, - { "verbose", prog_args::no_arg, 0, 'V' }, - { "version", prog_args::no_arg, 0, 'v' }, - { 0, 0, 0, 0 } + { "braindead", no_argument, 0, TRADITIONAL_OPTION }, + { "debug", no_argument, 0, 'd' }, + { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION }, + { "echo-commands", no_argument, 0, 'x' }, + { "eval", required_argument, 0, EVAL_OPTION }, + { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, + { "help", no_argument, 0, 'h' }, + { "image-path", required_argument, 0, IMAGE_PATH_OPTION }, + { "info-file", required_argument, 0, INFO_FILE_OPTION }, + { "info-program", required_argument, 0, INFO_PROG_OPTION }, + { "interactive", no_argument, 0, 'i' }, + { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, + { "no-history", no_argument, 0, 'H' }, + { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, + { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, + { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, + { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, + { "no-window-system", no_argument, 0, NO_WINDOW_SYSTEM_OPTION }, + { "norc", no_argument, 0, 'f' }, + { "path", required_argument, 0, 'p' }, + { "persist", no_argument, 0, PERSIST_OPTION }, + { "quiet", no_argument, 0, 'q' }, + { "silent", no_argument, 0, 'q' }, + { "traditional", no_argument, 0, TRADITIONAL_OPTION }, + { "verbose", no_argument, 0, 'V' }, + { "version", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } }; // Store the command-line options for later use. @@ -627,15 +628,19 @@ install_builtins (); - prog_args args (argc, argv, short_opts, long_opts); - bool forced_line_editing = false; bool read_history_file = true; - int optc; - while ((optc = args.get_option ()) != EOF) + while (true) { + int long_idx; + + int optc = getopt_long (argc, argv, short_opts, long_opts, &long_idx); + + if (optc < 0) + break; + switch (optc) { case 'H': @@ -667,8 +672,8 @@ break; case 'p': - if (args.option_argument ()) - load_path::set_command_line_path (args.option_argument ()); + if (optarg) + load_path::set_command_line_path (optarg); break; case 'q': @@ -687,38 +692,38 @@ break; case DOC_CACHE_FILE_OPTION: - if (args.option_argument ()) - bind_internal_variable ("doc_cache_file", args.option_argument ()); + if (optarg) + bind_internal_variable ("doc_cache_file", optarg); break; case EVAL_OPTION: - if (args.option_argument ()) + if (optarg) { if (code_to_eval.empty ()) - code_to_eval = args.option_argument (); + code_to_eval = optarg; else - code_to_eval += std::string (" ") + args.option_argument (); + code_to_eval += std::string (" ") + optarg; } break; case EXEC_PATH_OPTION: - if (args.option_argument ()) - set_exec_path (args.option_argument ()); + if (optarg) + set_exec_path (optarg); break; case IMAGE_PATH_OPTION: - if (args.option_argument ()) - set_image_path (args.option_argument ()); + if (optarg) + set_image_path (optarg); break; case INFO_FILE_OPTION: - if (args.option_argument ()) - bind_internal_variable ("info_file", args.option_argument ()); + if (optarg) + bind_internal_variable ("info_file", optarg); break; case INFO_PROG_OPTION: - if (args.option_argument ()) - bind_internal_variable ("info_program", args.option_argument ()); + if (optarg) + bind_internal_variable ("info_program", optarg); break; case LINE_EDITING_OPTION: @@ -817,7 +822,7 @@ // Additional arguments are taken as command line options for the // script. - int last_arg_idx = args.option_index (); + int last_arg_idx = optind; int remaining_args = argc - last_arg_idx;