-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (90 loc) · 3.61 KB
/
main.cpp
File metadata and controls
96 lines (90 loc) · 3.61 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
86
87
88
89
90
91
92
93
94
95
96
/*
* Stellarium Sky Culture Converter
* Copyright (C) 2025 Ruslan Kabatsayev
* Copyright (C) 2025 Mher Mnatsakanyan
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#include <iostream>
#include <QString>
#include <vector>
#include <string>
#include <QCoreApplication>
#include "SkyCultureConverter.hpp"
#include "Utils.hpp"
#include <QMetaEnum>
int usage(const char *argv0, const int ret)
{
auto &out = ret ? std::cerr : std::cout;
out << "Usage: " << argv0 << " [options...] skyCultureDir outputDir [skyCulturePoDir]\n"
<< "Options:\n"
<< " --footnotes-to-references Try to convert footnotes to references\n"
<< " --untrans-names-are-native Record untranslatable star/DSO names as native names\n"
<< " --native-locale LOCALE Use *_names.LOCALE.fab as a source for \"native\" constellation names (the\n"
" middle column in *_names.eng.fab will be moved to the \"pronounce\" entry.\n"
<< " --translated-md Generate localized Markdown files (for checking translations)\n";
return ret;
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QString inDir, outDir, poDir, nativeLocale;
bool footnotesToRefs = false, genTranslatedMD = false, convertUntranslatableNamesToNative = false;
// parse arguments
std::vector<QString> args(argv + 1, argv + argc);
for (const auto &arg : args)
{
if (!arg.isEmpty() && arg[0] != '-')
{
if (inDir.isEmpty())
inDir = arg;
else if (outDir.isEmpty())
outDir = arg;
else if (poDir.isEmpty())
poDir = arg;
else
return usage(argv[0], 1);
}
else if (arg == "--translated-md")
genTranslatedMD = true;
else if (arg == "--footnotes-to-references")
footnotesToRefs = true;
else if (arg == "--untrans-names-are-native")
convertUntranslatableNamesToNative = true;
else if (arg == "--native-locale")
{
static bool nextIsLocale = false;
nextIsLocale = !nextIsLocale;
if (nextIsLocale)
continue;
nativeLocale = arg;
}
else if (arg == "--help" || arg == "-h")
{
return usage(argv[0], 0);
}
else
return usage(argv[0], 1);
}
auto result = SkyCultureConverter::convert(inDir, outDir, poDir, nativeLocale,
footnotesToRefs, genTranslatedMD,
convertUntranslatableNamesToNative);
if (result != SkyCultureConverter::ReturnValue::CONVERT_SUCCESS)
{
std::cerr << "SkyCultureConverter::\tConversion failed with error code: "
<< QMetaEnum::fromType<SkyCultureConverter::ReturnValue>().valueToKey(static_cast<int>(result)) << "\n";
}
return static_cast<int>(result);
}