From 059f15597b0643d234f2e95d7d488ee59b09937e Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 28 Oct 2014 12:53:31 +0100
Subject: [PATCH] reimplement stringology binary

---
 astringology2/src/astringology.cpp | 44 +++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/astringology2/src/astringology.cpp b/astringology2/src/astringology.cpp
index f9b63c7e14..f839b21b4f 100644
--- a/astringology2/src/astringology.cpp
+++ b/astringology2/src/astringology.cpp
@@ -5,34 +5,58 @@
 #include <exception/AlibException.h>
 #include <string/String.h>
 #include <automaton/Automaton.h>
+#include <string/naive/ExactMatch.h>
 #include <stringology/exact/ExactMatchingAutomaton.h>
 
 int main(int argc, char* argv[]) {
 	try {
 
 		std::vector<std::string> allowed;
+		allowed.push_back("exactMatchingAutomaton");
 		allowed.push_back("exactMatch");
 		TCLAP::ValuesConstraint<std::string> allowedVals( allowed );
 
 		TCLAP::CmdLine cmd("Stringology algorithm access binary", ' ', "0.01");
-		TCLAP::ValueArg<std::string> algorithm(	"a",	"algorithm",		"Execute algorithm",		false,	"exactMatch",		&allowedVals);
+		TCLAP::ValueArg<std::string> algorithm(	"a",	"algorithm",	"Execute algorithm",		false,	"exactMatch",	&allowedVals);
 		cmd.add(algorithm);
 
-		TCLAP::UnlabeledValueArg<std::string> file( "file", "Read from file", false, "-", "file");
-                cmd.add( file );
+		TCLAP::ValueArg<std::string> subject(	"s",	"subject",	"Subject string from file",	false,	"-",		"file");
+		cmd.add( subject );
+
+		TCLAP::ValueArg<std::string> pattern(	"p",	"pattern",	"Pattern string from file",	false,	"-",		"file");
+                cmd.add( pattern );
 
 		cmd.parse(argc,argv);
 
-		std::list<sax::Token> tokens;
-		if(file.isSet()) {
-			sax::SaxParseInterface::parseFile(file.getValue(), tokens);
-		} else {
-			sax::SaxParseInterface::parseStdin(tokens);
+		std::list<sax::Token> subjectTokens;
+		if(subject.isSet()) {
+			if(subject.getValue() == "-") {
+				sax::SaxParseInterface::parseStdin(subjectTokens);
+			} else {
+				sax::SaxParseInterface::parseFile(subject.getValue(), subjectTokens);
+			}
+		}
+
+		std::list<sax::Token> patternTokens;
+		if(pattern.isSet()) {
+			if(pattern.getValue() == "-") {
+				sax::SaxParseInterface::parseStdin(patternTokens);
+			} else {
+				sax::SaxParseInterface::parseFile(pattern.getValue(), patternTokens);
+			}
 		}
 
 		if( algorithm.getValue() == "exactMatch") {
-			string::String string = alib::DataFactory::fromTokens<string::String>(tokens);
-			automaton::Automaton automaton = stringology::exact::ExactMatchingAutomaton::construct(string);
+			string::String subject = alib::DataFactory::fromTokens<string::String>(subjectTokens);
+			string::String pattern = alib::DataFactory::fromTokens<string::String>(patternTokens);
+			std::set<unsigned> res = string::naive::ExactMatch::match(subject, pattern);
+			for(unsigned number : res ) {
+				std::cout << number << std::endl;
+			}
+			return 0;
+		} else if( algorithm.getValue() == "exactMatchingAutomaton") {
+			string::String pattern = alib::DataFactory::fromTokens<string::String>(patternTokens);
+			automaton::Automaton automaton = stringology::exact::ExactMatchingAutomaton::construct(pattern);
 			alib::DataFactory::toStdout(automaton);
 			return 0;
 		} else {
-- 
GitLab