@@ -10,9 +10,7 @@ static map<std::string, bool> PARSE_REQUIRED{};
1010static map<std::string, bool > PARSE_HAVE{};
1111static string BIN_DIR{};
1212static string BIN_NAME{};
13- static int ARGC = 0 ;
1413static size_t SKIPPED_ARGS = 0 ;
15- static const char * const * ARGV = nullptr ;
1614static int CUR_ARG = 0 ;
1715ArgumentParser* PARSER{nullptr };
1816void ArgumentParser::mark_parsed (const char * arg) { PARSE_HAVE.emplace (arg, true ); }
@@ -79,11 +77,11 @@ void register_index(T& index, string v, string help, bool required)
7977}
8078string ArgumentParser::get_args ()
8179{
82- std::string args (ARGV [0 ]);
83- for (auto i = 1 ; i < ARGC ; ++i)
80+ std::string args (argv_ [0 ]);
81+ for (auto i = 1 ; i < argc_ ; ++i)
8482 {
8583 args.append (" " );
86- args.append (ARGV [i]);
84+ args.append (argv_ [i]);
8785 }
8886 return args;
8987}
@@ -142,8 +140,8 @@ void ArgumentParser::show_help_and_exit()
142140const char * ArgumentParser::get_arg () noexcept
143141{
144142 // check if we don't have any more arguments
145- fs::logging::check_fatal (CUR_ARG + 1 >= ARGC , " Missing argument to --%s" , ARGV [CUR_ARG]);
146- return ARGV [++CUR_ARG];
143+ fs::logging::check_fatal (CUR_ARG + 1 >= argc_ , " Missing argument to --%s" , argv_ [CUR_ARG]);
144+ return argv_ [++CUR_ARG];
147145}
148146size_t parse_size_t ()
149147{
@@ -184,16 +182,14 @@ ArgumentParser::ArgumentParser(
184182 const char * const argv[],
185183 const PositionalArgumentsRequired require_positional
186184)
187- : require_positional_{require_positional}
185+ : require_positional_{require_positional}, argc_{argc}, argv_{argv}
188186{
189187 logging::check_fatal (nullptr != PARSER, " Parser initialized multiple times" );
190188 PARSER = this ;
191189 add_usages (usages);
192190 fs::show_debug_settings ();
193- ARGC = argc;
194- ARGV = argv;
195191 assert (0 == CUR_ARG);
196- auto bin = string (ARGV [CUR_ARG++]);
192+ auto bin = string (argv_ [CUR_ARG++]);
197193 replace (bin.begin (), bin.end (), ' \\ ' , ' /' );
198194 const auto end = max (static_cast <size_t >(0 ), bin.rfind (' /' ) + 1 );
199195 BIN_DIR = bin.substr (0 , end);
@@ -207,9 +203,9 @@ ArgumentParser::ArgumentParser(
207203}
208204void ArgumentParser::parse_args ()
209205{
210- while (CUR_ARG < ARGC )
206+ while (CUR_ARG < argc_ )
211207 {
212- const string arg = ARGV [CUR_ARG];
208+ const string arg = argv_ [CUR_ARG];
213209 bool is_positional = !arg.starts_with (" -" );
214210 if (!is_positional)
215211 {
@@ -224,7 +220,7 @@ void ArgumentParser::parse_args()
224220 catch (std::exception&)
225221 {
226222 // CUR_ARG would be incremented while trying to parse at this point, so -1 is 'arg'
227- printf (" \n '%s' is not a valid value for argument %s\n\n " , ARGV [CUR_ARG], arg.c_str ());
223+ printf (" \n '%s' is not a valid value for argument %s\n\n " , argv_ [CUR_ARG], arg.c_str ());
228224 show_usage_and_exit ();
229225 }
230226 }
@@ -307,7 +303,7 @@ MainArgumentParser::MainArgumentParser(const int argc, const char* const argv[])
307303{
308304 register_flag (&Settings::setSaveAsAscii, true , " --ascii" , " Save grids as .asc" );
309305 register_flag (&Settings::setSaveAsTiff, false , " --no-tiff" , " Do not save grids as .tif" );
310- if (ARGC > 1 && 0 == strcmp (ARGV [1 ], " test" ))
306+ if (argc_ > 1 && 0 == strcmp (argv_ [1 ], " test" ))
311307 {
312308 fs::logging::note (" Running in test mode" );
313309 mode = TEST;
@@ -386,7 +382,7 @@ MainArgumentParser::MainArgumentParser(const int argc, const char* const argv[])
386382 false ,
387383 &parse_size_t
388384 );
389- if (ARGC > 1 && 0 == strcmp (ARGV [1 ], " surface" ))
385+ if (argc_ > 1 && 0 == strcmp (argv_ [1 ], " surface" ))
390386 {
391387 fs::logging::note (" Running in probability surface mode" );
392388 mode = SURFACE;
@@ -435,12 +431,12 @@ MainArgumentParser::MainArgumentParser(const int argc, const char* const argv[])
435431 false ,
436432 &parse_raw
437433 );
438- if (2 == ARGC && 0 == strcmp (ARGV [CUR_ARG], " -h" ))
434+ if (2 == argc_ && 0 == strcmp (argv_ [CUR_ARG], " -h" ))
439435 {
440436 // HACK: just do this for now
441437 show_help_and_exit ();
442438 }
443- else if (3 > (ARGC - SKIPPED_ARGS))
439+ else if (3 > (argc_ - SKIPPED_ARGS))
444440 {
445441 show_usage_and_exit ();
446442 }
@@ -495,7 +491,7 @@ FwiWeather MainArgumentParser::get_yesterday_weather() const
495491 dc
496492 };
497493}
498- const char * ArgumentParser::cur_arg () { return ARGV [CUR_ARG]; };
494+ const char * ArgumentParser::cur_arg () { return argv_ [CUR_ARG]; };
499495bool parse_flag (bool not_inverse)
500496{
501497 return parse_once<bool >([not_inverse] { return not_inverse; });
0 commit comments