1cdf0e10cSrcweir:
2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}'
3cdf0e10cSrcweir    if 0;
4*7e90fac2SAndrew Rist#**************************************************************
5*7e90fac2SAndrew Rist#
6*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*7e90fac2SAndrew Rist#  distributed with this work for additional information
9*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
12*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*7e90fac2SAndrew Rist#
14*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*7e90fac2SAndrew Rist#
16*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
18*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
20*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
21*7e90fac2SAndrew Rist#  under the License.
22*7e90fac2SAndrew Rist#
23*7e90fac2SAndrew Rist#**************************************************************
24*7e90fac2SAndrew Rist
25*7e90fac2SAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweiruse Cwd 'abs_path';
28cdf0e10cSrcweiruse File::Find;
29cdf0e10cSrcweiruse File::Copy qw/cp mv/;
30cdf0e10cSrcweiruse File::Basename;
31cdf0e10cSrcweiruse Benchmark;
32cdf0e10cSrcweir
33cdf0e10cSrcweir$t0 = new Benchmark;
34cdf0e10cSrcweir# update the tree files in <platform>/misc/*
35cdf0e10cSrcweir
36cdf0e10cSrcweir$| = 1;
37cdf0e10cSrcweir
38cdf0e10cSrcweirmy $prj = $ENV{ENVPRJ};
39cdf0e10cSrcweir
40cdf0e10cSrcweirmy $inpath = $ENV{INPATH};
41cdf0e10cSrcweirterminate() if ( ! defined $inpath );
42cdf0e10cSrcweir
43cdf0e10cSrcweirmy $destpath = $inpath;
44cdf0e10cSrcweirmy $with_lang = $ENV{WITH_LANG};
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweir# Always use / directory separators
48cdf0e10cSrcweir$prj =~ s/\\/\//g if defined($prj);
49cdf0e10cSrcweir$inpath =~ s/\\/\//g;
50cdf0e10cSrcweir$destpath =~ s/\\/\//g;
51cdf0e10cSrcweir
52cdf0e10cSrcweir
53cdf0e10cSrcweirif ( ! defined $prj ) {
54cdf0e10cSrcweir# do someting that works for manual call
55cdf0e10cSrcweir    ($scriptname = `pwd`) =~ s/\n/\/$0/;
56cdf0e10cSrcweir    ($tree_src = $scriptname) =~ s/\/update_tree.pl/\/..\/source\/auxiliary/;
57cdf0e10cSrcweir    ($tree_dest = $scriptname) =~ s/\/update_tree.pl/\/..\/$destpath\/misc/;
58cdf0e10cSrcweir    ($source_dir = $scriptname) =~ s/\/update_tree.pl/\/..\/source/;
59cdf0e10cSrcweir    ($source_dir_xhp = $scriptname) =~ s/\/update_tree.pl/\/..\/source/;
60cdf0e10cSrcweir
61cdf0e10cSrcweir    if ( defined $ENV{TRYSDF} || defined $ENV{LOCALIZESDF} )
62cdf0e10cSrcweir    {
63cdf0e10cSrcweir        if( defined $ENV{LOCALIZATION_FOUND} && $ENV{LOCALIZATION_FOUND} eq "YES" )
64cdf0e10cSrcweir        {
65cdf0e10cSrcweir            $source_dir = $ENV{TRYSDF};
66cdf0e10cSrcweir        }
67cdf0e10cSrcweir        else
68cdf0e10cSrcweir        {
69cdf0e10cSrcweir            $source_dir = $ENV{LOCALIZESDF};
70cdf0e10cSrcweir        }
71cdf0e10cSrcweir        $source_dir =~ s/\/auxiliary\/localize.sdf$// ;
72cdf0e10cSrcweir    }
73cdf0e10cSrcweir    #else {die "ERROR: The env variables TRYSDF LOCALIZATION_FOUND LOCALIZESDF not found ... something is wrong!\n";}
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir    $treestrings = "$source_dir/text/shared/tree_strings.xhp";
77cdf0e10cSrcweir} else {
78cdf0e10cSrcweir    $tree_src = "$prj\/source\/auxiliary";
79cdf0e10cSrcweir    $tree_dest = "$prj\/$destpath\/misc";
80cdf0e10cSrcweir    $source_dir = "$prj\/source";
81cdf0e10cSrcweir    $source_dir_xhp = "$prj\/source";
82cdf0e10cSrcweir    $treestrings = "$source_dir/text/shared/tree_strings.xhp";
83cdf0e10cSrcweir
84cdf0e10cSrcweir    if( defined $ENV{LOCALIZATION_FOUND} && $ENV{LOCALIZATION_FOUND} eq "YES" )
85cdf0e10cSrcweir    {
86cdf0e10cSrcweir        $source_dir = $ENV{TRYSDF};
87cdf0e10cSrcweir    }
88cdf0e10cSrcweir    else
89cdf0e10cSrcweir    {
90cdf0e10cSrcweir        $source_dir = $ENV{LOCALIZESDF};
91cdf0e10cSrcweir    }
92cdf0e10cSrcweir    $source_dir =~ s/\/auxiliary\/localize.sdf$// ;
93cdf0e10cSrcweir    #else {die "ERROR: The env variables TRYSDF LOCALIZATION_FOUND LOCALIZESDF not found ... something is wrong!\n";}
94cdf0e10cSrcweir
95cdf0e10cSrcweir}
96cdf0e10cSrcweir
97cdf0e10cSrcweir# Get the English tree files as master
98cdf0e10cSrcweir#-------------------------------
99cdf0e10cSrcweir# Update English from xhp
100cdf0e10cSrcweir#-------------------------------
101cdf0e10cSrcweir&do_english;
102cdf0e10cSrcweir#-------------------------------
103cdf0e10cSrcweir# Update localizations from sdf
104cdf0e10cSrcweir#-------------------------------
105cdf0e10cSrcweir
106cdf0e10cSrcweir@langs = split /\s+/, $with_lang;
107cdf0e10cSrcweir&read_loc;
108cdf0e10cSrcweirprint "################\nUpdating the treefiles for @langs \n";
109cdf0e10cSrcweirfor $l(@langs) {
110cdf0e10cSrcweir    if ($l ne "en-US") {
111cdf0e10cSrcweir        &do_lang($l);
112cdf0e10cSrcweir    }
113cdf0e10cSrcweir}
114cdf0e10cSrcweir
115cdf0e10cSrcweir#-------------------------------
116cdf0e10cSrcweir#
117cdf0e10cSrcweir$t1 = new Benchmark;
118cdf0e10cSrcweir$td = timediff($t1, $t0);
119cdf0e10cSrcweirprint timestr($td),"\n";
120cdf0e10cSrcweir
121cdf0e10cSrcweir####################
122cdf0e10cSrcweir# SUBS
123cdf0e10cSrcweir####################
124cdf0e10cSrcweirsub terminate {
125cdf0e10cSrcweir    $err = shift;
126cdf0e10cSrcweir    print "$err\n\n";
127cdf0e10cSrcweir    $msg = <<"MSG";
128cdf0e10cSrcweir
129cdf0e10cSrcweirupdate_tree.pl
130cdf0e10cSrcweir   all languages in WITH_LANG are processed. WITH_LANG=ALL is
131cdf0e10cSrcweir   not supported in manual calls.
132cdf0e10cSrcweir
133cdf0e10cSrcweir   Updates the *.tree files.
134cdf0e10cSrcweir   At first, the English file is updated based on the English
135cdf0e10cSrcweir   help topic titles as read from the help files. Then, the
136cdf0e10cSrcweir   localized tree files are written based on the English tree
137cdf0e10cSrcweir   file and the localized help topic titles.
138cdf0e10cSrcweir
139cdf0e10cSrcweir   Requires a valid SO/OOo environment.
140cdf0e10cSrcweirMSG
141cdf0e10cSrcweir   print "$msg\n";
142cdf0e10cSrcweir   exit( -1 );
143cdf0e10cSrcweir   # die "$msg\n";
144cdf0e10cSrcweir}
145cdf0e10cSrcweir
146cdf0e10cSrcweir#---------------------------------------------------
147cdf0e10cSrcweir
148cdf0e10cSrcweirsub do_english {
149cdf0e10cSrcweir    print "Processing en-US\n";
150cdf0e10cSrcweir    undef %helpsection; undef %node;
151cdf0e10cSrcweir    &readtreestrings;
152cdf0e10cSrcweir    &gettreefiles;
153cdf0e10cSrcweir    &processtreefiles('en-US');
154cdf0e10cSrcweir}
155cdf0e10cSrcweir
156cdf0e10cSrcweir#---------------------------------------------------
157cdf0e10cSrcweirsub do_lang {
158cdf0e10cSrcweir    $lng = shift;
159cdf0e10cSrcweir    print "\n---------------------------------------------------\nProcessing $lng\n";
160cdf0e10cSrcweir    &processtreefiles($lng);
161cdf0e10cSrcweir    print "\n";
162cdf0e10cSrcweir}
163cdf0e10cSrcweir
164cdf0e10cSrcweir#---------------------------------------------------
165cdf0e10cSrcweirsub readtreestrings {
166cdf0e10cSrcweir    print "Reading tree strings for en-US...";
167cdf0e10cSrcweir    if (open TREE, $treestrings) {
168cdf0e10cSrcweir        while (<TREE>) {
169cdf0e10cSrcweir            chomp;
170cdf0e10cSrcweir            s/<\/*help:productname>//gis;
171cdf0e10cSrcweir            if (/help_section/) {
172cdf0e10cSrcweir                s/^\s*<.*help_section//;
173cdf0e10cSrcweir                s/<\/.*$//;
174cdf0e10cSrcweir                ($id = $_) =~ s/^.*id=&quot;(\d+)&quot;.*$/$1/;
175cdf0e10cSrcweir                ($title = $_) =~ s/^.*title=&quot;(.*)&quot;.*$/$1/;
176cdf0e10cSrcweir                $helpsection{$id} = $title;
177cdf0e10cSrcweir            }
178cdf0e10cSrcweir
179cdf0e10cSrcweir            if (/node id=/) {
180cdf0e10cSrcweir                s/^\s*<.*node //;
181cdf0e10cSrcweir                s/<\/.*$//;
182cdf0e10cSrcweir                ($id = $_) =~ s/^.*id=&quot;(\d+)&quot;.*$/$1/;
183cdf0e10cSrcweir                ($title = $_) =~ s/^.*title=&quot;(.*)&quot;.*$/$1/;
184cdf0e10cSrcweir                $node{$id} = $title;
185cdf0e10cSrcweir            }
186cdf0e10cSrcweir        }
187cdf0e10cSrcweir        close TREE;
188cdf0e10cSrcweir    } else {
189cdf0e10cSrcweir	    &terminate("Error opening $treestrings");
190cdf0e10cSrcweir    }
191cdf0e10cSrcweir    print "done\n";
192cdf0e10cSrcweir}
193cdf0e10cSrcweir
194cdf0e10cSrcweir#------------------------------------
195cdf0e10cSrcweirsub gettreefiles {
196cdf0e10cSrcweir    # Read the tree files from the directory
197cdf0e10cSrcweir    # this list is also used for all foreign languages
198cdf0e10cSrcweir    print "Reading tree files...";
199cdf0e10cSrcweir    if (opendir ENUS, "$tree_src") {
200cdf0e10cSrcweir        @treeviews = grep /\.tree/, readdir ENUS;
201cdf0e10cSrcweir        closedir ENUS;
202cdf0e10cSrcweir    } else {
203cdf0e10cSrcweir        &terminate("Cannot open directory $tree_src");
204cdf0e10cSrcweir    }
205cdf0e10cSrcweir    print "done\n";
206cdf0e10cSrcweir}
207cdf0e10cSrcweir
208cdf0e10cSrcweir#------------------------------------
209cdf0e10cSrcweirsub processtreefiles {
210cdf0e10cSrcweir    $lng = shift;
211cdf0e10cSrcweir	use File::Temp qw/ tempfile /;
212cdf0e10cSrcweir	use File::Spec;
213cdf0e10cSrcweir
214cdf0e10cSrcweir	for $tv(@treeviews) {
215cdf0e10cSrcweir        print "\nProcessing $tv\n";
216cdf0e10cSrcweir        @lines = &readtv("$tree_src/$tv");
217cdf0e10cSrcweir        print "Read ".scalar @lines." lines\n";
218cdf0e10cSrcweir        for $l(@lines) {
219cdf0e10cSrcweir            if ($l =~ /topic/) {
220cdf0e10cSrcweir                ($id = $l) =~ s/^.*id="([^"]*)".*$/$1/gis;
221cdf0e10cSrcweir                ($module = $id) =~ s/^([^\/]*).*$/$1/;
222cdf0e10cSrcweir                $id =~ s/^.*?\///;
223cdf0e10cSrcweir                $file = "$source_dir_xhp/$id";
224cdf0e10cSrcweir
225cdf0e10cSrcweir                if ($lng eq 'en-US') { # english comes from the file
226cdf0e10cSrcweir                    if (open F,$file) {
227cdf0e10cSrcweir                        print ".";
228cdf0e10cSrcweir                        undef $/; $cnt = <F>; close F;
229cdf0e10cSrcweir                        $cnt =~ s/^.*<title[^>]+id="tit"[^>]*>([^<]*)<\/title>.*$/$1/gis;
230cdf0e10cSrcweir                        $cnt =~ s/&apos;/\'/gis; $cnt =~ s/&amp;/+/gis;
231cdf0e10cSrcweir                        $cnt =~ s/&quot;/\'/gis; $cnt =~ s/&/+/gis;
232cdf0e10cSrcweir                        $l = "<topic id=\"$module/$id\">$cnt</topic>\n";
233cdf0e10cSrcweir                    } else {
234cdf0e10cSrcweir                        print "!";
235cdf0e10cSrcweir                        $l = "<!-- removed $module/$id -->\n";
236cdf0e10cSrcweir                    }
237cdf0e10cSrcweir                } else { # localized comes from the localize sdf
238cdf0e10cSrcweir                    #print "\nid: $id";
239cdf0e10cSrcweir                    if (defined($loc_title{$lng}->{$id})) {
240cdf0e10cSrcweir                        print ".";
241cdf0e10cSrcweir                        $l = "<topic id=\"$module/$id\">$loc_title{$lng}->{$id}</topic>\n";
242cdf0e10cSrcweir                    } else {
243cdf0e10cSrcweir                        print "!";
244cdf0e10cSrcweir                    }
245cdf0e10cSrcweir                }
246cdf0e10cSrcweir            }
247cdf0e10cSrcweir
248cdf0e10cSrcweir            if ($l =~/<node/) {
249cdf0e10cSrcweir                ($id = $l) =~ s/^.*id="(\d+)".*$/$1/gis;
250cdf0e10cSrcweir                if ($lng eq 'en-US') {
251cdf0e10cSrcweir                    if (defined($node{$id})) {
252cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="$node{$id}"/;
253cdf0e10cSrcweir                    } else {
254cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="NOTFOUND:$id"/;
255cdf0e10cSrcweir                    }
256cdf0e10cSrcweir                } else {
257cdf0e10cSrcweir                    if (defined($node{$lng}->{$id})) {
258cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="$node{$lng}->{$id}"/;
259cdf0e10cSrcweir                    }
260cdf0e10cSrcweir                }
261cdf0e10cSrcweir            }
262cdf0e10cSrcweir
263cdf0e10cSrcweir            if ($l =~/<help_section/) {
264cdf0e10cSrcweir                ($id = $l) =~ s/^.*id="(\d+)".*$/$1/gis;
265cdf0e10cSrcweir                if ($lng eq 'en-US') {
266cdf0e10cSrcweir                    if (defined($helpsection{$id})) {
267cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="$helpsection{$id}"/;
268cdf0e10cSrcweir                    } else {
269cdf0e10cSrcweir                        print "#";
270cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="NOTFOUND:$id"/;
271cdf0e10cSrcweir                    }
272cdf0e10cSrcweir                } else {
273cdf0e10cSrcweir                    if (defined($helpsection{$lng}->{$id})) {
274cdf0e10cSrcweir                        $l =~ s/title="(.*)"/title="$helpsection{$lng}->{$id}"/;
275cdf0e10cSrcweir                    }
276cdf0e10cSrcweir                }
277cdf0e10cSrcweir            }
278cdf0e10cSrcweir        }
279cdf0e10cSrcweir 		if ( ! -d "$tree_dest/$lng" ) {
280cdf0e10cSrcweir	        mkdir "$tree_dest/$lng" or die "\nCouldn't create directory \"$tree_dest/$lng\"";
281cdf0e10cSrcweir		}
282cdf0e10cSrcweir		my $treeoutdir = "$tree_dest/$lng";
283cdf0e10cSrcweir		my $tmpname_template=$tv."_XXXXX";
284cdf0e10cSrcweir		my ( $treetmpfilehandle, $treetmpfile ) = tempfile($tmpname_template , DIR => File::Spec->tmpdir() );
285cdf0e10cSrcweir		close $treetmpfilehandle ;
286cdf0e10cSrcweir        if (open TV, ">$treetmpfile") {
287cdf0e10cSrcweir            for $line(@lines) {
288cdf0e10cSrcweir                $line =~ s/\$\[officename\]/%PRODUCTNAME/g;
289cdf0e10cSrcweir                $line =~ s/\$\[officeversion\]/%PRODUCTVERSION/g;
290cdf0e10cSrcweir                print TV $line;
291cdf0e10cSrcweir            }
292cdf0e10cSrcweir            close TV;
293cdf0e10cSrcweir			chmod 0664, $treetmpfile or &terminate("Cannot change rights on $treetmpfile");
294cdf0e10cSrcweir			if( $^O eq 'MSWin32' )
295cdf0e10cSrcweir			{
296cdf0e10cSrcweir				$tree_dest =~ s/\//\\/g ;
297cdf0e10cSrcweir				unlink "$tree_dest\\$lng\\$tv" ;
298cdf0e10cSrcweir                mv $treetmpfile , "$tree_dest\\$lng\\$tv" or &terminate("Cannot mv $treetmpfile to $tree_dest\\$lng\\$tv" );
299cdf0e10cSrcweir			}
300cdf0e10cSrcweir			else
301cdf0e10cSrcweir			{
302cdf0e10cSrcweir				unlink "$tree_dest/$lng/$tv" ;
303cdf0e10cSrcweir                my $ret=mv $treetmpfile , "$tree_dest/$lng/$tv$inpath" or &terminate("Cannot write to $tree_dest/$lng/$tv$inpath - Error $!");
304cdf0e10cSrcweir                my $ret=mv "$tree_dest/$lng/$tv$inpath" , "$tree_dest/$lng/$tv" or &terminate("Cannot write to $tree_dest/$lng/$tv - Error $!");
305cdf0e10cSrcweir			}
306cdf0e10cSrcweir      } else {
307cdf0e10cSrcweir            &terminate("Cannot write to $tvout");
308cdf0e10cSrcweir        }
309cdf0e10cSrcweir    }
310cdf0e10cSrcweir}
311cdf0e10cSrcweir
312cdf0e10cSrcweir#------------------------------------
313cdf0e10cSrcweirsub readtv {
314cdf0e10cSrcweir    my $f = shift;
315cdf0e10cSrcweir    if (open TV, $f) {
316cdf0e10cSrcweir        $/ = "\n";
317cdf0e10cSrcweir        my @l = <TV>;
318cdf0e10cSrcweir        close TV;
319cdf0e10cSrcweir        return @l;
320cdf0e10cSrcweir    } else {
321cdf0e10cSrcweir        &terminate("Error opening $f");
322cdf0e10cSrcweir    }
323cdf0e10cSrcweir}
324cdf0e10cSrcweir
325cdf0e10cSrcweir#------------------------------------
326cdf0e10cSrcweir# read entries form localize.sdf files
327cdf0e10cSrcweir#------------------------------------
328cdf0e10cSrcweirsub read_loc {
329cdf0e10cSrcweir    print "\n\nReading localized titles...";
330cdf0e10cSrcweir    $/ = "\n";
331cdf0e10cSrcweir    my $path = "$source_dir/text";
332cdf0e10cSrcweir    print " in $source_dir/text\n";
333cdf0e10cSrcweir    @files = `find $source_dir/text -name localize.sdf`;
334cdf0e10cSrcweir    for my $fname (@files) {
335cdf0e10cSrcweir        $FS = '\t';
336cdf0e10cSrcweir        print ".";
337cdf0e10cSrcweir        open(LOCALIZE_SDF, $fname) || die 'Cannot open "localize.sdf".'."$fname";
338cdf0e10cSrcweir        while (<LOCALIZE_SDF>) {
339cdf0e10cSrcweir            my $sdf_line = $_;
340cdf0e10cSrcweir	    my ($Fld1,$file,$Fld3,$Fld4,$id,$Fld6,$Fld7,$Fld8,$Fld9,$lang,$text) = split($FS, $sdf_line , 12);
341cdf0e10cSrcweir            next if ( $Fld1 =~ /^#/);
342cdf0e10cSrcweir	    if ($id eq 'tit') {
343cdf0e10cSrcweir                #strip filename
344cdf0e10cSrcweir                $file =~ s/.*text\\/text\\/g;
345cdf0e10cSrcweir                #convert \ to / in filename
346cdf0e10cSrcweir                $file =~ s/\\/\//g;
347cdf0e10cSrcweir                #fpe: i46823 - need to encode &s, added encoding
348cdf0e10cSrcweir                $text =~ s/&(?!amp;)/&amp;/g;
349cdf0e10cSrcweir                # add entry to the hash
350cdf0e10cSrcweir                $loc_title{$lang}->{$file} = $text;
351cdf0e10cSrcweir            }
352cdf0e10cSrcweir            if ($file =~ /tree_strings.xhp/) {
353cdf0e10cSrcweir                #strip filename
354cdf0e10cSrcweir                $file =~ s/.*text/text/g;
355cdf0e10cSrcweir                #convert \ to / in filename
356cdf0e10cSrcweir                $file =~ s/\\/\//g;
357cdf0e10cSrcweir                if ($text =~ /^<help_section/) {
358cdf0e10cSrcweir                    #example: <help_section application="scalc" id="08" title="表計算ドキュメント">
359cdf0e10cSrcweir                    my ($fld1,$app,$fld3,$id,$fld5,$sec_title) = split('"', $text, 7);
360cdf0e10cSrcweir                    #fpe: i46823 - need to encode &s, added encoding
361cdf0e10cSrcweir                    if( defined $sec_title )
362cdf0e10cSrcweir		            {
363cdf0e10cSrcweir		    	        $sec_title =~ s/&(?!amp;)/&amp;/g;
364cdf0e10cSrcweir		    	        #unquot \<item ... /\>
365cdf0e10cSrcweir			            terminate( "\n\nERROR: Bad string in file '$fname' will cause invalid xml tree file \n---\n'$sdf_line'\n---\nPlease remove or replace < = '&lt;' and  > = '&gt;' within the title attribute '$sec_title'\n") , if( $sec_title =~ /[\<\>]/ );
366cdf0e10cSrcweir		    	        $helpsection{$lang}->{$id} = $sec_title;
367cdf0e10cSrcweir		            }
368cdf0e10cSrcweir                } elsif ($text =~/<node id=/) {
369cdf0e10cSrcweir                    # example: <node id="0205" title="Tabelas em documentos de texto">
370cdf0e10cSrcweir                    # BEWARE: title may contain escaped '"' so only match " not preceded by \
371cdf0e10cSrcweir                    # using a zero‐width negative look‐behind assertion.
372cdf0e10cSrcweir                    my ($fld1,$id,$fld3,$node_title,$Fld5) = split(/(?<!\\)"/, $text, 5);
373cdf0e10cSrcweir                    #fpe: i46823 - need to encode &s, added encoding
374cdf0e10cSrcweir		            if( defined $node_title )
375cdf0e10cSrcweir		            {
376cdf0e10cSrcweir			            $node_title =~ s/&(?!amp;)/&amp;/g;
377cdf0e10cSrcweir		   	            terminate( "\n\nERROR: Bad string in '$fname' will cause invalid xml tree file \n---\n'$sdf_line'\n---\nPlease remove or replace < = '&lt;' and  > = '&gt;' within the title attribute '$node_title'\n") , if( $node_title =~ /[\<\>]/ );
378cdf0e10cSrcweir		            }
379cdf0e10cSrcweir		            $node{$lang}->{$id} = $node_title;
380cdf0e10cSrcweir                }
381cdf0e10cSrcweir            }
382cdf0e10cSrcweir        }
383cdf0e10cSrcweir        close LOCALIZE_SDF;
384cdf0e10cSrcweir    }
385cdf0e10cSrcweir    # statistics
386cdf0e10cSrcweir    $total_elements=0;
387cdf0e10cSrcweir    foreach $lang (keys %loc_title) {
388cdf0e10cSrcweir        $no_elements = scalar(keys(%{$loc_title{$lang}}));
389cdf0e10cSrcweir        push(@langstat, "$lang:\t ".$no_elements." matches\n");
390cdf0e10cSrcweir        $total_elements += $no_elements;
391cdf0e10cSrcweir    }
392cdf0e10cSrcweir    print "\ndone reading a total of ".$total_elements." localized titles for ".scalar(keys(%loc_title))." languages from ".scalar @files ." files\n";
393cdf0e10cSrcweir    print sort(@langstat);
394cdf0e10cSrcweir}
395cdf0e10cSrcweir
396