Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/lupdate/cpp.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5151#include <QtCore/QTextCodec>
    5252#include <QtCore/QTextStream>
     53#include <QtCore/QCoreApplication>
     54
     55#include <iostream>
    5356
    5457#include <ctype.h>              // for isXXX()
    5558
    5659QT_BEGIN_NAMESPACE
     60
     61class LU {
     62    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     63};
    5764
    5865/* qmake ignore Q_OBJECT */
     
    226233        int elseLine;
    227234    };
     235
     236    std::ostream &yyMsg(int line = 0);
    228237
    229238    uint getChar();
     
    353362}
    354363
     364
     365std::ostream &CppParser::yyMsg(int line)
     366{
     367    return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": ";
     368}
     369
    355370void CppParser::setInput(const QString &in)
    356371{
     
    475490STRING(friend);
    476491STRING(namespace);
     492STRING(operator);
    477493STRING(qtTrId);
    478494STRING(return);
     
    614630                                || yyBraceDepth != is.braceDepth1st
    615631                                || yyParenDepth != is.parenDepth1st)
    616                                 qWarning("%s:%d: Parenthesis/bracket/brace mismatch between "
    617                                          "#if and #else branches; using #if branch\n",
    618                                          qPrintable(yyFileName), is.elseLine);
     632                                yyMsg(is.elseLine)
     633                                    << qPrintable(LU::tr("Parenthesis/bracket/brace mismatch between "
     634                                                         "#if and #else branches; using #if branch\n"));
    619635                        } else {
    620636                            is.bracketDepth1st = yyBracketDepth;
     
    637653                                || yyBraceDepth != is.braceDepth1st
    638654                                || yyParenDepth != is.parenDepth1st)
    639                                 qWarning("%s:%d: Parenthesis/brace mismatch between "
    640                                          "#if and #else branches; using #if branch\n",
    641                                          qPrintable(yyFileName), is.elseLine);
     655                                yyMsg(is.elseLine)
     656                                    << qPrintable(LU::tr("Parenthesis/brace mismatch between "
     657                                                         "#if and #else branches; using #if branch\n"));
    642658                            yyBracketDepth = is.bracketDepth1st;
    643659                            yyBraceDepth = is.braceDepth1st;
     
    665681                            yyCh = getChar();
    666682                            if (yyCh == EOF) {
    667                                 qWarning("%s:%d: Unterminated C++ comment\n",
    668                                          qPrintable(yyFileName), yyLineNo);
     683                                yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
    669684                                break;
    670685                            }
     
    740755                    return Tok_namespace;
    741756                break;
     757            case 'o':
     758                if (yyWord == stroperator) {
     759                    // Operator overload declaration/definition.
     760                    // We need to prevent those characters from confusing the followup
     761                    // parsing. Actually using them does not add value, so just eat them.
     762                    while (isspace(yyCh))
     763                       yyCh = getChar();
     764                    while (yyCh == '+' || yyCh == '-' || yyCh == '*' || yyCh == '/' || yyCh == '%'
     765                           || yyCh == '=' || yyCh == '<' || yyCh == '>' || yyCh == '!'
     766                           || yyCh == '&' || yyCh == '|' || yyCh == '~' || yyCh == '^'
     767                           || yyCh == '[' || yyCh == ']')
     768                        yyCh = getChar();
     769                }
     770                break;
    742771            case 'q':
    743772                if (yyWord == strqtTrId)
     
    796825                        yyCh = getChar();
    797826                        if (yyCh == EOF) {
    798                             qWarning("%s:%d: Unterminated C++ comment\n",
    799                                      qPrintable(yyFileName), yyLineNo);
     827                            yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
    800828                            break;
    801829                        }
     
    830858
    831859                if (yyCh != '"')
    832                     qWarning("%s:%d: Unterminated C++ string\n",
    833                               qPrintable(yyFileName), yyLineNo);
     860                    yyMsg() << qPrintable(LU::tr("Unterminated C++ string\n"));
    834861                else
    835862                    yyCh = getChar();
     
    868895                forever {
    869896                    if (yyCh == EOF || yyCh == '\n') {
    870                         qWarning("%s:%d: Unterminated C++ character\n",
    871                                   qPrintable(yyFileName), yyLineNo);
     897                        yyMsg() << "Unterminated C++ character\n";
    872898                        break;
    873899                    }
     
    888914                if (yyBraceDepth == yyMinBraceDepth) {
    889915                    if (!inDefine)
    890                         qWarning("%s:%d: Excess closing brace in C++ code"
    891                                   " (or abuse of the C++ preprocessor)\n",
    892                                   qPrintable(yyFileName), yyCurLineNo);
     916                        yyMsg(yyCurLineNo)
     917                            << qPrintable(LU::tr("Excess closing brace in C++ code"
     918                                                 " (or abuse of the C++ preprocessor)\n"));
    893919                    // Avoid things getting messed up even more
    894920                    yyCh = getChar();
     
    906932            case ')':
    907933                if (yyParenDepth == 0)
    908                     qWarning("%s:%d: Excess closing parenthesis in C++ code"
    909                              " (or abuse of the C++ preprocessor)\n",
    910                              qPrintable(yyFileName), yyCurLineNo);
     934                    yyMsg(yyCurLineNo)
     935                        << qPrintable(LU::tr("Excess closing parenthesis in C++ code"
     936                                             " (or abuse of the C++ preprocessor)\n"));
    911937                else
    912938                    yyParenDepth--;
     
    921947            case ']':
    922948                if (yyBracketDepth == 0)
    923                     qWarning("%s:%d: Excess closing bracket in C++ code"
    924                              " (or abuse of the C++ preprocessor)\n",
    925                              qPrintable(yyFileName), yyCurLineNo);
     949                    yyMsg(yyCurLineNo)
     950                        << qPrintable(LU::tr("Excess closing bracket in C++ code"
     951                                             " (or abuse of the C++ preprocessor)\n"));
    926952                else
    927953                    yyBracketDepth--;
     
    12911317
    12921318    if (inclusions.contains(cleanFile)) {
    1293         qWarning("%s:%d: circular inclusion of %s\n",
    1294                  qPrintable(yyFileName), yyLineNo, qPrintable(cleanFile));
     1319        yyMsg() << qPrintable(LU::tr("circular inclusion of %1\n").arg(cleanFile));
    12951320        return;
    12961321    }
     
    13161341    QFile f(cleanFile);
    13171342    if (!f.open(QIODevice::ReadOnly)) {
    1318         qWarning("%s:%d: Cannot open %s: %s\n",
    1319                  qPrintable(yyFileName), yyLineNo,
    1320                  qPrintable(cleanFile), qPrintable(f.errorString()));
     1343        yyMsg() << qPrintable(LU::tr("Cannot open %1: %2\n").arg(cleanFile, f.errorString()));
    13211344        return;
    13221345    }
     
    16571680                    NamespaceList nsl;
    16581681                    if (!fullyQualify(namespaces, quali, true, &nsl, 0)) {
    1659                         qWarning("%s:%d: Ignoring definition of undeclared qualified class\n",
    1660                                  qPrintable(yyFileName), yyLineNo);
     1682                        yyMsg() << "Ignoring definition of undeclared qualified class\n";
    16611683                        break;
    16621684                    }
     
    16721694                prospectiveContext.clear();
    16731695                pendingContext.clear();
     1696
     1697                yyTok = getToken();
    16741698            }
    16751699            break;
     
    16851709                    namespaceDepths.push(namespaces.count());
    16861710                    enterNamespace(&namespaces, ns);
     1711
     1712                    functionContext = namespaces;
     1713                    functionContextUnresolved.clear();
     1714                    prospectiveContext.clear();
     1715                    pendingContext.clear();
    16871716                    yyTok = getToken();
    16881717                } else if (yyTok == Tok_Equals) {
     
    17581787                goto case_default;
    17591788            if (!sourcetext.isEmpty())
    1760                 qWarning("%s:%d: //%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n",
    1761                          qPrintable(yyFileName), yyLineNo);
     1789                yyMsg() << qPrintable(LU::tr("//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n"));
    17621790            utf8 = (yyTok == Tok_trUtf8);
    17631791            line = yyLineNo;
     
    17801808                    if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) {
    17811809                        functionContextUnresolved = unresolved.join(strColons);
    1782                         qWarning("%s:%d: Qualifying with unknown namespace/class %s::%s\n",
    1783                                  qPrintable(yyFileName), yyLineNo,
    1784                                  qPrintable(stringifyNamespace(functionContext)),
    1785                                  qPrintable(unresolved.first()));
     1810                        yyMsg() << qPrintable(LU::tr("Qualifying with unknown namespace/class %1::%2\n")
     1811                                              .arg(stringifyNamespace(functionContext)).arg(unresolved.first()));
    17861812                    }
    17871813                    pendingContext.clear();
     
    17911817                        int idx = functionContext.length();
    17921818                        if (idx < 2) {
    1793                             qWarning("%s:%d: tr() cannot be called without context\n",
    1794                                      qPrintable(yyFileName), yyLineNo);
     1819                            yyMsg() << qPrintable(LU::tr("tr() cannot be called without context\n"));
    17951820                            break;
    17961821                        }
     
    18011826                                fctx = findNamespace(functionContext)->classDef;
    18021827                                if (!fctx->complained) {
    1803                                     qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
    1804                                              qPrintable(yyFileName), yyLineNo,
    1805                                              qPrintable(context));
     1828                                    yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n")
     1829                                                         .arg(context));
    18061830                                    fctx->complained = true;
    18071831                                }
     
    18311855                    QString className = prefix.mid(last == -1 ? 0 : last + 2);
    18321856                    if (!className.isEmpty() && className == functionName) {
    1833                         qWarning("%s::%d: It is not recommended to call tr() from within a constructor '%s::%s' ",
    1834                                   qPrintable(yyFileName), yyLineNo,
    1835                                   className.constData(), functionName.constData());
     1857                        yyMsg() << qPrintable(LU::tr("It is not recommended to call tr() from within a constructor '%1::%2'\n")
     1858                                .arg(className).arg(functionName));
    18361859                    }
    18371860#endif
     
    18481871                        }
    18491872                        if (!fctx->hasTrFunctions && !fctx->complained) {
    1850                             qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
    1851                                      qPrintable(yyFileName), yyLineNo,
    1852                                      qPrintable(context));
     1873                            yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n").arg(context));
    18531874                            fctx->complained = true;
    18541875                        }
     
    18621883                recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
    18631884            }
     1885            sourcetext.clear(); // Will have warned about that already
    18641886            extracomment.clear();
    18651887            msgid.clear();
     
    18711893                goto case_default;
    18721894            if (!sourcetext.isEmpty())
    1873                 qWarning("%s:%d: //%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n",
    1874                          qPrintable(yyFileName), yyLineNo);
     1895                yyMsg() << qPrintable(LU::tr("//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n"));
    18751896            utf8 = (yyTok == Tok_translateUtf8);
    18761897            line = yyLineNo;
     
    19181939                recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
    19191940            }
     1941            sourcetext.clear(); // Will have warned about that already
    19201942            extracomment.clear();
    19211943            msgid.clear();
     
    19261948                goto case_default;
    19271949            if (!msgid.isEmpty())
    1928                 qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n",
    1929                          qPrintable(yyFileName), yyLineNo);
     1950                yyMsg() << qPrintable(LU::tr("//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n"));
    19301951            //utf8 = false; // Maybe use //%% or something like that
    19311952            line = yyLineNo;
     
    19942015                        continue;
    19952016                    if (c != '"') {
    1996                         qWarning("%s:%d: Unexpected character in meta string\n",
    1997                                  qPrintable(yyFileName), yyLineNo);
     2017                        yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
    19982018                        break;
    19992019                    }
     
    20012021                        if (p >= yyWord.length()) {
    20022022                          whoops:
    2003                             qWarning("%s:%d: Unterminated meta string\n",
    2004                                      qPrintable(yyFileName), yyLineNo);
     2023                            yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
    20052024                            break;
    20062025                        }
     
    20552074            yyTok = getToken();
    20562075            if (yyTok == Tok_tr || yyTok == Tok_trUtf8)
    2057                 qWarning("%s:%d: Cannot invoke tr() like this\n",
    2058                           qPrintable(yyFileName), yyLineNo);
     2076                yyMsg() << qPrintable(LU::tr("Cannot invoke tr() like this\n"));
    20592077            break;
    20602078        case Tok_ColonColon:
     
    20882106            prospectiveContext.clear();
    20892107            prefix.clear();
    2090             extracomment.clear();
    2091             msgid.clear();
    2092             extra.clear();
     2108            if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
     2109                yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
     2110                sourcetext.clear();
     2111                extracomment.clear();
     2112                msgid.clear();
     2113                extra.clear();
     2114            }
    20932115            yyTokColonSeen = false;
    20942116            yyTok = getToken();
     
    21242146
    21252147    if (yyBraceDepth != 0)
    2126         qWarning("%s:%d: Unbalanced opening brace in C++ code"
    2127                   " (or abuse of the C++ preprocessor)\n",
    2128                   qPrintable(yyFileName), yyBraceLineNo);
     2148        yyMsg(yyBraceLineNo)
     2149            << qPrintable(LU::tr("Unbalanced opening brace in C++ code"
     2150                                 " (or abuse of the C++ preprocessor)\n"));
    21292151    else if (yyParenDepth != 0)
    2130         qWarning("%s:%d: Unbalanced opening parenthesis in C++ code"
    2131                  " (or abuse of the C++ preprocessor)\n",
    2132                  qPrintable(yyFileName), yyParenLineNo);
     2152        yyMsg(yyParenLineNo)
     2153            << qPrintable(LU::tr("Unbalanced opening parenthesis in C++ code"
     2154                                 " (or abuse of the C++ preprocessor)\n"));
    21332155    else if (yyBracketDepth != 0)
    2134         qWarning("%s:%d: Unbalanced opening bracket in C++ code"
    2135                  " (or abuse of the C++ preprocessor)\n",
    2136                  qPrintable(yyFileName), yyBracketLineNo);
     2156        yyMsg(yyBracketLineNo)
     2157            << qPrintable(LU::tr("Unbalanced opening bracket in C++ code"
     2158                                 " (or abuse of the C++ preprocessor)\n"));
    21372159}
    21382160
     
    21952217        QFile file(filename);
    21962218        if (!file.open(QIODevice::ReadOnly)) {
    2197             cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    2198                 .arg(filename, file.errorString()));
     2219            cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    21992220            continue;
    22002221        }
  • trunk/tools/linguist/lupdate/java.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5151#include <QtCore/QString>
    5252#include <QtCore/QTextCodec>
     53#include <QtCore/QCoreApplication>
     54
     55#include <iostream>
    5356
    5457#include <ctype.h>
    5558
    5659QT_BEGIN_NAMESPACE
     60
     61class LU {
     62    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     63};
    5764
    5865enum { Tok_Eof, Tok_class, Tok_return, Tok_tr,
     
    107114static QStack<Scope*> yyScope;
    108115static QString yyDefaultContext;
     116
     117std::ostream &yyMsg(int line = 0)
     118{
     119    return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": ";
     120}
    109121
    110122static QChar getChar()
     
    190202                        yyCh = getChar();
    191203                        if ( yyCh == EOF ) {
    192                             qFatal( "%s: Unterminated Java comment starting at"
    193                                     " line %d\n",
    194                                     qPrintable(yyFileName), yyLineNo );
    195 
     204                            yyMsg() << qPrintable(LU::tr("Unterminated Java comment.\n"));
    196205                            return Tok_Comment;
    197206                        }
     
    229238                                    int sub(yyCh.toLower().toAscii() - 87);
    230239                                    if( sub > 15 || sub < 10) {
    231                                         qFatal( "%s:%d: Invalid Unicode",
    232                                             qPrintable(yyFileName), yyLineNo );
     240                                        yyMsg() << qPrintable(LU::tr("Invalid Unicode value.\n"));
     241                                        break;
    233242                                    }
    234243                                    unicode += sub;
     
    252261
    253262                if ( yyCh != QLatin1Char('"') )
    254                     qFatal( "%s:%d: Unterminated string",
    255                         qPrintable(yyFileName), yyLineNo );
     263                    yyMsg() << qPrintable(LU::tr("Unterminated string.\n"));
    256264
    257265                yyCh = getChar();
     
    366374            s += yyString;
    367375        else {
    368             qWarning( "%s:%d: String used in translation can only contain strings"
    369                 " concatenated with other strings, not expressions or numbers.",
    370                 qPrintable(yyFileName), yyLineNo );
     376            yyMsg() << qPrintable(LU::tr(
     377                "String used in translation can contain only literals"
     378                " concatenated with other literals, not expressions or numbers.\n"));
    371379            return false;
    372380        }
     
    476484            }
    477485            else {
    478                 qFatal( "%s:%d: Class must be followed by a classname",
    479                                           qPrintable(yyFileName), yyLineNo );
     486                yyMsg() << qPrintable(LU::tr("'class' must be followed by a class name.\n"));
     487                break;
    480488            }
    481489            while (!match(Tok_LeftBrace)) {
     
    548556        case Tok_RightBrace:
    549557            if ( yyScope.isEmpty() ) {
    550                 qFatal( "%s:%d: Unbalanced right brace in Java code\n",
    551                         qPrintable(yyFileName), yyLineNo );
     558                yyMsg() << qPrintable(LU::tr("Excess closing brace.\n"));
    552559            }
    553560            else
     
    578585                        break;
    579586                    default:
    580                          qFatal( "%s:%d: Package keyword should be followed by com.package.name;",
    581                                           qPrintable(yyFileName), yyLineNo );
     587                         yyMsg() << qPrintable(LU::tr("'package' must be followed by package name.\n"));
    582588                         break;
    583589                }
     
    592598
    593599    if ( !yyScope.isEmpty() )
    594         qFatal( "%s:%d: Unbalanced braces in Java code\n",
    595                  qPrintable(yyFileName), yyScope.top()->line );
     600        yyMsg(yyScope.top()->line) << qPrintable(LU::tr("Unbalanced opening brace.\n"));
    596601    else if ( yyParenDepth != 0 )
    597         qFatal( "%s:%d: Unbalanced parentheses in Java code\n",
    598                  qPrintable(yyFileName), yyParenLineNo );
     602        yyMsg(yyParenLineNo) << qPrintable(LU::tr("Unbalanced opening parenthesis.\n"));
    599603}
    600604
     
    604608    QFile file(filename);
    605609    if (!file.open(QIODevice::ReadOnly)) {
    606         cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    607             .arg(filename, file.errorString()));
     610        cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    608611        return false;
    609612    }
  • trunk/tools/linguist/lupdate/lupdate.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    8080bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd);
    8181bool loadUI(Translator &translator, const QString &filename, ConversionData &cd);
     82bool loadQml(Translator &translator, const QString &filename, ConversionData &cd);
    8283
    8384QT_END_NAMESPACE
  • trunk/tools/linguist/lupdate/lupdate.pro

    r561 r846  
    1616include(../shared/proparser.pri)
    1717
     18include($$QT_SOURCE_TREE/src/declarative/qml/parser/parser.pri)
     19INCLUDEPATH += $$QT_SOURCE_TREE/src/declarative/qml $$QT_BUILD_TREE/include/QtDeclarative
     20
    1821SOURCES += \
    1922    main.cpp \
     
    2427    java.cpp \
    2528    qscript.cpp \
     29    qdeclarative.cpp \
    2630    ui.cpp
    2731
  • trunk/tools/linguist/lupdate/main.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5353#include <QtCore/QStringList>
    5454#include <QtCore/QTextCodec>
     55#include <QtCore/QTranslator>
     56#include <QtCore/QLibraryInfo>
    5557
    5658#include <iostream>
     
    5860static QString m_defaultExtensions;
    5961
    60 static void printErr(const QString & out)
    61 {
    62     qWarning("%s", qPrintable(out));
    63 }
    64 
    6562static void printOut(const QString & out)
    6663{
    6764    std::cerr << qPrintable(out);
    6865}
     66
     67class LU {
     68    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     69};
    6970
    7071static void recursiveFileInfoList(const QDir &dir,
     
    8182static void printUsage()
    8283{
    83     printOut(QObject::tr(
     84    printOut(LU::tr(
    8485        "Usage:\n"
    8586        "    lupdate [options] [project-file]...\n"
    86         "    lupdate [options] [source-file|path]... -ts ts-files\n\n"
     87        "    lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file\n\n"
    8788        "lupdate is part of Qt's Linguist tool chain. It extracts translatable\n"
    8889        "messages from Qt UI files, C++, Java and JavaScript/QtScript source code.\n"
     
    133134        "    -version\n"
    134135        "           Display the version of lupdate and exit.\n"
     136        "    @lst-file\n"
     137        "           Read additional file names (one per line) from lst-file.\n"
    135138    ).arg(m_defaultExtensions));
    136139}
     
    149152        if (QFile(fileName).exists()) {
    150153            if (!tor.load(fileName, cd, QLatin1String("auto"))) {
    151                 printErr(cd.error());
     154                printOut(cd.error());
    152155                *fail = true;
    153156                continue;
     
    156159            cd.clearErrors();
    157160            if (setCodec && fetchedTor.codec() != tor.codec())
    158                 qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
    159                          "existing file's codec '%s'. Expect trouble.",
    160                          fetchedTor.codecName().constData(), tor.codecName().constData());
     161                printOut(LU::tr("lupdate warning: Codec for tr() '%1' disagrees with"
     162                                " existing file's codec '%2'. Expect trouble.\n")
     163                         .arg(QString::fromLatin1(fetchedTor.codecName()),
     164                              QString::fromLatin1(tor.codecName())));
    161165            if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode())
    162                 qWarning("lupdate warning: Specified target language '%s' disagrees with "
    163                          "existing file's language '%s'. Ignoring.",
    164                          qPrintable(targetLanguage), qPrintable(tor.languageCode()));
     166                printOut(LU::tr("lupdate warning: Specified target language '%1' disagrees with"
     167                                " existing file's language '%2'. Ignoring.\n")
     168                         .arg(targetLanguage, tor.languageCode()));
    165169            if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode())
    166                 qWarning("lupdate warning: Specified source language '%s' disagrees with "
    167                          "existing file's language '%s'. Ignoring.",
    168                          qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode()));
     170                printOut(LU::tr("lupdate warning: Specified source language '%1' disagrees with"
     171                                " existing file's language '%2'. Ignoring.\n")
     172                         .arg(sourceLanguage, tor.sourceLanguageCode()));
    169173        } else {
    170174            if (setCodec)
     
    185189            tor.setLocationsType(Translator::AbsoluteLocations);
    186190        if (options & Verbose)
    187             printOut(QObject::tr("Updating '%1'...\n").arg(fn));
     191            printOut(LU::tr("Updating '%1'...\n").arg(fn));
    188192
    189193        UpdateOptions theseOptions = options;
     
    200204        if (options & PluralOnly) {
    201205            if (options & Verbose)
    202                 printOut(QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn));
     206                printOut(LU::tr("Stripping non plural forms in '%1'...\n").arg(fn));
    203207            out.stripNonPluralForms();
    204208        }
     
    209213        out.normalizeTranslations(cd);
    210214        if (!cd.errors().isEmpty()) {
    211             printErr(cd.error());
     215            printOut(cd.error());
    212216            cd.clearErrors();
    213217        }
    214218        if (!out.save(fileName, cd, QLatin1String("auto"))) {
    215             printErr(cd.error());
     219            printOut(cd.error());
    216220            *fail = true;
    217221        }
     
    268272                 || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive))
    269273            loadQScript(fetchedTor, *it, cd);
     274        else if (it->endsWith(QLatin1String(".qml"), Qt::CaseInsensitive))
     275            loadQml(fetchedTor, *it, cd);
    270276        else
    271277            sourceFilesCpp << *it;
     
    293299        codecForSource = tmp.last().toLatin1();
    294300        if (!QTextCodec::codecForName(codecForSource)) {
    295             qWarning("lupdate warning: Codec for source '%s' is invalid. "
    296                      "Falling back to codec for tr().", codecForSource.constData());
     301            printOut(LU::tr("lupdate warning: Codec for source '%1' is invalid."
     302                            " Falling back to codec for tr().\n")
     303                     .arg(QString::fromLatin1(codecForSource)));
    297304            codecForSource.clear();
    298305        }
     
    344351        visitor.setVerbose(options & Verbose);
    345352
     353        QHash<QString, QStringList> lupdateConfig;
     354        lupdateConfig.insert(QLatin1String("CONFIG"), QStringList(QLatin1String("lupdate_run")));
     355        visitor.addVariables(lupdateConfig);
     356
    346357        QFileInfo pfi(proFile);
    347358        ProFile pro(pfi.absoluteFilePath());
     
    355366            if (parentTor) {
    356367                if (topLevel) {
    357                     std::cerr << "lupdate warning: TS files from command line "
    358                             "will override TRANSLATIONS in " << qPrintable(proFile) << ".\n";
     368                    std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line "
     369                                                   "will override TRANSLATIONS in %1.\n").arg(proFile));
    359370                    goto noTrans;
    360371                } else if (nestComplain) {
    361                     std::cerr << "lupdate warning: TS files from command line "
    362                             "prevent recursing into " << qPrintable(proFile) << ".\n";
     372                    std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line "
     373                                                   "prevent recursing into %1.\n").arg(proFile));
    363374                    continue;
    364375                }
     
    391402        if (!parentTor) {
    392403            if (topLevel)
    393                 std::cerr << "lupdate warning: no TS files specified. Only diagnostics "
    394                         "will be produced for '" << qPrintable(proFile) << "'.\n";
     404                std::cerr << qPrintable(LU::tr("lupdate warning: no TS files specified. Only diagnostics "
     405                                               "will be produced for '%1'.\n").arg(proFile));
    395406            Translator tor;
    396407            processProject(nestComplain, pfi, visitor, options, codecForSource,
     
    406417{
    407418    QCoreApplication app(argc, argv);
    408     m_defaultExtensions = QLatin1String("ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx");
     419#ifndef Q_OS_WIN32
     420    QTranslator translator;
     421    QTranslator qtTranslator;
     422    QString sysLocale = QLocale::system().name();
     423    QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
     424    if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir)
     425        && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) {
     426        app.installTranslator(&translator);
     427        app.installTranslator(&qtTranslator);
     428    }
     429#endif // Q_OS_WIN32
     430
     431    m_defaultExtensions = QLatin1String("java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml");
    409432
    410433    QStringList args = app.arguments();
     
    449472            ++i;
    450473            if (i == argc) {
    451                 qWarning("The option -target-language requires a parameter.");
     474                printOut(LU::tr("The option -target-language requires a parameter.\n"));
    452475                return 1;
    453476            }
     
    457480            ++i;
    458481            if (i == argc) {
    459                 qWarning("The option -source-language requires a parameter.");
     482                printOut(LU::tr("The option -source-language requires a parameter.\n"));
    460483                return 1;
    461484            }
     
    465488            ++i;
    466489            if (i == argc) {
    467                 qWarning("The option -disable-heuristic requires a parameter.");
     490                printOut(LU::tr("The option -disable-heuristic requires a parameter.\n"));
    468491                return 1;
    469492            }
     
    476499                options &= ~HeuristicNumber;
    477500            } else {
    478                 qWarning("Invalid heuristic name passed to -disable-heuristic.");
     501                printOut(LU::tr("Invalid heuristic name passed to -disable-heuristic.\n"));
    479502                return 1;
    480503            }
     
    483506            ++i;
    484507            if (i == argc) {
    485                 qWarning("The option -locations requires a parameter.");
     508                printOut(LU::tr("The option -locations requires a parameter.\n"));
    486509                return 1;
    487510            }
     
    493516                options |= AbsoluteLocations;
    494517            } else {
    495                 qWarning("Invalid parameter passed to -locations.");
     518                printOut(LU::tr("Invalid parameter passed to -locations.\n"));
    496519                return 1;
    497520            }
     
    519542            ++i;
    520543            if (i == argc) {
    521                 qWarning("The -codecfortr option should be followed by a codec name.");
     544                printOut(LU::tr("The -codecfortr option should be followed by a codec name.\n"));
    522545                return 1;
    523546            }
     
    530553            ++i;
    531554            if (i == argc) {
    532                 qWarning("The -extensions option should be followed by an extension list.");
     555                printOut(LU::tr("The -extensions option should be followed by an extension list.\n"));
    533556                return 1;
    534557            }
     
    538561            ++i;
    539562            if (i == argc) {
    540                 qWarning("The -pro option should be followed by a filename of .pro file.");
     563                printOut(LU::tr("The -pro option should be followed by a filename of .pro file.\n"));
    541564                return 1;
    542565            }
     
    548571                ++i;
    549572                if (i == argc) {
    550                     qWarning("The -I option should be followed by a path.");
     573                    printOut(LU::tr("The -I option should be followed by a path.\n"));
    551574                    return 1;
    552575                }
     
    557580            continue;
    558581        } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
    559             qWarning("Unrecognized option '%s'", qPrintable(arg));
     582            printOut(LU::tr("Unrecognized option '%1'.\n").arg(arg));
    560583            return 1;
    561584        }
    562585
     586        QStringList files;
     587        if (arg.startsWith(QLatin1String("@"))) {
     588            QFile lstFile(arg.mid(1));
     589            if (!lstFile.open(QIODevice::ReadOnly)) {
     590                printOut(LU::tr("lupdate error: List file '%1' is not readable.\n")
     591                         .arg(lstFile.fileName()));
     592                return 1;
     593            }
     594            while (!lstFile.atEnd())
     595                files << QString::fromLocal8Bit(lstFile.readLine().trimmed());
     596        } else {
     597            files << arg;
     598        }
    563599        if (metTsFlag) {
    564             bool found = false;
    565             foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) {
    566                 if (arg.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
    567                     QFileInfo fi(arg);
    568                     if (!fi.exists() || fi.isWritable()) {
    569                         tsFileNames.append(QFileInfo(arg).absoluteFilePath());
    570                     } else {
    571                         qWarning("lupdate warning: For some reason, '%s' is not writable.\n",
    572                                 qPrintable(arg));
     600            foreach (const QString &file, files) {
     601                bool found = false;
     602                foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) {
     603                    if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
     604                        QFileInfo fi(file);
     605                        if (!fi.exists() || fi.isWritable()) {
     606                            tsFileNames.append(QFileInfo(file).absoluteFilePath());
     607                        } else {
     608                            printOut(LU::tr("lupdate warning: For some reason, '%1' is not writable.\n")
     609                                     .arg(file));
     610                        }
     611                        found = true;
     612                        break;
    573613                    }
    574                     found = true;
    575                     break;
    576614                }
    577             }
    578             if (!found) {
    579                 qWarning("lupdate error: File '%s' has no recognized extension\n",
    580                          qPrintable(arg));
    581                 return 1;
    582             }
    583         } else if (arg.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive)
    584                 || arg.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) {
    585             proFiles << arg;
     615                if (!found) {
     616                    printOut(LU::tr("lupdate error: File '%1' has no recognized extension.\n")
     617                             .arg(file));
     618                    return 1;
     619                }
     620            }
    586621            numFiles++;
    587622        } else {
    588             QFileInfo fi(arg);
    589             if (!fi.exists()) {
    590                 qWarning("lupdate error: File '%s' does not exists\n", qPrintable(arg));
    591                 return 1;
    592             } else if (fi.isDir()) {
    593                 if (options & Verbose)
    594                     printOut(QObject::tr("Scanning directory '%1'...").arg(arg));
    595                 QDir dir = QDir(fi.filePath());
    596                 projectRoots.insert(dir.absolutePath() + QLatin1Char('/'));
    597                 if (extensionsNameFilters.isEmpty()) {
    598                     foreach (QString ext, extensions.split(QLatin1Char(','))) {
    599                         ext = ext.trimmed();
    600                         if (ext.startsWith(QLatin1Char('.')))
    601                             ext.remove(0, 1);
    602                         extensionsNameFilters.insert(ext);
     623            foreach (const QString &file, files) {
     624                QFileInfo fi(file);
     625                if (!fi.exists()) {
     626                    printOut(LU::tr("lupdate error: File '%1' does not exist.\n").arg(file));
     627                    return 1;
     628                }
     629                if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive)
     630                    || file.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) {
     631                    proFiles << file;
     632                } else if (fi.isDir()) {
     633                    if (options & Verbose)
     634                        printOut(LU::tr("Scanning directory '%1'...\n").arg(file));
     635                    QDir dir = QDir(fi.filePath());
     636                    projectRoots.insert(dir.absolutePath() + QLatin1Char('/'));
     637                    if (extensionsNameFilters.isEmpty()) {
     638                        foreach (QString ext, extensions.split(QLatin1Char(','))) {
     639                            ext = ext.trimmed();
     640                            if (ext.startsWith(QLatin1Char('.')))
     641                                ext.remove(0, 1);
     642                            extensionsNameFilters.insert(ext);
     643                        }
    603644                    }
     645                    QDir::Filters filters = QDir::Files | QDir::NoSymLinks;
     646                    if (recursiveScan)
     647                        filters |= QDir::AllDirs | QDir::NoDotAndDotDot;
     648                    QFileInfoList fileinfolist;
     649                    recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);
     650                    int scanRootLen = dir.absolutePath().length();
     651                    foreach (const QFileInfo &fi, fileinfolist) {
     652                        QString fn = QDir::cleanPath(fi.absoluteFilePath());
     653                        sourceFiles << fn;
     654
     655                        if (!fn.endsWith(QLatin1String(".java"))
     656                            && !fn.endsWith(QLatin1String(".jui"))
     657                            && !fn.endsWith(QLatin1String(".ui"))
     658                            && !fn.endsWith(QLatin1String(".js"))
     659                            && !fn.endsWith(QLatin1String(".qs"))
     660                            && !fn.endsWith(QLatin1String(".qml"))) {
     661                            int offset = 0;
     662                            int depth = 0;
     663                            do {
     664                                offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1);
     665                                QString ffn = fn.mid(offset + 1);
     666                                allCSources.insert(ffn, fn);
     667                            } while (++depth < 3 && offset > scanRootLen);
     668                        }
     669                    }
     670                } else {
     671                    sourceFiles << QDir::cleanPath(fi.absoluteFilePath());;
     672                    projectRoots.insert(fi.absolutePath() + QLatin1Char('/'));
    604673                }
    605                 QDir::Filters filters = QDir::Files | QDir::NoSymLinks;
    606                 if (recursiveScan)
    607                     filters |= QDir::AllDirs | QDir::NoDotAndDotDot;
    608                 QFileInfoList fileinfolist;
    609                 recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);
    610                 int scanRootLen = dir.absolutePath().length();
    611                 foreach (const QFileInfo &fi, fileinfolist) {
    612                     QString fn = QDir::cleanPath(fi.absoluteFilePath());
    613                     sourceFiles << fn;
    614 
    615                     if (!fn.endsWith(QLatin1String(".java"))
    616                         && !fn.endsWith(QLatin1String(".ui"))
    617                         && !fn.endsWith(QLatin1String(".js"))
    618                         && !fn.endsWith(QLatin1String(".qs"))) {
    619                         int offset = 0;
    620                         int depth = 0;
    621                         do {
    622                             offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1);
    623                             QString ffn = fn.mid(offset + 1);
    624                             allCSources.insert(ffn, fn);
    625                         } while (++depth < 3 && offset > scanRootLen);
    626                     }
    627                 }
    628             } else {
    629                 sourceFiles << QDir::cleanPath(fi.absoluteFilePath());;
    630674            }
    631675            numFiles++;
     
    639683
    640684    if (!targetLanguage.isEmpty() && tsFileNames.count() != 1)
    641         std::cerr << "lupdate warning: -target-language usually only "
    642                      "makes sense with exactly one TS file.\n";
     685        printOut(LU::tr("lupdate warning: -target-language usually only"
     686                        " makes sense with exactly one TS file.\n"));
    643687    if (!codecForTr.isEmpty() && tsFileNames.isEmpty())
    644         std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n";
     688        printOut(LU::tr("lupdate warning: -codecfortr has no effect without -ts.\n"));
    645689
    646690    bool fail = false;
    647691    if (proFiles.isEmpty()) {
    648692        if (tsFileNames.isEmpty())
    649             std::cerr << "lupdate warning: no TS files specified. "
    650                          "Only diagnostics will be produced.\n";
     693            printOut(LU::tr("lupdate warning:"
     694                            " no TS files specified. Only diagnostics will be produced.\n"));
    651695
    652696        Translator fetchedTor;
     
    662706    } else {
    663707        if (!sourceFiles.isEmpty() || !includePath.isEmpty()) {
    664             qWarning("lupdate error: Both project and source files / include paths specified.\n");
     708            printOut(LU::tr("lupdate error:"
     709                            " Both project and source files / include paths specified.\n"));
    665710            return 1;
    666711        }
  • trunk/tools/linguist/lupdate/merge.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4545#include "translator.h"
    4646
     47#include <QtCore/QCoreApplication>
    4748#include <QtCore/QDebug>
    4849#include <QtCore/QMap>
     
    5152#include <QtCore/QVector>
    5253
    53 
    5454QT_BEGIN_NAMESPACE
     55
     56class LU {
     57    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     58};
    5559
    5660static bool isDigitFriendly(QChar c)
     
    486490    if (options & Verbose) {
    487491        int totalFound = neww + known;
    488         err += QObject::tr("    Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known);
     492        err += LU::tr("    Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known);
    489493
    490494        if (obsoleted) {
    491495            if (options & NoObsolete) {
    492                 err += QObject::tr("    Removed %n obsolete entries\n", 0, obsoleted);
     496                err += LU::tr("    Removed %n obsolete entries\n", 0, obsoleted);
    493497            } else {
    494                 err += QObject::tr("    Kept %n obsolete entries\n", 0, obsoleted);
     498                err += LU::tr("    Kept %n obsolete entries\n", 0, obsoleted);
    495499            }
    496500        }
    497501
    498502        if (sameNumberHeuristicCount)
    499             err += QObject::tr("    Number heuristic provided %n translation(s)\n",
     503            err += LU::tr("    Number heuristic provided %n translation(s)\n",
    500504                      0, sameNumberHeuristicCount);
    501505        if (sameTextHeuristicCount)
    502             err += QObject::tr("    Same-text heuristic provided %n translation(s)\n",
     506            err += LU::tr("    Same-text heuristic provided %n translation(s)\n",
    503507                      0, sameTextHeuristicCount);
    504508        if (similarTextHeuristicCount)
    505             err += QObject::tr("    Similar-text heuristic provided %n translation(s)\n",
     509            err += LU::tr("    Similar-text heuristic provided %n translation(s)\n",
    506510                      0, similarTextHeuristicCount);
    507511    }
  • trunk/tools/linguist/lupdate/qscript.cpp

    r651 r846  
    22/****************************************************************************
    33**
    4 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    55** All rights reserved.
    66** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4040**
    4141****************************************************************************/
     42
     43
     44#define Q_SCRIPT_REGEXPLITERAL_RULE1 7
     45
     46#define Q_SCRIPT_REGEXPLITERAL_RULE2 8
     47
     48#include <translator.h>
     49
     50#include <QtCore/QCoreApplication>
     51#include <QtCore/qdebug.h>
     52#include <QtCore/qnumeric.h>
     53#include <QtCore/qstring.h>
     54#include <QtCore/qtextcodec.h>
     55#include <QtCore/qvariant.h>
     56
     57#include <iostream>
     58
     59#include <ctype.h>
     60#include <stdlib.h>
     61#include <stdio.h>
     62#include <string.h>
     63
     64QT_BEGIN_NAMESPACE
     65
     66class LU {
     67    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     68};
    4269
    4370class QScriptGrammar
     
    174201  }
    175202};
    176 
    177203
    178204const char *const QScriptGrammar::spell [] = {
     
    748774  -1, -1};
    749775
    750 
    751 #define Q_SCRIPT_REGEXPLITERAL_RULE1 7
    752 
    753 #define Q_SCRIPT_REGEXPLITERAL_RULE2 8
    754 
    755 #include <translator.h>
    756 
    757 #include <QtCore/qdebug.h>
    758 #include <QtCore/qnumeric.h>
    759 #include <QtCore/qstring.h>
    760 #include <QtCore/qtextcodec.h>
    761 #include <QtCore/qvariant.h>
    762 
    763 #include <ctype.h>
    764 #include <stdlib.h>
    765 #include <stdio.h>
    766 #include <string.h>
    767 
    768 QT_BEGIN_NAMESPACE
    769 
    770776static void recordMessage(
    771777    Translator *tor, const QString &context, const QString &text, const QString &comment,
    772     const QString &extracomment, bool plural, const QString &fileName, int lineNo)
     778    const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra,
     779    bool plural, const QString &fileName, int lineNo)
    773780{
    774781    TranslatorMessage msg(
     
    777784        TranslatorMessage::Unfinished, plural);
    778785    msg.setExtraComment(extracomment.simplified());
     786    msg.setId(msgid);
     787    msg.setExtras(extra);
    779788    tor->extend(msg);
    780789}
     
    784793{
    785794
     795class CommentProcessor
     796{
     797public:
     798    virtual ~CommentProcessor() {}
     799    virtual void processComment(const QChar *chars, int length) = 0;
     800};
     801
    786802class Lexer
    787803{
    788804public:
    789     Lexer();
     805    Lexer(CommentProcessor *);
    790806    ~Lexer();
    791807
    792     void setCode(const QString &c, int lineno);
     808    void setCode(const QString &c, const QString &fileName, int lineno);
    793809    int lex();
    794810
     811    QString fileName() const { return yyfilename; }
    795812    int currentLineNo() const { return yylineno; }
    796813    int currentColumnNo() const { return yycolumn; }
     
    872889
    873890private:
     891    QString yyfilename;
    874892    int yylineno;
    875893    bool done;
     
    925943    void syncProhibitAutomaticSemicolon();
    926944
     945    void processComment(const QChar *, int);
     946
    927947    const QChar *code;
    928948    uint length;
     
    951971    int parenthesesCount;
    952972    bool prohibitAutomaticSemicolon;
     973
     974    CommentProcessor *commentProcessor;
    953975};
    954976
     
    10271049} // namespace QScript
    10281050
    1029 QScript::Lexer::Lexer()
     1051QScript::Lexer::Lexer(QScript::CommentProcessor *proc)
    10301052    :
    10311053      yylineno(0),
     
    10381060      check_reserved(true),
    10391061      parenthesesState(IgnoreParentheses),
    1040       prohibitAutomaticSemicolon(false)
     1062      prohibitAutomaticSemicolon(false),
     1063      commentProcessor(proc)
    10411064{
    10421065    // allocate space for read buffers
     
    10531076}
    10541077
    1055 void QScript::Lexer::setCode(const QString &c, int lineno)
     1078void QScript::Lexer::setCode(const QString &c, const QString &fileName, int lineno)
    10561079{
    10571080    errmsg = QString();
     1081    yyfilename = fileName;
    10581082    yylineno = lineno;
    10591083    yycolumn = 1;
     
    14041428                recordStartPos();
    14051429                shift(1);
     1430                Q_ASSERT(pos16 == 0);
    14061431                state = InSingleLineComment;
    14071432            } else if (current == '/' && next1 == '*') {
    14081433                recordStartPos();
    14091434                shift(1);
     1435                Q_ASSERT(pos16 == 0);
    14101436                state = InMultiLineComment;
    14111437            } else if (current == 0) {
     
    14661492                    setDone(Bad);
    14671493                    err = IllegalCharacter;
    1468                     errmsg = QLatin1String("Illegal character");
     1494                    errmsg = LU::tr("Illegal character");
    14691495                }
    14701496            }
     
    14771503                setDone(Bad);
    14781504                err = UnclosedStringLiteral;
    1479                 errmsg = QLatin1String("Unclosed string at end of line");
     1505                errmsg = LU::tr("Unclosed string at end of line");
    14801506            } else if (current == '\\') {
    14811507                state = InEscapeSequence;
     
    15031529                    setDone(Bad);
    15041530                    err = IllegalEscapeSequence;
    1505                     errmsg = QLatin1String("Illegal escape squence");
     1531                    errmsg = LU::tr("Illegal escape squence");
    15061532                }
    15071533            } else if (current == 'x')
     
    15421568                setDone(Bad);
    15431569                err = IllegalUnicodeEscapeSequence;
    1544                 errmsg = QLatin1String("Illegal unicode escape sequence");
     1570                errmsg = LU::tr("Illegal unicode escape sequence");
    15451571            }
    15461572            break;
    15471573        case InSingleLineComment:
    15481574            if (isLineTerminator()) {
     1575                record16(current); // include newline
     1576                processComment(buffer16, pos16);
    15491577                shiftWindowsLineBreak();
    15501578                yylineno++;
    15511579                yycolumn = 0;
     1580                pos16 = 0;
    15521581                terminator = true;
    15531582                bol = true;
     
    15591588            } else if (current == 0) {
    15601589                setDone(Eof);
     1590            } else {
     1591                record16(current);
    15611592            }
    15621593            break;
     
    15651596                setDone(Bad);
    15661597                err = UnclosedComment;
    1567                 errmsg = QLatin1String("Unclosed comment at end of file");
     1598                errmsg = LU::tr("Unclosed comment at end of file");
    15681599            } else if (isLineTerminator()) {
    15691600                shiftWindowsLineBreak();
    15701601                yylineno++;
    15711602            } else if (current == '*' && next1 == '/') {
     1603                processComment(buffer16, pos16);
     1604                pos16 = 0;
    15721605                state = Start;
    15731606                shift(1);
     1607            } else {
     1608                record16(current);
    15741609            }
    15751610            break;
     
    16491684                setDone(Bad);
    16501685                err = IllegalExponentIndicator;
    1651                 errmsg = QLatin1String("Illegal syntax for exponential number");
     1686                errmsg = LU::tr("Illegal syntax for exponential number");
    16521687            }
    16531688            break;
     
    16751710        state = Bad;
    16761711        err = IllegalIdentifier;
    1677         errmsg = QLatin1String("Identifier cannot start with numeric literal");
     1712        errmsg = LU::tr("Identifier cannot start with numeric literal");
    16781713    }
    16791714
     
    19942029    while (1) {
    19952030        if (isLineTerminator() || current == 0) {
    1996             errmsg = QLatin1String("Unterminated regular expression literal");
     2031            errmsg = LU::tr("Unterminated regular expression literal");
    19972032            return false;
    19982033        }
     
    20332068}
    20342069
     2070void QScript::Lexer::processComment(const QChar *chars, int length)
     2071{
     2072    commentProcessor->processComment(chars, length);
     2073}
     2074
    20352075
    20362076class Translator;
    20372077
    2038 class QScriptParser: protected QScriptGrammar
     2078class QScriptParser: protected QScriptGrammar, public QScript::CommentProcessor
    20392079{
    20402080public:
     
    20522092    ~QScriptParser();
    20532093
    2054     bool parse(QScript::Lexer *lexer,
    2055                const QString &fileName,
    2056                Translator *translator);
    2057 
     2094    void setLexer(QScript::Lexer *);
     2095
     2096    bool parse(Translator *translator);
     2097
     2098    QString fileName() const
     2099    { return lexer->fileName(); }
    20582100    inline QString errorMessage() const
    20592101    { return error_message; }
     
    20712113    inline Location &loc(int index)
    20722114    { return location_stack [tos + index - 2]; }
     2115
     2116    std::ostream &yyMsg(int line = 0);
     2117
     2118    virtual void processComment(const QChar *, int);
    20732119
    20742120protected:
     
    20812127    int error_lineno;
    20822128    int error_column;
     2129
     2130private:
     2131    QScript::Lexer *lexer;
     2132    QString extracomment;
     2133    QString msgid;
     2134    QString sourcetext;
     2135    TranslatorMessage::ExtraData extra;
    20832136};
    20842137
     
    21072160    sym_stack(0),
    21082161    state_stack(0),
    2109     location_stack(0)
     2162    location_stack(0),
     2163    lexer(0)
    21102164{
    21112165}
     
    21292183}
    21302184
    2131 bool QScriptParser::parse(QScript::Lexer *lexer,
    2132                     const QString &fileName,
    2133                     Translator *translator)
    2134 {
     2185void QScriptParser::setLexer(QScript::Lexer *lex)
     2186{
     2187    lexer = lex;
     2188}
     2189
     2190bool QScriptParser::parse(Translator *translator)
     2191{
     2192  Q_ASSERT(lexer != 0);
    21352193  const int INITIAL_STATE = 0;
    21362194
     
    22142272    QString name = sym(1).toString();
    22152273    if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
     2274        if (!sourcetext.isEmpty())
     2275            yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
    22162276        QVariantList args = sym(2).toList();
    22172277        if (args.size() < 2) {
    2218             qWarning("%s:%d: %s() requires at least two arguments",
    2219                      qPrintable(fileName), identLineNo, qPrintable(name));
     2278            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name));
    22202279        } else {
    22212280            if ((args.at(0).type() != QVariant::String)
    22222281                || (args.at(1).type() != QVariant::String)) {
    2223                 qWarning("%s:%d: %s(): both arguments must be literal strings",
    2224                          qPrintable(fileName), identLineNo, qPrintable(name));
     2282                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name));
    22252283            } else {
    22262284                QString context = args.at(0).toString();
    22272285                QString text = args.at(1).toString();
    22282286                QString comment = args.value(2).toString();
    2229                 QString extracomment;
    22302287                bool plural = (args.size() > 4);
    22312288                recordMessage(translator, context, text, comment, extracomment,
    2232                               plural, fileName, identLineNo);
     2289                              msgid, extra, plural, fileName(), identLineNo);
    22332290            }
    22342291        }
     2292        sourcetext.clear();
     2293        extracomment.clear();
     2294        msgid.clear();
     2295        extra.clear();
    22352296    } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
     2297        if (!sourcetext.isEmpty())
     2298            yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
    22362299        QVariantList args = sym(2).toList();
    22372300        if (args.size() < 1) {
    2238             qWarning("%s:%d: %s() requires at least one argument",
    2239                      qPrintable(fileName), identLineNo, qPrintable(name));
     2301            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
    22402302        } else {
    22412303            if (args.at(0).type() != QVariant::String) {
    2242                 qWarning("%s:%d: %s(): text to translate must be a literal string",
    2243                          qPrintable(fileName), identLineNo, qPrintable(name));
     2304                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name));
    22442305            } else {
    2245                 QString context = QFileInfo(fileName).baseName();
     2306                QString context = QFileInfo(fileName()).baseName();
    22462307                QString text = args.at(0).toString();
    22472308                QString comment = args.value(1).toString();
    2248                 QString extracomment;
    22492309                bool plural = (args.size() > 2);
    22502310                recordMessage(translator, context, text, comment, extracomment,
    2251                               plural, fileName, identLineNo);
     2311                              msgid, extra, plural, fileName(), identLineNo);
    22522312            }
    22532313        }
     2314        sourcetext.clear();
     2315        extracomment.clear();
     2316        msgid.clear();
     2317        extra.clear();
     2318    } else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) {
     2319        if (!msgid.isEmpty())
     2320            yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name));
     2321        QVariantList args = sym(2).toList();
     2322        if (args.size() < 1) {
     2323            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
     2324        } else {
     2325            if (args.at(0).type() != QVariant::String) {
     2326                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name));
     2327            } else {
     2328                msgid = args.at(0).toString();
     2329                bool plural = (args.size() > 1);
     2330                recordMessage(translator, QString(), sourcetext, QString(), extracomment,
     2331                              msgid, extra, plural, fileName(), identLineNo);
     2332            }
     2333        }
     2334        sourcetext.clear();
     2335        extracomment.clear();
     2336        msgid.clear();
     2337        extra.clear();
    22542338    }
    22552339} break;
     
    22772361        sym(1) = QVariant();
    22782362} break;
     2363
     2364    case 171:
     2365
     2366    case 172:
     2367
     2368    case 173:
     2369
     2370    case 174:
     2371
     2372    case 175:
     2373
     2374    case 176:
     2375
     2376    case 177:
     2377
     2378    case 178:
     2379
     2380    case 179:
     2381
     2382    case 180:
     2383
     2384    case 181:
     2385
     2386    case 182:
     2387
     2388    case 183:
     2389
     2390    case 184:
     2391
     2392    case 185:
     2393    if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
     2394        yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
     2395        sourcetext.clear();
     2396        extracomment.clear();
     2397        msgid.clear();
     2398        extra.clear();
     2399    }
     2400    break;
    22792401
    22802402          } // switch
     
    23322454                {
    23332455                  if (first)
    2334                     error_message += QLatin1String ("Expected ");
     2456                    //: Beginning of the string that contains
     2457                    //: comma-separated list of expected tokens
     2458                    error_message += LU::tr("Expected ");
    23352459                  else
    23362460                    error_message += QLatin1String (", ");
     
    23562480}
    23572481
     2482std::ostream &QScriptParser::yyMsg(int line)
     2483{
     2484    return std::cerr << qPrintable(fileName()) << ':' << (line ? line : lexer->startLineNo()) << ": ";
     2485}
     2486
     2487void QScriptParser::processComment(const QChar *chars, int length)
     2488{
     2489    if (!length)
     2490        return;
     2491    // Try to match the logic of the C++ parser.
     2492    if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
     2493        extracomment += QString(chars+2, length-2);
     2494    } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) {
     2495        msgid = QString(chars+2, length-2).simplified();
     2496    } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
     2497        QString text = QString(chars+2, length-2).trimmed();
     2498        int k = text.indexOf(QLatin1Char(' '));
     2499        if (k > -1)
     2500            extra.insert(text.left(k), text.mid(k + 1).trimmed());
     2501    } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
     2502        sourcetext.reserve(sourcetext.length() + length-2);
     2503        ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length();
     2504        int p = 2, c;
     2505        forever {
     2506            if (p >= length)
     2507                break;
     2508            c = chars[p++].unicode();
     2509            if (isspace(c))
     2510                continue;
     2511            if (c != '"') {
     2512                yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
     2513                break;
     2514            }
     2515            forever {
     2516                if (p >= length) {
     2517                  whoops:
     2518                    yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
     2519                    break;
     2520                }
     2521                c = chars[p++].unicode();
     2522                if (c == '"')
     2523                    break;
     2524                if (c == '\\') {
     2525                    if (p >= length)
     2526                        goto whoops;
     2527                    c = chars[p++].unicode();
     2528                    if (c == '\n')
     2529                        goto whoops;
     2530                    *ptr++ = '\\';
     2531                }
     2532                *ptr++ = c;
     2533            }
     2534        }
     2535        sourcetext.resize(ptr - (ushort *)sourcetext.data());
     2536    }
     2537}
     2538
    23582539
    23592540bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd)
     
    23612542    QFile file(filename);
    23622543    if (!file.open(QIODevice::ReadOnly)) {
    2363         cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    2364             .arg(filename, file.errorString()));
     2544        cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    23652545        return false;
    23662546    }
     
    23752555
    23762556    QString code = ts.readAll();
    2377     QScript::Lexer lexer;
    2378     lexer.setCode(code, /*lineNumber=*/1);
    23792557    QScriptParser parser;
    2380     if (!parser.parse(&lexer, filename, &translator)) {
    2381         qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(),
    2382                  qPrintable(parser.errorMessage()));
     2558    QScript::Lexer lexer(&parser);
     2559    lexer.setCode(code, filename, /*lineNumber=*/1);
     2560    parser.setLexer(&lexer);
     2561    if (!parser.parse(&translator)) {
     2562        std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": "
     2563                  << qPrintable(parser.errorMessage()) << std::endl;
    23832564        return false;
    23842565    }
  • trunk/tools/linguist/lupdate/qscript.g

    r651 r846  
    11----------------------------------------------------------------------------
    22--
    3 -- Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3-- Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44-- All rights reserved.
    55-- Contact: Nokia Corporation (qt-info@nokia.com)
     
    8585#include <translator.h>
    8686
     87#include <QtCore/QCoreApplication>
    8788#include <QtCore/qdebug.h>
    8889#include <QtCore/qnumeric.h>
     
    9192#include <QtCore/qvariant.h>
    9293
     94#include <iostream>
     95
    9396#include <ctype.h>
    9497#include <stdlib.h>
     
    98101QT_BEGIN_NAMESPACE
    99102
     103class LU {
     104    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     105};
     106
    100107static void recordMessage(
    101108    Translator *tor, const QString &context, const QString &text, const QString &comment,
    102     const QString &extracomment, bool plural, const QString &fileName, int lineNo)
     109    const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra,
     110    bool plural, const QString &fileName, int lineNo)
    103111{
    104112    TranslatorMessage msg(
     
    107115        TranslatorMessage::Unfinished, plural);
    108116    msg.setExtraComment(extracomment.simplified());
    109     tor->replace(msg);
     117    msg.setId(msgid);
     118    msg.setExtras(extra);
     119    tor->extend(msg);
    110120}
    111121
     
    114124{
    115125
     126class CommentProcessor
     127{
     128public:
     129    virtual ~CommentProcessor() {}
     130    virtual void processComment(const QChar *chars, int length) = 0;
     131};
     132
    116133class Lexer
    117134{
    118135public:
    119     Lexer();
     136    Lexer(CommentProcessor *);
    120137    ~Lexer();
    121138
    122     void setCode(const QString &c, int lineno);
     139    void setCode(const QString &c, const QString &fileName, int lineno);
    123140    int lex();
    124141
     142    QString fileName() const { return yyfilename; }
    125143    int currentLineNo() const { return yylineno; }
    126144    int currentColumnNo() const { return yycolumn; }
     
    202220
    203221private:
     222    QString yyfilename;
    204223    int yylineno;
    205224    bool done;
     
    255274    void syncProhibitAutomaticSemicolon();
    256275
     276    void processComment(const QChar *, int);
     277
    257278    const QChar *code;
    258279    uint length;
     
    281302    int parenthesesCount;
    282303    bool prohibitAutomaticSemicolon;
     304
     305    CommentProcessor *commentProcessor;
    283306};
    284307
     
    357380} // namespace QScript
    358381
    359 QScript::Lexer::Lexer()
     382QScript::Lexer::Lexer(QScript::CommentProcessor *proc)
    360383    :
    361384      yylineno(0),
     
    368391      check_reserved(true),
    369392      parenthesesState(IgnoreParentheses),
    370       prohibitAutomaticSemicolon(false)
     393      prohibitAutomaticSemicolon(false),
     394      commentProcessor(proc)
    371395{
    372396    // allocate space for read buffers
     
    383407}
    384408
    385 void QScript::Lexer::setCode(const QString &c, int lineno)
     409void QScript::Lexer::setCode(const QString &c, const QString &fileName, int lineno)
    386410{
    387411    errmsg = QString();
     412    yyfilename = fileName;
    388413    yylineno = lineno;
    389414    yycolumn = 1;
     
    734759                recordStartPos();
    735760                shift(1);
     761                Q_ASSERT(pos16 == 0);
    736762                state = InSingleLineComment;
    737763            } else if (current == '/' && next1 == '*') {
    738764                recordStartPos();
    739765                shift(1);
     766                Q_ASSERT(pos16 == 0);
    740767                state = InMultiLineComment;
    741768            } else if (current == 0) {
     
    796823                    setDone(Bad);
    797824                    err = IllegalCharacter;
    798                     errmsg = QLatin1String("Illegal character");
     825                    errmsg = LU::tr("Illegal character");
    799826                }
    800827            }
     
    807834                setDone(Bad);
    808835                err = UnclosedStringLiteral;
    809                 errmsg = QLatin1String("Unclosed string at end of line");
     836                errmsg = LU::tr("Unclosed string at end of line");
    810837            } else if (current == '\\') {
    811838                state = InEscapeSequence;
     
    833860                    setDone(Bad);
    834861                    err = IllegalEscapeSequence;
    835                     errmsg = QLatin1String("Illegal escape squence");
     862                    errmsg = LU::tr("Illegal escape squence");
    836863                }
    837864            } else if (current == 'x')
     
    872899                setDone(Bad);
    873900                err = IllegalUnicodeEscapeSequence;
    874                 errmsg = QLatin1String("Illegal unicode escape sequence");
     901                errmsg = LU::tr("Illegal unicode escape sequence");
    875902            }
    876903            break;
    877904        case InSingleLineComment:
    878905            if (isLineTerminator()) {
     906                record16(current); // include newline
     907                processComment(buffer16, pos16);
    879908                shiftWindowsLineBreak();
    880909                yylineno++;
    881910                yycolumn = 0;
     911                pos16 = 0;
    882912                terminator = true;
    883913                bol = true;
     
    889919            } else if (current == 0) {
    890920                setDone(Eof);
     921            } else {
     922                record16(current);
    891923            }
    892924            break;
     
    895927                setDone(Bad);
    896928                err = UnclosedComment;
    897                 errmsg = QLatin1String("Unclosed comment at end of file");
     929                errmsg = LU::tr("Unclosed comment at end of file");
    898930            } else if (isLineTerminator()) {
    899931                shiftWindowsLineBreak();
    900932                yylineno++;
    901933            } else if (current == '*' && next1 == '/') {
     934                processComment(buffer16, pos16);
     935                pos16 = 0;
    902936                state = Start;
    903937                shift(1);
     938            } else {
     939                record16(current);
    904940            }
    905941            break;
     
    9791015                setDone(Bad);
    9801016                err = IllegalExponentIndicator;
    981                 errmsg = QLatin1String("Illegal syntax for exponential number");
     1017                errmsg = LU::tr("Illegal syntax for exponential number");
    9821018            }
    9831019            break;
     
    10051041        state = Bad;
    10061042        err = IllegalIdentifier;
    1007         errmsg = QLatin1String("Identifier cannot start with numeric literal");
     1043        errmsg = LU::tr("Identifier cannot start with numeric literal");
    10081044    }
    10091045
     
    13241360    while (1) {
    13251361        if (isLineTerminator() || current == 0) {
    1326             errmsg = QLatin1String("Unterminated regular expression literal");
     1362            errmsg = LU::tr("Unterminated regular expression literal");
    13271363            return false;
    13281364        }
     
    13631399}
    13641400
     1401void QScript::Lexer::processComment(const QChar *chars, int length)
     1402{
     1403    commentProcessor->processComment(chars, length);
     1404}
     1405
    13651406
    13661407class Translator;
    13671408
    1368 class QScriptParser: protected $table
     1409class QScriptParser: protected $table, public QScript::CommentProcessor
    13691410{
    13701411public:
     
    13821423    ~QScriptParser();
    13831424
    1384     bool parse(QScript::Lexer *lexer,
    1385                const QString &fileName,
    1386                Translator *translator);
    1387 
     1425    void setLexer(QScript::Lexer *);
     1426
     1427    bool parse(Translator *translator);
     1428
     1429    QString fileName() const
     1430    { return lexer->fileName(); }
    13881431    inline QString errorMessage() const
    13891432    { return error_message; }
     
    14011444    inline Location &loc(int index)
    14021445    { return location_stack [tos + index - 2]; }
     1446
     1447    std::ostream &yyMsg(int line = 0);
     1448
     1449    virtual void processComment(const QChar *, int);
    14031450
    14041451protected:
     
    14111458    int error_lineno;
    14121459    int error_column;
     1460
     1461private:
     1462    QScript::Lexer *lexer;
     1463    QString extracomment;
     1464    QString msgid;
     1465    QString sourcetext;
     1466    TranslatorMessage::ExtraData extra;
    14131467};
    14141468
     
    14371491    sym_stack(0),
    14381492    state_stack(0),
    1439     location_stack(0)
     1493    location_stack(0),
     1494    lexer(0)
    14401495{
    14411496}
     
    14591514}
    14601515
    1461 bool QScriptParser::parse(QScript::Lexer *lexer,
    1462                     const QString &fileName,
    1463                     Translator *translator)
    1464 {
     1516void QScriptParser::setLexer(QScript::Lexer *lex)
     1517{
     1518    lexer = lex;
     1519}
     1520
     1521bool QScriptParser::parse(Translator *translator)
     1522{
     1523  Q_ASSERT(lexer != 0);
    14651524  const int INITIAL_STATE = 0;
    14661525
     
    16291688    QString name = sym(1).toString();
    16301689    if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
     1690        if (!sourcetext.isEmpty())
     1691            yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
    16311692        QVariantList args = sym(2).toList();
    16321693        if (args.size() < 2) {
    1633             qWarning("%s:%d: %s() requires at least two arguments",
    1634                      qPrintable(fileName), identLineNo, qPrintable(name));
     1694            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name));
    16351695        } else {
    16361696            if ((args.at(0).type() != QVariant::String)
    16371697                || (args.at(1).type() != QVariant::String)) {
    1638                 qWarning("%s:%d: %s(): both arguments must be literal strings",
    1639                          qPrintable(fileName), identLineNo, qPrintable(name));
     1698                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name));
    16401699            } else {
    16411700                QString context = args.at(0).toString();
    16421701                QString text = args.at(1).toString();
    16431702                QString comment = args.value(2).toString();
    1644                 QString extracomment;
    16451703                bool plural = (args.size() > 4);
    16461704                recordMessage(translator, context, text, comment, extracomment,
    1647                               plural, fileName, identLineNo);
    1648             }
    1649         }
     1705                              msgid, extra, plural, fileName(), identLineNo);
     1706            }
     1707        }
     1708        sourcetext.clear();
     1709        extracomment.clear();
     1710        msgid.clear();
     1711        extra.clear();
    16501712    } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
     1713        if (!sourcetext.isEmpty())
     1714            yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
    16511715        QVariantList args = sym(2).toList();
    16521716        if (args.size() < 1) {
    1653             qWarning("%s:%d: %s() requires at least one argument",
    1654                      qPrintable(fileName), identLineNo, qPrintable(name));
     1717            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
    16551718        } else {
    16561719            if (args.at(0).type() != QVariant::String) {
    1657                 qWarning("%s:%d: %s(): text to translate must be a literal string",
    1658                          qPrintable(fileName), identLineNo, qPrintable(name));
     1720                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name));
    16591721            } else {
    1660                 QString context = QFileInfo(fileName).baseName();
     1722                QString context = QFileInfo(fileName()).baseName();
    16611723                QString text = args.at(0).toString();
    16621724                QString comment = args.value(1).toString();
    1663                 QString extracomment;
    16641725                bool plural = (args.size() > 2);
    16651726                recordMessage(translator, context, text, comment, extracomment,
    1666                               plural, fileName, identLineNo);
    1667             }
    1668         }
     1727                              msgid, extra, plural, fileName(), identLineNo);
     1728            }
     1729        }
     1730        sourcetext.clear();
     1731        extracomment.clear();
     1732        msgid.clear();
     1733        extra.clear();
     1734    } else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) {
     1735        if (!msgid.isEmpty())
     1736            yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name));
     1737        QVariantList args = sym(2).toList();
     1738        if (args.size() < 1) {
     1739            yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
     1740        } else {
     1741            if (args.at(0).type() != QVariant::String) {
     1742                yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name));
     1743            } else {
     1744                msgid = args.at(0).toString();
     1745                bool plural = (args.size() > 1);
     1746                recordMessage(translator, QString(), sourcetext, QString(), extracomment,
     1747                              msgid, extra, plural, fileName(), identLineNo);
     1748            }
     1749        }
     1750        sourcetext.clear();
     1751        extracomment.clear();
     1752        msgid.clear();
     1753        extra.clear();
    16691754    }
    16701755} break;
     
    18121897
    18131898Statement: Block ;
     1899/.
     1900    case $rule_number:
     1901./
    18141902Statement: VariableStatement ;
     1903/.
     1904    case $rule_number:
     1905./
    18151906Statement: EmptyStatement ;
     1907/.
     1908    case $rule_number:
     1909./
    18161910Statement: ExpressionStatement ;
     1911/.
     1912    case $rule_number:
     1913./
    18171914Statement: IfStatement ;
     1915/.
     1916    case $rule_number:
     1917./
    18181918Statement: IterationStatement ;
     1919/.
     1920    case $rule_number:
     1921./
    18191922Statement: ContinueStatement ;
     1923/.
     1924    case $rule_number:
     1925./
    18201926Statement: BreakStatement ;
     1927/.
     1928    case $rule_number:
     1929./
    18211930Statement: ReturnStatement ;
     1931/.
     1932    case $rule_number:
     1933./
    18221934Statement: WithStatement ;
     1935/.
     1936    case $rule_number:
     1937./
    18231938Statement: LabelledStatement ;
     1939/.
     1940    case $rule_number:
     1941./
    18241942Statement: SwitchStatement ;
     1943/.
     1944    case $rule_number:
     1945./
    18251946Statement: ThrowStatement ;
     1947/.
     1948    case $rule_number:
     1949./
    18261950Statement: TryStatement ;
     1951/.
     1952    case $rule_number:
     1953./
    18271954Statement: DebuggerStatement ;
     1955/.
     1956    case $rule_number:
     1957    if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
     1958        yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
     1959        sourcetext.clear();
     1960        extracomment.clear();
     1961        msgid.clear();
     1962        extra.clear();
     1963    }
     1964    break;
     1965./
    18281966
    18291967Block: T_LBRACE StatementListOpt T_RBRACE ;
     
    19642102                  if (first)
    19652103                    error_message += QLatin1String ("Expected ");
     2104                    //: Beginning of the string that contains
     2105                    //: comma-separated list of expected tokens
     2106                    error_message += LU::tr("Expected ");
    19662107                  else
    19672108                    error_message += QLatin1String (", ");
     
    19872128}
    19882129
     2130std::ostream &QScriptParser::yyMsg(int line)
     2131{
     2132    return std::cerr << qPrintable(fileName()) << ':' << (line ? line : lexer->startLineNo()) << ": ";
     2133}
     2134
     2135void QScriptParser::processComment(const QChar *chars, int length)
     2136{
     2137    if (!length)
     2138        return;
     2139    // Try to match the logic of the C++ parser.
     2140    if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
     2141        extracomment += QString(chars+2, length-2);
     2142    } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) {
     2143        msgid = QString(chars+2, length-2).simplified();
     2144    } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
     2145        QString text = QString(chars+2, length-2).trimmed();
     2146        int k = text.indexOf(QLatin1Char(' '));
     2147        if (k > -1)
     2148            extra.insert(text.left(k), text.mid(k + 1).trimmed());
     2149    } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
     2150        sourcetext.reserve(sourcetext.length() + length-2);
     2151        ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length();
     2152        int p = 2, c;
     2153        forever {
     2154            if (p >= length)
     2155                break;
     2156            c = chars[p++].unicode();
     2157            if (isspace(c))
     2158                continue;
     2159            if (c != '"') {
     2160                yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
     2161                break;
     2162            }
     2163            forever {
     2164                if (p >= length) {
     2165                  whoops:
     2166                    yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
     2167                    break;
     2168                }
     2169                c = chars[p++].unicode();
     2170                if (c == '"')
     2171                    break;
     2172                if (c == '\\') {
     2173                    if (p >= length)
     2174                        goto whoops;
     2175                    c = chars[p++].unicode();
     2176                    if (c == '\n')
     2177                        goto whoops;
     2178                    *ptr++ = '\\';
     2179                }
     2180                *ptr++ = c;
     2181            }
     2182        }
     2183        sourcetext.resize(ptr - (ushort *)sourcetext.data());
     2184    }
     2185}
     2186
    19892187
    19902188bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd)
     
    19922190    QFile file(filename);
    19932191    if (!file.open(QIODevice::ReadOnly)) {
    1994         cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    1995             .arg(filename, file.errorString()));
     2192        cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    19962193        return false;
    19972194    }
     
    20062203
    20072204    QString code = ts.readAll();
    2008     QScript::Lexer lexer;
    2009     lexer.setCode(code, /*lineNumber=*/1);
    20102205    QScriptParser parser;
    2011     if (!parser.parse(&lexer, filename, &translator)) {
    2012         qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(),
    2013                  qPrintable(parser.errorMessage()));
     2206    QScript::Lexer lexer(&parser);
     2207    lexer.setCode(code, filename, /*lineNumber=*/1);
     2208    parser.setLexer(&lexer);
     2209    if (!parser.parse(&translator)) {
     2210        std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": "
     2211                  << qPrintable(parser.errorMessage()) << std::endl;
    20142212        return false;
    20152213    }
  • trunk/tools/linguist/lupdate/ui.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4444#include <translator.h>
    4545
     46#include <QtCore/QCoreApplication>
    4647#include <QtCore/QDebug>
    4748#include <QtCore/QFile>
     
    5556
    5657QT_BEGIN_NAMESPACE
     58
     59class LU {
     60    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     61};
    5762
    5863class UiReader : public QXmlDefaultHandler
     
    153158bool UiReader::fatalError(const QXmlParseException &exception)
    154159{
    155     QString msg;
    156     msg.sprintf("XML error: Parse error at line %d, column %d (%s).",
    157                  exception.lineNumber(), exception.columnNumber(),
    158                  exception.message().toLatin1().data());
    159     m_cd.appendError(msg);
     160    QString msg = LU::tr("XML error: Parse error at line %1, column %2 (%3).")
     161        .arg(exception.lineNumber()).arg(exception.columnNumber())
     162        .arg(exception.message());
     163    m_cd.appendError(msg);
    160164    return false;
    161165}
     
    182186    QFile file(filename);
    183187    if (!file.open(QIODevice::ReadOnly)) {
    184         cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    185             .arg(filename, file.errorString()));
     188        cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    186189        return false;
    187190    }
     
    197200    bool result = reader.parse(in);
    198201    if (!result)
    199         cd.appendError(QLatin1String("Parse error in UI file"));
     202        cd.appendError(LU::tr("Parse error in UI file"));
    200203    reader.setContentHandler(0);
    201204    reader.setErrorHandler(0);
Note: See TracChangeset for help on using the changeset viewer.