summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt17
-rw-r--r--hscript/CMakeLists.txt15
-rw-r--r--hscript/script.cc27
-rw-r--r--hscript/script.hh8
-rw-r--r--tools/CMakeLists.txt1
-rw-r--r--tools/hscript-validate/CMakeLists.txt7
-rw-r--r--tools/hscript-validate/validator.cc0
7 files changed, 55 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f14aeb1..ac98dfb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,18 +10,5 @@ pkg_check_modules(LIBUDEV REQUIRED libudev)
pkg_check_modules(PARTED REQUIRED libparted)
find_library(BCNM_LIBRARY REQUIRED wpactrl PATH_SUFFIXES bcnm)
-set(HSCRIPT_SOURCE
- hscript/script.cc
-)
-
-set(HSCRIPT_INCLUDE
- hscript/script.hh
- hscript/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)
+add_subdirectory(hscript)
+add_subdirectory(tools)
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 <fstream>
+#include <iostream>
#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.
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644
index 0000000..4bf5423
--- /dev/null
+++ b/tools/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(hscript-validate)
diff --git a/tools/hscript-validate/CMakeLists.txt b/tools/hscript-validate/CMakeLists.txt
new file mode 100644
index 0000000..7ae6e52
--- /dev/null
+++ b/tools/hscript-validate/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(VALIDATE_SRCS
+ validator.cc
+)
+add_executable(hscript-validate ${VALIDATE_SRCS})
+target_link_libraries(hscript-validate hscript)
+
+install(TARGETS hscript-validate DESTINATION bin)
diff --git a/tools/hscript-validate/validator.cc b/tools/hscript-validate/validator.cc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/hscript-validate/validator.cc