From e84fd4aeeb15cd5894193dc403afc60e0dd7f321 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 19 Oct 2016 17:50:40 +0200 Subject: Factor global initialization into init() analogous to reset() --- build2/b.cxx | 18 ++++-------------- build2/utility | 6 ++++++ build2/utility.cxx | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/build2/b.cxx b/build2/b.cxx index d16a406..d800605 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -2,7 +2,6 @@ // copyright : Copyright (c) 2014-2016 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include // tzset() #include // strerror() #include // getenv() _putenv()(_WIN32) @@ -160,11 +159,11 @@ main (int argc, char* argv[]) fail << e; } - // Diagnostics verbosity. + // Global initializations. // - verb = ops.verbose_specified () - ? ops.verbose () - : ops.V () ? 3 : ops.v () ? 2 : ops.q () ? 0 : 1; + init (ops.verbose_specified () + ? ops.verbose () + : ops.V () ? 3 : ops.v () ? 2 : ops.q () ? 0 : 1); // Version. // @@ -205,10 +204,6 @@ main (int argc, char* argv[]) } } - // Initialize time conversion data that is used by localtime_r(). - // - tzset (); - // Register builtin modules. // { @@ -248,11 +243,6 @@ main (int argc, char* argv[]) bm["cli"] = mf {nullptr, &cli::init}; } - // Figure out work and home directories. - // - work = dir_path::current (); - home = dir_path::home (); - if (verb >= 5) { const char* p (getenv ("PATH")); diff --git a/build2/utility b/build2/utility index 2625d51..1499def 100644 --- a/build2/utility +++ b/build2/utility @@ -469,6 +469,12 @@ namespace build2 const std::string& find (const std::string& s) {return *emplace (s).first;} }; + + // Initialize build2 global state (verbosity, home/work dirrectories, etc). + // Should be called early in main() once. + // + void + init (uint16_t verbosity); } #include diff --git a/build2/utility.cxx b/build2/utility.cxx index 43a5370..0e97020 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -4,6 +4,8 @@ #include +#include // tzset() + #include // strlen(), str[n]cmp() #include // strtol() #include // cerr @@ -498,4 +500,21 @@ namespace build2 } bool exception_unwinding_dtor = false; + + void + init (uint16_t v) + { + // Diagnostics verbosity. + // + verb = v; + + // Initialize time conversion data that is used by localtime_r(). + // + tzset (); + + // Figure out work and home directories. + // + work = dir_path::current (); + home = dir_path::home (); + } } -- cgit v1.1