diff options
Diffstat (limited to 'tools/linguist/lupdate/main.cpp')
-rw-r--r-- | tools/linguist/lupdate/main.cpp | 88 |
1 files changed, 70 insertions, 18 deletions
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp index 737bfd0..ab88083 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -42,6 +42,7 @@ #include "lupdate.h" #include <translator.h> +#include <profileparser.h> #include <profileevaluator.h> #include <QtCore/QCoreApplication> @@ -61,12 +62,14 @@ static QString m_defaultExtensions; static void printOut(const QString & out) { - std::cout << qPrintable(out); + QTextStream stream(stdout); + stream << out; } static void printErr(const QString & out) { - std::cerr << qPrintable(out); + QTextStream stream(stderr); + stream << out; } class LU { @@ -227,6 +230,40 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil } } +static void print(const QString &fileName, int lineNo, const QString &msg) +{ + if (lineNo) + printErr(QString::fromLatin1("%2(%1): %3").arg(lineNo).arg(fileName, msg)); + else + printErr(msg); +} + +class ParseHandler : public ProFileParserHandler { +public: + virtual void parseError(const QString &fileName, int lineNo, const QString &msg) + { if (verbose) print(fileName, lineNo, msg); } + + bool verbose; +}; + +class EvalHandler : public ProFileEvaluatorHandler { +public: + virtual void configError(const QString &msg) + { printErr(msg); } + virtual void evalError(const QString &fileName, int lineNo, const QString &msg) + { if (verbose) print(fileName, lineNo, msg); } + virtual void fileMessage(const QString &msg) + { printErr(msg); } + + virtual void aboutToEval(ProFile *, ProFile *, EvalFileType) {} + virtual void doneWithEval(ProFile *) {} + + bool verbose; +}; + +static ParseHandler parseHandler; +static EvalHandler evalHandler; + static QStringList getSources(const char *var, const char *vvar, const QStringList &baseVPaths, const QString &projectDir, const ProFileEvaluator &visitor) { @@ -288,12 +325,14 @@ static void processSources(Translator &fetchedTor, static void processProjects( bool topLevel, bool nestComplain, const QStringList &proFiles, + ProFileOption *option, ProFileParser *parser, UpdateOptions options, const QByteArray &codecForSource, const QString &targetLanguage, const QString &sourceLanguage, Translator *parentTor, bool *fail); static void processProject( - bool nestComplain, const QFileInfo &pfi, ProFileEvaluator &visitor, + bool nestComplain, const QFileInfo &pfi, + ProFileOption *option, ProFileParser *parser, ProFileEvaluator &visitor, UpdateOptions options, const QByteArray &_codecForSource, const QString &targetLanguage, const QString &sourceLanguage, Translator *fetchedTor, bool *fail) @@ -321,7 +360,7 @@ static void processProject( else subProFiles << subPro; } - processProjects(false, nestComplain, subProFiles, options, codecForSource, + processProjects(false, nestComplain, subProFiles, option, parser, options, codecForSource, targetLanguage, sourceLanguage, fetchedTor, fail); } else { ConversionData cd; @@ -347,23 +386,25 @@ static void processProject( static void processProjects( bool topLevel, bool nestComplain, const QStringList &proFiles, + ProFileOption *option, ProFileParser *parser, UpdateOptions options, const QByteArray &codecForSource, const QString &targetLanguage, const QString &sourceLanguage, Translator *parentTor, bool *fail) { foreach (const QString &proFile, proFiles) { - ProFileEvaluator visitor; - visitor.setVerbose(options & Verbose); - - QHash<QString, QStringList> lupdateConfig; - lupdateConfig.insert(QLatin1String("CONFIG"), QStringList(QLatin1String("lupdate_run"))); - visitor.addVariables(lupdateConfig); - QFileInfo pfi(proFile); - ProFile pro(pfi.absoluteFilePath()); - if (!visitor.queryProFile(&pro) || !visitor.accept(&pro)) { + + ProFileEvaluator visitor(option, parser, &evalHandler); + ProFile *pro; + if (!(pro = parser->parsedProFile(QDir::cleanPath(pfi.absoluteFilePath())))) { + if (topLevel) + *fail = true; + continue; + } + if (!visitor.accept(pro)) { if (topLevel) *fail = true; + pro->deref(); continue; } @@ -376,6 +417,7 @@ static void processProjects( } else if (nestComplain) { printErr(LU::tr("lupdate warning: TS files from command line " "prevent recursing into %1.\n").arg(proFile)); + pro->deref(); continue; } } @@ -387,6 +429,7 @@ static void processProjects( // This might mean either a buggy PRO file or an intentional detach - // we can't know without seeing the actual RHS of the assignment ... // Just assume correctness and be silent. + pro->deref(); continue; } Translator tor; @@ -398,9 +441,10 @@ static void processProjects( tor.setCodecName(tmp.last().toLatin1()); setCodec = true; } - processProject(false, pfi, visitor, options, codecForSource, + processProject(false, pfi, option, parser, visitor, options, codecForSource, targetLanguage, sourceLanguage, &tor, fail); updateTsFiles(tor, tsFiles, setCodec, sourceLanguage, targetLanguage, options, fail); + pro->deref(); continue; } noTrans: @@ -409,12 +453,13 @@ static void processProjects( printErr(LU::tr("lupdate warning: no TS files specified. Only diagnostics " "will be produced for '%1'.\n").arg(proFile)); Translator tor; - processProject(nestComplain, pfi, visitor, options, codecForSource, + processProject(nestComplain, pfi, option, parser, visitor, options, codecForSource, targetLanguage, sourceLanguage, &tor, fail); } else { - processProject(nestComplain, pfi, visitor, options, codecForSource, + processProject(nestComplain, pfi, option, parser, visitor, options, codecForSource, targetLanguage, sourceLanguage, parentTor, fail); } + pro->deref(); } } @@ -714,15 +759,22 @@ int main(int argc, char **argv) " Both project and source files / include paths specified.\n")); return 1; } + + parseHandler.verbose = evalHandler.verbose = !!(options & Verbose); + ProFileOption option; + option.initProperties(app.applicationDirPath() + QLatin1String("/qmake")); + option.setCommandLineArguments(QStringList() << QLatin1String("CONFIG+=lupdate_run")); + ProFileParser parser(0, &parseHandler); + if (!tsFileNames.isEmpty()) { Translator fetchedTor; fetchedTor.setCodecName(codecForTr); - processProjects(true, true, proFiles, options, QByteArray(), + processProjects(true, true, proFiles, &option, &parser, options, QByteArray(), targetLanguage, sourceLanguage, &fetchedTor, &fail); updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(), sourceLanguage, targetLanguage, options, &fail); } else { - processProjects(true, false, proFiles, options, QByteArray(), + processProjects(true, false, proFiles, &option, &parser, options, QByteArray(), targetLanguage, sourceLanguage, 0, &fail); } } |