diff --git a/arun2/makefile b/arun2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..ea944d349794d40b7f35fffa32420ccb0746d072 --- /dev/null +++ b/arun2/makefile @@ -0,0 +1,128 @@ +SHELL:=/bin/bash +EXECUTABLE:=arun2 + +define NEW_LINE + + +endef + +export NEW_LINE + +LDFLAGS_DEBUG:=-L../alib2data/lib-debug -L../alib2algo/lib-debug -rdynamic -lxml2 -lalib2data -lalib2algo -Wl,-rpath,. + +LDFLAGS_RELEASE:=-L../alib2data/lib-release -L../alib2algo/lib-release -rdynamic -lxml2 -lalib2data -lalib2algo -Wl,-rpath,. + +OBJECTS_DEBUG:=$(patsubst src/%.cpp, obj-debug/%.o, $(shell find src/ -name *cpp)) + +OBJECTS_RELEASE:=$(patsubst src/%.cpp, obj-release/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build-debug clean-debug doc + +all: + @echo "What to do master?" + +obj%/makefile: makefile + mkdir -p $(dir $@) + echo "\ + SHELL:=/bin/bash$${NEW_LINE}\ + SRCDIR:=$${NEW_LINE}\ + DEPTH:=$${NEW_LINE}\ + OBJECTS_BASE_DIR:=$${NEW_LINE}\ + $${NEW_LINE}\ + define NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + $${NEW_LINE}\ + endef$${NEW_LINE}\ + $${NEW_LINE}\ + export NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + CXXFLAGS:= -std=c++11 \$$(CXX_OTHER_FLAGS) -c -Wall -pedantic -Wextra -fPIC -I/usr/include/libxml2/ -I../../\$$(DEPTH)alib2data/src/ -I../../\$$(DEPTH)alib2algo/src/$${NEW_LINE}\ + $${NEW_LINE}\ + SOURCES:= \$$(shell find ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")$${NEW_LINE}\ + DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d, \$$(SOURCES))$${NEW_LINE}\ + OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))$${NEW_LINE}\ + SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)$${NEW_LINE}\ + OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))$${NEW_LINE}\ + OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))$${NEW_LINE}\ + $${NEW_LINE}\ + .PHONY: all$${NEW_LINE}\ + .PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)$${NEW_LINE}\ + $${NEW_LINE}\ + all: \$$(OBJECTS_DIRS) \$$(OBJECTS)$${NEW_LINE}\ + $${NEW_LINE}\ + %.d: makefile$${NEW_LINE}\ + @echo \"\\$${NEW_LINE}\ + \$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)\$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,../\$$(DEPTH)\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\")) makefile\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \" > \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/makefile: makefile$${NEW_LINE}\ + mkdir -p \$$(dir \$$@)$${NEW_LINE}\ + cp makefile \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/: FORCE | %/makefile$${NEW_LINE}\ + @accesstime=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ OBJECTS_BASE_DIR=\$$(OBJECTS_BASE_DIR) SOURCES_BASE_DIR=\$$(SOURCES_BASE_DIR) CXX_OTHER_FLAGS=\"\$$(CXX_OTHER_FLAGS)\" && \\$${NEW_LINE}\ + accesstime2=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\$${NEW_LINE}\ + touch .; \\$${NEW_LINE}\ + fi$${NEW_LINE}\ + $${NEW_LINE}\ + FORCE:$${NEW_LINE}\ + $${NEW_LINE}\ + -include \$$(DEPENDENCIES)" > $@ + +debug: build-debug + +release: build-release + +clean: clean-debug clean-release + $(RM) -r doc + + + +bin-debug/$(EXECUTABLE): obj-debug/ $(OBJECTS_DEBUG) + mkdir -p $(dir $@) + $(CXX) $(OBJECTS_DEBUG) -o $@ $(LDFLAGS_DEBUG) + +bin-release/$(EXECUTABLE): obj-release/ $(OBJECTS_RELEASE) + mkdir -p $(dir $@) + $(CXX) $(OBJECTS_RELEASE) -o $@ $(LDFLAGS_RELEASE) + + + +obj-debug/: FORCE | obj-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-debug SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-g -O0" + +obj-release/: FORCE | obj-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=obj-release SOURCES_BASE_DIR=src CXX_OTHER_FLAGS="-O3" + + + +$(OBJECTS_DEBUG): obj-debug/ + +$(OBJECTS_RELEASE): obj-release/ + + +build-debug: bin-debug/$(EXECUTABLE) + +build-release: bin-release/$(EXECUTABLE) + + + +clean-debug: + $(RM) -r *.o *.d bin-debug obj-debug + +clean-release: + $(RM) -r *.o *.d bin-release obj-release + + + +FORCE: + + + +doc: + doxygen + diff --git a/arun2/src/arun.cpp b/arun2/src/arun.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9903f06ad453659b815b75dee94d5685707a2bd4 --- /dev/null +++ b/arun2/src/arun.cpp @@ -0,0 +1,78 @@ +#include <tclap/CmdLine.h> +#include <vector> + +#include <factory/DataFactory.hpp> +#include <exception/AlibException.h> +#include <string/String.h> +#include <automaton/Automaton.h> +#include <automaton/run/Accept.h> +#include <automaton/run/Occurrences.h> + +int main(int argc, char* argv[]) { + try { + + std::vector<std::string> allowed; + allowed.push_back("occurrences"); + allowed.push_back("accept"); + TCLAP::ValuesConstraint<std::string> allowedVals( allowed ); + + TCLAP::CmdLine cmd("Automaton run binary", ' ', "0.01"); + TCLAP::ValueArg<std::string> type( "t", "type", "run type", false, "accept", &allowedVals); + cmd.add(type); + + TCLAP::ValueArg<std::string> input( "s", "input", "Input from file", false, "-", "file"); + cmd.add( input ); + + TCLAP::ValueArg<std::string> automaton( "a", "automaton", "Automaton data", false, "-", "file"); + cmd.add( automaton ); + + cmd.parse(argc,argv); + + std::list<sax::Token> inputTokens; + if(input.isSet()) { + if(input.getValue() == "-") { + sax::SaxParseInterface::parseStdin(inputTokens); + } else { + sax::SaxParseInterface::parseFile(input.getValue(), inputTokens); + } + } + + std::list<sax::Token> automatonTokens; + if(automaton.isSet()) { + if(automaton.getValue() == "-") { + sax::SaxParseInterface::parseStdin(automatonTokens); + } else { + sax::SaxParseInterface::parseFile(automaton.getValue(), automatonTokens); + } + } + + if( type.getValue() == "occurrences") { + string::LinearString input = alib::DataFactory::fromTokens<string::LinearString>(inputTokens); + automaton::Automaton automaton = alib::DataFactory::fromTokens<automaton::Automaton>(automatonTokens); + std::set<unsigned> res = automaton::run::Occurrences::occurrences(automaton, input); + for(unsigned number : res ) { + std::cout << number << std::endl; + } + return 0; + } else if( type.getValue() == "accept") { + string::LinearString input = alib::DataFactory::fromTokens<string::LinearString>(inputTokens); + automaton::Automaton automaton = alib::DataFactory::fromTokens<automaton::Automaton>(automatonTokens); + bool res = automaton::run::Accept::accept(automaton, input); + if(res) { + std::cout << "Input matches." << std::endl; + return 0; + } else { + std::cout << "Input don't matches." << std::endl; + return 1; + } + } else { + throw exception::AlibException( "Invalid run type" ); + return 1; + } + } catch( const exception::AlibException & e ) { + alib::DataFactory::toStdout( e ); + return 1; + } catch (...) { + return 127; + } +} diff --git a/makefile b/makefile index a643393846567a1ad6bca60bb54dff2cf4f19132..59365399d47505d223a06705e56dec83d0d6cf6f 100644 --- a/makefile +++ b/makefile @@ -17,6 +17,7 @@ SUBDIRS_BINS = aaccept2 \ anormalize2 \ arand2 \ arename2 \ + arun2 \ astat2 \ astringology2 \ atrim2 \