diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-07-10 15:05:28 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-07-10 15:05:28 -0500 |
commit | 5a9f15cd47f438210b56cd9389257ed5320f2ad7 (patch) | |
tree | 5d8bee7cb7b2b98c288d06e08fde5a62b9576469 /hscript | |
parent | 69b86bd6b2cdfe99b61af19c067430aad9668554 (diff) | |
download | horizon-5a9f15cd47f438210b56cd9389257ed5320f2ad7.tar.gz horizon-5a9f15cd47f438210b56cd9389257ed5320f2ad7.tar.bz2 horizon-5a9f15cd47f438210b56cd9389257ed5320f2ad7.tar.xz horizon-5a9f15cd47f438210b56cd9389257ed5320f2ad7.zip |
hscript: Use curr_name; work around Alpine bug
On some Alpine systems, '/dev/stdin' cannot be canonicalised. We work
around this by hardcoding "<stdin>" as the internal name for scripts
read from stdin, similar to Python.
This change also ensures messages generated from the parser itself use
curr_name (the canonicalised name) instead of the name passed to the
Script object.
Diffstat (limited to 'hscript')
-rw-r--r-- | hscript/script.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/hscript/script.cc b/hscript/script.cc index 20ccbe5..6e436b7 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -225,7 +225,12 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, char nextline[SCRIPT_LINE_MAX]; const std::string delim(" \t"); int errors = 0, warnings = 0; - std::string curr_name = fs::canonical(fs::path(name)); + std::string curr_name; + if(name == "/dev/stdin") { + curr_name = "<stdin>"; + } else { + curr_name = fs::canonical(fs::path(name)); + } std::set<std::string> seen = {curr_name}; bool inherit = false; std::istream *my_stream = &sstream; @@ -311,7 +316,7 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } if(my_stream->fail() && !my_stream->eof()) { - output_error("installfile:" + std::to_string(lineno + 1), + output_error(curr_name + ":" + std::to_string(lineno + 1), "line exceeds maximum length", "Maximum line length is " + std::to_string(SCRIPT_LINE_MAX)); @@ -319,14 +324,14 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } if(my_stream->bad() && !my_stream->eof()) { - output_error("installfile:" + std::to_string(lineno), + output_error(curr_name + ":" + std::to_string(lineno), "I/O error while reading installfile", ""); errors++; } /* Ensure all required keys are present. */ #define MISSING_ERROR(key) \ - output_error(name, "expected value for key '" + std::string(key) + "'",\ + output_error(curr_name, "expected value for key '" + std::string(key) + "'",\ "this key is required");\ errors++; @@ -349,7 +354,7 @@ Script *Script::load(std::istream &sstream, const ScriptOptions &opts, } #undef MISSING_ERROR - output_log("parser", "0", name, + output_log("parser", "0", curr_name, std::to_string(errors) + " error(s), " + std::to_string(warnings) + " warning(s).", ""); |