diff --git a/src/chost.cpp b/src/chost.cpp index ab56337..a96f921 100644 --- a/src/chost.cpp +++ b/src/chost.cpp @@ -16,7 +16,7 @@ */ #include "chost.hpp" -#include "syspaths.hpp" +#include "run_context.hpp" #include "run_cmd.hpp" #include "gentoofunctions.hpp" #include "replace_bash_vars.hpp" @@ -65,7 +65,7 @@ namespace duck { } } //unnamed namespace - std::string chost(const SysPaths& sp) { + std::string chost(const RunContext& sp) { using std::string; { diff --git a/src/chost.hpp b/src/chost.hpp index 1f44861..b131ce5 100644 --- a/src/chost.hpp +++ b/src/chost.hpp @@ -20,7 +20,7 @@ #include namespace duck { - class SysPaths; + class RunContext; - std::string chost(const SysPaths&); + std::string chost(const RunContext&); } //namespace duck diff --git a/src/gentoofunctions.cpp b/src/gentoofunctions.cpp index 542652e..fbeeea7 100644 --- a/src/gentoofunctions.cpp +++ b/src/gentoofunctions.cpp @@ -19,7 +19,7 @@ #include "string_view_cat.hpp" #include "config.h" #include "run_cmd.hpp" -#include "syspaths.hpp" +#include "run_context.hpp" #include #if __cplusplus == 201703L # include @@ -72,7 +72,7 @@ namespace duck { } void generic_eprint ( - const SysPaths& sp, + const RunContext& rc, std::ostream& stream, std::string_view quiet_var, std::string_view msg_prefix_var, @@ -82,12 +82,12 @@ namespace duck { std::string_view msg, const char* newline ) { - if (yesno(sp, sp.env()[quiet_var])) { + if (yesno(rc, rc.env()[quiet_var])) { return; } else { - const auto& env = sp.env(); - if (not yesno(sp, env["RC_ENDCOL"]) and g_last_e_cmd == "ebegin") { + const auto& env = rc.env(); + if (not yesno(rc, env["RC_ENDCOL"]) and g_last_e_cmd == "ebegin") { stream << '\n'; } stream << ' ' << env[msg_prefix_var] << '*' @@ -95,19 +95,19 @@ namespace duck { << msg << newline; } - esyslog(sp, log_pri, log_tag, msg); + esyslog(rc, log_pri, log_tag, msg); g_last_e_cmd = new_e_cmd; } } //unnamed namespace - void vewarn (const SysPaths& sp, std::string_view msg) { - if (yesno(sp, sp.env()["EINFO_VERBOSE"], true)) - ewarn(sp, msg); + void vewarn (const RunContext& rc, std::string_view msg) { + if (yesno(rc, rc.env()["EINFO_VERBOSE"], true)) + ewarn(rc, msg); } - void ewarn (const SysPaths& sp, std::string_view msg) { + void ewarn (const RunContext& rc, std::string_view msg) { generic_eprint( - sp, + rc, std::clog, "EINFO_QUIET", "WARN", @@ -119,8 +119,8 @@ namespace duck { ); } - void esyslog(const SysPaths& sp, std::string_view pri, std::string_view tag, std::string_view msg) { - if (not sp.env()["EINFO_LOG"].empty() and not run_cmd_retcode("command -v logger > /dev/null 2>&1")) { + void esyslog(const RunContext& rc, std::string_view pri, std::string_view tag, std::string_view msg) { + if (not rc.env()["EINFO_LOG"].empty() and not run_cmd_retcode("command -v logger > /dev/null 2>&1")) { if (msg.empty()) return; @@ -128,7 +128,7 @@ namespace duck { } } - bool yesno (const SysPaths& sp, std::string_view var, bool force_quiet) { + bool yesno (const RunContext& rc, std::string_view var, bool force_quiet) { { const auto ret = yesno_impl(var); switch (ret) { @@ -139,7 +139,7 @@ namespace duck { } { - auto val = sp.env()[var]; + auto val = rc.env()[var]; if (val.empty()) return false; @@ -148,15 +148,15 @@ namespace duck { case Yes: return true; case No: return false; default: - vewarn(sp, std::string("\"") + var + "\" (\"" + val + "\") is not set properly"); + vewarn(rc, std::string("\"") + var + "\" (\"" + val + "\") is not set properly"); return false; } } } - void eerror (const SysPaths& sp, std::string_view msg) { + void eerror (const RunContext& rc, std::string_view msg) { generic_eprint( - sp, + rc, std::clog, "EERROR_QUIET", "BAD", diff --git a/src/gentoofunctions.hpp b/src/gentoofunctions.hpp index 31d5386..23ce6c0 100644 --- a/src/gentoofunctions.hpp +++ b/src/gentoofunctions.hpp @@ -21,11 +21,11 @@ #include namespace duck { - class SysPaths; + class RunContext; - void vewarn (const SysPaths& sp, std::string_view msg); - void ewarn (const SysPaths& sp, std::string_view msg); - bool yesno (const SysPaths& sp, std::string_view var, bool force_quiet=false); - void esyslog(const SysPaths& sp, std::string_view pri, std::string_view tag, std::string_view msg); - void eerror (const SysPaths& sp, std::string_view msg); + void vewarn (const RunContext& rc, std::string_view msg); + void ewarn (const RunContext& rc, std::string_view msg); + bool yesno (const RunContext& rc, std::string_view var, bool force_quiet=false); + void esyslog(const RunContext& rc, std::string_view pri, std::string_view tag, std::string_view msg); + void eerror (const RunContext& rc, std::string_view msg); } //namespace duck diff --git a/src/list_profiles.cpp b/src/list_profiles.cpp index e01e9ab..2b506cc 100644 --- a/src/list_profiles.cpp +++ b/src/list_profiles.cpp @@ -16,7 +16,7 @@ */ #include "list_profiles.hpp" -#include "syspaths.hpp" +#include "run_context.hpp" #include "config.h" #include "chost.hpp" #include "to_var_map.hpp" @@ -120,7 +120,7 @@ namespace duck { return ret; } - void list_profiles(const SysPaths& sp) { + void list_profiles(const RunContext& sp) { using std::string; if (sp.root() != "/") { diff --git a/src/list_profiles.hpp b/src/list_profiles.hpp index 52a8f44..b364264 100644 --- a/src/list_profiles.hpp +++ b/src/list_profiles.hpp @@ -18,7 +18,7 @@ #pragma once namespace duck { - class SysPaths; + class RunContext; - void list_profiles(const SysPaths& syspaths); + void list_profiles(const RunContext& syspaths); } //namespace duck diff --git a/src/main.cpp b/src/main.cpp index 351b486..e940c29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ #include #include "config.h" #include "list_profiles.hpp" -#include "syspaths.hpp" +#include "run_context.hpp" namespace { const char g_simple_colours[] = @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) { return 0; } - duck::SysPaths syspaths; + duck::RunContext syspaths; syspaths.add_to_env(g_simple_colours); #if !defined(NDEBUG) std::cout << syspaths << '\n'; diff --git a/src/meson.build b/src/meson.build index 4b2d6e1..a654f35 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,7 +11,7 @@ executable(meson.project_name(), 'main.cpp', project_config_file, 'list_profiles.cpp', - 'syspaths.cpp', + 'run_context.cpp', 'chost.cpp', 'run_cmd.cpp', 'gentoofunctions.cpp', diff --git a/src/replace_bash_vars.cpp b/src/replace_bash_vars.cpp index 680f79e..242f67d 100644 --- a/src/replace_bash_vars.cpp +++ b/src/replace_bash_vars.cpp @@ -17,7 +17,7 @@ #include "replace_bash_vars.hpp" #include "config.h" -#include "syspaths.hpp" +#include "run_context.hpp" #include #include @@ -37,7 +37,7 @@ namespace duck { // return text; //} - VarInfo extract_var_name (const SysPaths& sp, std::string_view text) { + VarInfo extract_var_name (const RunContext& sp, std::string_view text) { assert(not text.empty()); assert(text.front() == '$'); if (text.size() == 1) { @@ -76,7 +76,7 @@ namespace duck { } } //unnamed namespace - std::string replace_bash_vars (const SysPaths& sp, std::string_view text) { + std::string replace_bash_vars (const RunContext& sp, std::string_view text) { std::size_t pos = 0; std::size_t prev_start = 0; std::string rtext; diff --git a/src/replace_bash_vars.hpp b/src/replace_bash_vars.hpp index bde5efc..7a97b55 100644 --- a/src/replace_bash_vars.hpp +++ b/src/replace_bash_vars.hpp @@ -21,7 +21,7 @@ #include namespace duck { - class SysPaths; + class RunContext; - std::string replace_bash_vars (const SysPaths& sp, std::string_view text); + std::string replace_bash_vars (const RunContext& sp, std::string_view text); } //namespace duck diff --git a/src/syspaths.cpp b/src/run_context.cpp similarity index 80% rename from src/syspaths.cpp rename to src/run_context.cpp index 7bf1a1c..ceb292e 100644 --- a/src/syspaths.cpp +++ b/src/run_context.cpp @@ -15,7 +15,7 @@ * along with user-gcc. If not, see . */ -#include "syspaths.hpp" +#include "run_context.hpp" #include "to_var_map.hpp" #include "string_view_cat.hpp" #include @@ -36,7 +36,7 @@ namespace duck { } } //unnamed namespace - SysPaths::SysPaths() : + RunContext::RunContext() : m_env(), m_root(m_env.get("ROOT", "/")), m_eprefix(fix_eprefix(m_env.get("EPREFIX", ""))), @@ -46,35 +46,35 @@ namespace duck { { } - void SysPaths::add_to_env (std::string_view colours) { + void RunContext::add_to_env (std::string_view colours) { for (auto& entry : to_var_map_ignore_ownership(colours)) { m_env.set(entry.first, entry.second); } } - auto SysPaths::root() const -> const path_type& { + auto RunContext::root() const -> const path_type& { return m_root; } - auto SysPaths::eroot() const -> const path_type& { + auto RunContext::eroot() const -> const path_type& { return m_eroot; } - auto SysPaths::eprefix() const -> const path_type& { + auto RunContext::eprefix() const -> const path_type& { return m_eprefix; } - auto SysPaths::env_d() const -> const path_type& { + auto RunContext::env_d() const -> const path_type& { return m_env_d; } - auto SysPaths::gcc_env_d() const -> const path_type& { + auto RunContext::gcc_env_d() const -> const path_type& { return m_gcc_env_d; } #if !defined(NDEBUG) - std::ostream& operator<< (std::ostream& oss, const SysPaths& sp) { - oss << "SysPaths {\n" << + std::ostream& operator<< (std::ostream& oss, const RunContext& sp) { + oss << "RunContext {\n" << "\tROOT: " << sp.root() << '\n' << "\tEPREFIX: " << sp.eprefix() << '\n' << "\tEROOT: " << sp.eroot() << '\n' << diff --git a/src/syspaths.hpp b/src/run_context.hpp similarity index 91% rename from src/syspaths.hpp rename to src/run_context.hpp index 726074a..a093a6f 100644 --- a/src/syspaths.hpp +++ b/src/run_context.hpp @@ -28,12 +28,12 @@ #include namespace duck { - class SysPaths { + class RunContext { public: typedef std::filesystem::path path_type; - SysPaths(); - ~SysPaths() noexcept = default; + RunContext(); + ~RunContext() noexcept = default; EnvFake& env() noexcept { return m_env; } const EnvFake& env() const noexcept { return m_env; } @@ -56,6 +56,6 @@ namespace duck { }; #if !defined(NDEBUG) - std::ostream& operator<< (std::ostream&, const SysPaths& sp); + std::ostream& operator<< (std::ostream&, const RunContext& sp); #endif } //namespace duck