From 65f70c4d29fb2ffc75aad2435ac6b03059bb6e80 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 6 Oct 2019 13:46:57 -0500 Subject: Add skeleton logic --- hscript/CMakeLists.txt | 15 +++++++++++++++ hscript/script.cc | 27 +++++++++++++++++++++++++-- hscript/script.hh | 8 +++++--- 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 hscript/CMakeLists.txt (limited to 'hscript') diff --git a/hscript/CMakeLists.txt b/hscript/CMakeLists.txt new file mode 100644 index 0000000..da5ce1b --- /dev/null +++ b/hscript/CMakeLists.txt @@ -0,0 +1,15 @@ +set(HSCRIPT_SOURCE + script.cc +) + +set(HSCRIPT_INCLUDE + script.hh + key.hh +) + +add_library(hscript SHARED ${HSCRIPT_SOURCE}) +target_compile_features(hscript PRIVATE cxx_nullptr) +target_compile_features(hscript PUBLIC cxx_unicode_literals) + +install(TARGETS hscript DESTINATION lib) +install(FILES ${HSCRIPT_INCLUDE} DESTINATION include/hscript) diff --git a/hscript/script.cc b/hscript/script.cc index 876efa4..748b09a 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -10,6 +10,8 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +#include +#include #include "script.hh" #include "disk.hh" #include "meta.hh" @@ -34,11 +36,32 @@ struct Script::ScriptPrivate { Script::Script() { } -const Script *Script::load(std::string, ScriptOptions) { - return nullptr; +const Script *Script::load(std::string path, ScriptOptions opts) { + std::ifstream file; + std::string maybe_error; + + file.exceptions(std::ios::badbit); + try { + file.open(path); + } catch(const std::ios::failure &error) { + maybe_error = error.what(); + } catch(const std::exception &error) { + maybe_error = error.what(); + } + if(!file) { + std::cerr << "Cannot open installfile at \"" << path << "\": "; + std::cerr << maybe_error; + std::cerr << std::endl; + return nullptr; + } + + return Script::load(file, opts); } const Script *Script::load(std::istream &, ScriptOptions) { + Script *foo = new Script; + delete foo; + std::cout << "loaded" << std::endl; return nullptr; } diff --git a/hscript/script.hh b/hscript/script.hh index a2c2551..1150e78 100644 --- a/hscript/script.hh +++ b/hscript/script.hh @@ -27,8 +27,10 @@ namespace Horizon { #define SCRIPT_USE_NETWORK 0x0002 /*! Treat warnings as errors. */ #define SCRIPT_STRICT_MODE 0x0004 -/*! This is an Installation Environment - validate more keys */ +/*! This is an Installation Environment - validate more keys. */ #define SCRIPT_INSTALL_ENV 0x0008 +/*! "Pretty" output - used in interactive tooling only. */ +#define SCRIPT_PRETTY 0x0010 typedef uint32_t ScriptOptions; @@ -36,10 +38,10 @@ typedef uint32_t ScriptOptions; /*! Defines the Script class, which represents a HorizonScript. */ class Script { -public: +private: /*! Initialise the Script class. */ Script(); - +public: /*! Load a HorizonScript from the specified path. * @param path The path to load from. * @param options Options to use for parsing, validation, and execution. -- cgit v1.2.3-70-g09d2