summaryrefslogtreecommitdiff
path: root/development/translation/opie-lupdate
Unidiff
Diffstat (limited to 'development/translation/opie-lupdate') (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
5 files changed, 84 insertions, 22 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 @@
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
@@ -77,16 +83,19 @@ static char yyIdent[128];
77static size_t yyIdentLen; 83static size_t yyIdentLen;
78static char yyComment[65536]; 84static char yyComment[65536];
79static size_t yyCommentLen; 85static size_t yyCommentLen;
80static char yyString[16384]; 86static char yyString[16384];
81static size_t yyStringLen; 87static size_t yyStringLen;
82static QValueStack<int> yySavedBraceDepth; 88static QValueStack<int> yySavedBraceDepth;
89static QValueStack<int> yySavedParenDepth;
83static int yyBraceDepth; 90static int yyBraceDepth;
84static int yyParenDepth; 91static int yyParenDepth;
85static int yyLineNo; 92static int yyLineNo;
86static int yyCurLineNo; 93static int yyCurLineNo;
94static int yyBraceLineNo;
95static 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)
89static FILE *yyInFile; 98static 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)
92static QString yyInStr; 101static QString yyInStr;
@@ -116,15 +125,18 @@ static void startTokenizer( const char *fileName, int (*getCharFunc)() )
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
127static int getToken() 139static 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";
@@ -161,27 +173,37 @@ static int getToken()
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 ) {
@@ -219,24 +241,29 @@ static int getToken()
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 '/':
@@ -353,24 +380,32 @@ static int getToken()
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;
@@ -618,20 +653,20 @@ static void parse( MetaTranslator *tor, const char *initialContext,
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
634void fetchtr_cpp( const char *fileName, MetaTranslator *tor, 669void 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" );
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()
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
65static void updateTsFiles( const MetaTranslator& fetchedTor, 74static 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 )
@@ -147,13 +156,13 @@ int main( int argc, char **argv )
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
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 @@
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
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 @@
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
@@ -29,26 +35,26 @@
29 35
30typedef QMap<QCString, MetaTranslatorMessage> TMM; 36typedef QMap<QCString, MetaTranslatorMessage> TMM;
31typedef QValueList<MetaTranslatorMessage> TML; 37typedef QValueList<MetaTranslatorMessage> TML;
32 38
33static bool isDigitFriendly( int c ) 39static bool isDigitFriendly( int c )
34{ 40{
35 return ispunct( c ) || isspace( c ); 41 return ispunct((uchar)c) || isspace((uchar)c);
36} 42}
37 43
38static int numberLength( const char *s ) 44static 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
@@ -208,26 +214,26 @@ void applyNumberHeuristic( MetaTranslator *tor, bool verbose )
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",
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 @@
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