This repository was archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (76 loc) · 3.48 KB
/
main.cpp
File metadata and controls
85 lines (76 loc) · 3.48 KB
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
/*
* main.cpp
* This file is part of ProbabilisticTraceAlignment
*
* Copyright (C) 2020 - Giacomo Bergami
*
* ProbabilisticTraceAlignment is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ProbabilisticTraceAlignment is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProbabilisticTraceAlignment. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iomanip>
#include "ConfigurationFile.h"
#include <utils/xml_utils.h>
#include <QtWidgets/QApplication>
#include <gui/WSettings.h>
#include <args.hxx>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
args::ArgumentParser parser("FuzzyStringMatching (2) (c) 2020-2021 by Giacomo Bergami.", "This free and open software program implements the (Approximate) Probabilistic Trace Alignment. Youse at your own risk.");
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
args::Group group(parser, "You can use the following parameters", args::Group::Validators::DontCare, args::Options::Global);
args::Flag gui(group, "gui", "Shows the GUI for setting the specified configuration file (when no parameter is specified, this is the default behaviour). The gui will store the resulting configuration file file once the window is closed.", {'g', "gui"});
args::Flag run(group, "run", "Runs the program accordingly to the configuration file. If both --gui and --run are set, first the GUI is displayed, and then the benchmark is run", {'r', "run"});
args::ValueFlag<std::string> con(group, "configuration.yaml", "Specifies the configuration file to edit (--gui) or to use to run the program (--run). If no configuration file is specified, the program will look for 'configuration.yaml'. If that file is not provided, a default configuration will be set-up. Run --gui to see the file", {'c', "conf"});
try {
parser.ParseCLI(argc, argv);
} catch (args::Help& ) {
std::cout << parser;
return 0;
} catch (args::ParseError& e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
} catch (args::ValidationError& e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}
std::string yaml = "configuration.yaml";
if (con) {
yaml = args::get(con);
}
if (gui && run) { // Running the gui, and then possibly run the benchmarks
pid_t child = fork();
if (child) {
wait(nullptr); // Unfortunately, by quitting the window, the process will terminate. Therefore, I fork a child process for the gui, I wait for it, and then I run the benchmarks
} else {
QApplication app(argc, (char**)argv);
WSettings window{yaml};
window.show();
return app.exec();
}
}
if (run) {
ConfigurationFile conf{yaml};
conf.run();
} else if (gui) {
QApplication app(argc, (char**)argv);
WSettings window{yaml};
window.show();
return app.exec();
} else {
std::cout << parser;
}
return 0;
}