diff options
Diffstat (limited to 'tools/linguist/lrelease/main.cpp')
-rw-r--r-- | tools/linguist/lrelease/main.cpp | 127 |
1 files changed, 110 insertions, 17 deletions
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index 742c2e6..c45459a 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -42,7 +42,10 @@ #include "translator.h" #include "proreader.h" +#ifndef QT_BOOTSTRAPPED #include <QtCore/QCoreApplication> +#include <QtCore/QTranslator> +#endif #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFile> @@ -51,7 +54,14 @@ #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QTextStream> -#include <QtCore/QTranslator> + +#ifdef QT_BOOTSTRAPPED +static void initBinaryDir( +#ifndef Q_OS_WIN + const char *argv0 +#endif + ); +#endif static void printOut(const QString & out) { @@ -157,11 +167,18 @@ static bool releaseTsFile(const QString& tsFileName, int main(int argc, char **argv) { +#ifdef QT_BOOTSTRAPPED + initBinaryDir( +#ifndef Q_OS_WIN + argv[0] +#endif + ); +#else QCoreApplication app(argc, argv); - QStringList args = app.arguments(); QTranslator translator; if (translator.load(QLatin1String("lrelease_") + QLocale::system().name())) app.installTranslator(&translator); +#endif ConversionData cd; cd.m_verbose = true; // the default is true starting with Qt 4.2 @@ -171,50 +188,50 @@ int main(int argc, char **argv) QString outputFile; for (int i = 1; i < argc; ++i) { - if (args[i] == QLatin1String("-compress")) { + if (!strcmp(argv[i], "-compress")) { cd.m_saveMode = SaveStripped; continue; - } else if (args[i] == QLatin1String("-idbased")) { + } else if (!strcmp(argv[i], "-idbased")) { cd.m_idBased = true; continue; - } else if (args[i] == QLatin1String("-nocompress")) { + } else if (!strcmp(argv[i], "-nocompress")) { cd.m_saveMode = SaveEverything; continue; - } else if (args[i] == QLatin1String("-removeidentical")) { + } else if (!strcmp(argv[i], "-removeidentical")) { removeIdentical = true; continue; - } else if (args[i] == QLatin1String("-nounfinished")) { + } else if (!strcmp(argv[i], "-nounfinished")) { cd.m_ignoreUnfinished = true; continue; - } else if (args[i] == QLatin1String("-markuntranslated")) { + } else if (!strcmp(argv[i], "-markuntranslated")) { if (i == argc - 1) { printUsage(); return 1; } - cd.m_unTrPrefix = args[++i]; - } else if (args[i] == QLatin1String("-silent")) { + cd.m_unTrPrefix = QString::fromLocal8Bit(argv[++i]); + } else if (!strcmp(argv[i], "-silent")) { cd.m_verbose = false; continue; - } else if (args[i] == QLatin1String("-verbose")) { + } else if (!strcmp(argv[i], "-verbose")) { cd.m_verbose = true; continue; - } else if (args[i] == QLatin1String("-version")) { + } else if (!strcmp(argv[i], "-version")) { printOut(QCoreApplication::tr( "lrelease version %1\n").arg(QLatin1String(QT_VERSION_STR)) ); return 0; - } else if (args[i] == QLatin1String("-qm")) { + } else if (!strcmp(argv[i], "-qm")) { if (i == argc - 1) { printUsage(); return 1; } - outputFile = args[++i]; - } else if (args[i] == QLatin1String("-help")) { + outputFile = QString::fromLocal8Bit(argv[++i]); + } else if (!strcmp(argv[i], "-help")) { printUsage(); return 0; - } else if (args[i].startsWith(QLatin1Char('-'))) { + } else if (argv[i][0] == '-') { printUsage(); return 1; } else { - inputFiles << args[i]; + inputFiles << QString::fromLocal8Bit(argv[i]); } } @@ -261,3 +278,79 @@ int main(int argc, char **argv) return 0; } + +#ifdef QT_BOOTSTRAPPED + +#ifdef Q_OS_WIN +# include <windows.h> +#endif + +static QString binDir; + +static void initBinaryDir( +#ifndef Q_OS_WIN + const char *_argv0 +#endif + ) +{ +#ifdef Q_OS_WIN + wchar_t module_name[MAX_PATH]; + GetModuleFileName(0, module_name, MAX_PATH); + QFileInfo filePath = QString::fromWCharArray(module_name); + binDir = filePath.filePath(); +#else + QString argv0 = QFile::decodeName(QByteArray(_argv0)); + QString absPath; + + if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { + /* + If argv0 starts with a slash, it is already an absolute + file path. + */ + absPath = argv0; + } else if (argv0.contains(QLatin1Char('/'))) { + /* + If argv0 contains one or more slashes, it is a file path + relative to the current directory. + */ + absPath = QDir::current().absoluteFilePath(argv0); + } else { + /* + Otherwise, the file path has to be determined using the + PATH environment variable. + */ + QByteArray pEnv = qgetenv("PATH"); + QDir currentDir = QDir::current(); + QStringList paths = QString::fromLocal8Bit(pEnv.constData()).split(QLatin1String(":")); + for (QStringList::const_iterator p = paths.constBegin(); p != paths.constEnd(); ++p) { + if ((*p).isEmpty()) + continue; + QString candidate = currentDir.absoluteFilePath(*p + QLatin1Char('/') + argv0); + QFileInfo candidate_fi(candidate); + if (candidate_fi.exists() && !candidate_fi.isDir()) { + binDir = candidate_fi.canonicalPath(); + return; + } + } + return; + } + + QFileInfo fi(absPath); + if (fi.exists()) + binDir = fi.canonicalPath(); +#endif +} + +QT_BEGIN_NAMESPACE + +// The name is hard-coded in QLibraryInfo +QString qmake_libraryInfoFile() +{ + if (binDir.isEmpty()) + return QString(); + return QDir(binDir).filePath(QString::fromLatin1("qt.conf")); +} + +QT_END_NAMESPACE + +#endif // QT_BOOTSTRAPPED |