From 177cea995d02fd14dd82fa010957ebfbc1c5e760 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 17 Jul 2009 13:02:45 +0000 Subject: More work on the macrotool. Now fieldnames can be added and deleted, and a filehandler is able to add new macros assuring no conflicts in macro names/version/filenames happen. Error messages in MacroParser has been made more elaborate. --- server/src/macroparser.cc | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'server/src/macroparser.cc') diff --git a/server/src/macroparser.cc b/server/src/macroparser.cc index c5b524d..0f7ed76 100644 --- a/server/src/macroparser.cc +++ b/server/src/macroparser.cc @@ -28,6 +28,8 @@ #include "macroparser.h" #include "configuration.h" +#include + // For assert #include @@ -56,24 +58,37 @@ void MacroParser::error(const char* fmt, ...) PRACRO_ERR_LOG(macro, "Error in MacroParser: "); - va_list argp; - va_start(argp, fmt); - PRACRO_ERR_LOG_VA(macro, fmt, argp); - va_end(argp); + { + va_list argp; + va_start(argp, fmt); + PRACRO_ERR_LOG_VA(macro, fmt, argp); + va_end(argp); + + fprintf(stderr, "\n"); + } - fprintf(stderr, "\n"); + { + char *p; + va_list argp; + va_start(argp, fmt); + if(vasprintf(&p, fmt, argp) != -1) { + throw Exception("Error in MacroParser: " + std::string(p)); + free(p); + } + va_end(argp); + } - throw Exception("Error in MacroParser"); } -MacroParser::MacroParser(std::string macro) +MacroParser::MacroParser(std::string macro, bool abspath) { state = UNDEFINED; m = NULL; current_map = NULL; current_script = NULL; - file = Conf::xml_basedir + "/macros/" + macro + ".xml"; + if(!abspath) file = Conf::xml_basedir + "/macros/" + macro + ".xml"; + else file = macro; PRACRO_DEBUG(macro, "Using macro file: %s\n", file.c_str()); @@ -298,6 +313,13 @@ void MacroParser::parseError(char *buf, size_t len, std::string error, int linen PRACRO_ERR_LOG(macro, "\tBuffer %u bytes: [", len); if(fwrite(buf, len, 1, stderr) != len) {} PRACRO_ERR_LOG(macro, "]\n"); + + char *slineno; + if(asprintf(&slineno, " at line %d\n", lineno) != -1) { + throw Exception(error + slineno); + free(slineno); + } + } Macro *MacroParser::getMacro() -- cgit v1.2.3