2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
44 my $last_localize_file;
50 $SIG{INT
} = 'inthandler';
51 $SIG{QUIT
} = 'quithandler';
65 my $lock_file = $merge_dir."/lock.mk";
67 read_sdf_file_names
();
80 $reference = getNextIdentifier
( );
85 if( $_->module eq $reference->module && $_->dir eq $reference->dir )
92 # write content of the last localize.sdf file
95 write_buffer
( $last_path , $last_localize_file );
100 ##########################################################################################
105 print "WARNING: Lock file '$lock_file' 'found, waiting ....\n";
107 sleep 10 , while( -e
$lock_file && $cnt++ < 180 );
112 print "Writing lock file '$lock_file'\n";
113 open FILE
, ">$lock_file" or die "Can't create lock file '$lock_file'";
114 print FILE
"L10N_LOCK=YES" ;
120 print "Deleting lock file '$lock_file'\n";
121 unlink $lock_file, if( -e
$lock_file );
126 release_lock
() , if( $state eq "locked" );
131 release_lock
() , if( $state eq "locked" );
137 foreach my $file ( @file_names )
139 my $obj = new sdf_obj
;
140 open my $FILEHANDLE , "<$file" or die "Can't open file '$file'";
141 $obj->FILEHANDLE ( $FILEHANDLE ) ;
142 getNextSdfObj
( $obj );
144 print "Open file '$file'\n";
148 # get the next module/file
149 sub getNextIdentifier
152 return $a->module.$a->dir cmp $b->module.$b->dir;
154 return shift @sorted;
157 # update the obj with the next line
161 my $line = readline ( $obj->FILEHANDLE );
162 if ( $line eq undef )
164 $obj->endoffile( "true" );
168 $line =~ /^(([^\t]*)\t([^\t]*)[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t*)/o ;
169 if( defined $1 && defined $2 && defined $3 )
174 $obj->dir ( getDir
( $3 ) );
186 sub getNextSdfObjModule
189 while( !$obj->endoffile )
191 my $line = readline ( $obj->FILEHANDLE );
192 if ( $line eq undef )
194 $obj->endoffile( "true" );
198 $line =~ /^(([^\t]*)\t([^\t]*).*)/o ;
199 if( defined $1 && defined $2 && defined $3 )
204 $obj->dir ( getDir
( $3 ) );
213 return $obj , if( $obj->module eq $module_name )
222 my @tmp_path = split /\\/ , $path;
224 $path = join '\\' , @tmp_path;
234 push @tmpfiles , $_, if( !$_->endoffile );
242 my $localizeFile = $merge_dir."\\".$current[ 0 ]->module."\\".$current[ 0 ]->file;
243 my $path = getDir
( $localizeFile );
246 $localizeFile = $path."/localize.sdf";
248 return ( $path , $localizeFile );
254 my( $path , $localize_file ) = make_paths
();
256 $last_localize_file = $localize_file;
262 return , if ( $#current+1 eq 0 );
263 my( $path , $localize_file ) = make_paths
();
264 if( $path eq $last_path )
270 write_buffer
( $last_path , $last_localize_file );
273 $last_localize_file = $localize_file;
278 # Adds all lines that contain strings from one source file from every input file.
279 # TODO: Would it not be better to add lines for all files from a directory (i.e., replace
280 # "$afile eq $elem->file" by "$adir eq $elem->dir")? We could get rid of the delayed
281 # writing then. But maybe there is a reason for doing it this way...
287 foreach my $elem ( @current )
290 $amodule=$elem->module;
292 $plainline=$elem->line;
293 push @buffer, $plainline;
294 getNextSdfObj
( $elem );
295 } while ( !$elem->endoffile && $amodule eq $elem->module && $afile eq $elem->file );
299 # Writes the buffer to currently selected localize.sdf file.
303 my $localize_file = shift;
304 my $cnt = $#buffer+1;
305 print "Write to $path $cnt lines\n";
307 open FILE
, ">>$localize_file" or die "Can't open file '$localize_file'\n";
317 my $success = GetOptions
( 'sdf_files=s' => \
$sdf_filename , 'merge_dir=s' => \
$merge_dir ); #, 'module=s' => \$module_name );
318 if( ! ( $sdf_filename && $merge_dir && $success ) )
327 print "Usage: fast_merge -sdf_files <file containing sdf file names> -merge_dir <directory>\n" ;
330 sub read_sdf_file_names
332 open FILE
, "<$sdf_filename" or die "Can't open file '$sdf_filename'\n";
335 push @file_names , split " " , $_ ;