From 14e5ae07984d3e898d452ec3ddda10afac01be54 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 15 Oct 2014 17:00:12 +0200 Subject: first preliminary module searcher --- include/util/StringUtils.hpp | 2 ++ src/crawl/crawl.conf | 4 ++-- src/crawl/crawl.cpp | 23 ++++++++++++++++------- src/libutil/StringUtils.cpp | 12 ++++++++++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/util/StringUtils.hpp b/include/util/StringUtils.hpp index af8e82f..f2615e0 100644 --- a/include/util/StringUtils.hpp +++ b/include/util/StringUtils.hpp @@ -8,5 +8,7 @@ UTIL_DLL_VISIBLE bool stringicasecmp( const std::string &s1, const std::string &s2 ); UTIL_DLL_VISIBLE std::vector split( const std::string &s, const std::string &delimiter, bool keepEmpty = true ); +UTIL_DLL_VISIBLE bool endswith( const std::string &s, const std::string &endstring ); +UTIL_DLL_VISIBLE bool startswith( const std::string &s, const std::string &startstring ); #endif diff --git a/src/crawl/crawl.conf b/src/crawl/crawl.conf index 25e4003..bfcd07b 100644 --- a/src/crawl/crawl.conf +++ b/src/crawl/crawl.conf @@ -15,8 +15,8 @@ logger = { modules = { urlnormalizers = { - "mod_normalizer_simple", - "mod_normalizer_google" + "mod_urlnormalizer_simple", + "mod_urlnormalizer_googleurl" } } diff --git a/src/crawl/crawl.cpp b/src/crawl/crawl.cpp index 88f6aa3..147b2cc 100755 --- a/src/crawl/crawl.cpp +++ b/src/crawl/crawl.cpp @@ -14,6 +14,7 @@ #include "LuaVM.hpp" +#include "StringUtils.hpp" #include "FileUtils.hpp" #include @@ -97,15 +98,23 @@ int main( int /* argc */, char *argv[] ) << ( modulesSearchRecursive ? "(recursive)" : "" ); vector entries = directory_entries( modulePath, true, modulesSearchRecursive ); - vector::const_iterator it, end = entries.end( ); - for( it = entries.begin( ); it != end; it++ ) { - cout << (*it) << endl; - } vector modules = luaVm.getStringArray( "modules.urlnormalizers" ); - end = modules.end( ); - for( it = modules.begin( ); it != end; it++ ) { - cout << (*it) << endl; + vector::const_iterator it2, end2 = modules.end( ); + for( it2 = modules.begin( ); it2 != end2; it2++ ) { +#ifndef _WIN32 + string module = (*it2) + ".so"; +#else + string module = (*it2) + ".dll"; +#endif + cout << "Searching for module '" << module << "'" << endl; + + vector::const_iterator it, end = entries.end( ); + for( it = entries.begin( ); it != end; it++ ) { + if( endswith( (*it), module ) ) { + cout << " Found inf file '" << (*it) << "'" << endl; + } + } } vector normalizerModules; diff --git a/src/libutil/StringUtils.cpp b/src/libutil/StringUtils.cpp index 13be8d4..640ce20 100644 --- a/src/libutil/StringUtils.cpp +++ b/src/libutil/StringUtils.cpp @@ -45,3 +45,15 @@ std::vector split( const string &s, const string &delimiter, bool k return result; } + +bool endswith( const string &s, const string &endstring ) +{ + unsigned int pos = s.rfind( endstring ); + return pos != string::npos && pos + endstring.length( ) == s.length( ); +} + +bool startswith( const string &s, const string &startstring ) +{ + unsigned int pos = s.find( startstring ); + return pos != string::npos; +} -- cgit v1.2.3-54-g00ecf