From 6129736c8e7dda38e93adf15ff37326d00257232 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 29 Oct 2014 22:56:00 +0100 Subject: [PATCH] tclap in more binary files --- aepsilon2/src/aepsilon.cpp | 39 ++++++++++++++++++++----------- aminimize2/src/aminimize.cpp | 39 ++++++++++++++++++++----------- anormalize2/src/anormalize.cpp | 42 ++++++++++++++++++++++------------ arename2/src/arename.cpp | 2 -- 4 files changed, 79 insertions(+), 43 deletions(-) diff --git a/aepsilon2/src/aepsilon.cpp b/aepsilon2/src/aepsilon.cpp index 0256a31544..b4fc1ff14f 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 db1764078f..329d29a9ee 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 34483b8ba6..9a1ea4382e 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 fc358816f9..39b6f34acc 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" -- GitLab