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 "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;
{

View file

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

View file

@ -19,7 +19,7 @@
#include "string_view_cat.hpp"
#include "config.h"
#include "run_cmd.hpp"
#include "syspaths.hpp"
#include "run_context.hpp"
#include <iostream>
#if __cplusplus == 201703L
# include <experimental/array>
@ -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",

View file

@ -21,11 +21,11 @@
#include <string>
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

View file

@ -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() != "/") {

View file

@ -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

View file

@ -20,7 +20,7 @@
#include <string>
#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';

View file

@ -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',

View file

@ -17,7 +17,7 @@
#include "replace_bash_vars.hpp"
#include "config.h"
#include "syspaths.hpp"
#include "run_context.hpp"
#include <cassert>
#include <cctype>
@ -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;

View file

@ -21,7 +21,7 @@
#include <string>
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

View file

@ -15,7 +15,7 @@
* 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 "string_view_cat.hpp"
#include <unistd.h>
@ -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' <<

View file

@ -28,12 +28,12 @@
#include <optional>
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