summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-06-03 16:03:52 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-06-03 16:06:23 (GMT)
commit482159bddec1736a8854dc2db1b75cf856d00255 (patch)
tree26a411466ab467bf62ad937315ddb54dd6f50aaf /tools/linguist
parent29e294aee281b7a4dcdd1277eef0fe1552015536 (diff)
downloadQt-482159bddec1736a8854dc2db1b75cf856d00255.zip
Qt-482159bddec1736a8854dc2db1b75cf856d00255.tar.gz
Qt-482159bddec1736a8854dc2db1b75cf856d00255.tar.bz2
don't use qWarning() - or even qFatal()! - gratuitously.
Task-number: QTBUG-8044
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/lconvert/main.cpp8
-rw-r--r--tools/linguist/lrelease/main.cpp23
-rw-r--r--tools/linguist/lupdate/cpp.cpp124
-rw-r--r--tools/linguist/lupdate/java.cpp40
-rw-r--r--tools/linguist/lupdate/main.cpp90
-rw-r--r--tools/linguist/lupdate/qscript.cpp22
-rw-r--r--tools/linguist/lupdate/qscript.g22
-rw-r--r--tools/linguist/shared/profileevaluator.cpp6
-rw-r--r--tools/linguist/shared/translator.cpp21
9 files changed, 178 insertions, 178 deletions
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index 543c405..049ea43 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -240,7 +240,7 @@ int main(int argc, char *argv[])
tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name));
if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) {
- qWarning() << qPrintable(cd.error());
+ std::cerr << qPrintable(cd.error()) << std::endl;
return 2;
}
tr.reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose);
@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
for (int i = 1; i < inFiles.size(); ++i) {
Translator tr2;
if (!tr2.load(inFiles[i].name, cd, inFiles[i].format)) {
- qWarning() << qPrintable(cd.error());
+ std::cerr << qPrintable(cd.error()) << std::endl;
return 2;
}
tr2.reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose);
@@ -273,11 +273,11 @@ int main(int argc, char *argv[])
tr.normalizeTranslations(cd);
if (!cd.errors().isEmpty()) {
- qWarning("%s", qPrintable(cd.error()));
+ std::cerr << qPrintable(cd.error()) << std::endl;
cd.clearErrors();
}
if (!tr.save(outFileName, cd, outFormat)) {
- qWarning("%s", qPrintable(cd.error()));
+ std::cerr << qPrintable(cd.error()) << std::endl;
return 3;
}
return 0;
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp
index 266474e..df0b430 100644
--- a/tools/linguist/lrelease/main.cpp
+++ b/tools/linguist/lrelease/main.cpp
@@ -55,6 +55,8 @@
#include <QtCore/QStringList>
#include <QtCore/QTextStream>
+#include <iostream>
+
QT_USE_NAMESPACE
#ifdef QT_BOOTSTRAPPED
@@ -106,7 +108,7 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo
ConversionData cd;
bool ok = tor.load(tsFileName, cd, QLatin1String("auto"));
if (!ok) {
- qWarning("lrelease error: %s\n", qPrintable(cd.error()));
+ std::cerr << "lrelease error: " << qPrintable(cd.error()) << std::endl;
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
@@ -130,8 +132,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
QFile file(qmFileName);
if (!file.open(QIODevice::WriteOnly)) {
- qWarning("lrelease error: cannot create '%s': %s\n",
- qPrintable(qmFileName), qPrintable(file.errorString()));
+ std::cerr << "lrelease error: cannot create '" << qPrintable(qmFileName)
+ << "': " << qPrintable(file.errorString()) << std::endl;
return false;
}
@@ -140,8 +142,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
file.close();
if (!ok) {
- qWarning("lrelease error: cannot save '%s': %s\n",
- qPrintable(qmFileName), qPrintable(cd.error()));
+ std::cerr << "lrelease error: cannot save '" << qPrintable(qmFileName)
+ << "': " << qPrintable(cd.error()) << std::endl;
} else if (!cd.errors().isEmpty()) {
printOut(cd.error());
}
@@ -253,19 +255,20 @@ int main(int argc, char **argv)
visitor.setVerbose(cd.isVerbose());
if (!visitor.queryProFile(&pro)) {
- qWarning("lrelease error: cannot read project file '%s'.", qPrintable(inputFile));
+ std::cerr << "lrelease error: cannot read project file '"
+ << qPrintable(inputFile) << "'.\n";
continue;
}
if (!visitor.accept(&pro)) {
- qWarning("lrelease error: cannot process project file '%s'.", qPrintable(inputFile));
+ std::cerr << "lrelease error: cannot process project file '"
+ << qPrintable(inputFile) << "'.\n";
continue;
}
QStringList translations = visitor.values(QLatin1String("TRANSLATIONS"));
if (translations.isEmpty()) {
- qWarning("lrelease warning: Met no 'TRANSLATIONS' entry in"
- " project file '%s'\n",
- qPrintable(inputFile));
+ std::cerr << "lrelease warning: Met no 'TRANSLATIONS' entry in project file '"
+ << qPrintable(inputFile) << "'\n";
} else {
QDir proDir(fi.absolutePath());
foreach (const QString &trans, translations)
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp
index db4bbca..b3e7e84 100644
--- a/tools/linguist/lupdate/cpp.cpp
+++ b/tools/linguist/lupdate/cpp.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
+#include <iostream>
+
#include <ctype.h> // for isXXX()
QT_BEGIN_NAMESPACE
@@ -226,6 +228,8 @@ private:
int elseLine;
};
+ std::ostream &yyMsg(int line = 0);
+
uint getChar();
uint getToken();
bool getMacroArgs();
@@ -352,6 +356,12 @@ CppParser::CppParser(ParseResults *_results)
inDefine = false;
}
+
+std::ostream &CppParser::yyMsg(int line)
+{
+ return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": ";
+}
+
void CppParser::setInput(const QString &in)
{
yyInStr = in;
@@ -613,9 +623,9 @@ uint CppParser::getToken()
if (yyBracketDepth != is.bracketDepth1st
|| yyBraceDepth != is.braceDepth1st
|| yyParenDepth != is.parenDepth1st)
- qWarning("%s:%d: Parenthesis/bracket/brace mismatch between "
- "#if and #else branches; using #if branch\n",
- qPrintable(yyFileName), is.elseLine);
+ yyMsg(is.elseLine)
+ << "Parenthesis/bracket/brace mismatch between "
+ "#if and #else branches; using #if branch\n";
} else {
is.bracketDepth1st = yyBracketDepth;
is.braceDepth1st = yyBraceDepth;
@@ -636,9 +646,9 @@ uint CppParser::getToken()
if (yyBracketDepth != is.bracketDepth1st
|| yyBraceDepth != is.braceDepth1st
|| yyParenDepth != is.parenDepth1st)
- qWarning("%s:%d: Parenthesis/brace mismatch between "
- "#if and #else branches; using #if branch\n",
- qPrintable(yyFileName), is.elseLine);
+ yyMsg(is.elseLine)
+ << "Parenthesis/brace mismatch between "
+ "#if and #else branches; using #if branch\n";
yyBracketDepth = is.bracketDepth1st;
yyBraceDepth = is.braceDepth1st;
yyParenDepth = is.parenDepth1st;
@@ -664,8 +674,7 @@ uint CppParser::getToken()
forever {
yyCh = getChar();
if (yyCh == EOF) {
- qWarning("%s:%d: Unterminated C++ comment\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unterminated C++ comment\n";
break;
}
@@ -795,8 +804,7 @@ uint CppParser::getToken()
forever {
yyCh = getChar();
if (yyCh == EOF) {
- qWarning("%s:%d: Unterminated C++ comment\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unterminated C++ comment\n";
break;
}
*ptr++ = yyCh;
@@ -829,8 +837,7 @@ uint CppParser::getToken()
yyWord.resize(ptr - (ushort *)yyWord.unicode());
if (yyCh != '"')
- qWarning("%s:%d: Unterminated C++ string\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unterminated C++ string\n";
else
yyCh = getChar();
return Tok_String;
@@ -867,8 +874,7 @@ uint CppParser::getToken()
forever {
if (yyCh == EOF || yyCh == '\n') {
- qWarning("%s:%d: Unterminated C++ character\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unterminated C++ character\n";
break;
}
yyCh = getChar();
@@ -887,9 +893,9 @@ uint CppParser::getToken()
case '}':
if (yyBraceDepth == yyMinBraceDepth) {
if (!inDefine)
- qWarning("%s:%d: Excess closing brace in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyCurLineNo);
+ yyMsg(yyCurLineNo)
+ << "Excess closing brace in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
// Avoid things getting messed up even more
yyCh = getChar();
return Tok_Semicolon;
@@ -905,9 +911,9 @@ uint CppParser::getToken()
return Tok_LeftParen;
case ')':
if (yyParenDepth == 0)
- qWarning("%s:%d: Excess closing parenthesis in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyCurLineNo);
+ yyMsg(yyCurLineNo)
+ << "Excess closing parenthesis in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
else
yyParenDepth--;
yyCh = getChar();
@@ -920,9 +926,9 @@ uint CppParser::getToken()
return Tok_LeftBracket;
case ']':
if (yyBracketDepth == 0)
- qWarning("%s:%d: Excess closing bracket in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyCurLineNo);
+ yyMsg(yyCurLineNo)
+ << "Excess closing bracket in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
else
yyBracketDepth--;
yyCh = getChar();
@@ -1290,8 +1296,7 @@ void CppParser::processInclude(const QString &file, ConversionData &cd,
QString cleanFile = QDir::cleanPath(file);
if (inclusions.contains(cleanFile)) {
- qWarning("%s:%d: circular inclusion of %s\n",
- qPrintable(yyFileName), yyLineNo, qPrintable(cleanFile));
+ yyMsg() << "circular inclusion of " << qPrintable(cleanFile) << std::endl;
return;
}
@@ -1315,9 +1320,9 @@ void CppParser::processInclude(const QString &file, ConversionData &cd,
QFile f(cleanFile);
if (!f.open(QIODevice::ReadOnly)) {
- qWarning("%s:%d: Cannot open %s: %s\n",
- qPrintable(yyFileName), yyLineNo,
- qPrintable(cleanFile), qPrintable(f.errorString()));
+ yyMsg()
+ << "Cannot open " << qPrintable(cleanFile) << ": "
+ << qPrintable(f.errorString()) << std::endl;
return;
}
@@ -1656,8 +1661,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
// Forward-declared class definitions can be namespaced.
NamespaceList nsl;
if (!fullyQualify(namespaces, quali, true, &nsl, 0)) {
- qWarning("%s:%d: Ignoring definition of undeclared qualified class\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Ignoring definition of undeclared qualified class\n";
break;
}
namespaceDepths.push(namespaces.count());
@@ -1757,8 +1761,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!sourcetext.isEmpty())
- qWarning("%s:%d: //%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "//%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n";
utf8 = (yyTok == Tok_trUtf8);
line = yyLineNo;
yyTok = getToken();
@@ -1779,10 +1782,9 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
QStringList unresolved;
if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) {
functionContextUnresolved = unresolved.join(strColons);
- qWarning("%s:%d: Qualifying with unknown namespace/class %s::%s\n",
- qPrintable(yyFileName), yyLineNo,
- qPrintable(stringifyNamespace(functionContext)),
- qPrintable(unresolved.first()));
+ yyMsg() << "Qualifying with unknown namespace/class "
+ << qPrintable(stringifyNamespace(functionContext)) << "::"
+ << qPrintable(unresolved.first()) << std::endl;
}
pendingContext.clear();
}
@@ -1790,8 +1792,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (functionContextUnresolved.isEmpty()) {
int idx = functionContext.length();
if (idx < 2) {
- qWarning("%s:%d: tr() cannot be called without context\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "tr() cannot be called without context\n";
break;
}
Namespace *fctx;
@@ -1800,9 +1801,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
context = stringifyNamespace(functionContext);
fctx = findNamespace(functionContext)->classDef;
if (!fctx->complained) {
- qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
- qPrintable(yyFileName), yyLineNo,
- qPrintable(context));
+ yyMsg() << "Class '" << qPrintable(context)
+ << "' lacks Q_OBJECT macro\n";
fctx->complained = true;
}
goto gotctx;
@@ -1830,9 +1830,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
int last = prefix.lastIndexOf(strColons);
QString className = prefix.mid(last == -1 ? 0 : last + 2);
if (!className.isEmpty() && className == functionName) {
- qWarning("%s::%d: It is not recommended to call tr() from within a constructor '%s::%s' ",
- qPrintable(yyFileName), yyLineNo,
- className.constData(), functionName.constData());
+ yyMsg() << "It is not recommended to call tr() from within a constructor '"
+ << qPrintable(className) << "::" << qPrintable(functionName) << "'\n";
}
#endif
prefix.chop(2);
@@ -1847,9 +1846,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
context = fctx->trQualification;
}
if (!fctx->hasTrFunctions && !fctx->complained) {
- qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
- qPrintable(yyFileName), yyLineNo,
- qPrintable(context));
+ yyMsg() << "Class '" << qPrintable(context) << "' lacks Q_OBJECT macro\n";
fctx->complained = true;
}
} else {
@@ -1870,8 +1867,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!sourcetext.isEmpty())
- qWarning("%s:%d: //%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "//%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n";
utf8 = (yyTok == Tok_translateUtf8);
line = yyLineNo;
yyTok = getToken();
@@ -1925,8 +1921,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (!tor)
goto case_default;
if (!msgid.isEmpty())
- qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n";
//utf8 = false; // Maybe use //%% or something like that
line = yyLineNo;
yyTok = getToken();
@@ -1993,15 +1988,13 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
if (isspace(c))
continue;
if (c != '"') {
- qWarning("%s:%d: Unexpected character in meta string\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unexpected character in meta string\n";
break;
}
forever {
if (p >= yyWord.length()) {
whoops:
- qWarning("%s:%d: Unterminated meta string\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Unterminated meta string\n";
break;
}
c = yyWord.unicode()[p++].unicode();
@@ -2054,8 +2047,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
case Tok_Arrow:
yyTok = getToken();
if (yyTok == Tok_tr || yyTok == Tok_trUtf8)
- qWarning("%s:%d: Cannot invoke tr() like this\n",
- qPrintable(yyFileName), yyLineNo);
+ yyMsg() << "Cannot invoke tr() like this\n";
break;
case Tok_ColonColon:
if (yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0 && !yyTokColonSeen)
@@ -2123,17 +2115,17 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions)
}
if (yyBraceDepth != 0)
- qWarning("%s:%d: Unbalanced opening brace in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyBraceLineNo);
+ yyMsg(yyBraceLineNo)
+ << "Unbalanced opening brace in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
else if (yyParenDepth != 0)
- qWarning("%s:%d: Unbalanced opening parenthesis in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyParenLineNo);
+ yyMsg(yyParenLineNo)
+ << "Unbalanced opening parenthesis in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
else if (yyBracketDepth != 0)
- qWarning("%s:%d: Unbalanced opening bracket in C++ code"
- " (or abuse of the C++ preprocessor)\n",
- qPrintable(yyFileName), yyBracketLineNo);
+ yyMsg(yyBracketLineNo)
+ << "Unbalanced opening bracket in C++ code"
+ " (or abuse of the C++ preprocessor)\n";
}
const ParseResults *CppParser::recordResults(bool isHeader)
diff --git a/tools/linguist/lupdate/java.cpp b/tools/linguist/lupdate/java.cpp
index 27988b04..dc66e2b 100644
--- a/tools/linguist/lupdate/java.cpp
+++ b/tools/linguist/lupdate/java.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/QTextCodec>
+#include <iostream>
+
#include <ctype.h>
QT_BEGIN_NAMESPACE
@@ -107,6 +109,11 @@ static QString yyPackage;
static QStack<Scope*> yyScope;
static QString yyDefaultContext;
+std::ostream &yyMsg(int line = 0)
+{
+ return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": ";
+}
+
static QChar getChar()
{
if (yyInPos >= yyInStr.size())
@@ -189,10 +196,7 @@ static int getToken()
while ( !metAsterSlash ) {
yyCh = getChar();
if ( yyCh == EOF ) {
- qFatal( "%s: Unterminated Java comment starting at"
- " line %d\n",
- qPrintable(yyFileName), yyLineNo );
-
+ yyMsg() << "Unterminated Java comment.\n";
return Tok_Comment;
}
@@ -228,8 +232,8 @@ static int getToken()
else {
int sub(yyCh.toLower().toAscii() - 87);
if( sub > 15 || sub < 10) {
- qFatal( "%s:%d: Invalid Unicode",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "Invalid Unicode value.\n";
+ break;
}
unicode += sub;
}
@@ -251,8 +255,7 @@ static int getToken()
}
if ( yyCh != QLatin1Char('"') )
- qFatal( "%s:%d: Unterminated string",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "Unterminated string.\n";
yyCh = getChar();
@@ -365,9 +368,8 @@ static bool matchString( QString &s )
if (yyTok == Tok_String)
s += yyString;
else {
- qWarning( "%s:%d: String used in translation can only contain strings"
- " concatenated with other strings, not expressions or numbers.",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "String used in translation can contain only literals"
+ " concatenated with other literals, not expressions or numbers.\n";
return false;
}
yyTok = getToken();
@@ -475,8 +477,8 @@ static void parse( Translator *tor )
yyScope.push(new Scope(yyIdent, Scope::Clazz, yyLineNo));
}
else {
- qFatal( "%s:%d: Class must be followed by a classname",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "'class' must be followed by a class name.\n";
+ break;
}
while (!match(Tok_LeftBrace)) {
yyTok = getToken();
@@ -547,8 +549,7 @@ static void parse( Translator *tor )
case Tok_RightBrace:
if ( yyScope.isEmpty() ) {
- qFatal( "%s:%d: Unbalanced right brace in Java code\n",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "Excess closing brace.\n";
}
else
delete (yyScope.pop());
@@ -577,8 +578,7 @@ static void parse( Translator *tor )
yyPackage.append(QLatin1String("."));
break;
default:
- qFatal( "%s:%d: Package keyword should be followed by com.package.name;",
- qPrintable(yyFileName), yyLineNo );
+ yyMsg() << "'package' must be followed by package name.\n";
break;
}
yyTok = getToken();
@@ -591,11 +591,9 @@ static void parse( Translator *tor )
}
if ( !yyScope.isEmpty() )
- qFatal( "%s:%d: Unbalanced braces in Java code\n",
- qPrintable(yyFileName), yyScope.top()->line );
+ yyMsg(yyScope.top()->line) << "Unbalanced opening brace.\n";
else if ( yyParenDepth != 0 )
- qFatal( "%s:%d: Unbalanced parentheses in Java code\n",
- qPrintable(yyFileName), yyParenLineNo );
+ yyMsg(yyParenLineNo) << "Unbalanced opening parenthesis.\n";
}
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp
index 6c9157a..1715b79 100644
--- a/tools/linguist/lupdate/main.cpp
+++ b/tools/linguist/lupdate/main.cpp
@@ -57,16 +57,15 @@
static QString m_defaultExtensions;
-static void printErr(const QString & out)
-{
- qWarning("%s", qPrintable(out));
-}
-
static void printOut(const QString & out)
{
std::cerr << qPrintable(out);
}
+class LU {
+ Q_DECLARE_TR_FUNCTIONS(LUpdate);
+};
+
static void recursiveFileInfoList(const QDir &dir,
const QSet<QString> &nameFilters, QDir::Filters filter,
QFileInfoList *fileinfolist)
@@ -150,24 +149,25 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
cd.m_sortContexts = !(options & NoSort);
if (QFile(fileName).exists()) {
if (!tor.load(fileName, cd, QLatin1String("auto"))) {
- printErr(cd.error());
+ printOut(cd.error());
*fail = true;
continue;
}
tor.resolveDuplicates();
cd.clearErrors();
if (setCodec && fetchedTor.codec() != tor.codec())
- qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
- "existing file's codec '%s'. Expect trouble.",
- fetchedTor.codecName().constData(), tor.codecName().constData());
+ printOut(LU::tr("lupdate warning: Codec for tr() '%1' disagrees with"
+ " existing file's codec '%2'. Expect trouble.\n")
+ .arg(QString::fromLatin1(fetchedTor.codecName()),
+ QString::fromLatin1(tor.codecName())));
if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode())
- qWarning("lupdate warning: Specified target language '%s' disagrees with "
- "existing file's language '%s'. Ignoring.",
- qPrintable(targetLanguage), qPrintable(tor.languageCode()));
+ printOut(LU::tr("lupdate warning: Specified target language '%1' disagrees with"
+ " existing file's language '%2'. Ignoring.\n")
+ .arg(targetLanguage, tor.languageCode()));
if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode())
- qWarning("lupdate warning: Specified source language '%s' disagrees with "
- "existing file's language '%s'. Ignoring.",
- qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode()));
+ printOut(LU::tr("lupdate warning: Specified source language '%1' disagrees with"
+ " existing file's language '%2'. Ignoring.\n")
+ .arg(sourceLanguage, tor.sourceLanguageCode()));
} else {
if (setCodec)
tor.setCodec(fetchedTor.codec());
@@ -210,11 +210,11 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
out.normalizeTranslations(cd);
if (!cd.errors().isEmpty()) {
- printErr(cd.error());
+ printOut(cd.error());
cd.clearErrors();
}
if (!out.save(fileName, cd, QLatin1String("auto"))) {
- printErr(cd.error());
+ printOut(cd.error());
*fail = true;
}
}
@@ -296,8 +296,9 @@ static void processProject(
if (!tmp.isEmpty()) {
codecForSource = tmp.last().toLatin1();
if (!QTextCodec::codecForName(codecForSource)) {
- qWarning("lupdate warning: Codec for source '%s' is invalid. "
- "Falling back to codec for tr().", codecForSource.constData());
+ printOut(LU::tr("lupdate warning: Codec for source '%1' is invalid."
+ " Falling back to codec for tr().\n")
+ .arg(QString::fromLatin1(codecForSource)));
codecForSource.clear();
}
}
@@ -452,7 +453,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-target-language")) {
++i;
if (i == argc) {
- qWarning("The option -target-language requires a parameter.");
+ printOut(LU::tr("The option -target-language requires a parameter.\n"));
return 1;
}
targetLanguage = args[i];
@@ -460,7 +461,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-source-language")) {
++i;
if (i == argc) {
- qWarning("The option -source-language requires a parameter.");
+ printOut(LU::tr("The option -source-language requires a parameter.\n"));
return 1;
}
sourceLanguage = args[i];
@@ -468,7 +469,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-disable-heuristic")) {
++i;
if (i == argc) {
- qWarning("The option -disable-heuristic requires a parameter.");
+ printOut(LU::tr("The option -disable-heuristic requires a parameter.\n"));
return 1;
}
arg = args[i];
@@ -479,14 +480,14 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("number")) {
options &= ~HeuristicNumber;
} else {
- qWarning("Invalid heuristic name passed to -disable-heuristic.");
+ printOut(LU::tr("Invalid heuristic name passed to -disable-heuristic.\n"));
return 1;
}
continue;
} else if (arg == QLatin1String("-locations")) {
++i;
if (i == argc) {
- qWarning("The option -locations requires a parameter.");
+ printOut(LU::tr("The option -locations requires a parameter.\n"));
return 1;
}
if (args[i] == QLatin1String("none")) {
@@ -496,7 +497,7 @@ int main(int argc, char **argv)
} else if (args[i] == QLatin1String("absolute")) {
options |= AbsoluteLocations;
} else {
- qWarning("Invalid parameter passed to -locations.");
+ printOut(LU::tr("Invalid parameter passed to -locations.\n"));
return 1;
}
continue;
@@ -522,7 +523,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-codecfortr")) {
++i;
if (i == argc) {
- qWarning("The -codecfortr option should be followed by a codec name.");
+ printOut(LU::tr("The -codecfortr option should be followed by a codec name.\n"));
return 1;
}
codecForTr = args[i].toLatin1();
@@ -533,7 +534,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-extensions")) {
++i;
if (i == argc) {
- qWarning("The -extensions option should be followed by an extension list.");
+ printOut(LU::tr("The -extensions option should be followed by an extension list.\n"));
return 1;
}
extensions = args[i];
@@ -541,7 +542,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-pro")) {
++i;
if (i == argc) {
- qWarning("The -pro option should be followed by a filename of .pro file.");
+ printOut(LU::tr("The -pro option should be followed by a filename of .pro file.\n"));
return 1;
}
proFiles += args[i];
@@ -551,7 +552,7 @@ int main(int argc, char **argv)
if (arg.length() == 2) {
++i;
if (i == argc) {
- qWarning("The -I option should be followed by a path.");
+ printOut(LU::tr("The -I option should be followed by a path.\n"));
return 1;
}
includePath += args[i];
@@ -560,7 +561,7 @@ int main(int argc, char **argv)
}
continue;
} else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
- qWarning("Unrecognized option '%s'", qPrintable(arg));
+ printOut(LU::tr("Unrecognized option '%1'.\n").arg(arg));
return 1;
}
@@ -568,8 +569,8 @@ int main(int argc, char **argv)
if (arg.startsWith(QLatin1String("@"))) {
QFile lstFile(arg.mid(1));
if (!lstFile.open(QIODevice::ReadOnly)) {
- qWarning("lupdate error: List file '%s' is not readable",
- qPrintable(lstFile.fileName()));
+ printOut(LU::tr("lupdate error: List file '%1' is not readable.\n")
+ .arg(lstFile.fileName()));
return 1;
}
while (!lstFile.atEnd())
@@ -586,16 +587,16 @@ int main(int argc, char **argv)
if (!fi.exists() || fi.isWritable()) {
tsFileNames.append(QFileInfo(file).absoluteFilePath());
} else {
- qWarning("lupdate warning: For some reason, '%s' is not writable.\n",
- qPrintable(file));
+ printOut(LU::tr("lupdate warning: For some reason, '%1' is not writable.\n")
+ .arg(file));
}
found = true;
break;
}
}
if (!found) {
- qWarning("lupdate error: File '%s' has no recognized extension\n",
- qPrintable(file));
+ printOut(LU::tr("lupdate error: File '%1' has no recognized extension.\n")
+ .arg(file));
return 1;
}
}
@@ -604,7 +605,7 @@ int main(int argc, char **argv)
foreach (const QString &file, files) {
QFileInfo fi(file);
if (!fi.exists()) {
- qWarning("lupdate error: File '%s' does not exists\n", qPrintable(file));
+ printOut(LU::tr("lupdate error: File '%1' does not exist.\n").arg(file));
return 1;
}
if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive)
@@ -612,7 +613,7 @@ int main(int argc, char **argv)
proFiles << file;
} else if (fi.isDir()) {
if (options & Verbose)
- printOut(QObject::tr("Scanning directory '%1'...").arg(file));
+ printOut(QObject::tr("Scanning directory '%1'...\n").arg(file));
QDir dir = QDir(fi.filePath());
projectRoots.insert(dir.absolutePath() + QLatin1Char('/'));
if (extensionsNameFilters.isEmpty()) {
@@ -662,16 +663,16 @@ int main(int argc, char **argv)
}
if (!targetLanguage.isEmpty() && tsFileNames.count() != 1)
- std::cerr << "lupdate warning: -target-language usually only "
- "makes sense with exactly one TS file.\n";
+ printOut(LU::tr("lupdate warning: -target-language usually only"
+ " makes sense with exactly one TS file.\n"));
if (!codecForTr.isEmpty() && tsFileNames.isEmpty())
- std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n";
+ printOut(LU::tr("lupdate warning: -codecfortr has no effect without -ts.\n"));
bool fail = false;
if (proFiles.isEmpty()) {
if (tsFileNames.isEmpty())
- std::cerr << "lupdate warning: no TS files specified. "
- "Only diagnostics will be produced.\n";
+ printOut(LU::tr("lupdate warning:"
+ " no TS files specified. Only diagnostics will be produced.\n"));
Translator fetchedTor;
ConversionData cd;
@@ -685,7 +686,8 @@ int main(int argc, char **argv)
sourceLanguage, targetLanguage, options, &fail);
} else {
if (!sourceFiles.isEmpty() || !includePath.isEmpty()) {
- qWarning("lupdate error: Both project and source files / include paths specified.\n");
+ printOut(LU::tr("lupdate error:"
+ " Both project and source files / include paths specified.\n"));
return 1;
}
if (!tsFileNames.isEmpty()) {
diff --git a/tools/linguist/lupdate/qscript.cpp b/tools/linguist/lupdate/qscript.cpp
index 33276e6..188ac36 100644
--- a/tools/linguist/lupdate/qscript.cpp
+++ b/tools/linguist/lupdate/qscript.cpp
@@ -53,6 +53,8 @@
#include <QtCore/qtextcodec.h>
#include <QtCore/qvariant.h>
+#include <iostream>
+
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
@@ -2214,13 +2216,13 @@ case 66: {
if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
QVariantList args = sym(2).toList();
if (args.size() < 2) {
- qWarning("%s:%d: %s() requires at least two arguments",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "() requires at least two arguments.\n";
} else {
if ((args.at(0).type() != QVariant::String)
|| (args.at(1).type() != QVariant::String)) {
- qWarning("%s:%d: %s(): both arguments must be literal strings",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "(): both arguments must be literal strings.\n";
} else {
QString context = args.at(0).toString();
QString text = args.at(1).toString();
@@ -2234,12 +2236,12 @@ case 66: {
} else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- qWarning("%s:%d: %s() requires at least one argument",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "() requires at least one argument.\n";
} else {
if (args.at(0).type() != QVariant::String) {
- qWarning("%s:%d: %s(): text to translate must be a literal string",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "(): text to translate must be a literal string.\n";
} else {
QString context = QFileInfo(fileName).baseName();
QString text = args.at(0).toString();
@@ -2377,8 +2379,8 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData
lexer.setCode(code, /*lineNumber=*/1);
QScriptParser parser;
if (!parser.parse(&lexer, filename, &translator)) {
- qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(),
- qPrintable(parser.errorMessage()));
+ std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": "
+ << qPrintable(parser.errorMessage()) << std::endl;
return false;
}
diff --git a/tools/linguist/lupdate/qscript.g b/tools/linguist/lupdate/qscript.g
index a473500..a07753c 100644
--- a/tools/linguist/lupdate/qscript.g
+++ b/tools/linguist/lupdate/qscript.g
@@ -90,6 +90,8 @@
#include <QtCore/qtextcodec.h>
#include <QtCore/qvariant.h>
+#include <iostream>
+
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
@@ -1630,13 +1632,13 @@ case $rule_number: {
if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) {
QVariantList args = sym(2).toList();
if (args.size() < 2) {
- qWarning("%s:%d: %s() requires at least two arguments",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "() requires at least two arguments.\n";
} else {
if ((args.at(0).type() != QVariant::String)
|| (args.at(1).type() != QVariant::String)) {
- qWarning("%s:%d: %s(): both arguments must be literal strings",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "(): both arguments must be literal strings.\n";
} else {
QString context = args.at(0).toString();
QString text = args.at(1).toString();
@@ -1650,12 +1652,12 @@ case $rule_number: {
} else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) {
QVariantList args = sym(2).toList();
if (args.size() < 1) {
- qWarning("%s:%d: %s() requires at least one argument",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "() requires at least one argument.\n";
} else {
if (args.at(0).type() != QVariant::String) {
- qWarning("%s:%d: %s(): text to translate must be a literal string",
- qPrintable(fileName), identLineNo, qPrintable(name));
+ std::cerr << qPrintable(fileName) << ':' << identLineNo << ": "
+ << qPrintable(name) << "(): text to translate must be a literal string.\n";
} else {
QString context = QFileInfo(fileName).baseName();
QString text = args.at(0).toString();
@@ -2009,8 +2011,8 @@ bool loadQScript(Translator &translator, const QString &filename, ConversionData
lexer.setCode(code, /*lineNumber=*/1);
QScriptParser parser;
if (!parser.parse(&lexer, filename, &translator)) {
- qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(),
- qPrintable(parser.errorMessage()));
+ std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": "
+ << qPrintable(parser.errorMessage()) << std::endl;
return false;
}
diff --git a/tools/linguist/shared/profileevaluator.cpp b/tools/linguist/shared/profileevaluator.cpp
index 5e1ee1f..a21408c 100644
--- a/tools/linguist/shared/profileevaluator.cpp
+++ b/tools/linguist/shared/profileevaluator.cpp
@@ -2594,19 +2594,19 @@ void ProFileEvaluator::addProperties(const QHash<QString, QString> &properties)
void ProFileEvaluator::logMessage(const QString &message)
{
if (d->m_verbose && !d->m_skipLevel)
- qWarning("%s", qPrintable(message));
+ fprintf(stderr, "%s\n", qPrintable(message));
}
void ProFileEvaluator::fileMessage(const QString &message)
{
if (!d->m_skipLevel)
- qWarning("%s", qPrintable(message));
+ fprintf(stderr, "%s\n", qPrintable(message));
}
void ProFileEvaluator::errorMessage(const QString &message)
{
if (!d->m_skipLevel)
- qWarning("%s", qPrintable(message));
+ fprintf(stderr, "%s\n", qPrintable(message));
}
void ProFileEvaluator::setVerbose(bool on)
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index c86a9dd..8223dc6 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -43,6 +43,8 @@
#include "simtexth.h"
+#include <iostream>
+
#include <stdio.h>
#ifdef Q_OS_WIN
// required for _setmode, to avoid _O_TEXT streams...
@@ -586,22 +588,21 @@ void Translator::reportDuplicates(const Duplicates &dupes,
const QString &fileName, bool verbose)
{
if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) {
+ std::cerr << "Warning: dropping duplicate messages in '" << qPrintable(fileName);
if (!verbose) {
- qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).",
- qPrintable(fileName));
+ std::cerr << "'\n(try -verbose for more info).\n";
} else {
- qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName));
+ std::cerr << "':\n";
foreach (int i, dupes.byId)
- qWarning("\n* ID: %s", qPrintable(message(i).id()));
+ std::cerr << "\n* ID: " << qPrintable(message(i).id()) << std::endl;
foreach (int j, dupes.byContents) {
const TranslatorMessage &msg = message(j);
- qWarning("\n* Context: %s\n* Source: %s",
- qPrintable(msg.context()),
- qPrintable(msg.sourceText()));
+ std::cerr << "\n* Context: " << qPrintable(msg.context())
+ << "\n* Source: " << qPrintable(msg.sourceText()) << std::endl;
if (!msg.comment().isEmpty())
- qWarning("* Comment: %s", qPrintable(msg.comment()));
+ std::cerr << "* Comment: " << qPrintable(msg.comment()) << std::endl;
}
- qWarning();
+ std::cerr << std::endl;
}
}
}
@@ -737,7 +738,7 @@ void Translator::setCodecName(const QByteArray &name)
QTextCodec *codec = QTextCodec::codecForName(name);
if (!codec) {
if (!name.isEmpty())
- qWarning("No QTextCodec for %s available. Using Latin1\n", name.constData());
+ std::cerr << "No QTextCodec for " << name.constData() << " available. Using Latin1.\n";
m_codec = QTextCodec::codecForName("ISO-8859-1");
} else {
m_codec = codec;