-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
93 lines (86 loc) · 2.78 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
/* -----------------------------------------------------------------------------
* The Cyberiada GraphML C++ library implemention
*
* The testing program
*
* Copyright (C) 2024 Alexey Fedoseev <aleksey@fedoseev.net>
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see https://www.gnu.org/licenses/
* ----------------------------------------------------------------------------- */
#include <iostream>
#include <stdlib.h>
#include "cyberiadamlpp.h"
using namespace Cyberiada;
using namespace std;
void usage(const char* program)
{
cerr << program << " <print|convert> [[-f <cyberiada|yed>] -o <path-to-output-graphml-file>] <path-to-input-graphml-file>" << endl;
cerr << "\tprint\tPrint the graphml SM structure of the file <path-to-input-graphml-file>" << endl;
cerr << "\tconvert\tConvert the graphml SM file from <path-to-input-graphml-file> to <path-to-output-graphml-file> using format:" << endl;
cerr << "\t\t\tcyberiada Cyberiada-GraphML 1.0 format" << endl;
cerr << "\t\t\tyed Legacy Berloga-YED format" << endl;
exit(1);
}
int main(int argc, char** argv)
{
LocalDocument d;
DocumentFormat format;
string command, from_file, to_file, format_str;
if (argc < 3) {
usage(argv[0]);
}
command = argv[1];
if (command == "print" && argc == 3) {
from_file = argv[2];
} else if (command == "convert" && (argc == 5 || argc == 7)) {
if (argc == 5 && string(argv[2]) == "-o") {
to_file = argv[3];
from_file = argv[4];
} else if (argc == 7) {
if (string(argv[2]) == "-f" && string(argv[4]) == "-o") {
to_file = argv[5];
format_str = argv[3];
} else if (string(argv[2]) == "-o" && string(argv[4]) == "-f") {
to_file = argv[3];
format_str = argv[5];
} else {
usage(argv[0]);
}
from_file = argv[6];
} else {
usage(argv[0]);
}
if (format_str.empty() || format_str == "cyberiada") {
format = formatCyberiada10;
} else if (format_str == "yes") {
format = formatLegacyYED;
} else {
usage(argv[0]);
}
} else {
usage(argv[0]);
}
try {
d.open(from_file);
if (argc == 3) {
cout << d << endl;
} else {
d.save_as(to_file, format);
}
} catch (const Cyberiada::Exception& e) {
cerr << "Error while processing graphml file: " << e.str() << endl;
return 2;
}
return 0;
}