Removed exceptions

This commit is contained in:
Jack Andersen 2015-07-25 16:52:02 -10:00
parent 21b4fe88f7
commit 1c358b74a1
14 changed files with 124 additions and 116 deletions

View File

@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(hecl) project(hecl)
if(WIN32) if(MSVC)
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D_CRT_SECURE_NO_WARNINGS=1 /wd4267 /wd4244) add_definitions(-DUNICODE=1 -D_UNICODE=1 -D_CRT_SECURE_NO_WARNINGS=1 /wd4267 /wd4244)
else() 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() endif()
set(HECL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) set(HECL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(ATHENA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/Athena/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(ANGELSCRIPT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/AngelScript/angelscript/include)
set(LIBPNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libpng) set(LIBPNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libpng)
set(SQUISH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/libSquish) 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) add_subdirectory(extern)
include_directories(include ${LOG_VISOR_INCLUDE_DIR} ${ATHENA_INCLUDE_DIR} ${ANGELSCRIPT_INCLUDE_DIR}) include_directories(include ${LOG_VISOR_INCLUDE_DIR} ${ATHENA_INCLUDE_DIR} ${ANGELSCRIPT_INCLUDE_DIR})
add_subdirectory(lib) add_subdirectory(lib)

View File

@ -25,11 +25,11 @@ namespace Retro
extern HECL::Database::DataSpecEntry SpecEntMP3; 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 */ * there's no in-code reference.. this is a simple hack to solve that */
extern "C" void HECLDataSpecs() extern "C" void HECLDataSpecs()
{ {
HECL::Printf(Retro::SpecEntMP1.m_name); HECL::Printf(_S("%s\n"), Retro::SpecEntMP1.m_name);
HECL::Printf(Retro::SpecEntMP2.m_name); HECL::Printf(_S("%s\n"), Retro::SpecEntMP2.m_name);
HECL::Printf(Retro::SpecEntMP3.m_name); HECL::Printf(_S("%s\n"), Retro::SpecEntMP3.m_name);
} }

View File

@ -28,7 +28,7 @@ size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
{ {
if (readBytes >= bufSz) if (readBytes >= bufSz)
{ {
throw std::length_error("Pipe buffer overrun"); Log.report(LogVisor::FatalError, "Pipe buffer overrun\n");
*(buf-1) = '\0'; *(buf-1) = '\0';
return bufSz - 1; return bufSz - 1;
} }
@ -58,7 +58,7 @@ size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
} }
} }
err: err:
throw std::error_code(errno, std::system_category()); Log.report(LogVisor::FatalError, strerror(errno));
return 0; return 0;
} }
@ -81,7 +81,8 @@ size_t BlenderConnection::_writeLine(const char* buf)
#endif #endif
return (size_t)ret; return (size_t)ret;
err: 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) size_t BlenderConnection::_readBuf(char* buf, size_t len)
@ -97,7 +98,7 @@ size_t BlenderConnection::_readBuf(char* buf, size_t len)
#endif #endif
return ret; return ret;
err: err:
throw std::error_code(errno, std::system_category()); Log.report(LogVisor::FatalError, strerror(errno));
return 0; return 0;
} }
@ -114,7 +115,7 @@ size_t BlenderConnection::_writeBuf(const char* buf, size_t len)
#endif #endif
return ret; return ret;
err: err:
throw std::error_code(errno, std::system_category()); Log.report(LogVisor::FatalError, strerror(errno));
return 0; return 0;
} }
@ -312,9 +313,8 @@ bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter,
_readLine(lineBuf, sizeof(lineBuf)); _readLine(lineBuf, sizeof(lineBuf));
if (strcmp(expectedType.c_str(), lineBuf)) if (strcmp(expectedType.c_str(), lineBuf))
{ {
throw std::runtime_error("expected '" + m_loadedBlend + Log.report(LogVisor::Error, "expected '%s' to contain '%s' not '%s'",
"' to contain " + expectedType + m_loadedBlend.c_str(), expectedType.c_str(), lineBuf);
" not " + lineBuf);
return false; return false;
} }
_writeLine("ACK"); _writeLine("ACK");
@ -331,7 +331,7 @@ bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter,
if (!strcmp("SUCCESS", lineBuf)) if (!strcmp("SUCCESS", lineBuf))
return true; return true;
else if (!strcmp("EXCEPTION", lineBuf)) else if (!strcmp("EXCEPTION", lineBuf))
throw std::runtime_error("blender script exception"); Log.report(LogVisor::FatalError, "blender script exception");
return false; return false;
} }

View File

@ -30,12 +30,14 @@ class ToolBase
{ {
protected: protected:
const ToolPassInfo& m_info; const ToolPassInfo& m_info;
bool m_good = false;
public: public:
ToolBase(const ToolPassInfo& info) ToolBase(const ToolPassInfo& info)
: m_info(info) {} : m_info(info) {}
virtual ~ToolBase() {} virtual ~ToolBase() {}
virtual HECL::SystemString toolName() const=0; virtual HECL::SystemString toolName() const=0;
virtual int run()=0; virtual int run()=0;
inline operator bool() const {return m_good;}
}; };
#define RED "\033[0;31m" #define RED "\033[0;31m"

