Skip to content
Snippets Groups Projects
Commit c7c9c5b9 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

getopt on convert.automaton

parent 9442938e
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <fstream>
#include "AutomatonParser.h"
 
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "automaton/FSM/FSM.h"
 
#define FROM 1
#define TO 2
 
int fromAutomaton(std::istream& in, std::ostream& out) {
AutomatonParser parser(in);
......@@ -20,7 +27,45 @@ int toAutomaton(std::istream& in, std::ostream& out) {
}
 
int main(int argc, char* argv[]) {
int fromTo = FROM;
if(fromTo == FROM) return fromAutomaton(std::cin, std::cout);
else return toAutomaton(std::cin, std::cout);
int fromTo = 0;
int c;
while (1) {
static struct option long_options[] = {
{"from", no_argument, &fromTo, FROM},
{"to", no_argument, &fromTo, TO},
{0, 0, 0, 0}
};
int option_index = 0;
c = getopt_long (argc, argv, "", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 0:
break;
default:
optind--;
goto more;
}
}
more:
std::istream* in = &std::cin;
if(optind != argc) in = new std::ifstream(argv[optind]);
if(fromTo == FROM) {
fromAutomaton(*in, std::cout);
} else if(fromTo == TO) {
toAutomaton(*in, std::cout);
} else {
std::cerr << "error" << std::endl;
}
if(c != -1) delete in;
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment