13#include <QCommandLineOption>
14#include <QCommandLineParser>
15#include <QCoreApplication>
19#include <QRegularExpression>
29#include "../core/kconfig_version.h"
30#include "KConfigCommonStructs.h"
31#include "KConfigHeaderGenerator.h"
32#include "KConfigParameters.h"
33#include "KConfigSourceGenerator.h"
34#include "KConfigXmlParser.h"
55 result = varName(n, cfg);
77QString enumType(
const CfgEntry *e,
bool globalEnums)
79 QString result = e->choices.name();
90QString enumTypeQualifier(
const QString &n,
const CfgEntry::Choices &c)
96 }
else if (c.external()) {
97 result = c.externalQualifier();
176 const bool isAscii = std::none_of(str.
cbegin(), str.
cend(), [](
const QChar ch) {
177 return ch.unicode() > 127;
181 return QLatin1String(
"QStringLiteral( %1 )").arg(quoteString(str));
183 return QLatin1String(
"QString::fromUtf8( %1 )").arg(quoteString(str));
196bool isUnsigned(
const QString &type)
208 return QStringLiteral(
"const QString &");
210 return QStringLiteral(
"const QStringList &");
212 return QStringLiteral(
"const QFont &");
214 return QStringLiteral(
"const QRect &");
216 return QStringLiteral(
"const QRectF &");
218 return QStringLiteral(
"const QSize &");
220 return QStringLiteral(
"const QSizeF &");
222 return QStringLiteral(
"const QColor &");
224 return QStringLiteral(
"const QPoint &");
226 return QStringLiteral(
"const QPointF &");
228 return QStringLiteral(
"int");
230 return QStringLiteral(
"uint");
232 return QStringLiteral(
"bool");
234 return QStringLiteral(
"double");
236 return QStringLiteral(
"const QDateTime &");
238 return QStringLiteral(
"qint64");
240 return QStringLiteral(
"quint64");
242 return QStringLiteral(
"const QList<int> &");
244 return QStringLiteral(
"int");
246 return QStringLiteral(
"const QString &");
248 return QStringLiteral(
"const QStringList &");
250 return QStringLiteral(
"const QString &");
252 return QStringLiteral(
"const QUrl &");
254 return QStringLiteral(
"const QList<QUrl> &");
256 std::cerr <<
"kconfig_compiler_kf6 does not support type \"" << qPrintable(type) <<
"\"" << std::endl;
257 return QStringLiteral(
"QString");
268 return QStringLiteral(
"QString");
270 return QStringLiteral(
"QStringList");
272 return QStringLiteral(
"QFont");
274 return QStringLiteral(
"QRect");
276 return QStringLiteral(
"QRectF");
278 return QStringLiteral(
"QSize");
280 return QStringLiteral(
"QSizeF");
282 return QStringLiteral(
"QColor");
284 return QStringLiteral(
"QPoint");
286 return QStringLiteral(
"QPointF");
288 return QStringLiteral(
"int");
290 return QStringLiteral(
"uint");
292 return QStringLiteral(
"bool");
294 return QStringLiteral(
"double");
296 return QStringLiteral(
"QDateTime");
298 return QStringLiteral(
"qint64");
300 return QStringLiteral(
"quint64");
302 return QStringLiteral(
"QList<int>");
304 return QStringLiteral(
"int");
306 return QStringLiteral(
"QString");
308 return QStringLiteral(
"QStringList");
310 return QStringLiteral(
"QString");
312 return QStringLiteral(
"QUrl");
314 return QStringLiteral(
"QList<QUrl>");
316 std::cerr <<
"kconfig_compiler_kf6 does not support type \"" << qPrintable(type) <<
"\"" << std::endl;
317 return QStringLiteral(
"QString");
325 return QStringLiteral(
"\"\"");
327 return QStringLiteral(
"QStringList()");
329 return QStringLiteral(
"QFont()");
331 return QStringLiteral(
"QRect()");
333 return QStringLiteral(
"QRectF()");
335 return QStringLiteral(
"QSize()");
337 return QStringLiteral(
"QSizeF()");
339 return QStringLiteral(
"QColor(128, 128, 128)");
341 return QStringLiteral(
"QPoint()");
343 return QStringLiteral(
"QPointF()");
345 return QStringLiteral(
"0");
347 return QStringLiteral(
"0");
349 return QStringLiteral(
"false");
351 return QStringLiteral(
"0.0");
353 return QStringLiteral(
"QDateTime()");
355 return QStringLiteral(
"0");
357 return QStringLiteral(
"0");
359 return QStringLiteral(
"QList<int>()");
361 return QStringLiteral(
"0");
363 return QStringLiteral(
"\"\"");
365 return QStringLiteral(
"QStringList()");
367 return QStringLiteral(
"\"\"");
369 return QStringLiteral(
"QUrl()");
371 return QStringLiteral(
"QList<QUrl>()");
373 std::cerr <<
"Error, kconfig_compiler_kf6 does not support the \"" << qPrintable(type) <<
"\" type!" << std::endl;
374 return QStringLiteral(
"QString");
380 if (
type.isEmpty()) {
400 const QString argSuffix = (!e->param.
isEmpty()) ? (QStringLiteral(
"[%1]").arg(e->paramMax + 1)) :
QString();
403 if (!cfg.itemAccessors && !cfg.dpointer) {
404 result += QLatin1String{
" "} + (!e->signalList.
isEmpty() ? QStringLiteral(
"KConfigCompilerSignallingItem") : type);
405 result +=
QLatin1String(
" *item%1;\n").arg(fCap + argSuffix);
408 if (!e->signalList.
isEmpty()) {
409 result +=
QLatin1String(
" %1 *%2;\n").arg(type, innerItemVar(e, cfg) + argSuffix);
421 if (cfg.itemAccessors) {
442 return itemPath(e, cfg);
452 return cfg.dpointer ?
QLatin1String{
"d->"} + itemVar(e, cfg) : itemVar(e, cfg);
458 str +=
QLatin1String(
"( currentGroup(), %1, %2").arg(key, varPath(entry->name, cfg) + param);
475 return newInnerItem(entry, key, defaultValue, cfg, param);
479 str +=
QLatin1String(
"new KConfigCompilerSignallingItem(%1, this, notifyFunction, ").arg(innerItemVar(entry, cfg) + param);
481 const int listSize = sigs.
size();
482 for (
int i = 0; i < listSize; ++i) {
486 str += signalEnumName(sigs[i].name);
510 bool firstArg =
true;
511 for (
const auto ¶m : parameters) {
512 const QString paramName = param.name;
515 const QString tmp = QStringLiteral(
"%%1").
arg(i++);
537 return QLatin1String(
"QStringLiteral( \"%1\" )%2").arg(paramString, arguments);
544 switch (cfg.translationSystem) {
545 case KConfigParameters::QtTranslation:
547 result +=
QLatin1String(
"/*: %1 */ QCoreApplication::translate(\"").arg(context);
554 case KConfigParameters::KdeTranslation:
556 result +=
QLatin1String(
"i18ndc(%1, %2, ").arg(quoteString(cfg.translationDomain), quoteString(context));
557 }
else if (!cfg.translationDomain.
isEmpty()) {
558 result +=
QLatin1String(
"i18nd(%1, ").arg(quoteString(cfg.translationDomain));
559 }
else if (!context.
isEmpty()) {
560 result +=
QLatin1String(
"i18nc(%1, ").arg(quoteString(context));
568 QString resolvedString = string;
570 result += quoteString(resolvedString);
572 result += quoteString(
string);
584 if (itemVarStr.
isNull()) {
585 itemVarStr = itemPath(e, cfg);
588 txt +=
QLatin1String(
" %1->setLabel( %2 );\n").arg(itemVarStr, translatedString(cfg, e->label, e->labelContext, e->param, i));
591 txt +=
QLatin1String(
" %1->setToolTip( %2 );\n").arg(itemVarStr, translatedString(cfg, e->toolTip, e->toolTipContext, e->param, i));
594 txt +=
QLatin1String(
" %1->setWhatsThis( %2 );\n").arg(itemVarStr, translatedString(cfg, e->whatsThis, e->whatsThisContext, e->param, i));
605 if (cfg.qCategoryLoggingName.
isEmpty()) {
606 out <<
" qDebug() << \"" << setFunction(n);
608 out <<
" qCDebug(" << cfg.qCategoryLoggingName <<
") << \"" << setFunction(n);
615QString memberGetDefaultBody(
const CfgEntry *e)
622 out <<
" switch (i) {\n";
623 for (
int i = 0; i <= e->paramMax; ++i) {
624 if (!e->paramDefaultValues[i].
isEmpty()) {
625 out <<
" case " << i <<
": return " << e->paramDefaultValues[i] <<
";\n";
628 QString defaultValue = e->defaultValue;
630 out <<
" default:\n";
634 out <<
" return " << e->defaultValue <<
';';
648 out <<
"return " << itemPath(e, cfg);
664 while (!in.atEnd()) {
665 currLine = in.readLine();
667 for (
int i = 0; i < spaces; ++i) {
671 out << currLine <<
'\n';
676bool hasErrors(KConfigXmlParser &parser,
const ParseResult &parseResult,
const KConfigParameters &cfg)
681 std::cerr <<
"Class name missing" << std::endl;
685 if (cfg.singleton && !parseResult.parameters.
isEmpty()) {
686 std::cerr <<
"Singleton class can not have parameters" << std::endl;
690 if (!parseResult.cfgFileName.
isEmpty() && parseResult.cfgFileNameArg) {
691 std::cerr <<
"Having both a fixed filename and a filename as argument is not possible." << std::endl;
708 if (parseResult.entries.
isEmpty()) {
709 std::cerr <<
"No entries." << std::endl;
716int main(
int argc,
char **argv)
719 app.setApplicationName(QStringLiteral(
"kconfig_compiler"));
720 app.setApplicationVersion(QStringLiteral(KCONFIG_VERSION_STRING));
728 QStringLiteral(
"."));
735 parser.addPositionalArgument(QStringLiteral(
"file.kcfg"), QStringLiteral(
"Input kcfg XML file"));
736 parser.addPositionalArgument(QStringLiteral(
"file.kcfgc"), QStringLiteral(
"Code generation options file"));
738 parser.addOption(targetDirectoryOption);
739 parser.addOption(licenseOption);
741 parser.addVersionOption();
742 parser.addHelpOption();
745 if (parser.isSet(licenseOption)) {
746 std::cout <<
"Copyright 2003 Cornelius Schumacher, Waldo Bastian, Zack Rusin," << std::endl;
747 std::cout <<
" Reinhold Kainhofer, Duncan Mac-Vicar P., Harald Fernengel" << std::endl;
748 std::cout <<
"This program comes with ABSOLUTELY NO WARRANTY." << std::endl;
749 std::cout <<
"You may redistribute copies of this program" << std::endl;
750 std::cout <<
"under the terms of the GNU Library Public License." << std::endl;
751 std::cout <<
"For more information about these matters, see the file named COPYING." << std::endl;
755 const QStringList args = parser.positionalArguments();
756 if (args.
count() < 2) {
757 std::cerr <<
"Too few arguments." << std::endl;
761 if (args.
count() > 2) {
762 std::cerr <<
"Too many arguments." << std::endl;
765 inputFilename = args.
at(0);
766 codegenFilename = args.
at(1);
769 QString baseDir = parser.value(targetDirectoryOption);
781 KConfigXmlParser xmlParser(cfg, inputFilename);
787 ParseResult parseResult = xmlParser.getParseResult();
789 if (hasErrors(xmlParser, parseResult, cfg)) {
794 for (
const auto &signal : std::as_const(parseResult.signalList)) {
795 parseResult.hasNonModifySignals |= !signal.modify;
799 const QString baseName = inputFilename.
mid(0, inputFilename.
size() - 5);
800 KConfigHeaderGenerator headerGenerator(baseName, baseDir, cfg, parseResult);
801 headerGenerator.start();
802 headerGenerator.save();
804 KConfigSourceGenerator sourceGenerator(baseName, baseDir, cfg, parseResult);
805 sourceGenerator.start();
806 sourceGenerator.save();
808 qDeleteAll(parseResult.entries);
Configuration Compiler Configuration.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
char32_t toLower(char32_t ucs4)
char32_t toUpper(char32_t ucs4)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
qsizetype size() const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
const QChar at(qsizetype position) const const
const_iterator cbegin() const const
const_iterator cend() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool isNull() const const
QString mid(qsizetype position, qsizetype n) const const
QString number(double n, char format, int precision)
QString & prepend(QChar ch)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString toLower() const const