Rename SysPaths to RunContext

This commit is contained in:
King_DuckZ 2020-04-13 21:29:17 +02:00
parent 8a7002f5c5
commit 8a7e42cd3c
12 changed files with 54 additions and 54 deletions

View file

@ -16,7 +16,7 @@
*/ */
#include "chost.hpp" #include "chost.hpp"
#include "syspaths.hpp" #include "run_context.hpp"
#include "run_cmd.hpp" #include "run_cmd.hpp"
#include "gentoofunctions.hpp" #include "gentoofunctions.hpp"
#include "replace_bash_vars.hpp" #include "replace_bash_vars.hpp"
@ -65,7 +65,7 @@ namespace duck {
} }
} //unnamed namespace } //unnamed namespace
std::string chost(const SysPaths& sp) { std::string chost(const RunContext& sp) {
using std::string; using std::string;
{ {

View file

@ -20,7 +20,7 @@
#include <string> #include <string>
namespace duck { namespace duck {
class SysPaths; class RunContext;
std::string chost(const SysPaths&); std::string chost(const RunContext&);
} //namespace duck } //namespace duck

View file

@ -19,7 +19,7 @@
#include "string_view_cat.hpp" #include "string_view_cat.hpp"
#include "config.h" #include "config.h"
#include "run_cmd.hpp" #include "run_cmd.hpp"
#include "syspaths.hpp" #include "run_context.hpp"
#include <iostream> #include <iostream>
#if __cplusplus == 201703L #if __cplusplus == 201703L
# include <experimental/array> # include <experimental/array>
@ -72,7 +72,7 @@ namespace duck {
} }
void generic_eprint ( void generic_eprint (
const SysPaths& sp, const RunContext& rc,
std::ostream& stream, std::ostream& stream,
std::string_view quiet_var, std::string_view quiet_var,
std::string_view msg_prefix_var, std::string_view msg_prefix_var,
@ -82,12 +82,12 @@ namespace duck {
std::string_view msg, std::string_view msg,
const char* newline const char* newline
) { ) {
if (yesno(sp, sp.env()[quiet_var])) { if (yesno(rc, rc.env()[quiet_var])) {
return; return;
} }
else { else {
const auto& env = sp.env(); const auto& env = rc.env();
if (not yesno(sp, env["RC_ENDCOL"]) and g_last_e_cmd == "ebegin") { if (not yesno(rc, env["RC_ENDCOL"]) and g_last_e_cmd == "ebegin") {
stream << '\n'; stream << '\n';
} }
stream << ' ' << env[msg_prefix_var] << '*' stream << ' ' << env[msg_prefix_var] << '*'
@ -95,19 +95,19 @@ namespace duck {
<< msg << newline; << msg << newline;
} }
esyslog(sp, log_pri, log_tag, msg); esyslog(rc, log_pri, log_tag, msg);
g_last_e_cmd = new_e_cmd; g_last_e_cmd = new_e_cmd;
} }
} //unnamed namespace } //unnamed namespace
void vewarn (const SysPaths& sp, std::string_view msg) { void vewarn (const RunContext& rc, std::string_view msg) {
if (yesno(sp, sp.env()["EINFO_VERBOSE"], true)) if (yesno(rc, rc.env()["EINFO_VERBOSE"], true))
ewarn(sp, msg); ewarn(rc, msg);
} }
void ewarn (const SysPaths& sp, std::string_view msg) { void ewarn (const RunContext& rc, std::string_view msg) {
generic_eprint( generic_eprint(
sp, rc,
std::clog, std::clog,
"EINFO_QUIET", "EINFO_QUIET",
"WARN", "WARN",
@ -119,8 +119,8 @@ namespace duck {
); );
} }
void esyslog(const SysPaths& sp, std::string_view pri, std::string_view tag, std::string_view msg) { void esyslog(const RunContext& rc, 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")) { if (not rc.env()["EINFO_LOG"].empty() and not run_cmd_retcode("command -v logger > /dev/null 2>&1")) {
if (msg.empty()) if (msg.empty())
return; 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); const auto ret = yesno_impl(var);
switch (ret) { switch (ret) {
@ -139,7 +139,7 @@ namespace duck {
} }
{ {
auto val = sp.env()[var]; auto val = rc.env()[var];
if (val.empty()) if (val.empty())
return false; return false;
@ -148,15 +148,15 @@ namespace duck {
case Yes: return true; case Yes: return true;
case No: return false; case No: return false;
default: default:
vewarn(sp, std::string("\"") + var + "\" (\"" + val + "\") is not set properly"); vewarn(rc, std::string("\"") + var + "\" (\"" + val + "\") is not set properly");
return false; return false;
} }
} }
} }
void eerror (const SysPaths& sp, std::string_view msg) { void eerror (const RunContext& rc, std::string_view msg) {
generic_eprint( generic_eprint(
sp, rc,
std::clog, std::clog,
"EERROR_QUIET", "EERROR_QUIET",
"BAD", "BAD",

View file

@ -21,11 +21,11 @@
#include <string> #include <string>
namespace duck { namespace duck {
class SysPaths; class RunContext;
void vewarn (const SysPaths& sp, std::string_view msg); void vewarn (const RunContext& rc, std::string_view msg);
void ewarn (const SysPaths& sp, std::string_view msg); void ewarn (const RunContext& rc, std::string_view msg);
bool yesno (const SysPaths& sp, std::string_view var, bool force_quiet=false); bool yesno (const RunContext& rc, 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 esyslog(const RunContext& rc, std::string_view pri, std::string_view tag, std::string_view msg);
void eerror (const SysPaths& sp, std::string_view msg); void eerror (const RunContext& rc, std::string_view msg);
} //namespace duck } //namespace duck

View file

@ -16,7 +16,7 @@
*/ */
#include "list_profiles.hpp" #include "list_profiles.hpp"
#include "syspaths.hpp" #include "run_context.hpp"
#include "config.h" #include "config.h"
#include "chost.hpp" #include "chost.hpp"
#include "to_var_map.hpp" #include "to_var_map.hpp"
@ -120,7 +120,7 @@ namespace duck {
return ret; return ret;
} }
void list_profiles(const SysPaths& sp) { void list_profiles(const RunContext& sp) {
using std::string; using std::string;
if (sp.root() != "/") { if (sp.root() != "/") {

View file

@ -18,7 +18,7 @@
#pragma once #pragma once
namespace duck { namespace duck {
class SysPaths; class RunContext;
void list_profiles(const SysPaths& syspaths); void list_profiles(const RunContext& syspaths);
} //namespace duck } //namespace duck

View file

@ -20,7 +20,7 @@
#include <string> #include <string>
#include "config.h" #include "config.h"
#include "list_profiles.hpp" #include "list_profiles.hpp"
#include "syspaths.hpp" #include "run_context.hpp"
namespace { namespace {
const char g_simple_colours[] = const char g_simple_colours[] =
@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
return 0; return 0;
} }
duck::SysPaths syspaths; duck::RunContext syspaths;
syspaths.add_to_env(g_simple_colours); syspaths.add_to_env(g_simple_colours);
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::cout << syspaths << '\n'; std::cout << syspaths << '\n';

View file

@ -11,7 +11,7 @@ executable(meson.project_name(),
'main.cpp', 'main.cpp',
project_config_file, project_config_file,
'list_profiles.cpp', 'list_profiles.cpp',
'syspaths.cpp', 'run_context.cpp',
'chost.cpp', 'chost.cpp',
'run_cmd.cpp', 'run_cmd.cpp',
'gentoofunctions.cpp', 'gentoofunctions.cpp',

View file

@ -17,7 +17,7 @@
#include "replace_bash_vars.hpp" #include "replace_bash_vars.hpp"
#include "config.h" #include "config.h"
#include "syspaths.hpp" #include "run_context.hpp"
#include <cassert> #include <cassert>
#include <cctype> #include <cctype>
@ -37,7 +37,7 @@ namespace duck {
// return text; // 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(not text.empty());
assert(text.front() == '$'); assert(text.front() == '$');
if (text.size() == 1) { if (text.size() == 1) {
@ -76,7 +76,7 @@ namespace duck {
} }
} //unnamed namespace } //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 pos = 0;
std::size_t prev_start = 0; std::size_t prev_start = 0;
std::string rtext; std::string rtext;

View file

@ -21,7 +21,7 @@
#include <string> #include <string>
namespace duck { 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 } //namespace duck

View file

@ -15,7 +15,7 @@
* along with user-gcc. If not, see <http://www.gnu.org/licenses/>. * along with user-gcc. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "syspaths.hpp" #include "run_context.hpp"
#include "to_var_map.hpp" #include "to_var_map.hpp"
#include "string_view_cat.hpp" #include "string_view_cat.hpp"
#include <unistd.h> #include <unistd.h>
@ -36,7 +36,7 @@ namespace duck {
} }
} //unnamed namespace } //unnamed namespace
SysPaths::SysPaths() : RunContext::RunContext() :
m_env(), m_env(),
m_root(m_env.get("ROOT", "/")), m_root(m_env.get("ROOT", "/")),
m_eprefix(fix_eprefix(m_env.get("EPREFIX", ""))), 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)) { for (auto& entry : to_var_map_ignore_ownership(colours)) {
m_env.set(entry.first, entry.second); m_env.set(entry.first, entry.second);
} }
} }
auto SysPaths::root() const -> const path_type& { auto RunContext::root() const -> const path_type& {
return m_root; return m_root;
} }
auto SysPaths::eroot() const -> const path_type& { auto RunContext::eroot() const -> const path_type& {
return m_eroot; return m_eroot;
} }
auto SysPaths::eprefix() const -> const path_type& { auto RunContext::eprefix() const -> const path_type& {
return m_eprefix; return m_eprefix;
} }
auto SysPaths::env_d() const -> const path_type& { auto RunContext::env_d() const -> const path_type& {
return m_env_d; 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; return m_gcc_env_d;
} }
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::ostream& operator<< (std::ostream& oss, const SysPaths& sp) { std::ostream& operator<< (std::ostream& oss, const RunContext& sp) {
oss << "SysPaths {\n" << oss << "RunContext {\n" <<
"\tROOT: " << sp.root() << '\n' << "\tROOT: " << sp.root() << '\n' <<
"\tEPREFIX: " << sp.eprefix() << '\n' << "\tEPREFIX: " << sp.eprefix() << '\n' <<
"\tEROOT: " << sp.eroot() << '\n' << "\tEROOT: " << sp.eroot() << '\n' <<

View file

@ -28,12 +28,12 @@
#include <optional> #include <optional>
namespace duck { namespace duck {
class SysPaths { class RunContext {
public: public:
typedef std::filesystem::path path_type; typedef std::filesystem::path path_type;
SysPaths(); RunContext();
~SysPaths() noexcept = default; ~RunContext() noexcept = default;
EnvFake& env() noexcept { return m_env; } EnvFake& env() noexcept { return m_env; }
const EnvFake& env() const noexcept { return m_env; } const EnvFake& env() const noexcept { return m_env; }
@ -56,6 +56,6 @@ namespace duck {
}; };
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::ostream& operator<< (std::ostream&, const SysPaths& sp); std::ostream& operator<< (std::ostream&, const RunContext& sp);
#endif #endif
} //namespace duck } //namespace duck