Interpret command-line arguments
This commit is contained in:
parent
1736575ee8
commit
703c4a9b54
1 changed files with 28 additions and 1 deletions
29
src/main.cpp
29
src/main.cpp
|
|
@ -1,4 +1,31 @@
|
||||||
int main()
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "SimpleMarkov.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
if (argc > 5 || argc < 3) {
|
||||||
|
std::cout << "Usage: " << argv[0] << "<filename> [s] [...]" << std::endl;
|
||||||
|
std::cout << " s: [<number_of_paragraphs> [<length>]] -> SimpleMarkov" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string filename = argv[1];
|
||||||
|
std::string mode = argv[2];
|
||||||
|
|
||||||
|
if (mode == "s") {
|
||||||
|
int paragraphs = 1;
|
||||||
|
if (argc >= 4) paragraphs = std::stoi(argv[3]);
|
||||||
|
int length = 10;
|
||||||
|
if (argc >= 5) length = std::stoi(argv[4]);
|
||||||
|
|
||||||
|
SimpleMarkov m(length);
|
||||||
|
m.eat(filename);
|
||||||
|
std::cout << m.regurgitate(paragraphs);
|
||||||
|
} else {
|
||||||
|
std::cout << "Error: Incorrect mode." << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue