-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
284 lines (241 loc) · 10.2 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/**
* @file main.cpp
* @author ZHENG Robert (www.robert.hase-zheng.net)
* @brief header_docu
* @details fileheader parser for documentation with parser plugins and output writer plugins
* @version 1.3.0
* @date 2023-04-30
*
* @copyright Copyright (c) ZHENG Robert 2023
*
*/
#include <QCoreApplication>
#include <iostream>
#include <QDir>
#include <QFile>
/* https://github.com/jarro2783/cxxopts */
#include "Includes/cxxopts.hpp"
#include "Includes/rz_datetime.h"
#include "Includes/rz_dirfileinfo.h"
#include "Includes/rz_inifile.h"
#include "Includes/rz_inoutput.h"
#include "Includes/rz_snippets.h"
const std::string VERSION = "01.03.00";
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string prog = argv[0];
QDir path = QDir::currentPath();
QString dir = path.path();
DateTime datetime;
datetime.setDateTime();
QMap<QString, QString> pluginParserMap;
QMap<QString, QString> pluginWriterMap;
//Inifile;
QString pathToInifile = prog.c_str();
pathToInifile.append(".ini");
QString inputDir, outputDir, fileExtension, fileInType, fileOutType;
Inifile Inifile;
Snippets Snippets;
cxxopts::Options options(prog, "file header parser");
options.set_width(100)
.add_options()("a,auto",
"run with default Inifile")("c,create",
"create Inifile")("d,dir",
"parse directory <dir>",
cxxopts::value<std::string>())(
"e,ext",
"file extension to search for. E.g.:\n<*.h> | <*.hpp> | <*.c> | <*.cpp>",
cxxopts::value<std::string>())("f,file",
"parse <pathTo/fileName>",
cxxopts::value<std::string>())(
"i,ini",
"use Inifile <pathTo/inifile>",
cxxopts::value<std::string>()->default_value(
prog + ".ini"))("l,listini", "list Inifile (optional with --ini <pathTo/IniFile>)")(
"o,out",
"output directory <dir>",
cxxopts::value<std::string>())("p,parser",
"how to parse the input (use --plugins to list "
"available plugins):\ne.g.: <gh_markdown> | <doxygen>",
cxxopts::value<std::string>())("plugins",
"list available plugins")(
"w,writer",
"output type (use --plugins to list "
"available plugins):\ne.g.: <adoc> | <csv> | <html> | <json> | <md> | <txt>",
cxxopts::value<std::string>())("v,version", "Print program and version")("h, help",
"Print help");
auto result = options.parse(argc, argv);
if (argc <= 1 || result.count("help")) {
std::cout << options.help() << std::endl;
exit(0);
}
if (result.count("version")) {
std::cout << prog << "-" << VERSION << std::endl;
exit(0);
}
// create default Inifile
if (result.count("create")) {
Inifile.createIni(dir);
Snippets.checkBool(Inifile.saveIniToFile(dir, pathToInifile));
exit(0);
}
// load given Inifile
if (result.count("ini")) {
std::string dirfile = result["ini"].as<std::string>();
pathToInifile = dirfile.c_str();
Snippets.checkBool(Inifile.loadIni(pathToInifile));
}
else {
// load default Inifile
//qInfo() << "load default Ini: " << pathToInifile;
Snippets.checkBool(Inifile.loadIni(pathToInifile));
}
// list ini
if(result.count("listini")) {
Inifile.listIniEntries();
exit(0);
}
// input dir
if(result.count("dir")) {
Inifile.setInputDir(result["dir"].as<std::string>());
}
// file extension
if(result.count("ext")) {
Inifile.setInputDir(result["ext"].as<std::string>());
}
// parse single file
if(result.count("file")) {
Inifile.setInputDir(result["file"].as<std::string>());
}
// output dir
if(result.count("out")) {
Inifile.setOutputDir(result["out"].as<std::string>());
}
// input type
if(result.count("parser")) {
Inifile.setParserType(result["parser"].as<std::string>());
std::string fileintype = result["parser"].as<std::string>();
fileInType = fileintype.c_str();
} else {
fileInType = Inifile.getParserType();
}
// output type => deprecated -> writer
if(result.count("type")) {
Inifile.setFileType(result["type"].as<std::string>());
Inifile.setWriterType(result["type"].as<std::string>());
std::string fileoutputtype = result["type"].as<std::string>();
fileOutType = fileoutputtype.c_str();
}
// output type
if(result.count("writer")) {
Inifile.setWriterType(result["writer"].as<std::string>());
std::string fileoutputtype = result["writer"].as<std::string>();
fileOutType = fileoutputtype.c_str();
} else {
fileOutType = Inifile.getWriterType();
}
// list plug-ins
if (result.count("plugins")) {
qInfo() << "Parser Plug-Ins:\n================";
QString pluginsDir = Inifile.getParserPluginsDir();
Snippets.listPlugins(Snippets.getPlugins(pluginsDir));
qInfo() << "\nWriter Plug-Ins:\n================";
pluginsDir = Inifile.getWriterPluginsDir();
Snippets.listPlugins(Snippets.getPlugins(pluginsDir));
exit(0);
}
qInfo() << datetime.getHumanUTC() << " : " << prog << "-" << VERSION << " started";
// check config
Snippets.checkBool(Inifile.checkIniInputs());
Snippets.checkBool(Inifile.checkIniMeta());
Snippets.checkBool(Inifile.checkIniOutputs());
// get + check plugins
Snippets.checkBool(Inifile.checkIniPlugins(Snippets, pluginParserMap, pluginWriterMap));
// check given plugin
if(pluginParserMap.contains(fileInType) == false) {
qWarning() << "no parser plug-in for input format " << fileInType << " found.";
exit(1);
}
if(pluginWriterMap.contains(fileOutType) == false) {
qWarning() << "no writer plug-in for output format " << fileOutType << " found.";
exit(1);
}
//#######
// request single file parsing?
if(result.count("file")) {
inputDir = Inifile.getInputDir();
DirFileInfo df(inputDir);
df.addMapParseKeys(Inifile.getMetadata());
InputOutput* ioSingle = new InputOutput();
ioSingle->setpParser(pluginParserMap[fileInType]);
ioSingle->setwParser(pluginWriterMap[fileOutType]);
ioSingle->setData(df.mapParseKeys,df.mapFileAttribs);
//QString outPutFile = Inifile.getOutputDir() + "/" + df.mapFileAttribs["FILE_Name"] + "." + fileOutType;
QString outPutFile = ioSingle->setOutputDir(Inifile.getInputDir(), Inifile.getOutputDir(), df.mapFileAttribs["FILE_absolutePath"]);
//qInfo() << "\n\ntarget: " << outPutFile;
ioSingle->makeOutputDir(outPutFile);
outPutFile.append("/" + df.mapFileAttribs["FILE_baseFileName"] + "." + fileOutType);
//qInfo() << "target file: " << outPutFile;
Snippets.setCountedFiles(1);
ioSingle->setFiles(Inifile.getInputDir(), outPutFile);
ioSingle->runner();
}
// request parse dir
if(result.count("dir")) {
QDir dir = Inifile.getInputDir();
inputDir = Inifile.getInputDir();
outputDir = Inifile.getOutputDir();
QStringList filters = Inifile.getInputExtensions();
//Snippets.getDirsRecursive(dir, filters, pluginParserMap[fileInType], pluginWriterMap[fileOutType]);
Snippets.getDirsRecursive(dir,
inputDir,
outputDir,
filters,
pluginParserMap[Inifile.getParserType()],
pluginWriterMap[Inifile.getWriterType()],
fileOutType,
Inifile.getMetadata());
}
if (result.count("auto")) {
QDir dir = Inifile.getInputDir();
inputDir = Inifile.getInputDir();
outputDir = Inifile.getOutputDir();
QStringList filters = Inifile.getInputExtensions();
//Snippets.getDirsRecursive(dir, filters, pluginParserMap[fileInType], pluginWriterMap[fileOutType]);
Snippets.getDirsRecursive(dir,
inputDir,
outputDir,
filters,
pluginParserMap[Inifile.getParserType()],
pluginWriterMap[Inifile.getWriterType()],
fileOutType,
Inifile.getMetadata());
}
/*
// ##### TEST #####
qInfo() << "##### Test von Main #####";
QThread::currentThread()->setObjectName("Main");
qInfo() << "Main: " << QThread::currentThread();
QThreadPool pool;
qInfo() << pool.maxThreadCount() << "Threads";
QFutureWatcher<void> watcher;
//InputOutput gh_markdown;
InputOutput* gh_markdown = new InputOutput();
//gh_markdown.run();
QObject::connect(&watcher, &QFutureWatcher<void>::finished,gh_markdown,&InputOutput::run); //Auto connect "should" work
//QFuture<void> future = QtConcurrent::map(list,&multiply);
QFuture<void> future = QtConcurrent::run(&pool, gh_markdown->run);
watcher.setFuture(future);
qInfo() << "Back in main!";
watcher.waitForFinished(); //Blocking
*/
datetime.setDateTime();
// 2023-04-03 18:22:57 : Snippets.getCountedFiles() .cpp Files in folder ./src found. Output stored with format md in folder ./header_docu_cpp
qInfo() << datetime.getHumanUTC() << " : "
<< "File(s) parsed with " << fileInType << " header parser. Output stored with format "
<< fileOutType << " in folder: " << Inifile.getOutputDir();
// the end
exit(0);
return a.exec();
}