#include <string>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cstdio>
namespace {
inline bool IsWindows()
{
return std::strcmp(
gSystem->GetName(),
"WinNT") == 0;
}
inline bool IsMac()
{
return std::strcmp(
gSystem->GetName(),
"Macosx") == 0;
}
std::string QuoteForShell(const std::string &s)
{
if (s.empty())
return "''";
if (IsWindows()) {
std::replace(
q.begin(),
q.end(),
'"',
'\'');
} else {
std::string out;
out.reserve(s.size() + 2);
out.push_back('\'');
out += "'\"'\"'";
else
}
out.push_back('\'');
return out;
}
}
std::string GetEnvOrEmpty(
const char *
name)
{
if (
const char *
v = std::getenv(
name))
return {};
}
std::string MaybeBackground(std::string cmd)
{
if (!IsWindows())
cmd += " &";
return cmd;
}
}
void edit(const char *file)
{
const std::string
f = (file ? file :
"");
const std::string qf = QuoteForShell(
f);
const std::string editor = GetEnvOrEmpty("EDITOR");
std::string cmd;
if (IsWindows()) {
if (!editor.empty())
cmd = "start " + editor + " " + qf;
else
cmd = "start notepad " + qf;
} else if (IsMac()) {
if (!editor.empty())
cmd = MaybeBackground(editor + " " + qf);
else
cmd = MaybeBackground("open -e " + qf);
} else {
if (!editor.empty())
cmd = MaybeBackground(editor + " " + qf);
else
cmd =
MaybeBackground("(command -v xdg-open >/dev/null 2>&1 && xdg-open " + qf + ") || (xterm -e vi " + qf + ")");
}
}
void ls(const char *path = nullptr)
{
std::string cmd = IsWindows() ? "dir /w" : "ls";
if (path && *path) {
cmd += " ";
cmd += QuoteForShell(path);
}
}
void dir(const char *path = nullptr)
{
std::string cmd = IsWindows() ? "dir" : "ls -alF";
if (path && *path) {
cmd += " ";
cmd += QuoteForShell(path);
}
}
const char *pwd()
{
static std::string wd;
return wd.c_str();
}
const char *cd(const char *path = nullptr)
{
if (path && *path)
return pwd();
}
void bexec2(const char *macro)
{
std::printf("in bexec dir=%s\n", pwd());
std::printf("Processing benchmark: %s\n", macro);
if (!bench) {
return;
}
if (summary) {
if (auto *tmacro = summary->GetLineWith(macro))
tmacro->SetTextColor(4);
}
if (summary2) {
if (auto *tmacro2 = summary2->GetLineWith(macro))
tmacro2->SetTextColor(2);
}
}
R__EXTERN TSystem * gSystem
void Update() override
Update canvas pad buffers.
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
TObject * GetPrimitive(const char *name) const override
Get primitive.
A Pave (see TPave) with text, lines or/and boxes inside.