View File

@ -3,7 +3,6 @@
#include "ToolBase.hpp" #include "ToolBase.hpp"
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
#include <functional> #include <functional>
class ToolHelp final : public ToolBase class ToolHelp final : public ToolBase
@ -15,7 +14,11 @@ public:
: ToolBase(info) : ToolBase(info)
{ {
if (m_info.args.empty()) 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() ~ToolHelp()
@ -27,20 +30,20 @@ public:
static void Help(HelpOutput& help) static void Help(HelpOutput& help)
{ {
help.printBold( 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") _S("............/.`~,......`-.................................../ \n")
_S(".............`~.*-,.....................................|,./...,__ \n") _S(".............`~.*-,.....................................|,./...,__ \n")
@ -79,7 +82,7 @@ public:
helpFunc = ToolHelp::Help; helpFunc = ToolHelp::Help;
else 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; return;
} }

View File

@ -43,16 +43,11 @@ public:
{ {
if (!m_dir) if (!m_dir)
return -1; return -1;
try size_t ErrorRef = LogVisor::ErrorCount;
{ HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir)));
HECL::Database::Project proj((HECL::ProjectRootPath(*m_dir))); proj.enableDataSpecs({_S("hecl-little")});
proj.enableDataSpecs({_S("hecl-little")}); if (LogVisor::ErrorCount > ErrorRef)
}
catch (std::exception& e)
{
LogModule.report(LogVisor::Error, "unable to init project: %s", e.what());
return -1; return -1;
}
LogModule.report(LogVisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str()); LogModule.report(LogVisor::Info, _S("initialized project at '%s/.hecl'"), m_dir->c_str());
return 0; return 0;
} }

View File

@ -5,8 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <regex> #include <regex>
#include <stdexcept>
#include <list> #include <list>
#include "HECL/Database.hpp" #include "HECL/Database.hpp"
#include "LogVisor/LogVisor.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" #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 #if HECL_UCS2
int wmain(int argc, const wchar_t** argv) int wmain(int argc, const wchar_t** argv)
#else #else
int main(int argc, const char** argv) int main(int argc, const char** argv)
#endif #endif
{ {
//dummy();
/* Xterm check */ /* Xterm check */
const char* term = getenv("TERM"); const char* term = getenv("TERM");
if (term && !strncmp(term, "xterm", 5)) if (term && !strncmp(term, "xterm", 5))
XTERM_COLOR = true; XTERM_COLOR = true;
LogVisor::RegisterConsoleLogger(); LogVisor::RegisterConsoleLogger();
atSetExceptionHandler(AthenaExc);
//CBlenderConnection bconn(false); //CBlenderConnection bconn(false);
//return 0; //return 0;
@ -181,61 +206,50 @@ int main(int argc, const char** argv)
std::unique_ptr<HECL::Database::Project> project; std::unique_ptr<HECL::Database::Project> project;
if (rootPath.get()) 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 #if WIN_PAUSE
system("PAUSE"); system("PAUSE");
#endif #endif
delete newProj;
return -1; return -1;
} }
project.reset(newProj);
info.project = newProj;
} }
/* Construct selected tool */ /* Construct selected tool */
HECL::SystemString toolName(argv[1]); HECL::SystemString toolName(argv[1]);
HECL::ToLower(toolName); HECL::ToLower(toolName);
std::unique_ptr<ToolBase> tool; 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"))
tool.reset(new ToolSpec(info));
else if (toolName == _S("extract"))
tool.reset(new ToolExtract(info));
else if (toolName == _S("add"))
tool.reset(new ToolAdd(info));
else if (toolName == _S("remove") || toolName == _S("rm"))
tool.reset(new ToolRemove(info));
else if (toolName == _S("group"))
tool.reset(new ToolGroup(info));
else if (toolName == _S("cook"))
tool.reset(new ToolCook(info));
else if (toolName == _S("clean"))
tool.reset(new ToolClean(info));
else if (toolName == _S("package") || toolName == _S("pack"))
tool.reset(new ToolPackage(info));
else if (toolName == _S("help"))
tool.reset(new ToolHelp(info));
else
LogModule.report(LogVisor::Error, _S("unrecognized tool '%s'"), toolName.c_str());
if (LogVisor::ErrorCount > ErrorRef)
{ {
if (toolName == _S("init"))
tool.reset(new ToolInit(info));
else if (toolName == _S("spec"))
tool.reset(new ToolSpec(info));
else if (toolName == _S("extract"))
tool.reset(new ToolExtract(info));
else if (toolName == _S("add"))
tool.reset(new ToolAdd(info));
else if (toolName == _S("remove") || toolName == _S("rm"))
tool.reset(new ToolRemove(info));
else if (toolName == _S("group"))
tool.reset(new ToolGroup(info));
else if (toolName == _S("cook"))
tool.reset(new ToolCook(info));
else if (toolName == _S("clean"))
tool.reset(new ToolClean(info));
else if (toolName == _S("package") || toolName == _S("pack"))
tool.reset(new ToolPackage(info));
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)
{
#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 #if WIN_PAUSE
system("PAUSE"); system("PAUSE");
#endif #endif
@ -247,20 +261,10 @@ int main(int argc, const char** argv)
tool->toolName().c_str(), info.verbosityLevel); tool->toolName().c_str(), info.verbosityLevel);
/* Run tool */ /* Run tool */
int retval; ErrorRef = LogVisor::ErrorCount;
try 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 #if WIN_PAUSE
system("PAUSE"); system("PAUSE");
#endif #endif

