diff --git a/aepsilon2/src/aepsilon.cpp b/aepsilon2/src/aepsilon.cpp index 0256a31544d80620a1918386877f46efd574c891..b4fc1ff14fa66a9072503697e69a0d96813b2b72 100644 --- a/aepsilon2/src/aepsilon.cpp +++ b/aepsilon2/src/aepsilon.cpp @@ -1,9 +1,12 @@ -//============================================================================ -// Name : aepislon.cpp -// Author : Tomas Pecka -//============================================================================ +/* + * aepsilon.cpp + * + * Created on: 24. 2. 2014 + * Author: Jan Travnicek + */ #include <iostream> +#include <tclap/CmdLine.h> #include <factory/DataFactory.hpp> #include <exception/AlibException.h> @@ -13,23 +16,33 @@ int main(int argc, char** argv) { try { - if (argc == 2 && std::string("-h").compare(argv[1]) == 0) { - std::cout << "Remove epsilon transitions from automaton." << std::endl << "Usage: aepsilon [automaton.xml]" << std::endl; - return -1; - } else if (argc == 1 || (argc == 2 && std::string("--").compare(argv[1]) == 0)) { - alib::DataFactory::toStdout(automaton::simplify::EpsilonRemover::remove(alib::DataFactory::fromStdin<automaton::Automaton>())); - } else if (argc == 2) { - alib::DataFactory::toStdout(automaton::simplify::EpsilonRemover::remove(alib::DataFactory::fromFile<automaton::Automaton>(argv[1]))); + TCLAP::CmdLine cmd("Automaton rename binary", ' ', "0.01"); + + TCLAP::ValueArg<std::string> input( "a", "automaton", "Automaton where to remove epsilon transitions", false, "-", "file"); + cmd.add( input ); + + cmd.parse(argc, argv); + + std::list<sax::Token> tokens; + if(input.isSet()) { + if(input.getValue() == "-") { + sax::SaxParseInterface::parseStdin(tokens); + } else { + sax::SaxParseInterface::parseFile(input.getValue(), tokens); + } } else { - std::cout << "Automaton minimize require deterministic finite automaton" << std::endl; - return 1; + sax::SaxParseInterface::parseStdin(tokens); } + alib::DataFactory::toStdout(automaton::simplify::EpsilonRemover::remove(alib::DataFactory::fromTokens<automaton::Automaton>(tokens))); return 0; } catch (const exception::AlibException& exception) { alib::DataFactory::toStdout(exception); return 1; + } catch(const TCLAP::ArgException& exception) { + std::cout << exception.error() << std::endl; + return 2; } catch(...) { return 127; } diff --git a/aminimize2/src/aminimize.cpp b/aminimize2/src/aminimize.cpp index db1764078fdefe2cf45788cb8c1610f1c282730b..329d29a9ee99aae481986efff50b7df4b0cb8c76 100644 --- a/aminimize2/src/aminimize.cpp +++ b/aminimize2/src/aminimize.cpp @@ -1,9 +1,12 @@ -//============================================================================ -// Name : aminimize.cpp -// Author : Jan Travnicek -//============================================================================ +/* + * aminimize.cpp + * + * Created on: 24. 2. 2014 + * Author: Jan Travnicek + */ #include <iostream> +#include <tclap/CmdLine.h> #include <exception/AlibException.h> #include <factory/DataFactory.hpp> @@ -13,23 +16,33 @@ int main(int argc, char** argv) { try { - if (argc == 2 && std::string("-h").compare(argv[1]) == 0) { - std::cout << "Automaton minimize." << std::endl << "Usage: aminimize automaton.xml" << std::endl; - return -1; - } else if (argc == 1 || (argc == 2 && std::string("--").compare(argv[1]) == 0)) { - alib::DataFactory::toStdout(automaton::simplify::Minimize::minimize(alib::DataFactory::fromStdin<automaton::Automaton>())); - } else if (argc == 2) { - alib::DataFactory::toStdout(automaton::simplify::Minimize::minimize(alib::DataFactory::fromFile<automaton::Automaton>(argv[1]))); + TCLAP::CmdLine cmd("Automaton minimize binary", ' ', "0.01"); + + TCLAP::ValueArg<std::string> input( "a", "automaton", "Automaton to minimize", false, "-", "file"); + cmd.add( input ); + + cmd.parse(argc, argv); + + std::list<sax::Token> tokens; + if(input.isSet()) { + if(input.getValue() == "-") { + sax::SaxParseInterface::parseStdin(tokens); + } else { + sax::SaxParseInterface::parseFile(input.getValue(), tokens); + } } else { - std::cout << "Automaton minimize require deterministic finite automaton" << std::endl; - return 1; + sax::SaxParseInterface::parseStdin(tokens); } + alib::DataFactory::toStdout(automaton::simplify::Minimize::minimize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens))); return 0; } catch (const exception::AlibException& exception) { alib::DataFactory::toStdout(exception); return 1; + } catch(const TCLAP::ArgException& exception) { + std::cout << exception.error() << std::endl; + return 2; } catch(...) { return 127; } diff --git a/anormalize2/src/anormalize.cpp b/anormalize2/src/anormalize.cpp index 34483b8ba6ab100b61ca12df8bdd62790c85f0bc..9a1ea4382e5307b9468eb98393a5218df9b7078b 100644 --- a/anormalize2/src/anormalize.cpp +++ b/anormalize2/src/anormalize.cpp @@ -1,11 +1,12 @@ -//============================================================================ -// Name : anormalize.cpp -// Author : Jan Travnicek -//============================================================================ +/* + * anormalize.cpp + * + * Created on: 24. 2. 2014 + * Author: Jan Travnicek + */ #include <iostream> -#include <string> -#include <set> +#include <tclap/CmdLine.h> #include "exception/AlibException.h" #include "factory/DataFactory.hpp" @@ -14,22 +15,33 @@ int main(int argc, char** argv) { try { - if (argc == 2 && std::string("-h").compare(argv[1]) == 0) { - std::cout << "Automaton normalize." << std::endl << "Usage: anormalize automaton.xml" << std::endl; - return -1; - } else if (argc == 1 || (argc == 2 && std::string("--").compare(argv[1]) == 0)) { - alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromStdin<automaton::Automaton>())); - } else if (argc == 2) { - alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromFile<automaton::Automaton>(argv[1]))); + TCLAP::CmdLine cmd("Automaton normalize binary", ' ', "0.01"); + + TCLAP::ValueArg<std::string> input( "a", "automaton", "Automaton to normalize", false, "-", "file"); + cmd.add( input ); + + cmd.parse(argc, argv); + + std::list<sax::Token> tokens; + if(input.isSet()) { + if(input.getValue() == "-") { + sax::SaxParseInterface::parseStdin(tokens); + } else { + sax::SaxParseInterface::parseFile(input.getValue(), tokens); + } } else { - std::cout << "Automaton normalize require deterministic automaton" << std::endl; - return 1; + sax::SaxParseInterface::parseStdin(tokens); } + + alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens))); return 0; } catch (const exception::AlibException& exception) { alib::DataFactory::toStdout(exception); return 1; + } catch(const TCLAP::ArgException& exception) { + std::cout << exception.error() << std::endl; + return 2; } catch(...) { return 127; } diff --git a/arename2/src/arename.cpp b/arename2/src/arename.cpp index fc358816f9a752521d02dfb87bab8a06bb182680..39b6f34acc4e344e5b139d97ecb8e4726aeabfc5 100644 --- a/arename2/src/arename.cpp +++ b/arename2/src/arename.cpp @@ -6,8 +6,6 @@ */ #include <iostream> -#include <string> -#include <set> #include <tclap/CmdLine.h> #include "exception/AlibException.h"