olena-2.0-68-g3a65b8d Improve option parser.

* scribo/debug/option_check.hh: New function for verbose mode. * scribo/debug/option_parser.hh: Fix a bug with misplaced options. --- scribo/ChangeLog | 8 ++++++++ scribo/scribo/debug/option_check.hh | 19 ++++++++++++++++++- scribo/scribo/debug/option_parser.hh | 19 ++++++++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 6a68f43..f8d7491 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,13 @@ 2012-05-10 Guillaume Lazzara <z@lrde.epita.fr> + Improve option parser. + + * scribo/debug/option_check.hh: New function for verbose mode. + + * scribo/debug/option_parser.hh: Fix a bug with misplaced options. + +2012-05-10 Guillaume Lazzara <z@lrde.epita.fr> + Add Readme files about contests. * src/contest/DAE-2011/README, diff --git a/scribo/scribo/debug/option_check.hh b/scribo/scribo/debug/option_check.hh index 4a0acd1..11cceb1 100644 --- a/scribo/scribo/debug/option_check.hh +++ b/scribo/scribo/debug/option_check.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011, 2012 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -31,6 +32,7 @@ # include <vector> # include <iostream> # include <mln/core/contract.hh> +# include <scribo/debug/logger.hh> namespace scribo { @@ -42,6 +44,7 @@ namespace scribo bool check_ocr_lang(const std::vector<const char *>& args); bool check_sauvola_first_subsampling(const std::vector<const char *>& args); bool check_sauvola_split_ntrue(const std::vector<const char *>& args); + bool check_verbose_mode(const std::vector<const char *>& args); # ifndef MLN_INCLUDE_ONLY @@ -121,6 +124,20 @@ namespace scribo } + inline + bool check_verbose_mode(const std::vector<const char *>& args) + { + mln_assertion(args.size() == 1); + + if (logger().set_verbose_mode(txt_to_verbose_mode(args[0]))) + return true; + + std::cerr << "Error: Invalid verbose mode " << args[0] << std::endl; + + return false; + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::debug diff --git a/scribo/scribo/debug/option_parser.hh b/scribo/scribo/debug/option_parser.hh index 9795a78..c956064 100644 --- a/scribo/scribo/debug/option_parser.hh +++ b/scribo/scribo/debug/option_parser.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011, 2012 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -290,8 +291,17 @@ namespace scribo // I/O parameters default: - args_[arg_desc_[nrequired_argc].name] = argv[0]; - ++nrequired_argc; + if (nrequired_argc == required_argc_) + { + std::cerr << "Error: wrong number of arguments! \"" + << argv[0] << "\" was not expected!" << std::endl; + no_error = false; + } + else + { + args_[arg_desc_[nrequired_argc].name] = argv[0]; + ++nrequired_argc; + } ++argv; break; } @@ -301,8 +311,7 @@ namespace scribo { if (nrequired_argc) std::cerr << "Error: wrong number of arguments!" << std::endl; - print_help(); - return false; + no_error = false; } if (! no_error) -- 1.7.2.5
participants (1)
-
Guillaume Lazzara