2
hecl/extern/Athena vendored

@ -1 +1 @@
Subproject commit 4a688a1c33b7e11a505e821476296a5c3813f1a3 Subproject commit 99b6df7cc1192f95f64acb531bf6ab7ea2cdabeb

@ -1 +1 @@
Subproject commit 085920205b71a0a5a9bf710de5794cc136051b2d Subproject commit c61ff288b90a6b4c833d01f62196eb0534bf2860

@ -1 +1 @@
Subproject commit c526c7df855ddc1e403d70ae98d5e3d6f4d5a095 Subproject commit a517adcb010c5edca1c63d48d1a920c4d6882d81

View File

@ -11,7 +11,6 @@
#include <unordered_set> #include <unordered_set>
#include <memory> #include <memory>
#include <atomic> #include <atomic>
#include <stdexcept>
#include <fstream> #include <fstream>
#include <stdint.h> #include <stdint.h>
#include <assert.h> #include <assert.h>

View File

@ -21,7 +21,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <functional> #include <functional>
#include <stdexcept>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
@ -129,11 +128,11 @@ static inline void MakeDir(const SystemString& dir)
HRESULT err; HRESULT err;
if (!CreateDirectory(dir.c_str(), NULL)) if (!CreateDirectory(dir.c_str(), NULL))
if ((err = GetLastError()) != ERROR_ALREADY_EXISTS) 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 #else
if (mkdir(dir.c_str(), 0755)) if (mkdir(dir.c_str(), 0755))
if (errno != EEXIST) if (errno != EEXIST)
throw std::error_code(errno, std::system_category()); LogModule.report(LogVisor::FatalError, "MakeDir %s: %s", dir.c_str(), strerror(errno));
#endif #endif
} }
@ -160,7 +159,7 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
FILE* fp = fopen(path, mode); FILE* fp = fopen(path, mode);
#endif #endif
if (!fp) if (!fp)
throw std::error_code(errno, std::system_category()); LogModule.report(LogVisor::FatalError, "fopen %s: %s", path, strerror(errno));
if (lock) 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); LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == LWRITE) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov);
#else #else
if (flock(fileno(fp), ((lock == LWRITE) ? LOCK_EX : LOCK_SH) | LOCK_NB)) 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 #endif
} }

View File

@ -207,11 +207,16 @@ Project::Project(const ProjectRootPath& rootPath)
/* Stat for existing project directory (must already exist) */ /* Stat for existing project directory (must already exist) */
Sstat myStat; Sstat myStat;
if (HECL::Stat(m_rootPath.getAbsolutePath().c_str(), &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)) 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 */ /* Create project directory structure */
m_dotPath.makeDir(); m_dotPath.makeDir();

View File

@ -1,5 +1,4 @@
#include "HECL/HECL.hpp" #include "HECL/HECL.hpp"
#include <stdexcept>
#include <regex> #include <regex>
namespace HECL namespace HECL
@ -14,7 +13,7 @@ static SystemString canonRelPath(const SystemString& path)
/* Absolute paths not allowed */ /* Absolute paths not allowed */
if (path[0] == _S('/') || path[0] == _S('\\')) 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("."); return _S(".");
} }
@ -32,8 +31,7 @@ static SystemString canonRelPath(const SystemString& path)
if (comps.empty()) if (comps.empty())
{ {
/* Unable to resolve outside project */ /* Unable to resolve outside project */
SystemUTF8View pathView(path); LogModule.report(LogVisor::Error, _S("Unable to resolve outside project root in %s"), path.c_str());
throw std::invalid_argument("Unable to resolve outside project root in " + pathView);
return _S("."); return _S(".");
} }
comps.pop_back(); comps.pop_back();
@ -171,7 +169,10 @@ static void _recursiveGlob(std::vector<SystemString>& outPaths,
#else #else
DIR* dir = opendir(itStr.c_str()); DIR* dir = opendir(itStr.c_str());
if (!dir) 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; struct dirent* de;
while ((de = readdir(dir))) while ((de = readdir(dir)))