-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGener.cpp
58 lines (52 loc) · 1.39 KB
/
Gener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <fstream>
#include <vector>
#include "explainer/languageCheck.hpp"
int checkInput(std::string name);
int main(int argc, const char * argv[]) {
std::unique_ptr<languageCheck> explainer(new languageCheck);
std::vector<std::string> cmds;
std::vector<std::string> c;
std::vector<std::string> outputs;
std::string buff;
std::string from;
std::string dest = "out.html";
if(argc < 2){
std::cout<<"Input illegally."<<std::endl;
return -1;
}
if(checkInput(argv[1])){
from = argv[1];
}else{
std::cout<<"Not a legal markdown file."<<std::endl;
return 1;
}
if(argc > 2){
dest = argv[2];
}
std::ifstream file;
file.open(from);
if(!file){
std::cout<<"Error file\t" + from<<std::endl;
return -1;
}
while(getline(file,buff)){
c.push_back(buff);
}
c.push_back("");
explainer->setTitle(from);
explainer->getContent(c);
explainer->run(c);
explainer->outputMarkdown(outputs);
std::ofstream out;
out.open(dest);
for(auto s:outputs){
out<<s<<std::endl;
}
return 0;
}
int checkInput(std::string name){
std::smatch sm;
std::regex_match(name,sm,std::regex(".*[(md)(markdown)(mkd)(mdown)]"));
return static_cast<int>(sm.size());
};