mirror of https://github.com/AxioDL/metaforce.git
Removed exceptions
This commit is contained in:
parent
21b4fe88f7
commit
1c358b74a1
|
@ -1,9 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(hecl)
|
||||
if(WIN32)
|
||||
if(MSVC)
|
||||
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D_CRT_SECURE_NO_WARNINGS=1 /wd4267 /wd4244)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-multichar")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-multichar -fno-exceptions")
|
||||
endif()
|
||||
set(HECL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
set(ATHENA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/Athena/include)
|
||||
|
@ -11,7 +11,7 @@ set(LOG_VISOR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/LogVisor/include)
|
|||
set(ANGELSCRIPT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/AngelScript/angelscript/include)
|
||||
set(LIBPNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libpng)
|
||||
set(SQUISH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libSquish)
|
||||
add_definitions(-DAS_USE_NAMESPACE=1)
|
||||
add_definitions(-DAS_USE_NAMESPACE=1 -DAS_NO_EXCEPTIONS=1)
|
||||
add_subdirectory(extern)
|
||||
include_directories(include ${LOG_VISOR_INCLUDE_DIR} ${ATHENA_INCLUDE_DIR} ${ANGELSCRIPT_INCLUDE_DIR})
|
||||
add_subdirectory(lib)
|
||||
|
|
|
@ -25,11 +25,11 @@ namespace Retro
|
|||
extern HECL::Database::DataSpecEntry SpecEntMP3;
|
||||
}
|
||||
|
||||
/* An overzealous optimizing compiler may not init the specs if
|
||||
/* An overzealous optimizing compiler/linker may not init the specs if
|
||||
* there's no in-code reference.. this is a simple hack to solve that */
|
||||
extern "C" void HECLDataSpecs()
|
||||
{
|
||||
HECL::Printf(Retro::SpecEntMP1.m_name);
|
||||
HECL::Printf(Retro::SpecEntMP2.m_name);
|
||||
HECL::Printf(Retro::SpecEntMP3.m_name);
|
||||
HECL::Printf(_S("%s\n"), Retro::SpecEntMP1.m_name);
|
||||
HECL::Printf(_S("%s\n"), Retro::SpecEntMP2.m_name);
|
||||
HECL::Printf(_S("%s\n"), Retro::SpecEntMP3.m_name);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
|
|||
{
|
||||
if (readBytes >= bufSz)
|
||||
{
|
||||
throw std::length_error("Pipe buffer overrun");
|
||||
Log.report(LogVisor::FatalError, "Pipe buffer overrun\n");
|
||||
*(buf-1) = '\0';
|
||||
return bufSz - 1;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
|
|||
}
|
||||
}
|
||||
err:
|
||||
throw std::error_code(errno, std::system_category());
|
||||
Log.report(LogVisor::FatalError, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,8 @@ size_t BlenderConnection::_writeLine(const char* buf)
|
|||
#endif
|
||||
return (size_t)ret;
|
||||
err:
|
||||
throw std::error_code(errno, std::system_category());
|
||||
Log.report(LogVisor::FatalError, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t BlenderConnection::_readBuf(char* buf, size_t len)
|
||||
|
@ -97,7 +98,7 @@ size_t BlenderConnection::_readBuf(char* buf, size_t len)
|
|||
#endif
|
||||
return ret;
|
||||
err:
|
||||
throw std::error_code(errno, std::system_category());
|
||||
Log.report(LogVisor::FatalError, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -114,7 +115,7 @@ size_t BlenderConnection::_writeBuf(const char* buf, size_t len)
|
|||
#endif
|
||||
return ret;
|
||||
err:
|
||||
throw std::error_code(errno, std::system_category());
|
||||
Log.report(LogVisor::FatalError, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -312,9 +313,8 @@ bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter,
|
|||
_readLine(lineBuf, sizeof(lineBuf));
|
||||
if (strcmp(expectedType.c_str(), lineBuf))
|
||||
{
|
||||
throw std::runtime_error("expected '" + m_loadedBlend +
|
||||
"' to contain " + expectedType +
|
||||
" not " + lineBuf);
|
||||
Log.report(LogVisor::Error, "expected '%s' to contain '%s' not '%s'",
|
||||
m_loadedBlend.c_str(), expectedType.c_str(), lineBuf);
|
||||
return false;
|
||||
}
|
||||
_writeLine("ACK");
|
||||
|
@ -331,7 +331,7 @@ bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter,
|
|||
if (!strcmp("SUCCESS", lineBuf))
|
||||
return true;
|
||||
else if (!strcmp("EXCEPTION", lineBuf))
|
||||
throw std::runtime_error("blender script exception");
|
||||
Log.report(LogVisor::FatalError, "blender script exception");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -30,12 +30,14 @@ class ToolBase
|
|||
{
|
||||
protected:
|
||||
const ToolPassInfo& m_info;
|
||||
bool m_good = false;
|
||||
public:
|
||||
ToolBase(const ToolPassInfo& info)
|
||||
: m_info(info) {}
|
||||
virtual ~ToolBase() {}
|
||||
virtual HECL::SystemString toolName() const=0;
|
||||
virtual int run()=0;
|
||||
inline operator bool() const {return m_good;}
|
||||
};
|
||||
|
||||
#define RED "\033[0;31m"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "ToolBase.hpp"
|
||||
#include <stdio.h>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
|
||||
class ToolHelp final : public ToolBase
|
||||
|
@ -15,7 +14,11 @@ public:
|
|||
: ToolBase(info)
|
||||
{
|
||||
if (m_info.args.empty())
|
||||
LogModule.report(LogVisor::FatalError, "help requires a tool name argument");
|
||||
{
|
||||
LogModule.report(LogVisor::Error, "help requires a tool name argument");
|
||||
return;
|
||||
}
|
||||
m_good = true;
|
||||
}
|
||||
|
||||
~ToolHelp()
|
||||
|
@ -27,20 +30,20 @@ public:
|
|||
static void Help(HelpOutput& help)
|
||||
{
|
||||
help.printBold(
|
||||
_S("................................___________ \n")
|
||||
_S("...........................,.-'\"...........``~., \n")
|
||||
_S("........................,.-\".......................\"-., \n")
|
||||
_S("....................,/..................................\":, \n")
|
||||
_S("..................,?........................................, \n")
|
||||
_S("................/...........................................,}\n")
|
||||
_S("............../........................................,:`^`..}\n")
|
||||
_S("............./.......................................,:\"...../\n")
|
||||
_S("............?.....__..................................:`...../\n")
|
||||
_S(".........../__.(...\"~-,_...........................,:`....../\n")
|
||||
_S("........../(_....\"~,_....\"~,_.....................,:`...._/ \n")
|
||||
_S("..........{.._$;_....\"=,_.....\"-,_......,.-~-,},.~\";/....} \n")
|
||||
_S("...........((...*~_......\"=-._...\";,,./`........../\"..../ \n")
|
||||
_S("...,,,___.`~,......\"~.,....................`......}....../ \n")
|
||||
_S(" ___________ \n")
|
||||
_S(" ,.-'\"...........``~., \n")
|
||||
_S(" ,.-\".......................\"-., \n")
|
||||
_S(" ,/..................................\":, \n")
|
||||
_S(" .,?........................................, \n")
|
||||
_S(" /...........................................,}\n")
|
||||
_S(" ./........................................,:`^`..}\n")
|
||||
_S(" ./.......................................,:\"...../\n")
|
||||
_S(" ?.....__..................................:`...../\n")
|
||||
_S(" /__.(...\"~-,_...........................,:`....../\n")
|
||||
_S(" /(_....\"~,_....\"~,_.....................,:`...._/ \n")
|
||||
_S(" {.._$;_....\"=,_.....\"-,_......,.-~-,},.~\";/....} \n")
|
||||
_S(" ((...*~_......\"=-._...\";,,./`........../\"..../ \n")
|
||||
_S(" ,,,___.`~,......\"~.,....................`......}....../ \n")
|
||||
_S("............(....`=-,,...`.........................(...;_,,-\" \n")
|
||||
_S("............/.`~,......`-.................................../ \n")
|
||||
_S(".............`~.*-,.....................................|,./...,__ \n")
|
||||
|
@ -79,7 +82,7 @@ public:
|
|||
helpFunc = ToolHelp::Help;
|
||||
else
|
||||
{
|
||||
LogModule.report(LogVisor::FatalError, _S("unrecognized tool '%s' - can't help"), toolName.c_str());
|
||||
LogModule.report(LogVisor::Error, _S("unrecognized tool '%s' - can't help"), toolName.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,16 +43,11 @@ public:
|
|||
{
|
||||
if (!m_dir)
|
||||
return -1;
|
||||
try
|
||||
{
|
||||
size_t ErrorRef = LogVisor::ErrorCount;
|
||||
HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir)));
|
||||
proj.enableDataSpecs({_S("hecl-little")});
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LogModule.report(LogVisor::Error, "unable to init project: %s", e.what());
|
||||
if (LogVisor::ErrorCount > ErrorRef)
|
||||
return -1;
|
||||
}
|
||||
LogModule.report(LogVisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str());
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <regex>
|
||||
#include <stdexcept>
|
||||
#include <list>
|
||||
#include "HECL/Database.hpp"
|
||||
#include "LogVisor/LogVisor.hpp"
|
||||
|
@ -66,19 +66,44 @@ static const HECL::SystemRegex regFORCE(_S("-f"), std::regex::ECMAScript|std::re
|
|||
|
||||
#include "../blender/BlenderConnection.hpp"
|
||||
|
||||
static LogVisor::LogModule AthenaLog("Athena");
|
||||
static void AthenaExc(const Athena::error::Level& level, const char* file,
|
||||
const char*, int line, const char* fmt, ...)
|
||||
{
|
||||
LogVisor::Level vLevel = LogVisor::Info;
|
||||
switch (level)
|
||||
{
|
||||
case Athena::error::MESSAGE:
|
||||
vLevel = LogVisor::Info;
|
||||
break;
|
||||
case Athena::error::WARNING:
|
||||
vLevel = LogVisor::Warning;
|
||||
break;
|
||||
case Athena::error::ERROR:
|
||||
vLevel = LogVisor::Error;
|
||||
break;
|
||||
case Athena::error::FATAL:
|
||||
vLevel = LogVisor::FatalError;
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
AthenaLog.reportSource(vLevel, file, line, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#if HECL_UCS2
|
||||
int wmain(int argc, const wchar_t** argv)
|
||||
#else
|
||||
int main(int argc, const char** argv)
|
||||
#endif
|
||||
{
|
||||
//dummy();
|
||||
/* Xterm check */
|
||||
const char* term = getenv("TERM");
|
||||
if (term && !strncmp(term, "xterm", 5))
|
||||
XTERM_COLOR = true;
|
||||
|
||||
LogVisor::RegisterConsoleLogger();
|
||||
atSetExceptionHandler(AthenaExc);
|
||||
|
||||
//CBlenderConnection bconn(false);
|
||||
//return 0;
|
||||
|
@ -181,29 +206,26 @@ int main(int argc, const char** argv)
|
|||
std::unique_ptr<HECL::Database::Project> project;
|
||||
if (rootPath.get())
|
||||
{
|
||||
try
|
||||
size_t ErrorRef = LogVisor::ErrorCount;
|
||||
HECL::Database::Project* newProj = new HECL::Database::Project(*rootPath);
|
||||
if (LogVisor::ErrorCount > ErrorRef)
|
||||
{
|
||||
project.reset(new HECL::Database::Project(*rootPath));
|
||||
info.project = project.get();
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
LogModule.report(LogVisor::Error,
|
||||
_S("Unable to open discovered project at '%s'"),
|
||||
rootPath->getAbsolutePath().c_str());
|
||||
#if WIN_PAUSE
|
||||
system("PAUSE");
|
||||
#endif
|
||||
delete newProj;
|
||||
return -1;
|
||||
}
|
||||
project.reset(newProj);
|
||||
info.project = newProj;
|
||||
}
|
||||
|
||||
/* Construct selected tool */
|
||||
HECL::SystemString toolName(argv[1]);
|
||||
HECL::ToLower(toolName);
|
||||
std::unique_ptr<ToolBase> tool;
|
||||
try
|
||||
{
|
||||
|
||||
size_t ErrorRef = LogVisor::ErrorCount;
|
||||
if (toolName == _S("init"))
|
||||
tool.reset(new ToolInit(info));
|
||||
else if (toolName == _S("spec"))
|
||||
|
@ -225,17 +247,9 @@ int main(int argc, const char** argv)
|
|||
else if (toolName == _S("help"))
|
||||
tool.reset(new ToolHelp(info));
|
||||
else
|
||||
LogModule.report(LogVisor::FatalError, _S("unrecognized tool '%s'"), toolName.c_str());
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
LogModule.report(LogVisor::Error, _S("unrecognized tool '%s'"), toolName.c_str());
|
||||
if (LogVisor::ErrorCount > ErrorRef)
|
||||
{
|
||||
#if HECL_UCS2
|
||||
LogModule.report(LogVisor::Error, _S("Unable to construct HECL tool '%s': %S"),
|
||||
toolName.c_str(), ex.what());
|
||||
#else
|
||||
LogModule.report(LogVisor::Error, _S("Unable to construct HECL tool '%s': %s"),
|
||||
toolName.c_str(), ex.what());
|
||||
#endif
|
||||
#if WIN_PAUSE
|
||||
system("PAUSE");
|
||||
#endif
|
||||
|
@ -247,20 +261,10 @@ int main(int argc, const char** argv)
|
|||
tool->toolName().c_str(), info.verbosityLevel);
|
||||
|
||||
/* Run tool */
|
||||
int retval;
|
||||
try
|
||||
ErrorRef = LogVisor::ErrorCount;
|
||||
int retval = tool->run();
|
||||
if (LogVisor::ErrorCount > ErrorRef)
|
||||
{
|
||||
retval = tool->run();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
#if HECL_UCS2
|
||||
LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s': %S"),
|
||||
toolName.c_str(), ex.what());
|
||||
#else
|
||||
LogModule.report(LogVisor::Error, _S("Error running HECL tool '%s': %s"),
|
||||
toolName.c_str(), ex.what());
|
||||
#endif
|
||||
#if WIN_PAUSE
|
||||
system("PAUSE");
|
||||
#endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4a688a1c33b7e11a505e821476296a5c3813f1a3
|
||||
Subproject commit 99b6df7cc1192f95f64acb531bf6ab7ea2cdabeb
|
|
@ -1 +1 @@
|
|||
Subproject commit 085920205b71a0a5a9bf710de5794cc136051b2d
|
||||
Subproject commit c61ff288b90a6b4c833d01f62196eb0534bf2860
|
|
@ -1 +1 @@
|
|||
Subproject commit c526c7df855ddc1e403d70ae98d5e3d6f4d5a095
|
||||
Subproject commit a517adcb010c5edca1c63d48d1a920c4d6882d81
|
|
@ -11,7 +11,6 @@
|
|||
#include <unordered_set>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <regex>
|
||||
|
@ -129,11 +128,11 @@ static inline void MakeDir(const SystemString& dir)
|
|||
HRESULT err;
|
||||
if (!CreateDirectory(dir.c_str(), NULL))
|
||||
if ((err = GetLastError()) != ERROR_ALREADY_EXISTS)
|
||||
throw std::error_code(err, std::system_category());
|
||||
LogModule.report(LogVisor::FatalError, _S("MakeDir: %s"), dir.c_str());
|
||||
#else
|
||||
if (mkdir(dir.c_str(), 0755))
|
||||
if (errno != EEXIST)
|
||||
throw std::error_code(errno, std::system_category());
|
||||
LogModule.report(LogVisor::FatalError, "MakeDir %s: %s", dir.c_str(), strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -160,7 +159,7 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
|
|||
FILE* fp = fopen(path, mode);
|
||||
#endif
|
||||
if (!fp)
|
||||
throw std::error_code(errno, std::system_category());
|
||||
LogModule.report(LogVisor::FatalError, "fopen %s: %s", path, strerror(errno));
|
||||
|
||||
if (lock)
|
||||
{
|
||||
|
@ -169,7 +168,7 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
|
|||
LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == LWRITE) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov);
|
||||
#else
|
||||
if (flock(fileno(fp), ((lock == LWRITE) ? LOCK_EX : LOCK_SH) | LOCK_NB))
|
||||
throw std::error_code(errno, std::system_category());
|
||||
LogModule.report(LogVisor::FatalError, "flock %s: %s", path, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -207,11 +207,16 @@ Project::Project(const ProjectRootPath& rootPath)
|
|||
/* Stat for existing project directory (must already exist) */
|
||||
Sstat myStat;
|
||||
if (HECL::Stat(m_rootPath.getAbsolutePath().c_str(), &myStat))
|
||||
throw std::error_code(errno, std::system_category());
|
||||
{
|
||||
LogModule.report(LogVisor::Error, _S("unable to stat %s"), m_rootPath.getAbsolutePath().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!S_ISDIR(myStat.st_mode))
|
||||
throw std::invalid_argument("provided path must be a directory; '" +
|
||||
m_rootPath.getAbsolutePathUTF8() + "' isn't");
|
||||
{
|
||||
LogModule.report(LogVisor::Error, _S("provided path must be a directory; '%s' isn't"), m_rootPath.getAbsolutePath().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create project directory structure */
|
||||
m_dotPath.makeDir();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "HECL/HECL.hpp"
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
|
||||
namespace HECL
|
||||
|
@ -14,7 +13,7 @@ static SystemString canonRelPath(const SystemString& path)
|
|||
/* Absolute paths not allowed */
|
||||
if (path[0] == _S('/') || path[0] == _S('\\'))
|
||||
{
|
||||
throw std::invalid_argument("Absolute path provided; expected relative: " + path);
|
||||
LogModule.report(LogVisor::Error, "Absolute path provided; expected relative: %s", path.c_str());
|
||||
return _S(".");
|
||||
}
|
||||
|
||||
|
@ -32,8 +31,7 @@ static SystemString canonRelPath(const SystemString& path)
|
|||
if (comps.empty())
|
||||
{
|
||||
/* Unable to resolve outside project */
|
||||
SystemUTF8View pathView(path);
|
||||
throw std::invalid_argument("Unable to resolve outside project root in " + pathView);
|
||||
LogModule.report(LogVisor::Error, _S("Unable to resolve outside project root in %s"), path.c_str());
|
||||
return _S(".");
|
||||
}
|
||||
comps.pop_back();
|
||||
|
@ -171,7 +169,10 @@ static void _recursiveGlob(std::vector<SystemString>& outPaths,
|
|||
#else
|
||||
DIR* dir = opendir(itStr.c_str());
|
||||
if (!dir)
|
||||
throw std::runtime_error("unable to open directory for traversal at '" + itStr + "'");
|
||||
{
|
||||
LogModule.report(LogVisor::Error, "unable to open directory for traversal at '%s'", itStr.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent* de;
|
||||
while ((de = readdir(dir)))
|
||||
|
|
Loading…
Reference in New Issue