Skip (re-)creation of cmake files during build passes.
[profile/ivi/qtbase.git] / bin / findtr
1 #!/usr/bin/perl -w
2 # vi:wrap:
3 #############################################################################
4 ##
5 ## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
6 ## Contact: http://www.qt-project.org/
7 ##
8 ## This file is part of the translations of the Qt Toolkit.
9 ##
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ##
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ##
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
30 ##
31 ## Other Usage
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
34 ##
35 ##
36 ##
37 ##
38 ##
39 ##
40 ## $QT_END_LICENSE$
41 ##
42 #############################################################################
43
44 # See Qt I18N documentation for usage information.
45
46 use POSIX qw(strftime);
47
48 $projectid='PROJECT VERSION';
49 $datetime = strftime "%Y-%m-%d %X %Z", localtime;
50 $charset='iso-8859-1';
51 $translator='FULLNAME <EMAIL@ADDRESS>';
52 $revision_date='YYYY-MM-DD';
53
54 $real_mark = "tr";
55 $noop_mark = "QT_TR_NOOP";
56 $scoped_mark = "qApp->translate";
57 $noop_scoped_mark = "QT_TRANSLATE_NOOP";
58
59 $header=
60 '# This is a Qt message file in .po format.  Each msgid starts with
61 # a scope.  This scope should *NOT* be translated - eg. translating
62 # from French to English, "Foo::Bar" would be translated to "Pub",
63 # not "Foo::Pub".
64 msgid ""
65 msgstr ""
66 "Project-Id-Version: '.$projectid.'\n"
67 "POT-Creation-Date: '.$datetime.'\n"
68 "PO-Revision-Date: '.$revision_date.'\n"
69 "Last-Translator: '.$translator.'\n"
70 "Content-Type: text/plain; charset='.$charset.'\n"
71
72 ';
73
74
75
76
77 $scope = "";
78
79 if ( $#ARGV < 0 ) {
80     print STDERR "Usage:  findtr sourcefile ...  >project.po\n";
81     exit 1;
82 }
83
84
85 sub outmsg {
86     my ($file, $line, $scope, $msgid) = @_;
87     # unesc
88     $msgid =~ s/$esc:$esc:$esc/::/gs;
89     $msgid =~ s|$esc/$esc/$esc|//|gs;
90
91     # Remove blank lines
92     $msgid =~ s/\n\n+/\n/gs;
93     $msgid = "\"\"\n$msgid" if $msgid =~ /\n/s;
94     print "#: $file:$line\n";
95     $msgid =~ s/^"//; #"emacs bug
96     print "msgid \"${scope}::$msgid\n";
97     #print "msgstr \"$msgid\n";
98     print "msgstr \"\"\n";
99     print "\n";
100 }
101
102 sub justlines {
103     my $l = @_;
104     $l =~ tr|\n||dc;
105     return $l;
106 }
107
108 print $header;
109
110
111 foreach $file ( @ARGV ) {
112     next unless open( I, "< $file" );
113
114     $source = join( "", <I> );
115
116     # Find esc. Avoid bad case 1/// -> 1/1/1/1 -> ///1
117     $esc = 1;
118     while ( $source =~ m!(?:$esc/$esc/$esc)|(?:$esc///)
119             |(?:$esc:$esc:$esc)|(?:$esc:\:\:)! ) {
120         $esc++;
121     }
122
123     # Hide quoted :: in practically all strings
124     $source =~ s/\"([^"\n]*)::([^"\n]*)\"/\"$1$esc:$esc:$esc$2\"/g;
125
126     # Hide quoted // in practically all strings
127     $source =~ s|\"([^"\n]*)//([^"\n]*)\"|\"$1$esc/$esc/$esc$2\"|g;
128
129
130     # strip comments -- does not handle "/*" in strings
131     while( $source =~ s|/\*(.*?)\*/|justlines($1)|ges ) { }
132     while( $source =~ s|//(.*?)\n|\n|g ) { }
133
134     while( $source =~ /
135             (?:
136                 # Some doublequotes are "escaped" to help vim syntax highlight
137
138                 # $1 = scope; $2 = parameters etc.
139                 (?:
140                     # Scoped function name ($1 is scope).
141                     (\w+)::(?:\w+)
142                     \s*
143                     # Parameters etc up to open-curly - no semicolons
144                     \(([^();]*)\)
145                     \s*
146                     (?:\{|:)
147                 )
148               |
149                 # $3 - one-argument msgid
150                 (?:\b
151                     # One of the marks
152                     (?:$real_mark|$noop_mark)
153                     \s*
154                     # The parameter
155                     \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
156                 )
157               |
158                 # $4,$5 - two-argument msgid
159                 (?:\b
160                     # One of the scoped marks
161                     (?:$scoped_mark|$noop_scoped_mark)
162                     \s*
163                     # The parameters
164                     \(
165                         # The scope parameter
166                         \s*"([^\"]*)"
167                         \s*,\s*
168                         # The msgid parameter
169                         \s*((?:\"(?:[^"]|[^\\]\\")*"\s*)+) #"emacs
170                     \)
171                 )
172               |
173                 # $6,$7 - scoped one-argument msgid
174                 (?:\b
175                     # The scope
176                     (\w+)::
177                     # One of the marks
178                     (?:$real_mark)
179                     \s*
180                     # The parameter
181                     \(\s*((?:"(?:[^"]|[^\\]\\")*"\s*)+)\)
182                 )
183             )/gsx )
184     {
185         @lines = split /^/m, "$`";
186         $line = @lines;
187         if ( defined( $1 ) ) {
188             if ( $scope ne $1 ) {
189                 $sc=$1;
190                 $etc=$2;
191                 # remove strings
192                 $etc =~ s/"(?:[^"]|[^\\]\\")"//g;
193                 # count ( and )
194                 @open = split /\(/m, $etc;
195                 @close = split /\)/m, $etc;
196                 if ( $#open == $#close ) {
197                     $scope = $sc;
198                 }
199             }
200             next;
201         }
202
203         if ( defined( $3 ) ) {
204             $this_scope = $scope;
205             $msgid = $3;
206         } elsif ( defined( $4 ) ) {
207             $this_scope = $4;
208             $msgid = $5;
209         } elsif ( defined( $6 ) ) {
210             $this_scope = $6;
211             $msgid = $7;
212         } else {
213             next;
214         }
215
216         $msgid =~ s/^\s*//;
217         $msgid =~ s/\s*$//;
218
219         # Might still be non-unique eg. tr("A" "B")  vs.  tr("A"  "B").
220
221         $location{"${this_scope}::${msgid}"} = "$file:$line";
222     }
223 }
224
225 for $scoped_msgid ( sort keys %location ) {
226     ($scope,$msgid) = $scoped_msgid =~ m/([^:]*)::(.*)/s;
227     ($file,$line) = $location{$scoped_msgid} =~ m/([^:]*):(.*)/s;
228     outmsg($file,$line,$scope,$msgid);
229 }