diff options
Diffstat (limited to 'tools/linguist/lrelease/main.cpp')
-rw-r--r-- | tools/linguist/lrelease/main.cpp | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp index c88c909..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,10 +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); 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 @@ -260,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 |