summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--development/translation/opie-lupdate/fetchtr.cpp55
-rw-r--r--development/translation/opie-lupdate/main.cpp11
-rw-r--r--development/translation/opie-lupdate/merge.cpp6
-rw-r--r--development/translation/opie-lupdate/numberh.cpp28
-rw-r--r--development/translation/opie-lupdate/sametexth.cpp6
-rw-r--r--development/translation/shared/metatranslator.cpp34
-rw-r--r--development/translation/shared/metatranslator.h16
-rw-r--r--development/translation/shared/opie.h2
-rw-r--r--development/translation/shared/proparser.cpp111
-rw-r--r--development/translation/shared/proparser.h8
10 files changed, 228 insertions, 49 deletions
diff --git a/development/translation/opie-lupdate/fetchtr.cpp b/development/translation/opie-lupdate/fetchtr.cpp
index d1f5881..a137628 100644
--- a/development/translation/opie-lupdate/fetchtr.cpp
+++ b/development/translation/opie-lupdate/fetchtr.cpp
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
@@ -77,16 +83,19 @@ static char yyIdent[128];
static size_t yyIdentLen;
static char yyComment[65536];
static size_t yyCommentLen;
static char yyString[16384];
static size_t yyStringLen;
static QValueStack<int> yySavedBraceDepth;
+static QValueStack<int> yySavedParenDepth;
static int yyBraceDepth;
static int yyParenDepth;
static int yyLineNo;
static int yyCurLineNo;
+static int yyBraceLineNo;
+static int yyParenLineNo;
// the file to read from (if reading from a file)
static FILE *yyInFile;
// the string to read from and current position in the string (otherwise)
static QString yyInStr;
@@ -116,15 +125,18 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() )
yyInPos = 0;
getChar = getCharFunc;
yyFileName = fileName;
yyCh = getChar();
yySavedBraceDepth.clear();
+ yySavedParenDepth.clear();
yyBraceDepth = 0;
yyParenDepth = 0;
yyCurLineNo = 1;
+ yyBraceLineNo = 1;
+ yyParenLineNo = 1;
}
static int getToken()
{
const char tab[] = "abfnrtv";
const char backTab[] = "\a\b\f\n\r\t\v";
@@ -161,27 +173,37 @@ static int getToken()
return Tok_tr;
break;
case 'c':
if ( strcmp(yyIdent + 1, "lass") == 0 )
return Tok_class;
break;
+ case 'f':
+ /*
+ QTranslator::findMessage() has the same parameters as
+ QApplication::translate().
+ */
+ if ( strcmp(yyIdent + 1, "indMessage") == 0 )
+ return Tok_translate;
+ break;
+ case 'i':
+ /* FOR KDE APPS */
+ if ( strcmp( yyIdent + 1, "8n") == 0 )
+ return Tok_translate;
+ break;
case 'n':
if ( strcmp(yyIdent + 1, "amespace") == 0 )
return Tok_namespace;
break;
case 'r':
if ( strcmp(yyIdent + 1, "eturn") == 0 )
return Tok_return;
break;
case 's':
if ( strcmp(yyIdent + 1, "truct") == 0 )
return Tok_class;
break;
- case 'i':
- if( strcmp(yyIdent + 1, "18n") == 0 )
- return Tok_tr;
case 't':
if ( strcmp(yyIdent + 1, "r") == 0 ) {
return Tok_tr;
} else if ( qstrcmp(yyIdent + 1, "rUtf8") == 0 ) {
return Tok_trUtf8;
} else if ( qstrcmp(yyIdent + 1, "ranslate") == 0 ) {
@@ -219,24 +241,29 @@ static int getToken()
switch ( yyCh ) {
case 'i':
yyCh = getChar();
if ( yyCh == 'f' ) {
// if, ifdef, ifndef
yySavedBraceDepth.push( yyBraceDepth );
+ yySavedParenDepth.push( yyParenDepth );
}
break;
case 'e':
yyCh = getChar();
if ( yyCh == 'l' ) {
// elif, else
- if ( !yySavedBraceDepth.isEmpty() )
+ if ( !yySavedBraceDepth.isEmpty() ) {
yyBraceDepth = yySavedBraceDepth.top();
+ yyParenDepth = yySavedParenDepth.top();
+ }
} else if ( yyCh == 'n' ) {
// endif
- if ( !yySavedBraceDepth.isEmpty() )
+ if ( !yySavedBraceDepth.isEmpty() ) {
yySavedBraceDepth.pop();
+ yySavedParenDepth.pop();
+ }
}
}
while ( isalnum(yyCh) || yyCh == '_' )
yyCh = getChar();
break;
case '/':
@@ -353,24 +380,32 @@ static int getToken()
do {
yyCh = getChar();
} while ( yyCh != EOF && yyCh != '\'' );
yyCh = getChar();
break;
case '{':
+ if (yyBraceDepth == 0)
+ yyBraceLineNo = yyCurLineNo;
yyBraceDepth++;
yyCh = getChar();
return Tok_LeftBrace;
case '}':
+ if (yyBraceDepth == 0)
+ yyBraceLineNo = yyCurLineNo;
yyBraceDepth--;
yyCh = getChar();
return Tok_RightBrace;
case '(':
+ if (yyParenDepth == 0)
+ yyParenLineNo = yyCurLineNo;
yyParenDepth++;
yyCh = getChar();
return Tok_LeftParen;
case ')':
+ if (yyParenDepth == 0)
+ yyParenLineNo = yyCurLineNo;
yyParenDepth--;
yyCh = getChar();
return Tok_RightParen;
case ',':
yyCh = getChar();
return Tok_Comma;
@@ -618,20 +653,20 @@ static void parse( MetaTranslator *tor, const char *initialContext,
yyTok = getToken();
}
}
if ( yyBraceDepth != 0 )
fprintf( stderr,
- "%s: Unbalanced braces in C++ code (or abuse of the C++"
+ "%s:%d: Unbalanced braces in C++ code (or abuse of the C++"
" preprocessor)\n",
- (const char *) yyFileName );
- if ( yyParenDepth != 0 )
+ (const char *)yyFileName, yyBraceLineNo );
+ else if ( yyParenDepth != 0 )
fprintf( stderr,
- "%s: Unbalanced parentheses in C++ code (or abuse of the C++"
+ "%s:%d: Unbalanced parentheses in C++ code (or abuse of the C++"
" preprocessor)\n",
- (const char *) yyFileName );
+ (const char *)yyFileName, yyParenLineNo );
}
void fetchtr_cpp( const char *fileName, MetaTranslator *tor,
const char *defaultContext, bool mustExist )
{
yyInFile = fopen( fileName, "r" );
diff --git a/development/translation/opie-lupdate/main.cpp b/development/translation/opie-lupdate/main.cpp
index ce65e7a..bf16fd7 100644
--- a/development/translation/opie-lupdate/main.cpp
+++ b/development/translation/opie-lupdate/main.cpp
@@ -59,12 +59,21 @@ static void printUsage()
" -verbose\n"
" Explain what is being done\n"
" -version\n"
" Display the version of lupdate and exit\n" );
}
+/*static QString opie_escape( const QString& str ) {
+ QString ret = str.stripWhiteSpace();
+ qWarning(ret);
+ if ( ret.startsWith("$$(OPIEDIR)") )
+ ret = ret.replace("$$(OPIEDIR)", OPIE::self()->opieDir() );
+ qWarning(ret);
+ return ret;
+ }*/
+
static void updateTsFiles( const MetaTranslator& fetchedTor,
const QString& opiedir,
const QStringList& languages,
const QString& basename,
const QString& codec,
bool noObsolete, bool verbose )
@@ -147,13 +156,13 @@ int main( int argc, char **argv )
fetchedTor = MetaTranslator();
codec.truncate( 0 );
tsFileNames.clear();
isLib = FALSE;
- QMap<QString, QString> tagMap = proFileTagMap( fullText );
+ QMap<QString, QString> tagMap = proFileTagMap( fullText, OPIE::self()->opieDir() );
QMap<QString, QString>::Iterator it;
for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
QStringList toks = QStringList::split( ' ', it.data() );
QStringList::Iterator t;
diff --git a/development/translation/opie-lupdate/merge.cpp b/development/translation/opie-lupdate/merge.cpp
index a96104e..3001d4b 100644
--- a/development/translation/opie-lupdate/merge.cpp
+++ b/development/translation/opie-lupdate/merge.cpp
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
diff --git a/development/translation/opie-lupdate/numberh.cpp b/development/translation/opie-lupdate/numberh.cpp
index f7b7bf8..2f12c3d 100644
--- a/development/translation/opie-lupdate/numberh.cpp
+++ b/development/translation/opie-lupdate/numberh.cpp
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
@@ -29,26 +35,26 @@
typedef QMap<QCString, MetaTranslatorMessage> TMM;
typedef QValueList<MetaTranslatorMessage> TML;
static bool isDigitFriendly( int c )
{
- return ispunct( c ) || isspace( c );
+ return ispunct((uchar)c) || isspace((uchar)c);
}
static int numberLength( const char *s )
{
int i = 0;
- if ( isdigit(s[0]) ) {
+ if ( isdigit((uchar)s[0]) ) {
do {
i++;
- } while ( isdigit(s[i]) ||
- (isDigitFriendly(s[i]) &&
- (isdigit(s[i + 1]) ||
- (isDigitFriendly(s[i + 1]) && isdigit(s[i + 2])))) );
+ } while (isdigit((uchar)s[i]) ||
+ (isDigitFriendly(s[i]) &&
+ (isdigit((uchar)s[i + 1]) ||
+ (isDigitFriendly(s[i + 1]) && isdigit((uchar)s[i + 2])))));
}
return i;
}
/*
Returns a version of 'key' where all numbers have been replaced by zeroes. If
@@ -208,26 +214,26 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose )
TML::Iterator it;
int inserted = 0;
for ( it = all.begin(); it != all.end(); ++it ) {
if ( (*it).type() == MetaTranslatorMessage::Unfinished ) {
if ( (*it).translation().isEmpty() )
- untranslated.insert( zeroKey((*it).sourceText()), *it );
+ untranslated.insert(QCString((*it).context()) + "\n" + (*it).sourceText() + "\n"
+ + (*it).comment(), *it);
} else if ( !(*it).translation().isEmpty() ) {
translated.insert( zeroKey((*it).sourceText()), *it );
}
}
for ( u = untranslated.begin(); u != untranslated.end(); ++u ) {
- t = translated.find( u.key() );
+ t = translated.find( zeroKey((*u).sourceText()) );
if ( t != translated.end() && !t.key().isEmpty() &&
qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) {
MetaTranslatorMessage m( *u );
- m.setTranslation( translationAttempt((*t).translation(),
- (*t).sourceText(),
- (*u).sourceText()) );
+ m.setTranslation(translationAttempt((*t).translation(), (*t).sourceText(),
+ (*u).sourceText()));
tor->insert( m );
inserted++;
}
}
if ( verbose && inserted != 0 )
fprintf( stderr, " number heuristic provided %d translation%s\n",
diff --git a/development/translation/opie-lupdate/sametexth.cpp b/development/translation/opie-lupdate/sametexth.cpp
index 574cfd5..80909b3 100644
--- a/development/translation/opie-lupdate/sametexth.cpp
+++ b/development/translation/opie-lupdate/sametexth.cpp
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
diff --git a/development/translation/shared/metatranslator.cpp b/development/translation/shared/metatranslator.cpp
index a01e1eb..51270c5 100644
--- a/development/translation/shared/metatranslator.cpp
+++ b/development/translation/shared/metatranslator.cpp
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
@@ -135,17 +141,19 @@ bool TsHandler::endElement( const QString& /* namespaceURI */,
source = accum;
} else if ( qName == QString("comment") ) {
if ( inMessage ) {
comment = accum;
} else {
if ( contextIsUtf8 )
- tor->insert( MetaTranslatorMessage(context.utf8(), "",
+ tor->insert( MetaTranslatorMessage(context.utf8(),
+ ContextComment,
accum.utf8(), QString::null, TRUE,
MetaTranslatorMessage::Unfinished) );
else
- tor->insert( MetaTranslatorMessage(context.ascii(), "",
+ tor->insert( MetaTranslatorMessage(context.ascii(),
+ ContextComment,
accum.ascii(), QString::null, FALSE,
MetaTranslatorMessage::Unfinished) );
}
} else if ( qName == QString("translation") ) {
translation = accum;
} else if ( qName == QString("message") ) {
@@ -312,42 +320,45 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const
if ( delta == 0 )
delta = qstrcmp( comment(), m.comment() );
return delta < 0;
}
MetaTranslator::MetaTranslator()
- : codecName( "ISO-8859-1" ), codec( 0 )
{
+ clear();
}
MetaTranslator::MetaTranslator( const MetaTranslator& tor )
: mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec )
{
-
}
MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor )
{
mm = tor.mm;
codecName = tor.codecName;
codec = tor.codec;
return *this;
}
-bool MetaTranslator::load( const QString& filename )
+void MetaTranslator::clear()
{
mm.clear();
+ codecName = "ISO-8859-1";
+ codec = 0;
+}
+bool MetaTranslator::load( const QString& filename )
+{
QFile f( filename );
if ( !f.open(IO_ReadOnly) )
return FALSE;
QTextStream t( &f );
QXmlInputSource in( t );
QXmlSimpleReader reader;
- // don't click on these!
reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE );
reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE );
reader.setFeature( "http://trolltech.com/xml/features/report-whitespace"
"-only-CharData", FALSE );
QXmlDefaultHandler *hand = new TsHandler( this );
reader.setContentHandler( hand );
@@ -355,14 +366,12 @@ bool MetaTranslator::load( const QString& filename )
bool ok = reader.parse( in );
reader.setContentHandler( 0 );
reader.setErrorHandler( 0 );
delete hand;
f.close();
- if ( !ok )
- mm.clear();
return ok;
}
bool MetaTranslator::save( const QString& filename ) const
{
QFile f( filename );
@@ -381,13 +390,13 @@ bool MetaTranslator::save( const QString& filename ) const
TMMInv::Iterator i;
bool contextIsUtf8 = m.key().utf8();
QCString context = m.key().context();
QCString comment = "";
do {
- if ( QCString(m.key().sourceText()).isEmpty() ) {
+ if ( QCString(m.key().sourceText()) == ContextComment ) {
if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
contextIsUtf8 = m.key().utf8();
comment = QCString( m.key().comment() );
}
} else {
inv.insert( *m, m.key() );
@@ -434,13 +443,14 @@ bool MetaTranslator::save( const QString& filename ) const
}
t << "</TS>\n";
f.close();
return TRUE;
}
-bool MetaTranslator::release( const QString& filename, bool verbose ) const
+bool MetaTranslator::release( const QString& filename, bool verbose,
+ QTranslator::SaveMode mode ) const
{
QTranslator tor( 0 );
int finished = 0;
int unfinished = 0;
int untranslated = 0;
TMM::ConstIterator m;
@@ -476,13 +486,13 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const
translation) );
}
}
}
}
- bool saved = tor.save( filename, QTranslator::Stripped );
+ bool saved = tor.save( filename, mode );
if ( saved && verbose )
fprintf( stderr,
" %d finished, %d unfinished and %d untranslated messages\n",
finished, unfinished, untranslated );
return saved;
@@ -520,13 +530,13 @@ void MetaTranslator::stripObsoleteMessages()
void MetaTranslator::stripEmptyContexts()
{
TMM newmm;
TMM::Iterator m = mm.begin();
while ( m != mm.end() ) {
- if ( QCString(m.key().sourceText()).isEmpty() ) {
+ if ( QCString(m.key().sourceText()) == ContextComment ) {
TMM::Iterator n = m;
++n;
// the context comment is followed by other messages
if ( n != newmm.end() &&
qstrcmp(m.key().context(), n.key().context()) == 0 )
newmm.insert( m.key(), *m );
diff --git a/development/translation/shared/metatranslator.h b/development/translation/shared/metatranslator.h
index d35b202..a13f462 100644
--- a/development/translation/shared/metatranslator.h
+++ b/development/translation/shared/metatranslator.h
@@ -5,16 +5,22 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
@@ -67,15 +73,17 @@ class MetaTranslator
public:
MetaTranslator();
MetaTranslator( const MetaTranslator& tor );
MetaTranslator& operator=( const MetaTranslator& tor );
+ void clear();
bool load( const QString& filename );
bool save( const QString& filename ) const;
- bool release( const QString& filename, bool verbose = FALSE ) const;
+ bool release( const QString& filename, bool verbose = FALSE,
+ QTranslator::SaveMode mode = QTranslator::Stripped ) const;
bool contains( const char *context, const char *sourceText,
const char *comment ) const;
void insert( const MetaTranslatorMessage& m );
void stripObsoleteMessages();
@@ -93,7 +101,13 @@ private:
TMM mm;
QCString codecName;
QTextCodec *codec;
};
+/*
+ This is a quick hack. The proper way to handle this would be
+ to extend MetaTranslator's interface.
+*/
+#define ContextComment "QT_LINGUIST_INTERNAL_CONTEXT_COMMENT"
+
#endif
diff --git a/development/translation/shared/opie.h b/development/translation/shared/opie.h
index 4646bb0..28b2a61 100644
--- a/development/translation/shared/opie.h
+++ b/development/translation/shared/opie.h
@@ -6,13 +6,13 @@
class OPIE {
public:
static OPIE* self();
/** get the list of languages */
QStringList languageList(const QString& opiedir = QString::null)const;
- QString opieDir(const QString& opieDir)const;
+ QString opieDir(const QString& opieDir = QString::null)const;
private:
OPIE();
~OPIE();
static OPIE* m_self;
diff --git a/development/translation/shared/proparser.cpp b/development/translation/shared/proparser.cpp
index 21d2f86..f616c5a 100644
--- a/development/translation/shared/proparser.cpp
+++ b/development/translation/shared/proparser.cpp
@@ -5,51 +5,96 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "proparser.h"
+#include <qfile.h>
#include <qregexp.h>
#include <qstringlist.h>
+#include <qtextstream.h>
+
+#ifdef Q_OS_UNIX
+#include <unistd.h>
+#endif
+
+#ifdef Q_OS_WIN32
+#define QT_POPEN _popen
+#else
+#define QT_POPEN popen
+#endif
+
+QString loadFile( const QString &fileName )
+{
+ QFile file( fileName );
+ if ( !file.open(IO_ReadOnly) ) {
+ fprintf( stderr, "error: Cannot load '%s': %s\n",
+ file.name().latin1(),
+ file.errorString().latin1() );
+ return QString();
+ }
+
+ QTextStream in( &file );
+ return in.read();
+}
-QMap<QString, QString> proFileTagMap( const QString& text )
+QMap<QString, QString> proFileTagMap( const QString& text, const QString& opieDir )
{
QString t = text;
/*
+ Process include() commands.
+ */
+ QRegExp callToInclude("include\\s*\\(\\s*([^()\\s]+)\\s*\\)");
+ int i = 0;
+ while ( (i = callToInclude.search(t, i)) != -1 ) {
+ QString after = loadFile( callToInclude.cap(1) );
+ t.replace( i, callToInclude.matchedLength(), after );
+ i += after.length();
+ }
+
+ /*
Strip comments, merge lines ending with backslash, add
spaces around '=' and '+=', replace '\n' with ';', and
simplify white spaces.
*/
- t.replace( QRegExp(QString("#[^\n]$")), QString(" ") );
- t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") );
+ t.replace( QRegExp(QString("#[^\n]*\n")), QString(" ") );
+ t.replace( QRegExp(QString("\\\\[^\n\\S]*\n")), QString(" ") );
t.replace( "=", QString(" = ") );
t.replace( "+ =", QString(" += ") );
t.replace( "\n", QString(";") );
t = t.simplifyWhiteSpace();
+ /*
+ Populate tagMap with 'key = value' entries.
+ */
QMap<QString, QString> tagMap;
-
QStringList lines = QStringList::split( QChar(';'), t );
QStringList::Iterator line;
for ( line = lines.begin(); line != lines.end(); ++line ) {
QStringList toks = QStringList::split( QChar(' '), *line );
- if ( toks.count() >= 3 &&
+ if ( toks.count() >= 3 &&
(toks[1] == QString("=") || toks[1] == QString("+=")) ) {
QString tag = toks.first();
int k = tag.findRev( QChar(':') ); // as in 'unix:'
if ( k != -1 )
tag = tag.mid( k + 1 );
toks.remove( toks.begin() );
@@ -65,23 +110,65 @@ QMap<QString, QString> proFileTagMap( const QString& text )
} else {
tagMap[tag] = toks.join( QChar(' ') );
}
}
}
- QRegExp var( "\\$\\$[a-zA-Z0-9_]+" );
+ /*
+ Expand $$variables within the 'value' part of a 'key = value'
+ pair.
+ */
+ QRegExp var( "\\$\\$[({]?([a-zA-Z0-9_]+)[)}]?" );
QMap<QString, QString>::Iterator it;
for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
int i = 0;
-
- while ( (i = var.search(it.data(), i)) != -1 ) {
+ while ( (i = var.search((*it), i)) != -1 ) {
int len = var.matchedLength();
- QString invocation = (*it).mid( i + 2, len - 2 );
+ QString invocation = var.cap(1);
QString after;
- if ( tagMap.contains(invocation) )
- after = tagMap[invocation];
- (*it).replace( i, len, after );
+
+ if ( invocation == "system" ) {
+ // skip system(); it will be handled in the next pass
+ ++i;
+ } else if ( invocation == "OPIEDIR") {
+ (*it).replace( i, len, opieDir );
+ }else {
+ if ( tagMap.contains(invocation) )
+ after = tagMap[invocation];
+ (*it).replace( i, len, after );
+ }
+ }
+ }
+
+ /*
+ Execute system() calls.
+ */
+ QRegExp callToSystem( "\\$\\$system\\s*\\(([^()]*)\\)" );
+ for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
+ int i = 0;
+ while ( (i = callToSystem.search((*it), i)) != -1 ) {
+ /*
+ This code is stolen from qmake's project.cpp file.
+ Ideally we would use the same parser, so we wouldn't
+ have this code duplication.
+ */
+ QString after;
+ char buff[256];
+ FILE *proc = QT_POPEN( callToSystem.cap(1).latin1(), "r" );
+ while ( proc && !feof(proc) ) {
+ int read_in = fread( buff, 1, 255, proc );
+ if ( !read_in )
+ break;
+ for ( int i = 0; i < read_in; i++ ) {
+ if ( buff[i] == '\n' || buff[i] == '\t' )
+ buff[i] = ' ';
+ }
+ buff[read_in] = '\0';
+ after += buff;
+ }
+ (*it).replace( i, callToSystem.matchedLength(), after );
i += after.length();
}
}
+
return tagMap;
}
diff --git a/development/translation/shared/proparser.h b/development/translation/shared/proparser.h
index 6a61d90..e5678d6 100644
--- a/development/translation/shared/proparser.h
+++ b/development/translation/shared/proparser.h
@@ -5,25 +5,31 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef PROPARSER_H
#define PROPARSER_H
#include <qmap.h>
#include <qstring.h>
-QMap<QString, QString> proFileTagMap( const QString& text );
+QMap<QString, QString> proFileTagMap( const QString& text, const QString& = QString::null );
#endif