diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-07 16:41:09 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-07 16:41:09 -0500 |
commit | e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0 (patch) | |
tree | d05a1e4b43acc9849a6350fe64cd9cd7e42d8a67 | |
parent | 6fe1d4ea7c32a7c20a40d9bc7887b5a7d665ed8c (diff) | |
download | horizon-e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0.tar.gz horizon-e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0.tar.bz2 horizon-e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0.tar.xz horizon-e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0.zip |
hscript: Define warning macro, count warnings/errors
-rw-r--r-- | hscript/script.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/hscript/script.cc b/hscript/script.cc index 0e72c81..487ea9b 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -60,20 +60,25 @@ bool is_key(std::string key) { } #define PARSER_ERROR(err_str) \ - any_error = true;\ + errors++;\ output_error("installfile:" + std::to_string(lineno),\ err_str, "", (opts.test(Pretty)));\ if(!opts.test(ScriptOptionFlags::KeepGoing)) {\ break;\ } +#define PARSER_WARNING(warn_str) \ + warnings++;\ + output_warning("installfile:" + std::to_string(lineno),\ + warn_str, "", (opts.test(Pretty))); + const Script *Script::load(std::istream &sstream, ScriptOptions opts) { Script *the_script = new Script; int lineno = 0; char nextline[LINE_MAX]; const std::string delim(" \t"); - bool any_error = false; + int errors = 0, warnings = 0; while(sstream.getline(nextline, sizeof(nextline))) { lineno++; @@ -99,19 +104,22 @@ const Script *Script::load(std::istream &sstream, ScriptOptions opts) { PARSER_ERROR("key '" + key + "' has no value") } - if(!is_key(line.substr(start, key_end))) { + if(!is_key(key)) { /* Invalid key */ if(opts.test(StrictMode)) { PARSER_ERROR("key '" + key + "' is not defined") } else { - output_warning("installfile:" + std::to_string(lineno), - "key '" + key + "' is not defined", "", - opts.test(Pretty)); + PARSER_WARNING("key '" + key + "' is not defined") } } } - if(any_error) { + output_message("parser", "0", "installfile", + std::to_string(errors) + " error(s), " + + std::to_string(warnings) + " warning(s).", + "", opts.test(Pretty)); + + if(errors > 0) { delete the_script; return nullptr; } |