Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
3 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/lupdate/lupdate.pro

    r385 r561  
    1515include(../shared/formats.pri)
    1616include(../shared/proparser.pri)
    17 include(../shared/translatortools.pri)
    1817
    19 SOURCES += main.cpp
     18SOURCES += \
     19    main.cpp \
     20    merge.cpp \
     21    ../shared/simtexth.cpp \
     22    \
     23    cpp.cpp \
     24    java.cpp \
     25    qscript.cpp \
     26    ui.cpp
     27
     28HEADERS += \
     29    lupdate.h \
     30    ../shared/simtexth.h
    2031
    2132DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
  • trunk/tools/linguist/lupdate/main.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the Qt Linguist of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
    4040****************************************************************************/
    4141
    42 #include "translator.h"
    43 #include "translatortools.h"
    44 #include "profileevaluator.h"
     42#include "lupdate.h"
     43
     44#include <translator.h>
     45#include <profileevaluator.h>
     46#include <proreader.h>
    4547
    4648#include <QtCore/QCoreApplication>
     
    5355#include <QtCore/QTextCodec>
    5456
     57
     58
    5559static QString m_defaultExtensions;
    5660
    57 static void printOut(const QString & out)
     61static void print(const QString & out)
    5862{
    5963    qWarning("%s", qPrintable(out));
    6064}
    6165
     66
     67
     68
     69
     70
    6271static void recursiveFileInfoList(const QDir &dir,
    63     const QStringList &nameFilters, QDir::Filters filter, bool recursive,
     72    const QS,
    6473    QFileInfoList *fileinfolist)
    6574{
    66     if (recursive)
    67         filter |= QDir::AllDirs;
    68     QFileInfoList entries = dir.entryInfoList(nameFilters, filter);
    69 
    70     QFileInfoList::iterator it;
    71     for (it = entries.begin(); it != entries.end(); ++it) {
    72         QString fname = it->fileName();
    73         if (fname != QLatin1String(".") && fname != QLatin1String("..")) {
    74             if (it->isDir())
    75                 recursiveFileInfoList(QDir(it->absoluteFilePath()), nameFilters, filter, recursive, fileinfolist);
    76             else
    77                 fileinfolist->append(*it);
    78         }
    79     }
     75    foreach (const QFileInfo &fi, dir.entryInfoList(filter))
     76        if (fi.isDir())
     77            recursiveFileInfoList(QDir(fi.absoluteFilePath()), nameFilters, filter, fileinfolist);
     78        else if (nameFilters.contains(fi.suffix()))
     79            fileinfolist->append(fi);
    8080}
    8181
     
    8484    printOut(QObject::tr(
    8585        "Usage:\n"
    86         "    lupdate [options] [project-file]\n"
     86        "    lupdate [options] [project-file]\n"
    8787        "    lupdate [options] [source-file|path]... -ts ts-files\n\n"
    88         "lupdate is part of Qt's Linguist tool chain. It can be used as a\n"
    89         "stand-alone tool to create XML based translations files in the .ts\n"
    90         "format from translatable messages in C++ and Java source code.\n\n"
    91         "lupdate can also merge such messages into existing .ts files.\n\n"
     88        "lupdate is part of Qt's Linguist tool chain. It \n"
     89        "\n"
     90        "\n"
     91        " files.\n\n"
    9292        "Options:\n"
    9393        "    -help  Display this information and exit.\n"
     
    103103        "           Do not explain what is being done.\n"
    104104        "    -no-sort\n"
    105         "           Do not sort contexts in .ts files.\n"
     105        "           Do not sort contexts in files.\n"
    106106        "    -no-recursive\n"
    107107        "           Do not recursively scan the following directories.\n"
    108108        "    -recursive\n"
    109         "           Recursively scan the following directories.\n"
     109        "           Recursively scan the following directories (default).\n"
     110        "    -I <includepath> or -I<includepath>\n"
     111        "           Additional location to look for include files.\n"
     112        "           May be specified multiple times.\n"
    110113        "    -locations {absolute|relative|none}\n"
    111         "           Specify/override how source code references are saved in ts files.\n"
     114        "           Specify/override how source code references are saved in files.\n"
    112115        "           Default is absolute.\n"
    113116        "    -no-ui-lines\n"
    114         "           Do not record line numbers in references to .ui files.\n"
     117        "           Do not record line numbers in references to files.\n"
    115118        "    -disable-heuristic {sametext|similartext|number}\n"
    116119        "           Disable the named merge heuristic. Can be specified multiple times.\n"
     
    119122        "           file syntax but different file suffix\n"
    120123        "    -source-language <language>[_<region>]\n"
    121         "           Specify/override the language of the source strings. Defaults to\n"
    122         "           POSIX if not specified and the file does not name it yet.\n"
     124        "           Specify\n"
     125        "           .\n"
    123126        "    -target-language <language>[_<region>]\n"
    124         "           Specify/override the language of the translation.\n"
    125         "           The target language is guessed from the file name if this option\n"
    126         "           is not specified and the file contents name no language yet.\n"
     127        "           Specify the language of the translations for new files.\n"
     128        "           Guessed from the file name if not specified.\n"
    127129        "    -version\n"
    128130        "           Display the version of lupdate and exit.\n"
     
    143145        if (QFile(fileName).exists()) {
    144146            if (!tor.load(fileName, cd, QLatin1String("auto"))) {
    145                 printOut(cd.error());
     147                print(cd.error());
    146148                *fail = true;
    147149                continue;
     
    166168            if (!targetLanguage.isEmpty())
    167169                tor.setLanguageCode(targetLanguage);
     170
     171
    168172            if (!sourceLanguage.isEmpty())
    169173                tor.setSourceLanguageCode(sourceLanguage);
     
    179183            printOut(QObject::tr("Updating '%1'...\n").arg(fn));
    180184
     185
    181186        if (tor.locationsType() == Translator::NoLocations) // Could be set from file
    182             options |= NoLocations;
    183         Translator out = merge(tor, fetchedTor, options, err);
     187            ptions |= NoLocations;
     188        Translator out = merge(tor, fetchedTor, ptions, err);
    184189        if (!codecForTr.isEmpty())
    185190            out.setCodecName(codecForTr);
     
    198203        out.stripEmptyContexts();
    199204
     205
     206
     207
     208
     209
    200210        if (!out.save(fileName, cd, QLatin1String("auto"))) {
    201             printOut(cd.error());
     211            print(cd.error());
    202212            *fail = true;
    203213        }
     
    217227    QStringList tsFileNames;
    218228    QStringList proFiles;
     229
     230
    219231    QStringList sourceFiles;
     232
    220233    QString targetLanguage;
    221234    QString sourceLanguage;
     
    230243
    231244    QString extensions = m_defaultExtensions;
    232     QStringList extensionsNameFilters;
     245    QS extensionsNameFilters;
    233246
    234247    for (int  i = 1; i < argc; ++i) {
     
    343356            proFiles += args[i];
    344357            numFiles++;
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
    345370            continue;
    346371        } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
     
    388413                    printOut(QObject::tr("Scanning directory '%1'...").arg(arg));
    389414                QDir dir = QDir(fi.filePath());
     415
    390416                if (extensionsNameFilters.isEmpty()) {
    391                     extensions = extensions.trimmed();
    392                     // Remove the potential dot in front of each extension
    393                     if (extensions.startsWith(QLatin1Char('.')))
    394                         extensions.remove(0,1);
    395                     extensions.replace(QLatin1String(",."), QLatin1String(","));
    396 
    397                     extensions.insert(0, QLatin1String("*."));
    398                     extensions.replace(QLatin1Char(','), QLatin1String(",*."));
    399                     extensionsNameFilters = extensions.split(QLatin1Char(','));
     417                    foreach (QString ext, extensions.split(QLatin1Char(','))) {
     418                        ext = ext.trimmed();
     419                        if (ext.startsWith(QLatin1Char('.')))
     420                            ext.remove(0, 1);
     421                        extensionsNameFilters.insert(ext);
     422                    }
    400423                }
    401424                QDir::Filters filters = QDir::Files | QDir::NoSymLinks;
     425
     426
    402427                QFileInfoList fileinfolist;
    403                 recursiveFileInfoList(dir, extensionsNameFilters, filters,
    404                     recursiveScan, &fileinfolist);
    405                 QFileInfoList::iterator ii;
    406                 QString fn;
    407                 for (ii = fileinfolist.begin(); ii != fileinfolist.end(); ++ii) {
    408                     // Make sure the path separator is stored with '/' in the ts file
    409                     sourceFiles << ii->canonicalFilePath().replace(QLatin1Char('\\'), QLatin1Char('/'));
     428                recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);
     429                int scanRootLen = dir.absolutePath().length();
     430                foreach (const QFileInfo &fi, fileinfolist) {
     431                    QString fn = QDir::cleanPath(fi.absoluteFilePath());
     432                    sourceFiles << fn;
     433
     434                    if (!fn.endsWith(QLatin1String(".java"))
     435                        && !fn.endsWith(QLatin1String(".ui"))
     436                        && !fn.endsWith(QLatin1String(".js"))
     437                        && !fn.endsWith(QLatin1String(".qs"))) {
     438                        int offset = 0;
     439                        int depth = 0;
     440                        do {
     441                            offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1);
     442                            QString ffn = fn.mid(offset + 1);
     443                            allCSources.insert(ffn, fn);
     444                        } while (++depth < 3 && offset > scanRootLen);
     445                    }
    410446                }
    411447            } else {
    412                 sourceFiles << fi.canonicalFilePath().replace(QLatin1Char('\\'), QLatin1Char('/'));
     448                sourceFiles << ;
    413449            }
    414450        }
    415451    } // for args
    416452
     453
     454
    417455
    418456    bool firstPass = true;
     
    422460        cd.m_defaultContext = defaultContext;
    423461        cd.m_noUiLines = options & NoUiLines;
     462
     463
     464
    424465
    425466        QStringList tsFiles = tsFileNames;
     
    451492            }
    452493
    453             evaluateProFile(visitor, &variables);
     494            cd.m_includePath += visitor.values(QLatin1String("INCLUDEPATH"));
     495
     496            evaluateProFile(visitor, &variables, pfi.absolutePath());
    454497
    455498            sourceFiles = variables.value("SOURCES");
     
    459502                codecForTr = tmp.first().toLatin1();
    460503                fetchedTor.setCodecName(codecForTr);
     504
    461505            }
    462506            tmp = variables.value("CODECFORSRC");
     
    473517        }
    474518
     519
    475520        for (QStringList::iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) {
    476             if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) {
    477                 cd.m_sourceFileName = *it;
    478                 fetchedTor.load(*it, cd, QLatin1String("java"));
    479                 //fetchtr_java(*it, &fetchedTor, defaultContext, true, codecForSource);
    480             }
    481             else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive)) {
    482                 fetchedTor.load(*it, cd, QLatin1String("ui"));
    483                 //fetchedTor.load(*it + QLatin1String(".h"), cd, QLatin1String("cpp"));
    484                 //fetchtr_ui(*it, &fetchedTor, defaultContext, true);
    485                 //fetchtr_cpp(*it + QLatin1String(".h"), &fetchedTor,
    486                 //             defaultContext, false, codecForSource);
    487             }
     521            if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive))
     522                loadJava(fetchedTor, *it, cd);
     523            else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive)
     524                     || it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive))
     525                loadUI(fetchedTor, *it, cd);
    488526            else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive)
    489                 || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) {
    490                 fetchedTor.load(*it, cd, QLatin1String("js"));
    491             } else {
    492                 fetchedTor.load(*it, cd, QLatin1String("cpp"));
    493                 //fetchtr_cpp(*it, &fetchedTor, defaultContext, true, codecForSource);
    494             }
    495         }
     527                     || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive))
     528                loadQScript(fetchedTor, *it, cd);
     529            else
     530                sourceFilesCpp << *it;
     531        }
     532        loadCPP(fetchedTor, sourceFilesCpp, cd);
    496533        if (!cd.error().isEmpty())
    497534            printOut(cd.error());
Note: See TracChangeset for help on using the changeset viewer.