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
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Assistant of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "../shared/helpgenerator.h"
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtGui/QGuiApplication>
#include <QtCore/QTranslator>
#include <QtCore/QLocale>
#include <QtCore/QLibraryInfo>
#include <private/qhelpprojectdata_p.h>
QT_USE_NAMESPACE
class QHG {
Q_DECLARE_TR_FUNCTIONS(QHelpGenerator)
};
int main(int argc, char *argv[])
{
QString error;
QString arg;
QString compressedFile;
QString projectFile;
QString basePath;
bool showHelp = false;
bool showVersion = false;
bool checkLinks = false;
bool silent = false;
// don't require a window manager even though we're a QGuiApplication
qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("minimal"));
QGuiApplication app(argc, argv);
#ifndef Q_OS_WIN32
QTranslator translator;
QTranslator qtTranslator;
QTranslator qt_helpTranslator;
QString sysLocale = QLocale::system().name();
QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (translator.load(QLatin1String("assistant_") + sysLocale, resourceDir)
&& qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)
&& qt_helpTranslator.load(QLatin1String("qt_help_") + sysLocale, resourceDir)) {
app.installTranslator(&translator);
app.installTranslator(&qtTranslator);
app.installTranslator(&qt_helpTranslator);
}
#endif // Q_OS_WIN32
for (int i = 1; i < argc; ++i) {
arg = QString::fromLocal8Bit(argv[i]);
if (arg == QLatin1String("-o")) {
if (++i < argc) {
QFileInfo fi(QString::fromLocal8Bit(argv[i]));
compressedFile = fi.absoluteFilePath();
} else {
error = QHG::tr("Missing output file name.");
}
} else if (arg == QLatin1String("-v")) {
showVersion = true;
} else if (arg == QLatin1String("-h")) {
showHelp = true;
} else if (arg == QLatin1String("-c")) {
checkLinks = true;
} else if (arg == QLatin1String("-s")) {
silent = true;
} else {
QFileInfo fi(arg);
projectFile = fi.absoluteFilePath();
basePath = fi.absolutePath();
}
}
if (showVersion) {
fputs(qPrintable(QHG::tr("Qt Help Generator version 1.0 (Qt %1)\n")
.arg(QT_VERSION_STR)), stdout);
return 0;
}
if (projectFile.isEmpty() && !showHelp)
error = QHG::tr("Missing Qt help project file.");
QString help = QHG::tr("\nUsage:\n\n"
"qhelpgenerator <help-project-file> [options]\n\n"
" -o <compressed-file> Generates a Qt compressed help\n"
" file called <compressed-file>.\n"
" If this option is not specified\n"
" a default name will be used.\n"
" -c Checks whether all links in HTML files\n"
" point to files in this help project.\n"
" -s Suppresses status messages.\n"
" -v Displays the version of \n"
" qhelpgenerator.\n\n");
if (showHelp) {
fputs(qPrintable(help), stdout);
return 0;
}else if (!error.isEmpty()) {
fprintf(stderr, "%s\n\n%s", qPrintable(error), qPrintable(help));
return -1;
}
QFile file(projectFile);
if (!file.open(QIODevice::ReadOnly)) {
fputs(qPrintable(QHG::tr("Could not open %1.\n").arg(projectFile)), stderr);
return -1;
}
if (compressedFile.isEmpty()) {
if (!checkLinks) {
QFileInfo fi(projectFile);
compressedFile = basePath + QDir::separator()
+ fi.baseName() + QLatin1String(".qch");
}
} else {
// check if the output dir exists -- create if it doesn't
QFileInfo fi(compressedFile);
QDir parentDir = fi.dir();
if (!parentDir.exists()) {
if (!parentDir.mkpath(QLatin1String("."))) {
fputs(qPrintable(QHG::tr("Could not create output directory: %1\n")
.arg(parentDir.path())), stderr);
}
}
}
QHelpProjectData *helpData = new QHelpProjectData();
if (!helpData->readData(projectFile)) {
fprintf(stderr, "%s\n", qPrintable(helpData->errorMessage()));
return -1;
}
HelpGenerator generator(silent);
bool success = true;
if (checkLinks)
success = generator.checkLinks(*helpData);
if (success && !compressedFile.isEmpty())
success = generator.generate(helpData, compressedFile);
delete helpData;
if (!success) {
fprintf(stderr, "%s\n", qPrintable(generator.error()));
return -1;
}
return 0;
}
|