author | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-01-09 19:13:35 (UTC) |
commit | 56bb9961db1158250bbfe971f4556b56c0bd6581 (patch) (unidiff) | |
tree | a4f40da98f695b5aadd845b68aaab41ac3d81826 | |
parent | 6875988077013544246ae0df7cc2e5d538a7f152 (diff) | |
download | opie-56bb9961db1158250bbfe971f4556b56c0bd6581.zip opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.gz opie-56bb9961db1158250bbfe971f4556b56c0bd6581.tar.bz2 |
Update lupdate and shared to Qt3.3 qt-copy sources
Some special replacement for $$(OPIEDIR) to make ar_* happy
-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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include <metatranslator.h> | 27 | #include <metatranslator.h> |
22 | 28 | ||
@@ -75,20 +81,23 @@ static QCString yyFileName; | |||
75 | static int yyCh; | 81 | static int yyCh; |
76 | static char yyIdent[128]; | 82 | static char yyIdent[128]; |
77 | static size_t yyIdentLen; | 83 | static size_t yyIdentLen; |
78 | static char yyComment[65536]; | 84 | static char yyComment[65536]; |
79 | static size_t yyCommentLen; | 85 | static size_t yyCommentLen; |
80 | static char yyString[16384]; | 86 | static char yyString[16384]; |
81 | static size_t yyStringLen; | 87 | 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; |
84 | static int yyParenDepth; | 91 | static int yyParenDepth; |
85 | static int yyLineNo; | 92 | static int yyLineNo; |
86 | static int yyCurLineNo; | 93 | static int yyCurLineNo; |
94 | static int yyBraceLineNo; | ||
95 | static int yyParenLineNo; | ||
87 | 96 | ||
88 | // the file to read from (if reading from a file) | 97 | // the file to read from (if reading from a file) |
89 | static FILE *yyInFile; | 98 | static FILE *yyInFile; |
90 | 99 | ||
91 | // the string to read from and current position in the string (otherwise) | 100 | // the string to read from and current position in the string (otherwise) |
92 | static QString yyInStr; | 101 | static QString yyInStr; |
93 | static int yyInPos; | 102 | static int yyInPos; |
94 | 103 | ||
@@ -114,19 +123,22 @@ static int getCharFromString() | |||
114 | static void startTokenizer( const char *fileName, int (*getCharFunc)() ) | 123 | static void startTokenizer( const char *fileName, int (*getCharFunc)() ) |
115 | { | 124 | { |
116 | yyInPos = 0; | 125 | yyInPos = 0; |
117 | getChar = getCharFunc; | 126 | getChar = getCharFunc; |
118 | 127 | ||
119 | yyFileName = fileName; | 128 | yyFileName = fileName; |
120 | yyCh = getChar(); | 129 | yyCh = getChar(); |
121 | yySavedBraceDepth.clear(); | 130 | yySavedBraceDepth.clear(); |
131 | yySavedParenDepth.clear(); | ||
122 | yyBraceDepth = 0; | 132 | yyBraceDepth = 0; |
123 | yyParenDepth = 0; | 133 | yyParenDepth = 0; |
124 | yyCurLineNo = 1; | 134 | yyCurLineNo = 1; |
135 | yyBraceLineNo = 1; | ||
136 | yyParenLineNo = 1; | ||
125 | } | 137 | } |
126 | 138 | ||
127 | static int getToken() | 139 | static int getToken() |
128 | { | 140 | { |
129 | const char tab[] = "abfnrtv"; | 141 | const char tab[] = "abfnrtv"; |
130 | const char backTab[] = "\a\b\f\n\r\t\v"; | 142 | const char backTab[] = "\a\b\f\n\r\t\v"; |
131 | uint n; | 143 | uint n; |
132 | 144 | ||
@@ -159,31 +171,41 @@ static int getToken() | |||
159 | // TR() for when all else fails | 171 | // TR() for when all else fails |
160 | if ( qstricmp(yyIdent + 1, "R") == 0 ) | 172 | if ( qstricmp(yyIdent + 1, "R") == 0 ) |
161 | return Tok_tr; | 173 | return Tok_tr; |
162 | break; | 174 | break; |
163 | case 'c': | 175 | case 'c': |
164 | if ( strcmp(yyIdent + 1, "lass") == 0 ) | 176 | if ( strcmp(yyIdent + 1, "lass") == 0 ) |
165 | return Tok_class; | 177 | return Tok_class; |
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': |
168 | if ( strcmp(yyIdent + 1, "amespace") == 0 ) | 193 | if ( strcmp(yyIdent + 1, "amespace") == 0 ) |
169 | return Tok_namespace; | 194 | return Tok_namespace; |
170 | break; | 195 | break; |
171 | case 'r': | 196 | case 'r': |
172 | if ( strcmp(yyIdent + 1, "eturn") == 0 ) | 197 | if ( strcmp(yyIdent + 1, "eturn") == 0 ) |
173 | return Tok_return; | 198 | return Tok_return; |
174 | break; | 199 | break; |
175 | case 's': | 200 | case 's': |
176 | if ( strcmp(yyIdent + 1, "truct") == 0 ) | 201 | if ( strcmp(yyIdent + 1, "truct") == 0 ) |
177 | return Tok_class; | 202 | return Tok_class; |
178 | break; | 203 | break; |
179 | case 'i': | ||
180 | if( strcmp(yyIdent + 1, "18n") == 0 ) | ||
181 | return Tok_tr; | ||
182 | case 't': | 204 | case 't': |
183 | if ( strcmp(yyIdent + 1, "r") == 0 ) { | 205 | if ( strcmp(yyIdent + 1, "r") == 0 ) { |
184 | return Tok_tr; | 206 | return Tok_tr; |
185 | } else if ( qstrcmp(yyIdent + 1, "rUtf8") == 0 ) { | 207 | } else if ( qstrcmp(yyIdent + 1, "rUtf8") == 0 ) { |
186 | return Tok_trUtf8; | 208 | return Tok_trUtf8; |
187 | } else if ( qstrcmp(yyIdent + 1, "ranslate") == 0 ) { | 209 | } else if ( qstrcmp(yyIdent + 1, "ranslate") == 0 ) { |
188 | return Tok_translate; | 210 | return Tok_translate; |
189 | } | 211 | } |
@@ -217,28 +239,33 @@ static int getToken() | |||
217 | } while ( isspace(yyCh) && yyCh != '\n' ); | 239 | } while ( isspace(yyCh) && yyCh != '\n' ); |
218 | 240 | ||
219 | switch ( yyCh ) { | 241 | switch ( yyCh ) { |
220 | case 'i': | 242 | case 'i': |
221 | yyCh = getChar(); | 243 | yyCh = getChar(); |
222 | if ( yyCh == 'f' ) { | 244 | if ( yyCh == 'f' ) { |
223 | // if, ifdef, ifndef | 245 | // if, ifdef, ifndef |
224 | yySavedBraceDepth.push( yyBraceDepth ); | 246 | yySavedBraceDepth.push( yyBraceDepth ); |
247 | yySavedParenDepth.push( yyParenDepth ); | ||
225 | } | 248 | } |
226 | break; | 249 | break; |
227 | case 'e': | 250 | case 'e': |
228 | yyCh = getChar(); | 251 | yyCh = getChar(); |
229 | if ( yyCh == 'l' ) { | 252 | if ( yyCh == 'l' ) { |
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 | } |
238 | } | 265 | } |
239 | while ( isalnum(yyCh) || yyCh == '_' ) | 266 | while ( isalnum(yyCh) || yyCh == '_' ) |
240 | yyCh = getChar(); | 267 | yyCh = getChar(); |
241 | break; | 268 | break; |
242 | case '/': | 269 | case '/': |
243 | yyCh = getChar(); | 270 | yyCh = getChar(); |
244 | if ( yyCh == '/' ) { | 271 | if ( yyCh == '/' ) { |
@@ -351,28 +378,36 @@ static int getToken() | |||
351 | yyCh = getChar(); | 378 | yyCh = getChar(); |
352 | 379 | ||
353 | do { | 380 | do { |
354 | yyCh = getChar(); | 381 | yyCh = getChar(); |
355 | } while ( yyCh != EOF && yyCh != '\'' ); | 382 | } while ( yyCh != EOF && yyCh != '\'' ); |
356 | yyCh = getChar(); | 383 | yyCh = getChar(); |
357 | break; | 384 | break; |
358 | case '{': | 385 | case '{': |
386 | if (yyBraceDepth == 0) | ||
387 | yyBraceLineNo = yyCurLineNo; | ||
359 | yyBraceDepth++; | 388 | yyBraceDepth++; |
360 | yyCh = getChar(); | 389 | yyCh = getChar(); |
361 | return Tok_LeftBrace; | 390 | return Tok_LeftBrace; |
362 | case '}': | 391 | case '}': |
392 | if (yyBraceDepth == 0) | ||
393 | yyBraceLineNo = yyCurLineNo; | ||
363 | yyBraceDepth--; | 394 | yyBraceDepth--; |
364 | yyCh = getChar(); | 395 | yyCh = getChar(); |
365 | return Tok_RightBrace; | 396 | return Tok_RightBrace; |
366 | case '(': | 397 | case '(': |
398 | if (yyParenDepth == 0) | ||
399 | yyParenLineNo = yyCurLineNo; | ||
367 | yyParenDepth++; | 400 | yyParenDepth++; |
368 | yyCh = getChar(); | 401 | yyCh = getChar(); |
369 | return Tok_LeftParen; | 402 | return Tok_LeftParen; |
370 | case ')': | 403 | case ')': |
404 | if (yyParenDepth == 0) | ||
405 | yyParenLineNo = yyCurLineNo; | ||
371 | yyParenDepth--; | 406 | yyParenDepth--; |
372 | yyCh = getChar(); | 407 | yyCh = getChar(); |
373 | return Tok_RightParen; | 408 | return Tok_RightParen; |
374 | case ',': | 409 | case ',': |
375 | yyCh = getChar(); | 410 | yyCh = getChar(); |
376 | return Tok_Comma; | 411 | return Tok_Comma; |
377 | case ';': | 412 | case ';': |
378 | yyCh = getChar(); | 413 | yyCh = getChar(); |
@@ -616,24 +651,24 @@ static void parse( MetaTranslator *tor, const char *initialContext, | |||
616 | break; | 651 | break; |
617 | default: | 652 | default: |
618 | yyTok = getToken(); | 653 | yyTok = getToken(); |
619 | } | 654 | } |
620 | } | 655 | } |
621 | 656 | ||
622 | if ( yyBraceDepth != 0 ) | 657 | if ( yyBraceDepth != 0 ) |
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 | } |
633 | 668 | ||
634 | void fetchtr_cpp( const char *fileName, MetaTranslator *tor, | 669 | void fetchtr_cpp( const char *fileName, MetaTranslator *tor, |
635 | const char *defaultContext, bool mustExist ) | 670 | const char *defaultContext, bool mustExist ) |
636 | { | 671 | { |
637 | yyInFile = fopen( fileName, "r" ); | 672 | yyInFile = fopen( fileName, "r" ); |
638 | if ( yyInFile == 0 ) { | 673 | if ( yyInFile == 0 ) { |
639 | if ( mustExist ) | 674 | if ( mustExist ) |
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 | |||
@@ -57,16 +57,25 @@ static void printUsage() | |||
57 | " -noobsolete\n" | 57 | " -noobsolete\n" |
58 | " Drop all obsolete strings\n" | 58 | " Drop all obsolete strings\n" |
59 | " -verbose\n" | 59 | " -verbose\n" |
60 | " Explain what is being done\n" | 60 | " Explain what is being done\n" |
61 | " -version\n" | 61 | " -version\n" |
62 | " Display the version of lupdate and exit\n" ); | 62 | " Display the version of lupdate and exit\n" ); |
63 | } | 63 | } |
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, |
66 | const QString& opiedir, | 75 | const QString& opiedir, |
67 | const QStringList& languages, | 76 | const QStringList& languages, |
68 | const QString& basename, | 77 | const QString& basename, |
69 | const QString& codec, | 78 | const QString& codec, |
70 | bool noObsolete, bool verbose ) | 79 | bool noObsolete, bool verbose ) |
71 | { | 80 | { |
72 | QStringList::ConstIterator it = languages.begin(); | 81 | QStringList::ConstIterator it = languages.begin(); |
@@ -145,17 +154,17 @@ int main( int argc, char **argv ) | |||
145 | fullText = t.read(); | 154 | fullText = t.read(); |
146 | f.close(); | 155 | f.close(); |
147 | 156 | ||
148 | fetchedTor = MetaTranslator(); | 157 | fetchedTor = MetaTranslator(); |
149 | codec.truncate( 0 ); | 158 | codec.truncate( 0 ); |
150 | tsFileNames.clear(); | 159 | tsFileNames.clear(); |
151 | isLib = FALSE; | 160 | isLib = FALSE; |
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; |
155 | 164 | ||
156 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { | 165 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { |
157 | QStringList toks = QStringList::split( ' ', it.data() ); | 166 | QStringList toks = QStringList::split( ' ', it.data() ); |
158 | QStringList::Iterator t; | 167 | QStringList::Iterator t; |
159 | 168 | ||
160 | for ( t = toks.begin(); t != toks.end(); ++t ) { | 169 | for ( t = toks.begin(); t != toks.end(); ++t ) { |
161 | if ( it.key() == "HEADERS" || it.key() == "SOURCES" ) { | 170 | if ( it.key() == "HEADERS" || it.key() == "SOURCES" ) { |
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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include <metatranslator.h> | 27 | #include <metatranslator.h> |
22 | 28 | ||
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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include <metatranslator.h> | 27 | #include <metatranslator.h> |
22 | 28 | ||
@@ -27,30 +33,30 @@ | |||
27 | 33 | ||
28 | #include <ctype.h> | 34 | #include <ctype.h> |
29 | 35 | ||
30 | typedef QMap<QCString, MetaTranslatorMessage> TMM; | 36 | typedef QMap<QCString, MetaTranslatorMessage> TMM; |
31 | typedef QValueList<MetaTranslatorMessage> TML; | 37 | typedef QValueList<MetaTranslatorMessage> TML; |
32 | 38 | ||
33 | static bool isDigitFriendly( int c ) | 39 | static bool isDigitFriendly( int c ) |
34 | { | 40 | { |
35 | return ispunct( c ) || isspace( c ); | 41 | return ispunct((uchar)c) || isspace((uchar)c); |
36 | } | 42 | } |
37 | 43 | ||
38 | static int numberLength( const char *s ) | 44 | static int numberLength( const char *s ) |
39 | { | 45 | { |
40 | int i = 0; | 46 | int i = 0; |
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 | } |
50 | return i; | 56 | return i; |
51 | } | 57 | } |
52 | 58 | ||
53 | /* | 59 | /* |
54 | Returns a version of 'key' where all numbers have been replaced by zeroes. If | 60 | Returns a version of 'key' where all numbers have been replaced by zeroes. If |
55 | there were none, returns "". | 61 | there were none, returns "". |
56 | */ | 62 | */ |
@@ -206,30 +212,30 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose ) | |||
206 | TMM::Iterator t, u; | 212 | TMM::Iterator t, u; |
207 | TML all = tor->messages(); | 213 | TML all = tor->messages(); |
208 | TML::Iterator it; | 214 | TML::Iterator it; |
209 | int inserted = 0; | 215 | int inserted = 0; |
210 | 216 | ||
211 | for ( it = all.begin(); it != all.end(); ++it ) { | 217 | for ( it = all.begin(); it != all.end(); ++it ) { |
212 | if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { | 218 | if ( (*it).type() == MetaTranslatorMessage::Unfinished ) { |
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() ) { |
216 | translated.insert( zeroKey((*it).sourceText()), *it ); | 223 | translated.insert( zeroKey((*it).sourceText()), *it ); |
217 | } | 224 | } |
218 | } | 225 | } |
219 | 226 | ||
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() && |
223 | qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) { | 230 | qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) { |
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 ); |
229 | inserted++; | 235 | inserted++; |
230 | } | 236 | } |
231 | } | 237 | } |
232 | if ( verbose && inserted != 0 ) | 238 | if ( verbose && inserted != 0 ) |
233 | fprintf( stderr, " number heuristic provided %d translation%s\n", | 239 | fprintf( stderr, " number heuristic provided %d translation%s\n", |
234 | inserted, inserted == 1 ? "" : "s" ); | 240 | inserted, inserted == 1 ? "" : "s" ); |
235 | } | 241 | } |
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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include <metatranslator.h> | 27 | #include <metatranslator.h> |
22 | 28 | ||
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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include "metatranslator.h" | 27 | #include "metatranslator.h" |
22 | 28 | ||
@@ -133,21 +139,23 @@ bool TsHandler::endElement( const QString& /* namespaceURI */, | |||
133 | context = accum; | 139 | context = accum; |
134 | } else if ( qName == QString("source") ) { | 140 | } else if ( qName == QString("source") ) { |
135 | source = accum; | 141 | source = accum; |
136 | } else if ( qName == QString("comment") ) { | 142 | } else if ( qName == QString("comment") ) { |
137 | if ( inMessage ) { | 143 | if ( inMessage ) { |
138 | comment = accum; | 144 | comment = accum; |
139 | } else { | 145 | } else { |
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, |
143 | MetaTranslatorMessage::Unfinished) ); | 150 | MetaTranslatorMessage::Unfinished) ); |
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, |
147 | MetaTranslatorMessage::Unfinished) ); | 155 | MetaTranslatorMessage::Unfinished) ); |
148 | } | 156 | } |
149 | } else if ( qName == QString("translation") ) { | 157 | } else if ( qName == QString("translation") ) { |
150 | translation = accum; | 158 | translation = accum; |
151 | } else if ( qName == QString("message") ) { | 159 | } else if ( qName == QString("message") ) { |
152 | if ( messageIsUtf8 ) | 160 | if ( messageIsUtf8 ) |
153 | tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(), | 161 | tor->insert( MetaTranslatorMessage(context.utf8(), source.utf8(), |
@@ -310,61 +318,62 @@ bool MetaTranslatorMessage::operator<( const MetaTranslatorMessage& m ) const | |||
310 | if ( delta == 0 ) | 318 | if ( delta == 0 ) |
311 | delta = qstrcmp( sourceText(), m.sourceText() ); | 319 | delta = qstrcmp( sourceText(), m.sourceText() ); |
312 | if ( delta == 0 ) | 320 | if ( delta == 0 ) |
313 | delta = qstrcmp( comment(), m.comment() ); | 321 | delta = qstrcmp( comment(), m.comment() ); |
314 | return delta < 0; | 322 | return delta < 0; |
315 | } | 323 | } |
316 | 324 | ||
317 | MetaTranslator::MetaTranslator() | 325 | MetaTranslator::MetaTranslator() |
318 | : codecName( "ISO-8859-1" ), codec( 0 ) | ||
319 | { | 326 | { |
327 | clear(); | ||
320 | } | 328 | } |
321 | 329 | ||
322 | MetaTranslator::MetaTranslator( const MetaTranslator& tor ) | 330 | MetaTranslator::MetaTranslator( const MetaTranslator& tor ) |
323 | : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec ) | 331 | : mm( tor.mm ), codecName( tor.codecName ), codec( tor.codec ) |
324 | { | 332 | { |
325 | |||
326 | } | 333 | } |
327 | 334 | ||
328 | MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) | 335 | MetaTranslator& MetaTranslator::operator=( const MetaTranslator& tor ) |
329 | { | 336 | { |
330 | mm = tor.mm; | 337 | mm = tor.mm; |
331 | codecName = tor.codecName; | 338 | codecName = tor.codecName; |
332 | codec = tor.codec; | 339 | codec = tor.codec; |
333 | return *this; | 340 | return *this; |
334 | } | 341 | } |
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 ); |
341 | if ( !f.open(IO_ReadOnly) ) | 353 | if ( !f.open(IO_ReadOnly) ) |
342 | return FALSE; | 354 | return FALSE; |
343 | 355 | ||
344 | QTextStream t( &f ); | 356 | QTextStream t( &f ); |
345 | QXmlInputSource in( t ); | 357 | QXmlInputSource in( t ); |
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 ); |
349 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); | 360 | reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", TRUE ); |
350 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" | 361 | reader.setFeature( "http://trolltech.com/xml/features/report-whitespace" |
351 | "-only-CharData", FALSE ); | 362 | "-only-CharData", FALSE ); |
352 | QXmlDefaultHandler *hand = new TsHandler( this ); | 363 | QXmlDefaultHandler *hand = new TsHandler( this ); |
353 | reader.setContentHandler( hand ); | 364 | reader.setContentHandler( hand ); |
354 | reader.setErrorHandler( hand ); | 365 | reader.setErrorHandler( hand ); |
355 | 366 | ||
356 | bool ok = reader.parse( in ); | 367 | bool ok = reader.parse( in ); |
357 | reader.setContentHandler( 0 ); | 368 | reader.setContentHandler( 0 ); |
358 | reader.setErrorHandler( 0 ); | 369 | reader.setErrorHandler( 0 ); |
359 | delete hand; | 370 | delete hand; |
360 | f.close(); | 371 | f.close(); |
361 | if ( !ok ) | ||
362 | mm.clear(); | ||
363 | return ok; | 372 | return ok; |
364 | } | 373 | } |
365 | 374 | ||
366 | bool MetaTranslator::save( const QString& filename ) const | 375 | bool MetaTranslator::save( const QString& filename ) const |
367 | { | 376 | { |
368 | QFile f( filename ); | 377 | QFile f( filename ); |
369 | if ( !f.open(IO_WriteOnly) ) | 378 | if ( !f.open(IO_WriteOnly) ) |
370 | return FALSE; | 379 | return FALSE; |
@@ -379,17 +388,17 @@ bool MetaTranslator::save( const QString& filename ) const | |||
379 | while ( m != mm.end() ) { | 388 | while ( m != mm.end() ) { |
380 | TMMInv inv; | 389 | TMMInv inv; |
381 | TMMInv::Iterator i; | 390 | TMMInv::Iterator i; |
382 | bool contextIsUtf8 = m.key().utf8(); | 391 | bool contextIsUtf8 = m.key().utf8(); |
383 | QCString context = m.key().context(); | 392 | QCString context = m.key().context(); |
384 | QCString comment = ""; | 393 | QCString comment = ""; |
385 | 394 | ||
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 ) { |
389 | contextIsUtf8 = m.key().utf8(); | 398 | contextIsUtf8 = m.key().utf8(); |
390 | comment = QCString( m.key().comment() ); | 399 | comment = QCString( m.key().comment() ); |
391 | } | 400 | } |
392 | } else { | 401 | } else { |
393 | inv.insert( *m, m.key() ); | 402 | inv.insert( *m, m.key() ); |
394 | } | 403 | } |
395 | } while ( ++m != mm.end() && QCString(m.key().context()) == context ); | 404 | } while ( ++m != mm.end() && QCString(m.key().context()) == context ); |
@@ -432,17 +441,18 @@ bool MetaTranslator::save( const QString& filename ) const | |||
432 | } | 441 | } |
433 | t << "</context>\n"; | 442 | t << "</context>\n"; |
434 | } | 443 | } |
435 | t << "</TS>\n"; | 444 | t << "</TS>\n"; |
436 | f.close(); | 445 | f.close(); |
437 | return TRUE; | 446 | return TRUE; |
438 | } | 447 | } |
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 | { |
442 | QTranslator tor( 0 ); | 452 | QTranslator tor( 0 ); |
443 | int finished = 0; | 453 | int finished = 0; |
444 | int unfinished = 0; | 454 | int unfinished = 0; |
445 | int untranslated = 0; | 455 | int untranslated = 0; |
446 | TMM::ConstIterator m; | 456 | TMM::ConstIterator m; |
447 | 457 | ||
448 | for ( m = mm.begin(); m != mm.end(); ++m ) { | 458 | for ( m = mm.begin(); m != mm.end(); ++m ) { |
@@ -474,17 +484,17 @@ bool MetaTranslator::release( const QString& filename, bool verbose ) const | |||
474 | } else { | 484 | } else { |
475 | tor.insert( QTranslatorMessage(context, sourceText, "", | 485 | tor.insert( QTranslatorMessage(context, sourceText, "", |
476 | translation) ); | 486 | translation) ); |
477 | } | 487 | } |
478 | } | 488 | } |
479 | } | 489 | } |
480 | } | 490 | } |
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 ) |
484 | fprintf( stderr, | 494 | fprintf( stderr, |
485 | " %d finished, %d unfinished and %d untranslated messages\n", | 495 | " %d finished, %d unfinished and %d untranslated messages\n", |
486 | finished, unfinished, untranslated ); | 496 | finished, unfinished, untranslated ); |
487 | 497 | ||
488 | return saved; | 498 | return saved; |
489 | } | 499 | } |
490 | 500 | ||
@@ -518,17 +528,17 @@ void MetaTranslator::stripObsoleteMessages() | |||
518 | } | 528 | } |
519 | 529 | ||
520 | void MetaTranslator::stripEmptyContexts() | 530 | void MetaTranslator::stripEmptyContexts() |
521 | { | 531 | { |
522 | TMM newmm; | 532 | TMM newmm; |
523 | 533 | ||
524 | TMM::Iterator m = mm.begin(); | 534 | TMM::Iterator m = mm.begin(); |
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; |
528 | ++n; | 538 | ++n; |
529 | // the context comment is followed by other messages | 539 | // the context comment is followed by other messages |
530 | if ( n != newmm.end() && | 540 | if ( n != newmm.end() && |
531 | qstrcmp(m.key().context(), n.key().context()) == 0 ) | 541 | qstrcmp(m.key().context(), n.key().context()) == 0 ) |
532 | newmm.insert( m.key(), *m ); | 542 | newmm.insert( m.key(), *m ); |
533 | } else { | 543 | } else { |
534 | newmm.insert( m.key(), *m ); | 544 | 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 | |||
@@ -3,20 +3,26 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #ifndef METATRANSLATOR_H | 27 | #ifndef METATRANSLATOR_H |
22 | #define METATRANSLATOR_H | 28 | #define METATRANSLATOR_H |
@@ -65,19 +71,21 @@ private: | |||
65 | class MetaTranslator | 71 | class MetaTranslator |
66 | { | 72 | { |
67 | public: | 73 | public: |
68 | MetaTranslator(); | 74 | MetaTranslator(); |
69 | MetaTranslator( const MetaTranslator& tor ); | 75 | MetaTranslator( const MetaTranslator& tor ); |
70 | 76 | ||
71 | MetaTranslator& operator=( const MetaTranslator& tor ); | 77 | MetaTranslator& operator=( const MetaTranslator& tor ); |
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 | ||
77 | bool contains( const char *context, const char *sourceText, | 85 | bool contains( const char *context, const char *sourceText, |
78 | const char *comment ) const; | 86 | const char *comment ) const; |
79 | void insert( const MetaTranslatorMessage& m ); | 87 | void insert( const MetaTranslatorMessage& m ); |
80 | 88 | ||
81 | void stripObsoleteMessages(); | 89 | void stripObsoleteMessages(); |
82 | void stripEmptyContexts(); | 90 | void stripEmptyContexts(); |
83 | 91 | ||
@@ -91,9 +99,15 @@ private: | |||
91 | typedef QMap<MetaTranslatorMessage, int> TMM; | 99 | typedef QMap<MetaTranslatorMessage, int> TMM; |
92 | typedef QMap<int, MetaTranslatorMessage> TMMInv; | 100 | typedef QMap<int, MetaTranslatorMessage> TMMInv; |
93 | 101 | ||
94 | TMM mm; | 102 | TMM mm; |
95 | QCString codecName; | 103 | QCString codecName; |
96 | QTextCodec *codec; | 104 | QTextCodec *codec; |
97 | }; | 105 | }; |
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 | |||
@@ -4,17 +4,17 @@ | |||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | 6 | ||
7 | class OPIE { | 7 | class OPIE { |
8 | public: | 8 | public: |
9 | static OPIE* self(); | 9 | static OPIE* self(); |
10 | /** get the list of languages */ | 10 | /** get the list of languages */ |
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 | ||
14 | private: | 14 | private: |
15 | OPIE(); | 15 | OPIE(); |
16 | ~OPIE(); | 16 | ~OPIE(); |
17 | static OPIE* m_self; | 17 | static OPIE* m_self; |
18 | 18 | ||
19 | }; | 19 | }; |
20 | 20 | ||
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 | |||
@@ -3,55 +3,100 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #include "proparser.h" | 27 | #include "proparser.h" |
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 | { |
28 | QString t = text; | 60 | QString t = text; |
29 | 61 | ||
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 |
32 | spaces around '=' and '+=', replace '\n' with ';', and | 75 | spaces around '=' and '+=', replace '\n' with ';', and |
33 | simplify white spaces. | 76 | simplify white spaces. |
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(" = ") ); |
38 | t.replace( "+ =", QString(" += ") ); | 81 | t.replace( "+ =", QString(" += ") ); |
39 | t.replace( "\n", QString(";") ); | 82 | t.replace( "\n", QString(";") ); |
40 | t = t.simplifyWhiteSpace(); | 83 | t = t.simplifyWhiteSpace(); |
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 ); |
45 | QStringList::Iterator line; | 90 | QStringList::Iterator line; |
46 | for ( line = lines.begin(); line != lines.end(); ++line ) { | 91 | for ( line = lines.begin(); line != lines.end(); ++line ) { |
47 | QStringList toks = QStringList::split( QChar(' '), *line ); | 92 | QStringList toks = QStringList::split( QChar(' '), *line ); |
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("+=")) ) { |
51 | QString tag = toks.first(); | 96 | QString tag = toks.first(); |
52 | int k = tag.findRev( QChar(':') ); // as in 'unix:' | 97 | int k = tag.findRev( QChar(':') ); // as in 'unix:' |
53 | if ( k != -1 ) | 98 | if ( k != -1 ) |
54 | tag = tag.mid( k + 1 ); | 99 | tag = tag.mid( k + 1 ); |
55 | toks.remove( toks.begin() ); | 100 | toks.remove( toks.begin() ); |
56 | 101 | ||
57 | QString action = toks.first(); | 102 | QString action = toks.first(); |
@@ -63,25 +108,67 @@ QMap<QString, QString> proFileTagMap( const QString& text ) | |||
63 | else | 108 | else |
64 | tagMap[tag] += QChar( ' ' ) + toks.join( QChar(' ') ); | 109 | tagMap[tag] += QChar( ' ' ) + toks.join( QChar(' ') ); |
65 | } else { | 110 | } else { |
66 | tagMap[tag] = toks.join( QChar(' ') ); | 111 | tagMap[tag] = toks.join( QChar(' ') ); |
67 | } | 112 | } |
68 | } | 113 | } |
69 | } | 114 | } |
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; |
73 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { | 122 | for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { |
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(); |
84 | } | 170 | } |
85 | } | 171 | } |
172 | |||
86 | return tagMap; | 173 | return tagMap; |
87 | } | 174 | } |
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 | |||
@@ -3,27 +3,33 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of Qt Linguist. | 4 | ** This file is part of Qt Linguist. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
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 |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 17 | ** |
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 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 22 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 23 | ** not clear to you. |
18 | ** | 24 | ** |
19 | **********************************************************************/ | 25 | **********************************************************************/ |
20 | 26 | ||
21 | #ifndef PROPARSER_H | 27 | #ifndef PROPARSER_H |
22 | #define PROPARSER_H | 28 | #define PROPARSER_H |
23 | 29 | ||
24 | #include <qmap.h> | 30 | #include <qmap.h> |
25 | #include <qstring.h> | 31 | #include <qstring.h> |
26 | 32 | ||
27 | QMap<QString, QString> proFileTagMap( const QString& text ); | 33 | QMap<QString, QString> proFileTagMap( const QString& text, const QString& = QString::null ); |
28 | 34 | ||
29 | #endif | 35 | #endif |