From 0c6af413a9ff1c7e0d311a636cfe75704f034ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 20 May 2015 15:22:39 +0000 Subject: [PATCH] some bugs fixed, logging is quite good now --- src/commands.hxx | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/commands.hxx b/src/commands.hxx index 8337143..fcb7bdb 100644 --- a/src/commands.hxx +++ b/src/commands.hxx @@ -75,7 +75,7 @@ class Function; class Logger { public: - Logger(Command* command, Script* script); + Logger(Command* command, Script* script, bool showLines = true); void operator[](QString txt); void operator()(QString txt); ~Logger(); @@ -178,17 +178,16 @@ class Command: public QObject { return commands; } QStringList commaSeparatedList(QString value) { + if (!value.size()) return QStringList(); switch (value.size()>1&&value.at(0)==value.at(value.size()-1) ?value.at(0).toLatin1():'\0') { case '"': case '\'': { return value.mid(1, value.size()-2) .split(QRegularExpression(QString(value[0])+", *" - +QString(value[0])), - QString::SkipEmptyParts); + +QString(value[0]))); } break; default: { - return value.split(QRegularExpression(", *"), - QString::SkipEmptyParts); + return value.split(QRegularExpression(", *")); } } } @@ -274,7 +273,11 @@ class Comment: public Command { return cmd; } bool execute(Script* script, QWebFrame*) { + this->log(false); Logger log(this, script); + this->log(true); + log(_comment); + this->log(false); return true; } private: @@ -858,10 +861,10 @@ class Script: public QObject { Command* cmd(command?command:_command); if (cmd) prefix += QString("%2:%3%1 ") - .arg(QString(' ', cmd->indent())) - .arg(cmd->file(), 20) - .arg(cmd->line(), -4, 10); - text = prefix+text.split('\n').join("\n "+prefix); + .arg(QString(cmd->indent(), QChar(' '))) + .arg(cmd->file(), 20, QChar(' ')) + .arg(cmd->line(), -4, 10, QChar(' ')); + text = prefix+text.split('\n').join("\n"+prefix+" "); logging(text); std::cout< cmd(new Function()); if (!args.size()) throw BadArgument(tag()+" requires a "); - QStringList allargs(args.split(" ", QString::SkipEmptyParts)); + QStringList allargs(args.split(" ")); cmd->_name = allargs.takeFirst().trimmed(); cmd->_vars = commaSeparatedList(allargs.join(' ')); script->function(cmd->_name, cmd); @@ -1962,7 +1965,7 @@ class Function: public Command { return cmd; } bool execute(Script* script, QWebFrame*) { - Logger log(this, script); + Logger log(this, script, false); return true; } bool call(Command* parentCommand, QStringList args, @@ -2000,7 +2003,7 @@ class Call: public Command { QStringList&, QString, int, int) { std::shared_ptr cmd(new Call()); if (!args.size()) throw BadArgument(tag()+" requires a "); - QStringList allargs(args.split(" ", QString::SkipEmptyParts)); + QStringList allargs(args.split(" ")); cmd->_name = allargs.takeFirst().trimmed(); cmd->_args = commaSeparatedList(allargs.join(' ')); return cmd; @@ -2060,7 +2063,7 @@ class If: public Command { return cmd; } bool execute(Script* script, QWebFrame* frame) { - Logger log(this, script); + Logger log(this, script, false); QString value(script->replacevars(_value)); bool check(false); switch (_cmp) { @@ -2253,11 +2256,15 @@ inline bool Screenshot::execute(Script* script, QWebFrame* frame) { return true; } -inline Logger::Logger(Command* command, Script* script): +inline Logger::Logger(Command* command, Script* script, bool showLines): _command(command), _script(script) { _previous = _script->command(); _script->command(command); - if (_command->log()) _script->log("\\ "+_command->command(), _command); + if (_command->log()) + if (showLines) + _script->log("\\ "+_command->command(), _command); + else + _script->log("\\ "+_command->command().split('\n').first(), _command); } inline void Logger::operator()(QString txt) { if (_command->log()) _script->log(" "+txt, _command); @@ -2266,7 +2273,7 @@ inline void Logger::operator[](QString txt) { _script->plainlog(txt); } inline Logger::~Logger() { - if (_command->log()) _script->log("/ "+_command->command(), _command); + if (_command->log()) _script->log("/ "+_command->tag(), _command); _script->command(_previous); } @@ -2280,8 +2287,11 @@ inline bool Command::runScript(Command* parentCommand, if (args.size()!=vars.size()) throw WrongNumberOfArguments(vars, args); for (QStringList::iterator var(vars.begin()), arg(args.begin()); - varlog("argument: "+*var+" = "+parent->replacevars(*arg), + parentCommand); scriptCopy.set(*var, parent->replacevars(*arg)); + } try { connect(&scriptCopy, SIGNAL(logging(QString)), parent, SLOT(parentlog(QString)));