From e9df07a02ba5af1ebb2872aea2dd73282d6ac6c0 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Mon, 7 Oct 2019 16:41:09 -0500 Subject: hscript: Define warning macro, count warnings/errors --- hscript/script.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'hscript/script.cc') 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; } -- cgit v1.2.3-60-g2f50