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 /development/translation/opie-lupdate/fetchtr.cpp | |
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
Diffstat (limited to 'development/translation/opie-lupdate/fetchtr.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | development/translation/opie-lupdate/fetchtr.cpp | 55 |
1 files changed, 45 insertions, 10 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 | |||
@@ -1,26 +1,32 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
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 | ||
23 | #include <qfile.h> | 29 | #include <qfile.h> |
24 | #include <qregexp.h> | 30 | #include <qregexp.h> |
25 | #include <qstring.h> | 31 | #include <qstring.h> |
26 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
@@ -71,28 +77,31 @@ enum { Tok_Eof, Tok_class, Tok_namespace, Tok_return, Tok_tr, | |||
71 | The tokenizer maintains the following global variables. The names | 77 | The tokenizer maintains the following global variables. The names |
72 | should be self-explanatory. | 78 | should be self-explanatory. |
73 | */ | 79 | */ |
74 | static QCString yyFileName; | 80 | 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 | ||
95 | static int (*getChar)(); | 104 | static int (*getChar)(); |
96 | 105 | ||
97 | static int getCharFromFile() | 106 | static int getCharFromFile() |
98 | { | 107 | { |
@@ -110,27 +119,30 @@ static int getCharFromString() | |||
110 | return yyInStr[yyInPos++].latin1(); | 119 | return yyInStr[yyInPos++].latin1(); |
111 | } | 120 | } |
112 | } | 121 | } |
113 | 122 | ||
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 | ||
133 | yyIdentLen = 0; | 145 | yyIdentLen = 0; |
134 | yyCommentLen = 0; | 146 | yyCommentLen = 0; |
135 | yyStringLen = 0; | 147 | yyStringLen = 0; |
136 | 148 | ||
@@ -155,39 +167,49 @@ static int getToken() | |||
155 | return Tok_translate; | 167 | return Tok_translate; |
156 | } | 168 | } |
157 | break; | 169 | break; |
158 | case 'T': | 170 | case 'T': |
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 | } |
190 | } | 212 | } |
191 | return Tok_Ident; | 213 | return Tok_Ident; |
192 | } else { | 214 | } else { |
193 | switch ( yyCh ) { | 215 | switch ( yyCh ) { |
@@ -213,36 +235,41 @@ static int getToken() | |||
213 | #else. | 235 | #else. |
214 | */ | 236 | */ |
215 | do { | 237 | do { |
216 | yyCh = getChar(); | 238 | yyCh = getChar(); |
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 == '/' ) { |
245 | do { | 272 | do { |
246 | yyCh = getChar(); | 273 | yyCh = getChar(); |
247 | } while ( yyCh != EOF && yyCh != '\n' ); | 274 | } while ( yyCh != EOF && yyCh != '\n' ); |
248 | } else if ( yyCh == '*' ) { | 275 | } else if ( yyCh == '*' ) { |
@@ -347,36 +374,44 @@ static int getToken() | |||
347 | return Tok_Colon; | 374 | return Tok_Colon; |
348 | case '\'': | 375 | case '\'': |
349 | yyCh = getChar(); | 376 | yyCh = getChar(); |
350 | if ( yyCh == '\\' ) | 377 | if ( yyCh == '\\' ) |
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(); |
379 | return Tok_Semicolon; | 414 | return Tok_Semicolon; |
380 | default: | 415 | default: |
381 | yyCh = getChar(); | 416 | yyCh = getChar(); |
382 | } | 417 | } |
@@ -612,32 +647,32 @@ static void parse( MetaTranslator *tor, const char *initialContext, | |||
612 | functionContext = defaultContext; | 647 | functionContext = defaultContext; |
613 | missing_Q_OBJECT = FALSE; | 648 | missing_Q_OBJECT = FALSE; |
614 | } | 649 | } |
615 | yyTok = getToken(); | 650 | yyTok = getToken(); |
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 ) |
640 | fprintf( stderr, | 675 | fprintf( stderr, |
641 | "lupdate error: Cannot open C++ source file '%s': %s\n", | 676 | "lupdate error: Cannot open C++ source file '%s': %s\n", |
642 | fileName, strerror(errno) ); | 677 | fileName, strerror(errno) ); |
643 | return; | 678 | return; |