summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-10-15 02:21:12 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-10-15 02:21:12 +0100
commita3119379e695f8bcbef103b8f4aeb8c0bd5c0084 (patch)
tree677cb0ebc71b96e6be43f7a45591153b5d307b6a
parentSet cxxflags specifically, not cflags (diff)
downloadgentoobrowse-api-a3119379e695f8bcbef103b8f4aeb8c0bd5c0084.tar.bz2
gentoobrowse-api-a3119379e695f8bcbef103b8f4aeb8c0bd5c0084.tar.xz
gentoobrowse-api-a3119379e695f8bcbef103b8f4aeb8c0bd5c0084.zip
Use file utils and lexer now in libadhocutil
-rw-r--r--gentoobrowse-api/service/depend.cpp85
-rw-r--r--gentoobrowse-api/service/depend.h4
-rw-r--r--gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp4
-rw-r--r--gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp3
-rw-r--r--gentoobrowse-api/service/maintenance/masksProcessor.cpp3
-rw-r--r--gentoobrowse-api/service/maintenance/newsProcessor.cpp9
-rw-r--r--gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp4
-rw-r--r--gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp6
-rw-r--r--gentoobrowse-api/service/maintenance/useGroupProcessor.cpp4
-rw-r--r--gentoobrowse-api/service/maintenance/useLocalProcessor.cpp6
-rw-r--r--gentoobrowse-api/service/maintenanceBugs.cpp13
-rw-r--r--gentoobrowse-api/service/news.cpp103
-rw-r--r--gentoobrowse-api/service/news.h4
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.cpp4
-rw-r--r--gentoobrowse-api/service/utils/ebuildCacheParser.h4
-rw-r--r--gentoobrowse-api/service/utils/fileUtils.cpp60
-rw-r--r--gentoobrowse-api/service/utils/fileUtils.h45
-rw-r--r--gentoobrowse-api/service/utils/lexer.cpp137
-rw-r--r--gentoobrowse-api/service/utils/lexer.h62
-rw-r--r--gentoobrowse-api/unittests/Jamfile.jam6
-rw-r--r--gentoobrowse-api/unittests/testNews.cpp6
21 files changed, 132 insertions, 440 deletions
diff --git a/gentoobrowse-api/service/depend.cpp b/gentoobrowse-api/service/depend.cpp
index 0a0dd4d..86f9646 100644
--- a/gentoobrowse-api/service/depend.cpp
+++ b/gentoobrowse-api/service/depend.cpp
@@ -1,12 +1,13 @@
#include "depend.h"
#include <boost/algorithm/string/split.hpp>
+#include <lexer-regex.h>
-Gentoo::Utils::Lexer::PatternPtr WhenUse_Begin(Gentoo::Utils::Lexer::regex("\\s*(!?[[:alnum:]-_@]+)\\?\\s*\\(\\s*", G_REGEX_OPTIMIZE));
-Gentoo::Utils::Lexer::PatternPtr WhenUse_End(Gentoo::Utils::Lexer::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE));
-Gentoo::Utils::Lexer::PatternPtr Or_Begin(Gentoo::Utils::Lexer::regex("\\s*\\|\\|\\s*\\(\\s*", G_REGEX_OPTIMIZE));
-Gentoo::Utils::Lexer::PatternPtr Or_Group(Gentoo::Utils::Lexer::regex("\\s*\\(\\s*", G_REGEX_OPTIMIZE));
-Gentoo::Utils::Lexer::PatternPtr Or_End(Gentoo::Utils::Lexer::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE));
-Gentoo::Utils::Lexer::PatternPtr AtomSpec(Gentoo::Utils::Lexer::regex("\\s*"
+AdHoc::Lexer::PatternPtr WhenUse_Begin(AdHoc::LexerMatchers::regex("\\s*(!?[[:alnum:]-_@]+)\\?\\s*\\(\\s*", G_REGEX_OPTIMIZE));
+AdHoc::Lexer::PatternPtr WhenUse_End(AdHoc::LexerMatchers::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE));
+AdHoc::Lexer::PatternPtr Or_Begin(AdHoc::LexerMatchers::regex("\\s*\\|\\|\\s*\\(\\s*", G_REGEX_OPTIMIZE));
+AdHoc::Lexer::PatternPtr Or_Group(AdHoc::LexerMatchers::regex("\\s*\\(\\s*", G_REGEX_OPTIMIZE));
+AdHoc::Lexer::PatternPtr Or_End(AdHoc::LexerMatchers::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE));
+AdHoc::Lexer::PatternPtr AtomSpec(AdHoc::LexerMatchers::regex("\\s*"
"([[:punct:]]+)?" // op
"([[:alnum:]-]+)\\/" // cat
"([^ ]+)" // package
@@ -37,42 +38,44 @@ namespace Portage {
return rtn;
}
- Depend::Depend()
+ Depend::Depend() :
+ AdHoc::Lexer({
+ // use? (
+ { { InitialState, InWhen, InOr }, WhenUse_Begin, [this](auto es) {
+ es->pushState(InWhen);
+ when.push_back(*es->pattern()->match(1));
+ } },
+ // )
+ { { InWhen }, WhenUse_End, [this](auto es) {
+ es->popState();
+ when.pop_back();
+ } },
+ // || (
+ { { InitialState, InWhen, InOr }, Or_Begin, [this](auto es) {
+ es->pushState(InOr);
+ } },
+ // (
+ { { InitialState, InWhen, InOr }, Or_Group, [this](auto es) {
+ es->pushState(InOr);
+ } },
+ // )
+ { { InOr }, Or_End, [this](auto es) {
+ es->popState();
+ } },
+ // [op]some-cat/package[-version][:slot][uses]
+ { { InitialState, InWhen, InOr }, AtomSpec, [this](auto es) {
+ ds.push_back(new Gentoo::Dependency(
+ when,
+ iuo<std::string>(es->pattern()->match(1)), // op
+ *es->pattern()->match(2), // category
+ *es->pattern()->match(3), // package
+ iuo<std::string>(es->pattern()->match(5)), // version
+ iuo<std::string>(es->pattern()->match(11)), // slot
+ split<std::string>(es->pattern()->match(14)) // use
+ ));
+ } }
+ })
{
- // use? (
- rules.push_back({ { InitialState, InWhen, InOr }, WhenUse_Begin, [this](auto es) {
- es->pushState(InWhen);
- when.push_back(*es->pattern->match(1));
- } });
- // )
- rules.push_back({ { InWhen }, WhenUse_End, [this](auto es) {
- es->popState();
- when.pop_back();
- } });
- // || (
- rules.push_back({ { InitialState, InWhen, InOr }, Or_Begin, [this](auto es) {
- es->pushState(InOr);
- } });
- // (
- rules.push_back({ { InitialState, InWhen, InOr }, Or_Group, [this](auto es) {
- es->pushState(InOr);
- } });
- // )
- rules.push_back({ { InOr }, Or_End, [this](auto es) {
- es->popState();
- } });
- // [op]some-cat/package[-version][:slot][uses]
- rules.push_back({ { InitialState, InWhen, InOr }, AtomSpec, [this](auto es) {
- ds.push_back(new Gentoo::Dependency(
- when,
- iuo<std::string>(es->pattern->match(1)), // op
- *es->pattern->match(2), // category
- *es->pattern->match(3), // package
- iuo<std::string>(es->pattern->match(5)), // version
- iuo<std::string>(es->pattern->match(11)), // slot
- split<std::string>(es->pattern->match(14)) // use
- ));
- } });
}
std::vector<Gentoo::DependencyPtr>
diff --git a/gentoobrowse-api/service/depend.h b/gentoobrowse-api/service/depend.h
index c384a11..abd9f06 100644
--- a/gentoobrowse-api/service/depend.h
+++ b/gentoobrowse-api/service/depend.h
@@ -4,11 +4,11 @@
#include <istream>
#include <vector>
#include <portage-models.h>
-#include "utils/lexer.h"
+#include <lexer.h>
namespace Portage {
namespace Utils {
- class Depend : Gentoo::Utils::Lexer {
+ class Depend : AdHoc::Lexer {
private:
Depend();
Gentoo::StringList when;
diff --git a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
index 235faa2..bf75b16 100644
--- a/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/categoryMetaProcessor.cpp
@@ -1,12 +1,12 @@
#include "categoryMetaProcessor.h"
#include <modifycommand.h>
-#include "utils/fileUtils.h"
+#include <fileUtils.h>
#include "utils/xmlUtils.h"
#include "utils/dbUtils.h"
#include <sql/maintenance/categoryMetaUpdate.sql.h>
namespace U = Gentoo::Utils;
-using namespace Gentoo::Utils::File;
+using namespace AdHoc::FileUtils;
namespace Gentoo {
namespace Service {
diff --git a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
index 4560e95..cbc74bd 100644
--- a/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/ebuildMetaProcessor.cpp
@@ -8,7 +8,6 @@
#include <glibmm/regex.h>
#include <tablepatch.h>
#include "depend.h"
-#include "utils/fileUtils.h"
#include "utils/dbUtils.h"
#include "utils/ebuildCacheParser.h"
#include "utils/splitEbuildProps.h"
@@ -26,7 +25,7 @@
#include <sql/maintenance/ebuildArchsInsert.sql.h>
namespace U = Gentoo::Utils;
-using namespace Gentoo::Utils::File;
+using namespace AdHoc::FileUtils;
static Glib::RefPtr<Glib::Regex> packageVersion = Glib::Regex::create("^(.+)-([0-9].*)$");
diff --git a/gentoobrowse-api/service/maintenance/masksProcessor.cpp b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
index 58975f1..1634167 100644
--- a/gentoobrowse-api/service/maintenance/masksProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/masksProcessor.cpp
@@ -4,15 +4,12 @@
#include <modifycommand.h>
#include <sqlWriter.h>
#include <tablepatch.h>
-#include "utils/fileUtils.h"
#include "utils/dbUtils.h"
#include <glibmm/regex.h>
#include <glibmm/iochannel.h>
#include "sql/maintenance/masksSets.sql.h"
#include "sql/maintenance/masksEbuilds.sql.h"
-using namespace Gentoo::Utils::File;
-
static Glib::RefPtr<Glib::Regex> maskHead = Glib::Regex::create(
"^# ([^<]+)? ?<(.+?@[^>]+)> \\((\\d+ *(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) \\d+)\\)",
Glib::RegexCompileFlags::REGEX_CASELESS);
diff --git a/gentoobrowse-api/service/maintenance/newsProcessor.cpp b/gentoobrowse-api/service/maintenance/newsProcessor.cpp
index 0b5b920..848d704 100644
--- a/gentoobrowse-api/service/maintenance/newsProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/newsProcessor.cpp
@@ -1,7 +1,5 @@
#include "newsProcessor.h"
-#include "utils/fileUtils.h"
-#include "utils/xmlUtils.h"
-#include "utils/dbUtils.h"
+#include <fileUtils.h>
#include "news.h"
#include <modifycommand.h>
#include <slicer/slicer.h>
@@ -9,9 +7,6 @@
#include <db/sqlUpdateSerializer.h>
#include <sql/maintenance/newsDelete.sql.h>
-namespace U = Gentoo::Utils;
-using namespace Gentoo::Utils::File;
-
namespace Gentoo {
namespace Service {
const int NewsProcessor::FILETYPEID = 11;
@@ -32,7 +27,7 @@ namespace Gentoo {
void
NewsProcessor::importNews(DB::Connection * dbc, const boost::filesystem::path & path)
{
- Gentoo::Utils::MemMap m(path);
+ AdHoc::FileUtils::MemMap m(path);
auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size);
news->newsid = path.parent_path().leaf().string();
Slicer::SerializeAny<Serializer>(news, dbc, "gentoobrowse.news");
diff --git a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
index 5be86ec..837cc18 100644
--- a/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/packageMetaProcessor.cpp
@@ -1,12 +1,12 @@
#include "packageMetaProcessor.h"
#include <modifycommand.h>
-#include "utils/fileUtils.h"
+#include <fileUtils.h>
#include "utils/xmlUtils.h"
#include "utils/dbUtils.h"
#include <sql/maintenance/packageMetaUpdate.sql.h>
namespace U = Gentoo::Utils;
-using namespace Gentoo::Utils::File;
+using namespace AdHoc::FileUtils;
namespace Gentoo {
namespace Service {
diff --git a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
index 457383f..f3b3b5a 100644
--- a/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/useGlobalProcessor.cpp
@@ -1,11 +1,11 @@
#include "useGlobalProcessor.h"
#include <modifycommand.h>
#include <tablepatch.h>
-#include "utils/fileUtils.h"
+#include <fileUtils.h>
#include "utils/dbUtils.h"
#include <glibmm/regex.h>
-using namespace Gentoo::Utils::File;
+using namespace AdHoc::FileUtils;
static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^ ]*)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE);
@@ -28,7 +28,7 @@ namespace Gentoo {
p.pk = { "use" };
p.cols = { "use", "description" };
- Utils::MemMap u(path);
+ AdHoc::FileUtils::MemMap u(path);
Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size));
Glib::MatchInfo matches;
auto i = Utils::Database::tablePatchInserter(dbc, p);
diff --git a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp
index 9749ba7..52e4e31 100644
--- a/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/useGroupProcessor.cpp
@@ -2,7 +2,7 @@
#include <modifycommand.h>
#include <selectcommandUtil.impl.h>
#include <tablepatch.h>
-#include "utils/fileUtils.h"
+#include <fileUtils.h>
#include "utils/dbUtils.h"
#include "utils/entityWhereFilter.h"
#include <glibmm/regex.h>
@@ -49,7 +49,7 @@ namespace Gentoo {
p.cols = { "useGroupId", "use", "description" };
p.where = &gwf;
- Utils::MemMap u(path);
+ AdHoc::FileUtils::MemMap u(path);
Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size));
Glib::MatchInfo matches;
auto i = Utils::Database::tablePatchInserter(dbc, p);
diff --git a/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp
index 1738e9c..62b1180 100644
--- a/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp
+++ b/gentoobrowse-api/service/maintenance/useLocalProcessor.cpp
@@ -2,12 +2,12 @@
#include <modifycommand.h>
#include <sqlWriter.h>
#include <tablepatch.h>
-#include "utils/fileUtils.h"
+#include <fileUtils.h>
#include "utils/dbUtils.h"
#include <glibmm/regex.h>
#include "sql/maintenance/useLocalMap.sql.h"
-using namespace Gentoo::Utils::File;
+using namespace AdHoc::FileUtils;
static Glib::RefPtr<Glib::Regex> useDesc = Glib::Regex::create("^([^#\\s][^/]*)/([^:]+):([^ ]+)\\s+-\\s+(.*)$", Glib::RegexCompileFlags::REGEX_MULTILINE);
@@ -37,7 +37,7 @@ namespace Gentoo {
p.pk = { "packageId", "use" };
p.cols = { "packageId", "use", "description" };
- Utils::MemMap u(path);
+ AdHoc::FileUtils::MemMap u(path);
Glib::ustring d(std::string(reinterpret_cast<const char *>(u.data), u.getStat().st_size));
Glib::MatchInfo matches;
auto i = tempTable.second;
diff --git a/gentoobrowse-api/service/maintenanceBugs.cpp b/gentoobrowse-api/service/maintenanceBugs.cpp
index c850929..6526923 100644
--- a/gentoobrowse-api/service/maintenanceBugs.cpp
+++ b/gentoobrowse-api/service/maintenanceBugs.cpp
@@ -10,23 +10,24 @@
#include <curlStream.h>
#include <libxml++/parsers/saxparser.h>
#pragma GCC diagnostic pop
-#include <utils/lexer.h>
+#include <lexer.h>
+#include <lexer-regex.h>
#include <utils/dbUtils.h>
namespace Gentoo {
namespace Service {
- Utils::Lexer::PatternPtr bugLink = Utils::Lexer::regex(
+ AdHoc::Lexer::PatternPtr bugLink = AdHoc::LexerMatchers::regex(
"Bug:(\\d+) - \"\" status:(\\w*) resolution:(\\w*) severity:(\\w*).*", G_REGEX_OPTIMIZE);
- class BugListParser : public xmlpp::SaxParser, Utils::Lexer {
+ class BugListParser : public xmlpp::SaxParser, AdHoc::Lexer {
public:
BugListParser(DB::ModifyCommandPtr i) :
ins(i)
{
rules.push_back({ { InitialState }, bugLink, [this](auto es) {
- ins->bindParamI(0, boost::lexical_cast<int64_t>(*es->pattern->match(1)));
- ins->bindParamS(2, *es->pattern->match(2));
- ins->bindParamS(1, *es->pattern->match(4));
+ ins->bindParamI(0, boost::lexical_cast<int64_t>(*es->pattern()->match(1)));
+ ins->bindParamS(2, *es->pattern()->match(2));
+ ins->bindParamS(1, *es->pattern()->match(4));
}});
}
diff --git a/gentoobrowse-api/service/news.cpp b/gentoobrowse-api/service/news.cpp
index 726f9b4..34b811a 100644
--- a/gentoobrowse-api/service/news.cpp
+++ b/gentoobrowse-api/service/news.cpp
@@ -1,14 +1,15 @@
#include "news.h"
#include <boost/algorithm/string/split.hpp>
+#include <lexer-regex.h>
-Gentoo::Utils::Lexer::PatternPtr Title(Gentoo::Utils::Lexer::regex("^Title: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr DisplayIfInstalled(Gentoo::Utils::Lexer::regex("^Display-If-Installed: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr Author(Gentoo::Utils::Lexer::regex("^Author: (.+) <([^>]+)>$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr Posted(Gentoo::Utils::Lexer::regex("^Posted: ([0-9]{4}-[0-9]{2}-[0-9]{2})$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr IgnoredHeader(Gentoo::Utils::Lexer::regex("^[^ :]+: .+$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr BlankLine(Gentoo::Utils::Lexer::regex("^$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr BodyText(Gentoo::Utils::Lexer::regex("^(.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
-Gentoo::Utils::Lexer::PatternPtr Link(Gentoo::Utils::Lexer::regex("^\\[[[:digit:]]+\\] ([[:alpha:]]+://.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr Title(AdHoc::LexerMatchers::regex("^Title: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr DisplayIfInstalled(AdHoc::LexerMatchers::regex("^Display-If-Installed: (.+)$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr Author(AdHoc::LexerMatchers::regex("^Author: (.+) <([^>]+)>$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr Posted(AdHoc::LexerMatchers::regex("^Posted: ([0-9]{4}-[0-9]{2}-[0-9]{2})$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr IgnoredHeader(AdHoc::LexerMatchers::regex("^[^ :]+: .+$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr BlankLine(AdHoc::LexerMatchers::regex("^$\\s", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr BodyText(AdHoc::LexerMatchers::regex("^(.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
+AdHoc::Lexer::PatternPtr Link(AdHoc::LexerMatchers::regex("^\\[[[:digit:]]+\\] ([[:alpha:]]+://.*)$\\s?", (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_MULTILINE)));
const std::string Body("Body");
@@ -32,49 +33,51 @@ namespace Portage {
return rtn;
}
- News::News()
+ News::News() :
+ AdHoc::Lexer({
+ // title: words
+ { { InitialState }, Title, [this](auto es) {
+ news->title = *es->pattern()->match(1);
+ } },
+ // posted: date
+ { { InitialState }, Posted, [this](auto es) {
+ news->posted = *es->pattern()->match(1);
+ } },
+ // display-if-installed: atomspec
+ { { InitialState }, DisplayIfInstalled, [this](auto es) {
+ news->atomspec.push_back(*es->pattern()->match(1));
+ } },
+ // author: name <email>
+ { { InitialState }, Author, [this](auto es) {
+ news->authorname = *es->pattern()->match(1);
+ news->authoremail = *es->pattern()->match(2);
+ } },
+ // other headers
+ { { InitialState }, IgnoredHeader, [this](auto) {
+ } },
+ // blank
+ { { InitialState }, BlankLine, [this](auto es) {
+ es->setState(Body);
+ news->body.push_back(std::string());
+ } },
+ // body blank
+ { { Body }, BlankLine, [this](auto) {
+ news->body.push_back(std::string());
+ } },
+ // link
+ { { Body }, Link, [this](auto es) {
+ news->urls.push_back(*es->pattern()->match(1));
+ } },
+ // body text
+ { { Body }, BodyText, [this](auto es) {
+ if (!news->body.back().empty()) {
+ news->body.back().append(" ");
+ }
+ news->body.back().append(*es->pattern()->match(1));
+ } }
+ }),
+ news(new Gentoo::NewsItem())
{
- // title: words
- rules.push_back({ { InitialState }, Title, [this](auto es) {
- news->title = *es->pattern->match(1);
- } });
- // posted: date
- rules.push_back({ { InitialState }, Posted, [this](auto es) {
- news->posted = *es->pattern->match(1);
- } });
- // display-if-installed: atomspec
- rules.push_back({ { InitialState }, DisplayIfInstalled, [this](auto es) {
- news->atomspec.push_back(*es->pattern->match(1));
- } });
- // author: name <email>
- rules.push_back({ { InitialState }, Author, [this](auto es) {
- news->authorname = *es->pattern->match(1);
- news->authoremail = *es->pattern->match(2);
- } });
- // other headers
- rules.push_back({ { InitialState }, IgnoredHeader, [this](auto) {
- } });
- // blank
- rules.push_back({ { InitialState }, BlankLine, [this](auto es) {
- es->setState(Body);
- news->body.push_back(std::string());
- } });
- // body blank
- rules.push_back({ { Body }, BlankLine, [this](auto) {
- news->body.push_back(std::string());
- } });
- // link
- rules.push_back({ { Body }, Link, [this](auto es) {
- news->urls.push_back(*es->pattern->match(1));
- } });
- // body text
- rules.push_back({ { Body }, BodyText, [this](auto es) {
- if (!news->body.back().empty()) {
- news->body.back().append(" ");
- }
- news->body.back().append(*es->pattern->match(1));
- } });
- news = new Gentoo::NewsItem();
}
Gentoo::NewsItemPtr
diff --git a/gentoobrowse-api/service/news.h b/gentoobrowse-api/service/news.h
index 2887b5d..7c7b495 100644
--- a/gentoobrowse-api/service/news.h
+++ b/gentoobrowse-api/service/news.h
@@ -4,11 +4,11 @@
#include <istream>
#include <vector>
#include <portage-models.h>
-#include "utils/lexer.h"
+#include <lexer.h>
namespace Portage {
namespace Utils {
- class News : Gentoo::Utils::Lexer {
+ class News : AdHoc::Lexer {
private:
News();
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
index 068d10b..c305578 100644
--- a/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.cpp
@@ -1,11 +1,9 @@
#include "ebuildCacheParser.h"
-namespace U = Gentoo::Utils;
-
namespace Gentoo {
namespace Utils {
EbuildCacheParser::EbuildCacheParser(const boost::filesystem::path & p) :
- U::MemMap(p)
+ AdHoc::FileUtils::MemMap(p)
{
const char * chardata = (const char *)this->data;
while (const char * eq = strchr(chardata, '=')) {
diff --git a/gentoobrowse-api/service/utils/ebuildCacheParser.h b/gentoobrowse-api/service/utils/ebuildCacheParser.h
index c7449c7..3aa5573 100644
--- a/gentoobrowse-api/service/utils/ebuildCacheParser.h
+++ b/gentoobrowse-api/service/utils/ebuildCacheParser.h
@@ -1,7 +1,7 @@
#ifndef GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
#define GENTOOBROWSE_API_SERVICE_MAINTENANCE_EBUILDCACHEPARSER_H
-#include "fileUtils.h"
+#include <fileUtils.h>
#include <map>
#include <boost/optional.hpp>
#include <boost/filesystem/path.hpp>
@@ -9,7 +9,7 @@
namespace Gentoo {
namespace Utils {
- class EbuildCacheParser : public Gentoo::Utils::MemMap {
+ class EbuildCacheParser : public AdHoc::FileUtils::MemMap {
public:
typedef std::pair<const char *, const char *> Range;
typedef std::map<std::string, const Range> KVs;
diff --git a/gentoobrowse-api/service/utils/fileUtils.cpp b/gentoobrowse-api/service/utils/fileUtils.cpp
deleted file mode 100644
index 1446b9f..0000000
--- a/gentoobrowse-api/service/utils/fileUtils.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "fileUtils.h"
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/mman.h>
-
-namespace Gentoo {
- namespace Utils {
- namespace File {
- boost::filesystem::path operator/(const boost::filesystem::path & p, unsigned int n)
- {
- auto pp = p.begin();
- while (n--) ++pp;
- return *pp;
- }
- }
-
- FileHandle::FileHandle(const boost::filesystem::path & path) :
- fh(open(path.c_str(), O_RDONLY))
- {
- if (fh < 0) {
- throw std::runtime_error("Failed to open " + path.string());
- }
- }
-
- FileHandle::~FileHandle()
- {
- close(fh);
- }
-
- FileHandleStat::FileHandleStat(const boost::filesystem::path & path) :
- FileHandle(path)
- {
- if (fstat(fh, &st)) {
- throw std::runtime_error("Failed to stat " + path.string());
- }
- }
-
- const struct stat &
- FileHandleStat::getStat() const
- {
- return st;
- }
-
- MemMap::MemMap(const boost::filesystem::path & path) :
- FileHandleStat(path),
- data(mmap(0, st.st_size, PROT_READ, MAP_SHARED, fh, 0))
- {
- if (data == (void*)-1) {
- throw std::runtime_error("Failed to mmap " + path.string());
- }
- }
-
- MemMap::~MemMap()
- {
- munmap(data, st.st_size);
- }
-
- }
-}
-
diff --git a/gentoobrowse-api/service/utils/fileUtils.h b/gentoobrowse-api/service/utils/fileUtils.h
deleted file mode 100644
index d73b1ef..0000000
--- a/gentoobrowse-api/service/utils/fileUtils.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef GENTOOBROWSE_API_SERVICE_FILEUTILS_H
-#define GENTOOBROWSE_API_SERVICE_FILEUTILS_H
-
-#include <boost/filesystem/path.hpp>
-#include <sys/stat.h>
-
-namespace Gentoo {
- namespace Utils {
- namespace File {
- boost::filesystem::path operator/(const boost::filesystem::path & p, unsigned int n);
- }
-
- class FileHandle {
- public:
- FileHandle(const boost::filesystem::path & path);
- virtual ~FileHandle();
-
- protected:
- const int fh;
- };
-
- class FileHandleStat : public FileHandle {
- public:
- FileHandleStat(const boost::filesystem::path & path);
-
- const struct stat & getStat() const;
-
- protected:
- struct stat st;
- };
-
- class MemMap : public FileHandleStat {
- public:
- MemMap(const boost::filesystem::path & path);
- ~MemMap();
-
- void * const data;
- };
-
- }
-}
-
-#endif
-
-
diff --git a/gentoobrowse-api/service/utils/lexer.cpp b/gentoobrowse-api/service/utils/lexer.cpp
deleted file mode 100644
index a3352f8..0000000
--- a/gentoobrowse-api/service/utils/lexer.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-#include "lexer.h"
-
-namespace Gentoo {
- namespace Utils {
- const Lexer::State Lexer::InitialState = "";
-
- class Regex : public Lexer::Pattern {
- public:
- Regex(const Glib::ustring & pattern, GRegexCompileFlags compile, GRegexMatchFlags match) :
- err(nullptr),
- regex(g_regex_new(pattern.c_str(), compile, match, &err)),
- info(nullptr)
- {
- if (!regex) {
- std::runtime_error e(std::string("Failed to create GRegex: ") + err->message);
- g_error_free(err);
- throw e;
- }
- }
-
- ~Regex()
- {
- if (err) {
- g_error_free(err);
- }
- if (info) {
- g_match_info_free(info);
- }
- g_regex_unref(regex);
- }
-
- bool matches(const gchar * string, size_t length, size_t position) const override
- {
- if (info) {
- g_match_info_free(info);
- }
- g_regex_match_full(regex, string, length, position, G_REGEX_MATCH_ANCHORED, &info, &err);
- if (err) {
- std::runtime_error e(std::string("Failed to execute regex: ") + err->message);
- g_error_free(err);
- throw e;
- }
- str = string;
- return g_match_info_matches(info);
- }
-
- size_t matchedLength() const override
- {
- gint start, end;
- g_match_info_fetch_pos(info, 0, &start, &end);
- return end - start;
- }
-
- boost::optional<Glib::ustring> match(int n) const override
- {
- gint start, end;
- if (g_match_info_fetch_pos(info, n, &start, &end)) {
- if (start == -1 && end == -1) {
- return boost::optional<Glib::ustring>();
- }
- return Glib::ustring(str + start, end - start);
- }
- return boost::optional<Glib::ustring>();
- }
-
- private:
- mutable GError * err;
- GRegex * regex;
- mutable GMatchInfo * info;
- mutable const gchar * str;
- };
-
- Lexer::PatternPtr
- Lexer::regex(const Glib::ustring & pattern, GRegexCompileFlags compile, GRegexMatchFlags match)
- {
- return PatternPtr(new Regex(pattern, compile, match));
- }
-
- void
- Lexer::extract(const gchar * string, size_t length) const
- {
- ExecuteState es;
- while (es.position < length) {
- const Rule * selected = nullptr;
- for (const auto & r : rules) {
- const auto & s = boost::get<0>(r);
- if (s.find(es.getState()) == s.end()) {
- continue;
- }
- const auto & p = boost::get<1>(r);
- if (p->matches(string, length, es.position)) {
- selected = &r;
- break;
- }
- }
- if (!selected) {
- throw std::runtime_error(std::string("Unexpected input in state (" + es.getState() + ") at ") + (string + es.position));
- }
- es.pattern = boost::get<1>(*selected);
- const auto & h = boost::get<2>(*selected);
- h(&es);
- es.position += es.pattern->matchedLength();
- }
-
- }
-
- Lexer::ExecuteState::ExecuteState() :
- position(0)
- {
- stateStack.push_back(InitialState);
- }
-
- void
- Lexer::ExecuteState::setState(const State & s)
- {
- stateStack.back() = s;
- }
-
- void
- Lexer::ExecuteState::pushState(const State & s)
- {
- stateStack.push_back(s);
- }
-
- void
- Lexer::ExecuteState::popState()
- {
- stateStack.pop_back();
- }
-
- const Lexer::State &
- Lexer::ExecuteState::getState() const
- {
- return stateStack.back();
- }
- }
-}
diff --git a/gentoobrowse-api/service/utils/lexer.h b/gentoobrowse-api/service/utils/lexer.h
deleted file mode 100644
index 44d3d57..0000000
--- a/gentoobrowse-api/service/utils/lexer.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef GENTOOBROWSE_SERVICE_UTILS_LEXER_H
-#define GENTOOBROWSE_SERVICE_UTILS_LEXER_H
-
-#include <vector>
-#include <glibmm/ustring.h>
-#include <set>
-#include <boost/tuple/tuple.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/optional.hpp>
-
-namespace Gentoo {
- namespace Utils {
- class Lexer {
- public:
- class Pattern {
- public:
- virtual ~Pattern() = default;
-
- virtual bool matches(const gchar *, size_t, size_t) const = 0;
- virtual size_t matchedLength() const = 0;
- virtual boost::optional<Glib::ustring> match(int) const = 0;
- };
- typedef boost::shared_ptr<Pattern> PatternPtr;
-
- typedef std::string State;
- typedef std::set<State> States;
-
- class ExecuteState {
- public:
- ExecuteState();
-
- void pushState(const State &);
- void popState();
- void setState(const State &);
- const State & getState() const;
-
- size_t position;
- PatternPtr pattern;
-
- private:
- std::vector<State> stateStack;
- };
-
- typedef boost::function<void(ExecuteState *)> Handler;
- typedef boost::tuple<States, PatternPtr, Handler> Rule;
- typedef std::vector<Rule> Rules;
-
- static const State InitialState;
- Rules rules;
-
- static PatternPtr regex(const Glib::ustring &, GRegexCompileFlags compile = (GRegexCompileFlags)0, GRegexMatchFlags match = (GRegexMatchFlags)0);
-
- public:
- void extract(const gchar * string, size_t length) const;
- };
-
- }
-}
-
-#endif
-
diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam
index 0bedd4f..92501c0 100644
--- a/gentoobrowse-api/unittests/Jamfile.jam
+++ b/gentoobrowse-api/unittests/Jamfile.jam
@@ -43,7 +43,7 @@ lib testCommon :
;
run
- testDepend.cpp ../service/depend.cpp ../service/utils/lexer.cpp
+ testDepend.cpp ../service/depend.cpp
: : :
<define>BOOST_TEST_DYN_LINK
<library>testCommon
@@ -51,7 +51,7 @@ run
explicit testDependAll ;
run
- testDependAll.cpp ../service/utils/fileUtils.cpp ../service/utils/ebuildCacheParser.cpp ../service/depend.cpp ../service/utils/lexer.cpp
+ testDependAll.cpp ../service/utils/ebuildCacheParser.cpp ../service/depend.cpp
: : :
<define>BOOST_TEST_DYN_LINK
<library>testCommon
@@ -66,7 +66,7 @@ run
: testChangeLog ;
run
- testNews.cpp ../service/utils/fileUtils.cpp ../service/news.cpp ../service/utils/lexer.cpp
+ testNews.cpp ../service/news.cpp
: : :
<define>BOOST_TEST_DYN_LINK
<library>testCommon
diff --git a/gentoobrowse-api/unittests/testNews.cpp b/gentoobrowse-api/unittests/testNews.cpp
index 734a91e..291f49c 100644
--- a/gentoobrowse-api/unittests/testNews.cpp
+++ b/gentoobrowse-api/unittests/testNews.cpp
@@ -2,12 +2,12 @@
#include <boost/test/unit_test.hpp>
#include <news.h>
-#include <utils/fileUtils.h>
+#include <fileUtils.h>
#include <definedDirs.h>
BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable )
{
- Gentoo::Utils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2016-04-07-kde-plasma5-stable" / "2016-04-07-kde-plasma5-stable.en.txt");
+ AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2016-04-07-kde-plasma5-stable" / "2016-04-07-kde-plasma5-stable.en.txt");
auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size);
BOOST_REQUIRE_EQUAL(news->title, "KDE Plasma 5 Upgrade");
BOOST_REQUIRE(news->authorname);
@@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable )
BOOST_AUTO_TEST_CASE( news_2010_03_23_new_subprofiles )
{
- Gentoo::Utils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2010-03-23-new-subprofiles" / "2010-03-23-new-subprofiles.en.txt");
+ AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2010-03-23-new-subprofiles" / "2010-03-23-new-subprofiles.en.txt");
auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size);
BOOST_REQUIRE_EQUAL(news->title, "New desktop subprofiles for GNOME and KDE");
BOOST_REQUIRE(news->authorname);