-rw-r--r-- | development/translation/opie-lupdate/fetchtr.cpp | 55 | ||||
-rw-r--r-- | development/translation/opie-lupdate/main.cpp | 11 | ||||
-rw-r--r-- | development/translation/opie-lupdate/merge.cpp | 6 | ||||
-rw-r--r-- | development/translation/opie-lupdate/numberh.cpp | 28 | ||||
-rw-r--r-- | development/translation/opie-lupdate/sametexth.cpp | 6 | ||||
-rw-r--r-- | development/translation/shared/metatranslator.cpp | 34 | ||||
-rw-r--r-- | development/translation/shared/metatranslator.h | 16 | ||||
-rw-r--r-- | development/translation/shared/opie.h | 2 | ||||
-rw-r--r-- | development/translation/shared/proparser.cpp | 111 | ||||
-rw-r--r-- | development/translation/shared/proparser.h | 8 |
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -82,2 +88,3 @@ static size_t yyStringLen; | |||
82 | static QValueStack<int> yySavedBraceDepth; | 88 | static QValueStack<int> yySavedBraceDepth; |
89 | static QValueStack<int> yySavedParenDepth; | ||
83 | static int yyBraceDepth; | 90 | static int yyBraceDepth; |
@@ -86,2 +93,4 @@ static int yyLineNo; | |||
86 | static int yyCurLineNo; | 93 | static int yyCurLineNo; |
94 | static int yyBraceLineNo; | ||
95 | static int yyParenLineNo; | ||
87 | 96 | ||
@@ -121,2 +130,3 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() ) | |||
121 | yySavedBraceDepth.clear(); | 130 | yySavedBraceDepth.clear(); |
131 | yySavedParenDepth.clear(); | ||
122 | yyBraceDepth = 0; | 132 | yyBraceDepth = 0; |
@@ -124,2 +134,4 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() ) | |||
124 | yyCurLineNo = 1; | 134 | yyCurLineNo = 1; |
135 | yyBraceLineNo = 1; | ||
136 | yyParenLineNo = 1; | ||
125 | } | 137 | } |
@@ -166,2 +178,15 @@ static int getToken() | |||
166 | break; | 178 | break; |
179 | case 'f': | ||
180 | /* | ||
181 | QTranslator::findMessage() has the same parameters as | ||
182 | QApplication::translate(). | ||
183 | */ | ||
184 | if ( strcmp(yyIdent + 1, "indMessage") == 0 ) | ||
185 | return Tok_translate; | ||
186 | break; | ||
187 | case 'i': | ||
188 | /* FOR KDE APPS */ | ||
189 | if ( strcmp( yyIdent + 1, "8n") == 0 ) | ||
190 | return Tok_translate; | ||
191 | break; | ||
167 | case 'n': | 192 | case 'n': |
@@ -178,5 +203,2 @@ static int getToken() | |||
178 | break; | 203 | break; |
179 | case 'i': | ||
180 | if( strcmp(yyIdent + 1, "18n") == 0 ) | ||
181 | return Tok_tr; | ||
182 | case 't': | 204 | case 't': |
@@ -224,2 +246,3 @@ static int getToken() | |||
224 | yySavedBraceDepth.push( yyBraceDepth ); | 246 | yySavedBraceDepth.push( yyBraceDepth ); |
247 | yySavedParenDepth.push( yyParenDepth ); | ||
225 | } | 248 | } |
@@ -230,8 +253,12 @@ static int getToken() | |||
230 | // elif, else | 253 | // elif, else |
231 | if ( !yySavedBraceDepth.isEmpty() ) | 254 | if ( !yySavedBraceDepth.isEmpty() ) { |
232 | yyBraceDepth = yySavedBraceDepth.top(); | 255 | yyBraceDepth = yySavedBraceDepth.top(); |
256 | yyParenDepth = yySavedParenDepth.top(); | ||
257 | } | ||
233 | } else if ( yyCh == 'n' ) { | 258 | } else if ( yyCh == 'n' ) { |
234 | // endif | 259 | // endif |
235 | if ( !yySavedBraceDepth.isEmpty() ) | 260 | if ( !yySavedBraceDepth.isEmpty() ) { |
236 | yySavedBraceDepth.pop(); | 261 | yySavedBraceDepth.pop(); |
262 | yySavedParenDepth.pop(); | ||
263 | } | ||
237 | } | 264 | } |
@@ -358,2 +385,4 @@ static int getToken() | |||
358 | case '{': | 385 | case '{': |
386 | if (yyBraceDepth == 0) | ||
387 | yyBraceLineNo = yyCurLineNo; | ||
359 | yyBraceDepth++; | 388 | yyBraceDepth++; |
@@ -362,2 +391,4 @@ static int getToken() | |||
362 | case '}': | 391 | case '}': |
392 | if (yyBraceDepth == 0) | ||
393 | yyBraceLineNo = yyCurLineNo; | ||
363 | yyBraceDepth--; | 394 | yyBraceDepth--; |
@@ -366,2 +397,4 @@ static int getToken() | |||
366 | case '(': | 397 | case '(': |
398 | if (yyParenDepth == 0) | ||
399 | yyParenLineNo = yyCurLineNo; | ||
367 | yyParenDepth++; | 400 | yyParenDepth++; |
@@ -370,2 +403,4 @@ static int getToken() | |||
370 | case ')': | 403 | case ')': |
404 | if (yyParenDepth == 0) | ||
405 | yyParenLineNo = yyCurLineNo; | ||
371 | yyParenDepth--; | 406 | yyParenDepth--; |
@@ -623,10 +658,10 @@ static void parse( MetaTranslator *tor, const char *initialContext, | |||
623 | fprintf( stderr, | 658 | fprintf( stderr, |
624 | "%s: Unbalanced braces in C++ code (or abuse of the C++" | 659 | "%s:%d: Unbalanced braces in C++ code (or abuse of the C++" |
625 | " preprocessor)\n", | 660 | " preprocessor)\n", |
626 | (const char *) yyFileName ); | 661 | (const char *)yyFileName, yyBraceLineNo ); |
627 | if ( yyParenDepth != 0 ) | 662 | else if ( yyParenDepth != 0 ) |
628 | fprintf( stderr, | 663 | fprintf( stderr, |
629 | "%s: Unbalanced parentheses in C++ code (or abuse of the C++" | 664 | "%s:%d: Unbalanced parentheses in C++ code (or abuse of the C++" |
630 | " preprocessor)\n", | 665 | " preprocessor)\n", |
631 | (const char *) yyFileName ); | 666 | (const char *)yyFileName, yyParenLineNo ); |
632 | } | 667 | } |
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 | |||
@@ -64,2 +64,11 @@ static void printUsage() | |||
64 | 64 | ||
65 | /*static QString opie_escape( const QString& str ) { | ||
66 | QString ret = str.stripWhiteSpace(); | ||
67 | qWarning(ret); | ||
68 | if ( ret.startsWith("$$(OPIEDIR)") ) | ||
69 | ret = ret.replace("$$(OPIEDIR)", OPIE::self()->opieDir() ); | ||
70 | qWarning(ret); | ||
71 | return ret; | ||
72 | }*/ | ||
73 | |||
65 | static void updateTsFiles( const MetaTranslator& fetchedTor, | 74 | static void updateTsFiles( const MetaTranslator& fetchedTor, |
@@ -152,3 +161,3 @@ int main( int argc, char **argv ) | |||
152 | 161 | ||
153 | QMap<QString, QString> tagMap = proFileTagMap( fullText ); | 162 | QMap<QString, QString> tagMap = proFileTagMap( fullText, OPIE::self()->opieDir() ); |
154 | QMap<QString, QString>::Iterator it; | 163 | QMap<QString, QString>::Iterator it; |
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -34,3 +40,3 @@ static bool isDigitFriendly( int c ) | |||
34 | { | 40 | { |
35 | return ispunct( c ) || isspace( c ); | 41 | return ispunct((uchar)c) || isspace((uchar)c); |
36 | } | 42 | } |
@@ -41,9 +47,9 @@ static int numberLength( const char *s ) | |||
41 | 47 | ||
42 | if ( isdigit(s[0]) ) { | 48 | if ( isdigit((uchar)s[0]) ) { |
43 | do { | 49 | do { |
44 | i++; | 50 | i++; |
45 | } while ( isdigit(s[i]) || | 51 | } while (isdigit((uchar)s[i]) || |
46 | (isDigitFriendly(s[i]) && | 52 | (isDigitFriendly(s[i]) && |
47 | (isdigit(s[i + 1]) || | 53 | (isdigit((uchar)s[i + 1]) || |
48 | (isDigitFriendly(s[i + 1]) && isdigit(s[i + 2])))) ); | 54 | (isDigitFriendly(s[i + 1]) && isdigit((uchar)s[i + 2]))))); |
49 | } | 55 | } |
@@ -213,3 +219,4 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) | |||
213 | if ( (*it).translation().isEmpty() ) | 219 | if ( (*it).translation().isEmpty() ) |
214 | untranslated.insert( zeroKey((*it).sourceText()), *it ); | 220 | untranslated.insert(QCString((*it).context()) + "\n" + (*it).sourceText() + "\n" |
221 | + (*it).comment(), *it); | ||
215 | } else if ( !(*it).translation().isEmpty() ) { | 222 | } else if ( !(*it).translation().isEmpty() ) { |
@@ -220,3 +227,3 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) | |||
220 | for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { | 227 | for ( u = untranslated.begin(); u != untranslated.end(); ++u ) { |
221 | t = translated.find( u.key() ); | 228 | t = translated.find( zeroKey((*u).sourceText()) ); |
222 | if ( t != translated.end() && !t.key().isEmpty() && | 229 | if ( t != translated.end() && !t.key().isEmpty() && |
@@ -224,5 +231,4 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) | |||
224 | MetaTranslatorMessage m( *u ); | 231 | MetaTranslatorMessage m( *u ); |
225 | m.setTranslation( translationAttempt((*t).translation(), | 232 | m.setTranslation(translationAttempt((*t).translation(), (*t).sourceText(), |
226 | (*t).sourceText(), | 233 | (*u).sourceText())); |
227 | (*u).sourceText()) ); | ||
228 | tor->insert( m ); | 234 | tor->insert( m ); |
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -140,3 +146,4 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, | |||
140 | if ( contextIsUtf8 ) | 146 | if ( contextIsUtf8 ) |
141 | tor->insert( MetaTranslatorMessage(context.utf8(), "", | 147 | tor->insert( MetaTranslatorMessage(context.utf8(), |
148 | ContextComment, | ||
142 | accum.utf8(), QString::null, TRUE, | 149 | accum.utf8(), QString::null, TRUE, |
@@ -144,3 +151,4 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, | |||
144 | else | 151 | else |
145 | tor->insert( MetaTranslatorMessage(context.ascii(), "", | 152 | tor->insert( MetaTranslatorMessage(context.ascii(), |
153 | ContextComment, | ||
146 | accum.ascii(), QString::null, FALSE, | 154 | accum.ascii(), QString::null, FALSE, |
@@ -317,4 +325,4 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const | |||
317 | MetaTranslator::MetaTranslator() | 325 | MetaTranslator::MetaTranslator() |
318 | : codecName( "ISO-8859-1" ), codec( 0 ) | ||
319 | { | 326 | { |
327 | clear(); | ||
320 | } | 328 | } |
@@ -324,3 +332,2 @@ MetaTranslator::MetaTranslator( const MetaTranslator& tor ) | |||
324 | { | 332 | { |
325 | |||
326 | } | 333 | } |
@@ -335,6 +342,11 @@ MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) | |||
335 | 342 | ||
336 | bool MetaTranslator::load( const QString& filename ) | 343 | void MetaTranslator::clear() |
337 | { | 344 | { |
338 | mm.clear(); | 345 | mm.clear(); |
346 | codecName = "ISO-8859-1"; | ||
347 | codec = 0; | ||
348 | } | ||
339 | 349 | ||
350 | bool MetaTranslator::load( const QString& filename ) | ||
351 | { | ||
340 | QFile f( filename ); | 352 | QFile f( filename ); |
@@ -346,3 +358,2 @@ bool MetaTranslator::load( const QString& filename ) | |||
346 | QXmlSimpleReader reader; | 358 | QXmlSimpleReader reader; |
347 | // don't click on these! | ||
348 | reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); | 359 | reader.setFeature( "http://xml.org/sax/features/namespaces", FALSE ); |
@@ -360,4 +371,2 @@ bool MetaTranslator::load( const QString& filename ) | |||
360 | f.close(); | 371 | f.close(); |
361 | if ( !ok ) | ||
362 | mm.clear(); | ||
363 | return ok; | 372 | return ok; |
@@ -386,3 +395,3 @@ bool MetaTranslator::save( const QString& filename ) const | |||
386 | do { | 395 | do { |
387 | if ( QCString(m.key().sourceText()).isEmpty() ) { | 396 | if ( QCString(m.key().sourceText()) == ContextComment ) { |
388 | if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { | 397 | if ( m.key().type() != MetaTranslatorMessage::Obsolete ) { |
@@ -439,3 +448,4 @@ bool MetaTranslator::save( const QString& filename ) const | |||
439 | 448 | ||
440 | bool MetaTranslator::release( const QString& filename, bool verbose ) const | 449 | bool MetaTranslator::release( const QString& filename, bool verbose, |
450 | QTranslator::SaveMode mode ) const | ||
441 | { | 451 | { |
@@ -481,3 +491,3 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const | |||
481 | 491 | ||
482 | bool saved = tor.save( filename, QTranslator::Stripped ); | 492 | bool saved = tor.save( filename, mode ); |
483 | if ( saved && verbose ) | 493 | if ( saved && verbose ) |
@@ -525,3 +535,3 @@ void MetaTranslator::stripEmptyContexts() | |||
525 | while ( m != mm.end() ) { | 535 | while ( m != mm.end() ) { |
526 | if ( QCString(m.key().sourceText()).isEmpty() ) { | 536 | if ( QCString(m.key().sourceText()) == ContextComment ) { |
527 | TMM::Iterator n = m; | 537 | TMM::Iterator n = 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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -72,5 +78,7 @@ public: | |||
72 | 78 | ||
79 | void clear(); | ||
73 | bool load( const QString& filename ); | 80 | bool load( const QString& filename ); |
74 | bool save( const QString& filename ) const; | 81 | bool save( const QString& filename ) const; |
75 | bool release( const QString& filename, bool verbose = FALSE ) const; | 82 | bool release( const QString& filename, bool verbose = FALSE, |
83 | QTranslator::SaveMode mode = QTranslator::Stripped ) const; | ||
76 | 84 | ||
@@ -98,2 +106,8 @@ private: | |||
98 | 106 | ||
107 | /* | ||
108 | This is a quick hack. The proper way to handle this would be | ||
109 | to extend MetaTranslator's interface. | ||
110 | */ | ||
111 | #define ContextComment "QT_LINGUIST_INTERNAL_CONTEXT_COMMENT" | ||
112 | |||
99 | #endif | 113 | #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 | |||
@@ -11,3 +11,3 @@ public: | |||
11 | QStringList languageList(const QString& opiedir = QString::null)const; | 11 | QStringList languageList(const QString& opiedir = QString::null)const; |
12 | QString opieDir(const QString& opieDir)const; | 12 | QString opieDir(const QString& opieDir = QString::null)const; |
13 | 13 | ||
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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -22,6 +28,32 @@ | |||
22 | 28 | ||
29 | #include <qfile.h> | ||
23 | #include <qregexp.h> | 30 | #include <qregexp.h> |
24 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qtextstream.h> | ||
33 | |||
34 | #ifdef Q_OS_UNIX | ||
35 | #include <unistd.h> | ||
36 | #endif | ||
37 | |||
38 | #ifdef Q_OS_WIN32 | ||
39 | #define QT_POPEN _popen | ||
40 | #else | ||
41 | #define QT_POPEN popen | ||
42 | #endif | ||
43 | |||
44 | QString loadFile( const QString &fileName ) | ||
45 | { | ||
46 | QFile file( fileName ); | ||
47 | if ( !file.open(IO_ReadOnly) ) { | ||
48 | fprintf( stderr, "error: Cannot load '%s': %s\n", | ||
49 | file.name().latin1(), | ||
50 | file.errorString().latin1() ); | ||
51 | return QString(); | ||
52 | } | ||
53 | |||
54 | QTextStream in( &file ); | ||
55 | return in.read(); | ||
56 | } | ||
25 | 57 | ||
26 | QMap<QString, QString> proFileTagMap( const QString& text ) | 58 | QMap<QString, QString> proFileTagMap( const QString& text, const QString& opieDir ) |
27 | { | 59 | { |
@@ -30,2 +62,13 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
30 | /* | 62 | /* |
63 | Process include() commands. | ||
64 | */ | ||
65 | QRegExp callToInclude("include\\s*\\(\\s*([^()\\s]+)\\s*\\)"); | ||
66 | int i = 0; | ||
67 | while ( (i = callToInclude.search(t, i)) != -1 ) { | ||
68 | QString after = loadFile( callToInclude.cap(1) ); | ||
69 | t.replace( i, callToInclude.matchedLength(), after ); | ||
70 | i += after.length(); | ||
71 | } | ||
72 | |||
73 | /* | ||
31 | Strip comments, merge lines ending with backslash, add | 74 | Strip comments, merge lines ending with backslash, add |
@@ -34,4 +77,4 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
34 | */ | 77 | */ |
35 | t.replace( QRegExp(QString("#[^\n]$")), QString(" ") ); | 78 | t.replace( QRegExp(QString("#[^\n]*\n")), QString(" ") ); |
36 | t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") ); | 79 | t.replace( QRegExp(QString("\\\\[^\n\\S]*\n")), QString(" ") ); |
37 | t.replace( "=", QString(" = ") ); | 80 | t.replace( "=", QString(" = ") ); |
@@ -41,4 +84,6 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
41 | 84 | ||
85 | /* | ||
86 | Populate tagMap with 'key = value' entries. | ||
87 | */ | ||
42 | QMap<QString, QString> tagMap; | 88 | QMap<QString, QString> tagMap; |
43 | |||
44 | QStringList lines = QStringList::split( QChar(';'), t ); | 89 | QStringList lines = QStringList::split( QChar(';'), t ); |
@@ -48,3 +93,3 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
48 | 93 | ||
49 | if ( toks.count() >= 3 && | 94 | if ( toks.count() >= 3 && |
50 | (toks[1] == QString("=") || toks[1] == QString("+=")) ) { | 95 | (toks[1] == QString("=") || toks[1] == QString("+=")) ) { |
@@ -70,3 +115,7 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
70 | 115 | ||
71 | QRegExp var( "\\$\\$[a-zA-Z0-9_]+" ); | 116 | /* |
117 | Expand $$variables within the 'value' part of a 'key = value' | ||
118 | pair. | ||
119 | */ | ||
120 | QRegExp var( "\\$\\$[({]?([a-zA-Z0-9_]+)[)}]?" ); | ||
72 | QMap<QString, QString>::Iterator it; | 121 | QMap<QString, QString>::Iterator it; |
@@ -74,10 +123,47 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
74 | int i = 0; | 123 | int i = 0; |
75 | 124 | while ( (i = var.search((*it), i)) != -1 ) { | |
76 | while ( (i = var.search(it.data(), i)) != -1 ) { | ||
77 | int len = var.matchedLength(); | 125 | int len = var.matchedLength(); |
78 | QString invocation = (*it).mid( i + 2, len - 2 ); | 126 | QString invocation = var.cap(1); |
79 | QString after; | 127 | QString after; |
80 | if ( tagMap.contains(invocation) ) | 128 | |
81 | after = tagMap[invocation]; | 129 | if ( invocation == "system" ) { |
82 | (*it).replace( i, len, after ); | 130 | // skip system(); it will be handled in the next pass |
131 | ++i; | ||
132 | } else if ( invocation == "OPIEDIR") { | ||
133 | (*it).replace( i, len, opieDir ); | ||
134 | }else { | ||
135 | if ( tagMap.contains(invocation) ) | ||
136 | after = tagMap[invocation]; | ||
137 | (*it).replace( i, len, after ); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | Execute system() calls. | ||
144 | */ | ||
145 | QRegExp callToSystem( "\\$\\$system\\s*\\(([^()]*)\\)" ); | ||
146 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { | ||
147 | int i = 0; | ||
148 | while ( (i = callToSystem.search((*it), i)) != -1 ) { | ||
149 | /* | ||
150 | This code is stolen from qmake's project.cpp file. | ||
151 | Ideally we would use the same parser, so we wouldn't | ||
152 | have this code duplication. | ||
153 | */ | ||
154 | QString after; | ||
155 | char buff[256]; | ||
156 | FILE *proc = QT_POPEN( callToSystem.cap(1).latin1(), "r" ); | ||
157 | while ( proc && !feof(proc) ) { | ||
158 | int read_in = fread( buff, 1, 255, proc ); | ||
159 | if ( !read_in ) | ||
160 | break; | ||
161 | for ( int i = 0; i < read_in; i++ ) { | ||
162 | if ( buff[i] == '\n' || buff[i] == '\t' ) | ||
163 | buff[i] = ' '; | ||
164 | } | ||
165 | buff[read_in] = '\0'; | ||
166 | after += buff; | ||
167 | } | ||
168 | (*it).replace( i, callToSystem.matchedLength(), after ); | ||
83 | i += after.length(); | 169 | i += after.length(); |
@@ -85,2 +171,3 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
85 | } | 171 | } |
172 | |||
86 | return tagMap; | 173 | 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 | |||
@@ -10,2 +10,6 @@ | |||
10 | ** | 10 | ** |
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
12 | ** licenses may use this file in accordance with the Qt Commercial License | ||
13 | ** Agreement provided with the Software. | ||
14 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
@@ -14,2 +18,4 @@ | |||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
20 | ** information about Qt Commercial License Agreements. | ||
15 | ** | 21 | ** |
@@ -26,3 +32,3 @@ | |||
26 | 32 | ||
27 | QMap<QString, QString> proFileTagMap( const QString& text ); | 33 | QMap<QString, QString> proFileTagMap( const QString& text, const QString& = QString::null ); |
28 | 34 | ||