Commit bd781e15 authored by Jack Andersen's avatar Jack Andersen

Massive fmtlib refactor

parent 56912f29
......@@ -55,9 +55,9 @@ protected:
bool continuePrompt() {
if (!m_info.yes) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("\n" BLUE BOLD "Continue?" NORMAL " (Y/n) "));
fmt::print(fmt(_SYS_STR("\n" BLUE BOLD "Continue?" NORMAL " (Y/n) ")));
else
hecl::Printf(_SYS_STR("\nContinue? (Y/n) "));
fmt::print(fmt(_SYS_STR("\nContinue? (Y/n) ")));
fflush(stdout);
int ch;
......@@ -73,7 +73,7 @@ protected:
#endif
{
if (ch == 'n' || ch == 'N') {
hecl::Printf(_SYS_STR("\n"));
fmt::print(fmt(_SYS_STR("\n")));
return false;
}
if (ch == 'y' || ch == 'Y' || ch == '\r' || ch == '\n')
......@@ -83,7 +83,7 @@ protected:
tcsetattr(0, TCSANOW, &tioOld);
#endif
}
hecl::Printf(_SYS_STR("\n"));
fmt::print(fmt(_SYS_STR("\n")));
return true;
}
......@@ -175,27 +175,27 @@ public:
#endif
}
void print(const hecl::SystemChar* str) { hecl::FPrintf(m_sout, _SYS_STR("%s"), str); }
void print(const hecl::SystemChar* str) { fmt::print(m_sout, fmt(_SYS_STR("{}")), str); }
void printBold(const hecl::SystemChar* str) {
if (XTERM_COLOR)
hecl::FPrintf(m_sout, _SYS_STR("" BOLD "%s" NORMAL ""), str);
fmt::print(m_sout, fmt(_SYS_STR("" BOLD "{}" NORMAL "")), str);
else
hecl::FPrintf(m_sout, _SYS_STR("%s"), str);
fmt::print(m_sout, fmt(_SYS_STR("{}")), str);
}
void secHead(const hecl::SystemChar* headName) {
if (XTERM_COLOR)
hecl::FPrintf(m_sout, _SYS_STR("" BOLD "%s" NORMAL "\n"), headName);
fmt::print(m_sout, fmt(_SYS_STR("" BOLD "{}" NORMAL "\n")), headName);
else
hecl::FPrintf(m_sout, _SYS_STR("%s\n"), headName);
fmt::print(m_sout, fmt(_SYS_STR("{}\n")), headName);
}
void optionHead(const hecl::SystemChar* flag, const hecl::SystemChar* synopsis) {
if (XTERM_COLOR)
hecl::FPrintf(m_sout, _SYS_STR("" BOLD "%s" NORMAL " (%s)\n"), flag, synopsis);
fmt::print(m_sout, fmt(_SYS_STR("" BOLD "{}" NORMAL " ({})\n")), flag, synopsis);
else
hecl::FPrintf(m_sout, _SYS_STR("%s (%s)\n"), flag, synopsis);
fmt::print(m_sout, fmt(_SYS_STR("{} ({})\n")), flag, synopsis);
}
void beginWrap() { m_wrapBuffer.clear(); }
......@@ -213,7 +213,7 @@ public:
void endWrap() {
_wrapBuf(m_wrapBuffer);
m_wrapBuffer += _SYS_STR('\n');
hecl::FPrintf(m_sout, _SYS_STR("%s"), m_wrapBuffer.c_str());
fmt::print(m_sout, fmt(_SYS_STR("{}")), m_wrapBuffer);
m_wrapBuffer.clear();
}
};
......
......@@ -38,7 +38,7 @@ public:
}
}
if (!m_spec)
LogModule.report(logvisor::Fatal, "unable to find data spec '%s'", specName.c_str());
LogModule.report(logvisor::Fatal, fmt("unable to find data spec '{}'"), specName);
continue;
} else if (arg.size() >= 2 && arg[0] == _SYS_STR('-') && arg[1] == _SYS_STR('-'))
continue;
......@@ -51,18 +51,18 @@ public:
m_useProj = m_fallbackProj.get();
} else if (m_fallbackProj->getProjectRootPath() != root)
LogModule.report(logvisor::Fatal,
_SYS_STR("hecl cook can only process multiple items in the same project; ")
_SYS_STR("'%s' and '%s' are different projects"),
m_fallbackProj->getProjectRootPath().getAbsolutePath().data(),
root.getAbsolutePath().data());
fmt(_SYS_STR("hecl cook can only process multiple items in the same project; ")
_SYS_STR("'{}' and '{}' are different projects")),
m_fallbackProj->getProjectRootPath().getAbsolutePath(),
root.getAbsolutePath());
m_selectedItems.emplace_back(*m_useProj, subPath);
}
}
}
if (!m_useProj)
LogModule.report(logvisor::Fatal,
"hecl cook must be ran within a project directory or "
"provided a path within a project");
fmt("hecl cook must be ran within a project directory or "
"provided a path within a project"));
/* Default case: recursive at root */
if (m_selectedItems.empty()) {
......
......@@ -29,7 +29,7 @@ class ToolExtract final : public ToolBase {
public:
ToolExtract(const ToolPassInfo& info) : ToolBase(info) {
if (!m_info.args.size())
LogModule.report(logvisor::Fatal, "hecl extract needs a source path as its first argument");
LogModule.report(logvisor::Fatal, fmt("hecl extract needs a source path as its first argument"));
if (!info.project) {
hecl::SystemString rootDir;
......@@ -47,7 +47,7 @@ public:
baseFile.assign(baseFile.begin(), baseFile.begin() + dotPos);
if (baseFile.empty())
LogModule.report(logvisor::Fatal, "hecl extract must be ran within a project directory");
LogModule.report(logvisor::Fatal, fmt("hecl extract must be ran within a project directory"));
rootDir = info.cwd + baseFile;
} else {
......@@ -62,8 +62,8 @@ public:
newProjRoot.makeDir();
m_fallbackProj.reset(new hecl::Database::Project(newProjRoot));
if (logvisor::ErrorCount > ErrorRef)
LogModule.report(logvisor::Fatal, "unable to init project at '%s'", rootDir.c_str());
LogModule.report(logvisor::Info, _SYS_STR("initialized project at '%s/.hecl'"), rootDir.c_str());
LogModule.report(logvisor::Fatal, fmt("unable to init project at '{}'"), rootDir);
LogModule.report(logvisor::Info, fmt(_SYS_STR("initialized project at '{}/.hecl'")), rootDir);
m_useProj = m_fallbackProj.get();
} else
m_useProj = info.project;
......@@ -116,15 +116,15 @@ public:
static void _recursivePrint(int level, hecl::Database::IDataSpec::ExtractReport& rep) {
for (int l = 0; l < level; ++l)
hecl::Printf(_SYS_STR(" "));
fmt::print(fmt(_SYS_STR(" ")));
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" BOLD "%s" NORMAL ""), rep.name.c_str());
fmt::print(fmt(_SYS_STR("" BOLD "{}" NORMAL "")), rep.name);
else
hecl::Printf(_SYS_STR("%s"), rep.name.c_str());
fmt::print(fmt(_SYS_STR("{}")), rep.name);
if (rep.desc.size())
hecl::Printf(_SYS_STR(" [%s]"), rep.desc.c_str());
hecl::Printf(_SYS_STR("\n"));
fmt::print(fmt(_SYS_STR(" [{}]")), rep.desc);
fmt::print(fmt(_SYS_STR("\n")));
for (hecl::Database::IDataSpec::ExtractReport& child : rep.childOpts)
_recursivePrint(level + 1, child);
}
......@@ -132,32 +132,32 @@ public:
int run() {
if (m_specPasses.empty()) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"));
fmt::print(fmt(_SYS_STR("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n")));
else
hecl::Printf(_SYS_STR("NOTHING TO EXTRACT\n"));
fmt::print(fmt(_SYS_STR("NOTHING TO EXTRACT\n")));
return 1;
}
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" GREEN BOLD "ABOUT TO EXTRACT:" NORMAL "\n"));
fmt::print(fmt(_SYS_STR("" GREEN BOLD "ABOUT TO EXTRACT:" NORMAL "\n")));
else
hecl::Printf(_SYS_STR("ABOUT TO EXTRACT:\n"));
fmt::print(fmt(_SYS_STR("ABOUT TO EXTRACT:\n")));
for (hecl::Database::IDataSpec::ExtractReport& rep : m_reps) {
_recursivePrint(0, rep);
hecl::Printf(_SYS_STR("\n"));
fmt::print(fmt(_SYS_STR("\n")));
}
fflush(stdout);
if (continuePrompt()) {
for (SpecExtractPass& ds : m_specPasses) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" MAGENTA BOLD "Using DataSpec %s:" NORMAL "\n"), ds.m_entry->m_name.data());
fmt::print(fmt(_SYS_STR("" MAGENTA BOLD "Using DataSpec {}:" NORMAL "\n")), ds.m_entry->m_name);
else
hecl::Printf(_SYS_STR("Using DataSpec %s:\n"), ds.m_entry->m_name.data());
fmt::print(fmt(_SYS_STR("Using DataSpec {}:\n")), ds.m_entry->m_name);
ds.m_instance->doExtract(m_einfo, {true});
hecl::Printf(_SYS_STR("\n\n"));
fmt::print(fmt(_SYS_STR("\n\n")));
}
}
......
......@@ -9,7 +9,7 @@ class ToolHelp final : public ToolBase {
public:
ToolHelp(const ToolPassInfo& info) : ToolBase(info) {
if (m_info.args.empty()) {
LogModule.report(logvisor::Error, "help requires a tool name argument");
LogModule.report(logvisor::Error, fmt("help requires a tool name argument"));
return;
}
m_good = true;
......@@ -64,7 +64,7 @@ public:
else if (toolName == _SYS_STR("help"))
helpFunc = ToolHelp::Help;
else {
LogModule.report(logvisor::Error, _SYS_STR("unrecognized tool '%s' - can't help"), toolName.c_str());
LogModule.report(logvisor::Error, fmt(_SYS_STR("unrecognized tool '{}' - can't help")), toolName);
return;
}
......
......@@ -17,7 +17,7 @@ class ToolImage final : public ToolBase {
public:
ToolImage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) {
if (!info.project)
LogModule.report(logvisor::Fatal, "hecl image must be ran within a project directory");
LogModule.report(logvisor::Fatal, fmt("hecl image must be ran within a project directory"));
/* Scan args */
if (info.args.size()) {
......@@ -40,8 +40,8 @@ public:
}
if (!m_useProj)
LogModule.report(logvisor::Fatal,
"hecl image must be ran within a project directory or "
"provided a path within a project");
fmt("hecl image must be ran within a project directory or "
"provided a path within a project"));
}
~ToolImage() {}
......@@ -75,29 +75,29 @@ public:
int run() {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" GREEN BOLD "ABOUT TO IMAGE:" NORMAL "\n"));
fmt::print(fmt(_SYS_STR("" GREEN BOLD "ABOUT TO IMAGE:" NORMAL "\n")));
else
hecl::Printf(_SYS_STR("ABOUT TO IMAGE:\n"));
fmt::print(fmt(_SYS_STR("ABOUT TO IMAGE:\n")));
hecl::Printf(_SYS_STR(" %s\n"), m_useProj->getProjectRootPath().getAbsolutePath().data());
fmt::print(fmt(_SYS_STR(" {}\n")), m_useProj->getProjectRootPath().getAbsolutePath());
fflush(stdout);
if (continuePrompt()) {
hecl::ProjectPath outPath(m_useProj->getProjectWorkingPath(), _SYS_STR("out"));
if (!outPath.isDirectory()) {
LogModule.report(logvisor::Error, _SYS_STR("%s is not a directory"), outPath.getAbsolutePath().data());
LogModule.report(logvisor::Error, fmt(_SYS_STR("{} is not a directory")), outPath.getAbsolutePath());
return 1;
}
hecl::ProjectPath bootBinPath(outPath, _SYS_STR("sys/boot.bin"));
if (!bootBinPath.isFile()) {
LogModule.report(logvisor::Error, _SYS_STR("%s is not a file"), bootBinPath.getAbsolutePath().data());
LogModule.report(logvisor::Error, fmt(_SYS_STR("{} is not a file")), bootBinPath.getAbsolutePath());
return 1;
}
athena::io::FileReader r(bootBinPath.getAbsolutePath());
if (r.hasError()) {
LogModule.report(logvisor::Error, _SYS_STR("unable to open %s"), bootBinPath.getAbsolutePath().data());
LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open {}")), bootBinPath.getAbsolutePath());
return 1;
}
std::string id = r.readString(6);
......@@ -113,7 +113,7 @@ public:
fileOut += _SYS_STR(".gcm");
if (nod::DiscBuilderGCN::CalculateTotalSizeRequired(outPath.getAbsolutePath()) == UINT64_MAX)
return 1;
LogModule.report(logvisor::Info, _SYS_STR("Generating %s as GameCube image"), fileOut.c_str());
LogModule.report(logvisor::Info, fmt(_SYS_STR("Generating {} as GameCube image")), fileOut);
nod::DiscBuilderGCN db(fileOut, progFunc);
if (db.buildFromDirectory(outPath.getAbsolutePath()) != nod::EBuildResult::Success)
return 1;
......@@ -122,7 +122,7 @@ public:
bool dualLayer;
if (nod::DiscBuilderWii::CalculateTotalSizeRequired(outPath.getAbsolutePath(), dualLayer) == UINT64_MAX)
return 1;
LogModule.report(logvisor::Info, _SYS_STR("Generating %s as %s-layer Wii image"), fileOut.c_str(),
LogModule.report(logvisor::Info, fmt(_SYS_STR("Generating {} as {}-layer Wii image")), fileOut,
dualLayer ? _SYS_STR("dual") : _SYS_STR("single"));
nod::DiscBuilderWii db(fileOut, dualLayer, progFunc);
if (db.buildFromDirectory(outPath.getAbsolutePath()) != nod::EBuildResult::Success)
......
......@@ -18,18 +18,18 @@ public:
if (hecl::Stat(dir->c_str(), &theStat)) {
hecl::MakeDir(dir->c_str());
if (hecl::Stat(dir->c_str(), &theStat)) {
LogModule.report(logvisor::Fatal, _SYS_STR("unable to stat '%s'"), dir->c_str());
LogModule.report(logvisor::Fatal, fmt(_SYS_STR("unable to stat '{}'")), *dir);
return;
}
}
if (!S_ISDIR(theStat.st_mode)) {
LogModule.report(logvisor::Fatal, _SYS_STR("'%s' is not a directory"), dir->c_str());
LogModule.report(logvisor::Fatal, fmt(_SYS_STR("'{}' is not a directory")), *dir);
return;
}
hecl::SystemString testPath = *dir + _SYS_STR("/.hecl/beacon");
if (!hecl::Stat(testPath.c_str(), &theStat)) {
LogModule.report(logvisor::Fatal, _SYS_STR("project already exists at '%s'"), dir->c_str());
LogModule.report(logvisor::Fatal, fmt(_SYS_STR("project already exists at '{}'")), *dir);
return;
}
......@@ -43,7 +43,7 @@ public:
hecl::Database::Project proj((hecl::ProjectRootPath(*m_dir)));
if (logvisor::ErrorCount > ErrorRef)
return 1;
LogModule.report(logvisor::Info, _SYS_STR("initialized project at '%s/.hecl'"), m_dir->c_str());
LogModule.report(logvisor::Info, fmt(_SYS_STR("initialized project at '{}/.hecl'")), *m_dir);
return 0;
}
......
......@@ -61,7 +61,7 @@ class ToolPackage final : public ToolBase {
public:
ToolPackage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) {
if (!info.project)
LogModule.report(logvisor::Fatal, "hecl package must be ran within a project directory");
LogModule.report(logvisor::Fatal, fmt("hecl package must be ran within a project directory"));
/* Scan args */
if (info.args.size()) {
......@@ -82,7 +82,7 @@ public:
}
}
if (!m_spec)
LogModule.report(logvisor::Fatal, "unable to find data spec '%s'", specName.c_str());
LogModule.report(logvisor::Fatal, fmt("unable to find data spec '{}'"), specName);
continue;
} else if (arg.size() >= 2 && arg[0] == _SYS_STR('-') && arg[1] == _SYS_STR('-'))
continue;
......@@ -96,10 +96,10 @@ public:
m_useProj = m_fallbackProj.get();
} else if (m_fallbackProj->getProjectRootPath() != root)
LogModule.report(logvisor::Fatal,
_SYS_STR("hecl package can only process multiple items in the same project; ")
_SYS_STR("'%s' and '%s' are different projects"),
m_fallbackProj->getProjectRootPath().getAbsolutePath().data(),
root.getAbsolutePath().data());
fmt(_SYS_STR("hecl package can only process multiple items in the same project; ")
_SYS_STR("'{}' and '{}' are different projects")),
m_fallbackProj->getProjectRootPath().getAbsolutePath(),
root.getAbsolutePath());
FindSelectedItems({*m_useProj, subPath}, true);
}
......@@ -107,8 +107,8 @@ public:
}
if (!m_useProj)
LogModule.report(logvisor::Fatal,
"hecl package must be ran within a project directory or "
"provided a path within a project");
fmt("hecl package must be ran within a project directory or "
"provided a path within a project"));
/* Default case: recursive at root */
if (m_selectedItems.empty())
......@@ -160,12 +160,12 @@ public:
int run() {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" GREEN BOLD "ABOUT TO PACKAGE:" NORMAL "\n"));
fmt::print(fmt(_SYS_STR("" GREEN BOLD "ABOUT TO PACKAGE:" NORMAL "\n")));
else
hecl::Printf(_SYS_STR("ABOUT TO PACKAGE:\n"));
fmt::print(fmt(_SYS_STR("ABOUT TO PACKAGE:\n")));
for (auto& item : m_selectedItems)
hecl::Printf(_SYS_STR(" %s\n"), item.getRelativePath().data());
fmt::print(fmt(_SYS_STR(" {}\n")), item.getRelativePath());
fflush(stdout);
if (continuePrompt()) {
......@@ -173,7 +173,7 @@ public:
hecl::ClientProcess cp(&printer);
for (const hecl::ProjectPath& path : m_selectedItems) {
if (!m_useProj->packagePath(path, printer, m_fast, m_spec, &cp))
LogModule.report(logvisor::Error, _SYS_STR("Unable to package %s"), path.getAbsolutePath().data());
LogModule.report(logvisor::Error, fmt(_SYS_STR("Unable to package {}")), path.getAbsolutePath());
}
cp.waitUntilComplete();
}
......
......@@ -13,7 +13,7 @@ public:
return;
if (!info.project)
LogModule.report(logvisor::Fatal, "hecl spec must be ran within a project directory");
LogModule.report(logvisor::Fatal, fmt("hecl spec must be ran within a project directory"));
const auto& specs = info.project->getDataSpecs();
hecl::SystemString firstArg = info.args.front();
......@@ -27,7 +27,7 @@ public:
return;
if (info.args.size() < 2)
LogModule.report(logvisor::Fatal, "Speclist argument required");
LogModule.report(logvisor::Fatal, fmt("Speclist argument required"));
auto it = info.args.begin();
++it;
......@@ -41,7 +41,7 @@ public:
}
}
if (!found)
LogModule.report(logvisor::Fatal, _SYS_STR("'%s' is not found in the dataspec registry"), it->c_str());
LogModule.report(logvisor::Fatal, fmt(_SYS_STR("'{}' is not found in the dataspec registry")), *it);
}
}
......@@ -77,10 +77,10 @@ public:
if (!m_info.project) {
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" BOLD CYAN "%s" NORMAL "\n"), spec->m_name.data());
fmt::print(fmt(_SYS_STR("" BOLD CYAN "{}" NORMAL "\n")), spec->m_name);
else
hecl::Printf(_SYS_STR("%s\n"), spec->m_name.data());
hecl::Printf(_SYS_STR(" %s\n"), spec->m_desc.data());
fmt::print(fmt(_SYS_STR("{}\n")), spec->m_name);
fmt::print(fmt(_SYS_STR(" {}\n")), spec->m_desc);
}
return 0;
}
......@@ -89,16 +89,16 @@ public:
if (mode == MLIST) {
for (auto& spec : specs) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" BOLD CYAN "%s" NORMAL ""), spec.spec.m_name.data());
fmt::print(fmt(_SYS_STR("" BOLD CYAN "{}" NORMAL "")), spec.spec.m_name);
else
hecl::Printf(_SYS_STR("%s"), spec.spec.m_name.data());
fmt::print(fmt(_SYS_STR("{}")), spec.spec.m_name);
if (spec.active) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR(" " BOLD GREEN "[ENABLED]" NORMAL ""));
fmt::print(fmt(_SYS_STR(" " BOLD GREEN "[ENABLED]" NORMAL "")));
else
hecl::Printf(_SYS_STR(" [ENABLED]"));
fmt::print(fmt(_SYS_STR(" [ENABLED]")));
}
hecl::Printf(_SYS_STR("\n %s\n"), spec.spec.m_desc.data());
fmt::print(fmt(_SYS_STR("\n {}\n")), spec.spec.m_desc);
}
return 0;
}
......
......@@ -45,20 +45,20 @@ bool XTERM_COLOR = false;
/* Main usage message */
static void printHelp(const hecl::SystemChar* pname) {
if (XTERM_COLOR)
hecl::Printf(_SYS_STR("" BOLD "HECL" NORMAL ""));
fmt::print(fmt(_SYS_STR("" BOLD "HECL" NORMAL "")));
else
hecl::Printf(_SYS_STR("HECL"));
fmt::print(fmt(_SYS_STR("HECL")));
#if HECL_HAS_NOD
#define TOOL_LIST "extract|init|cook|package|image|help"
#else
#define TOOL_LIST "extract|init|cook|package|help"
#endif
#if HECL_GIT
hecl::Printf(_SYS_STR(" Commit " HECL_GIT_S " " HECL_BRANCH_S "\nUsage: %s " TOOL_LIST "\n"), pname);
fmt::print(fmt(_SYS_STR(" Commit " HECL_GIT_S " " HECL_BRANCH_S "\nUsage: {} " TOOL_LIST "\n")), pname);
#elif HECL_VER
hecl::Printf(_SYS_STR(" Version " HECL_VER_S "\nUsage: %s " TOOL_LIST "\n"), pname);
fmt::print(fmt(_SYS_STR(" Version " HECL_VER_S "\nUsage: {} " TOOL_LIST "\n")), pname);
#else
hecl::Printf(_SYS_STR("\nUsage: %s " TOOL_LIST "\n"), pname);
fmt::print(fmt(_SYS_STR("\nUsage: {} " TOOL_LIST "\n")), pname);
#endif
}
......@@ -77,11 +77,9 @@ static void SIGINTHandler(int sig) {
}
static logvisor::Module AthenaLog("Athena");
static void AthenaExc(athena::error::Level level, const char* file, const char*, int line, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
AthenaLog.report(logvisor::Level(level), fmt, ap);
va_end(ap);
static void AthenaExc(athena::error::Level level, const char* file, const char*, int line,
fmt::string_view fmt, fmt::format_args args) {
AthenaLog.vreport(logvisor::Level(level), fmt, args);
}
static hecl::SystemChar cwdbuf[1024];
......@@ -96,7 +94,7 @@ int main(int argc, const char** argv)
#endif
{
if (argc > 1 && !hecl::StrCmp(argv[1], _SYS_STR("--dlpackage"))) {
printf("%s\n", HECL_DLPACKAGE);
fmt::print(fmt("{}\n"), HECL_DLPACKAGE);
return 100;
}
......@@ -278,7 +276,7 @@ int main(int argc, const char** argv)
else {
FILE* fp = hecl::Fopen(argv[1], _SYS_STR("rb"));
if (!fp)
LogModule.report(logvisor::Error, _SYS_STR("unrecognized tool '%s'"), toolName.c_str());
LogModule.report(logvisor::Error, fmt(_SYS_STR("unrecognized tool '{}'")), toolName);
else {
/* Shortcut-case: implicit extract */
fclose(fp);
......@@ -295,8 +293,7 @@ int main(int argc, const char** argv)
}
if (info.verbosityLevel)
LogModule.report(logvisor::Info, _SYS_STR("Constructed tool '%s' %d\n"), tool->toolName().c_str(),
info.verbosityLevel);
LogModule.report(logvisor::Info, fmt(_SYS_STR("Constructed tool '{}' {}\n")), tool->toolName(), info.verbosityLevel);
/* Run tool */
ErrorRef = logvisor::ErrorCount;
......
Subproject commit f3852eb0d2643a9b1d1358c3a89c0002b2cadb90
Subproject commit 478d75f1cb6ff25fbbd0d22357b6de395c3ab662
Subproject commit b2bf7549f510ce12ee7b834e0a5c3562846d6303
Subproject commit deefc8e99520ffacd0d70c27a6beeb1047a0c131
......@@ -30,6 +30,7 @@
#include "athena/MemoryWriter.hpp"
#include <optional>
#include "Token.hpp"
#include <fmt/ostream.h>
namespace hecl::blender {
using namespace std::literals;
......@@ -86,11 +87,8 @@ public:
}
~PyOutStream() { close(); }
void close();
#if __GNUC__
__attribute__((__format__(__printf__, 2, 3)))
#endif
void
format(const char* fmt, ...);
template <typename S, typename... Args, typename Char = fmt::char_t<S>>
void format(const S& format, Args&&... args);
void linkBlend(const char* target, const char* objName, bool link = true);
void linkBackground(const char* target, const char* sceneName = nullptr);
void AABBToBMesh(const atVec3f& min, const atVec3f& max);
......@@ -713,6 +711,7 @@ class Connection {
uint32_t _writeStr(const char* str, uint32_t len, int wpipe);
uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); }
uint32_t _writeStr(const char* str) { return _writeStr(str, strlen(str)); }
uint32_t _writeStr(const std::string& str) { return _writeStr(str.c_str(), str.size()); }
size_t _readBuf(void* buf, size_t len);
size_t _writeBuf(const void* buf, size_t len);
void _closePipe();
......@@ -738,14 +737,14 @@ public:
PyOutStream beginPythonOut(bool deleteOnError = false) {
bool expect = false;
if (!m_lock.compare_exchange_strong(expect, true))
BlenderLog.report(logvisor::Fatal, "lock already held for blender::Connection::beginPythonOut()");
BlenderLog.report(logvisor::Fatal, fmt("lock already held for blender::Connection::beginPythonOut()"));
return PyOutStream(this, deleteOnError);
}
DataStream beginData() {
bool expect = false;
if (!m_lock.compare_exchange_strong(expect, true))
BlenderLog.report(logvisor::Fatal, "lock already held for blender::Connection::beginDataIn()");
BlenderLog.report(logvisor::Fatal, fmt("lock already held for blender::Connection::beginDataIn()"));
return DataStream(this);
}
......@@ -760,6 +759,14 @@ public:
static void Shutdown();
};
template <typename S, typename... Args, typename Char>
void PyOutStream::format(const S& format, Args&&... args)
{
if (!m_parent || !m_parent->m_lock)
BlenderLog.report(logvisor::Fatal, fmt("lock not held for PyOutStream::format()"));
fmt::print(*this, format, std::forward<Args>(args)...);
}
class HMDLBuffers {
public:
struct Surface;
......
......@@ -77,12 +77,12 @@ struct Evaluation {
#ifdef _LIBCPP_VERSION
using StageBinaryData = std::shared_ptr<uint8_t>;
static inline StageBinaryData MakeStageBinaryData(size_t sz) {
inline StageBinaryData MakeStageBinaryData(size_t sz) {
return StageBinaryData(new uint8_t[sz], std::default_delete<uint8_t[]>{});
}
#else
using StageBinaryData = std::shared_ptr<uint8_t[]>;
static inline StageBinaryData MakeStageBinaryData(size_t sz) { return StageBinaryData(new uint8_t[sz]); }
inline StageBinaryData MakeStageBinaryData(size_t sz) { return StageBinaryData(new uint8_t[sz]); }
#endif
template <typename P, typename S>
......
......@@ -26,13 +26,13 @@ class Console {
Console* m_con;
LogVisorAdapter(Console* con) : m_con(con) {}
~LogVisorAdapter() {}
void report(const char* modName, logvisor::Level severity, const char* format, va_list ap);
void report(const char* modName, logvisor::Level severity, const wchar_t* format, va_list ap);
~LogVisorAdapter() = default;
void report(const char* modName, logvisor::Level severity, fmt::string_view format, fmt::format_args args);
void report(const char* modName, logvisor::Level severity, fmt::wstring_view format, fmt::wformat_args args);
void reportSource(const char* modName, logvisor::Level severity, const char* file, unsigned linenum,
const char* format, va_list ap);
fmt::string_view format, fmt::format_args args);
void reportSource(const char* modName, logvisor::Level severity, const char* file, unsigned linenum,
const wchar_t* format, va_list ap);
fmt::wstring_view format, fmt::wformat_args args);
};
public:
......@@ -80,8 +80,13 @@ public:
void listCommands(Console* con, const std::vector<std::string>& args);
bool commandExists(std::string_view cmd);
void report(Level level, const char* fmt, va_list list);
void report(Level level, const char* fmt, ...);
void vreport(Level level, fmt::string_view format, fmt::format_args args);
template <typename S, typename... Args, typename Char = fmt::char_t<S>>
void report(Level level, const S& format, Args&&... args) {
vreport(level, fmt::to_string_view<Char>(format),
fmt::basic_format_args<fmt::buffer_context<Char>>(
fmt::internal::make_args_checked<Args...>(format, args...)));
}
void init(boo::IWindow* ctx);
void proc();
......
......@@ -94,7 +94,7 @@ public:
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps) {
(void)info;
(void)reps;
LogModule.report(logvisor::Error, "not implemented");
LogModule.report(logvisor::Error, fmt("not implemented"));
return false;
}
virtual void doExtract(const ExtractPassInfo& info, const MultiProgressPrinter& progress) {
......@@ -104,7 +104,7 @@ public:
virtual bool canCook(const ProjectPath& path, blender::Token& btok) {
(void)path;
LogModule.report(logvisor::Error, "not implemented");
LogModule.report(logvisor::Error, fmt("not implemented"));
return false;
}
virtual const DataSpecEntry* overrideDataSpec(const ProjectPath& path,
......
......@@ -37,9 +37,9 @@ public:
bool operator!=(uint32_t other) const { return num != other; }
std::string toString() const { return std::string(fcc, 4); }
uint32_t toUint32() const { return num; }
operator uint32_t() const { return num; }
const char* getChars() const { return fcc; }
char* getChars() { return fcc; }
bool IsValid() const { return num != 0; }
};
#define FOURCC(chars) FourCC(SBIG(chars))