From a85ac9698a77da1cd446e7d91010ebe62cbc5f76 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Tue, 28 Sep 2010 20:40:05 +0200 Subject: Unify debug messages and Match structs --- src/ruleparser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ruleparser.cpp') diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp index 10a22ac..5927c5a 100644 --- a/src/ruleparser.cpp +++ b/src/ruleparser.cpp @@ -187,12 +187,14 @@ void Rules::load() repo = Repository(); // clear repo.name = repoLine.cap(1); repo.lineNumber = lineNumber; + repo.filename = filename; } else if (isMatchRule) { // match rule state = ReadingMatch; match = Match(); match.rx = QRegExp(matchLine.cap(1), Qt::CaseSensitive, QRegExp::RegExp2); match.lineNumber = lineNumber; + match.filename = filename; } else if (isVariableRule) { QString variable = declareLine.cap(1); QString value = declareLine.cap(2); @@ -207,7 +209,7 @@ void Rules::load() #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug s, const Rules::Match &rule) { - s.nospace() << rule.rx.pattern() << " (line " << rule.lineNumber << ")"; + s.nospace() << rule.info(); return s.space(); } -- cgit v1.2.1 From d1737a1713da27f825682fff0e9838b559ea81a3 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Wed, 29 Sep 2010 19:45:20 +0200 Subject: Die when a rule file contains an invalid regexp --- src/ruleparser.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ruleparser.cpp') diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp index 5927c5a..1744969 100644 --- a/src/ruleparser.cpp +++ b/src/ruleparser.cpp @@ -193,6 +193,10 @@ void Rules::load() state = ReadingMatch; match = Match(); match.rx = QRegExp(matchLine.cap(1), Qt::CaseSensitive, QRegExp::RegExp2); + if( !match.rx.isValid() ) + qFatal("Malformed regular expression '%s' in file:'%s':%d, Error: %s", + qPrintable(matchLine.cap(1)), qPrintable(filename), lineNumber, + qPrintable(match.rx.errorString())); match.lineNumber = lineNumber; match.filename = filename; } else if (isVariableRule) { -- cgit v1.2.1 From 7ca174999ae5fa86e5fc39a0b1b7b02c06c80840 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Wed, 29 Sep 2010 19:46:09 +0200 Subject: const++ --- src/ruleparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ruleparser.cpp') diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp index 1744969..d8467ac 100644 --- a/src/ruleparser.cpp +++ b/src/ruleparser.cpp @@ -31,12 +31,12 @@ Rules::~Rules() { } -QList Rules::repositories() +const QList Rules::repositories() const { return m_repositories; } -QList Rules::matchRules() +const QList Rules::matchRules() const { return m_matchRules; } -- cgit v1.2.1 From a741bdb1913c28a320ff0e01518e4d39ed430289 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Wed, 29 Sep 2010 19:53:24 +0200 Subject: Allow more then one rule file to be used in a single run. --- src/ruleparser.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/ruleparser.cpp') diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp index d8467ac..4ab8f08 100644 --- a/src/ruleparser.cpp +++ b/src/ruleparser.cpp @@ -22,6 +22,41 @@ #include "ruleparser.h" +RulesList::RulesList(const QString &filenames) + : m_filenames(filenames) +{ +} + +RulesList::~RulesList() {} + +void RulesList::load() +{ + foreach(const QString filename, m_filenames.split(',') ) { + qDebug() << "Loading rules from:" << filename; + Rules *rules = new Rules(filename); + m_rules.append(rules); + rules->load(); + m_allrepositories.append(rules->repositories()); + QList matchRules = rules->matchRules(); + m_allMatchRules.append( QList(matchRules)); + } +} + +const QList RulesList::allRepositories() const +{ + return m_allrepositories; +} + +const QList > RulesList::allMatchRules() const +{ + return m_allMatchRules; +} + +const QList RulesList::rules() const +{ + return m_rules; +} + Rules::Rules(const QString &fn) : filename(fn) { -- cgit v1.2.1