office-gobmx/l10ntools/scripts/fast_merge.pl

335 lines
7.8 KiB
Perl
Raw Normal View History

:
eval 'exec perl -wS $0 ${1+"$@"}'
if 0;
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org. If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************
use strict;
use Class::Struct;
use Getopt::Long;
use File::Temp;
use File::Path;
my @files;
my @file_names;
my $module_name = '';
my @current;
my @buffer;
my $last_file;
my $last_path;
my $last_localize_file;
my $first_run = "1";
my $sdf_filename;
my $merge_dir;
my $state = "none";
$SIG{INT} = 'inthandler';
$SIG{QUIT} = 'quithandler';
struct ( sdf_obj =>
{
module => '$',
file => '$',
dir => '$',
FILEHANDLE => '$',
line => '$',
endoffile => '$'
}
);
parse_options();
my $lock_file = $merge_dir."/lock.mk";
acquire_lock();
read_sdf_file_names();
init();
my $reference;
my $path ;
my $localize_file;
while( hasLines() )
{
@current = ();
foreach ( @files )
{
push @current , $_;
}
$reference = getNextIdentifier( );
@current = ();
foreach ( @files )
{
if( $_->module eq $reference->module && $_->dir eq $reference->dir )
{
push @current , $_ ;
}
}
write_lines();
}
if( $#current+1 ne 0 )
{
( $path , $localize_file ) = make_paths();
add_to_buffer();
write_buffer( $path , $localize_file );
}
release_lock();
exit( 0 );
##########################################################################################
sub acquire_lock
{
if( -e $lock_file ){
$state = "blocked";
print "WARNING: Lock file '$lock_file' 'found, waiting ....\n";
my $cnt = 0;
sleep 10 , while( -e $lock_file && $cnt++ < 180 );
exit( 0 );
}else
{
$state = "locked";
print "Writing lock file '$lock_file'\n";
open FILE, ">$lock_file" or die "Can't create lock file '$lock_file'";
print FILE "L10N_LOCK=YES" ;
close ( FILE );
}
}
sub release_lock
{
print "Deleting lock file '$lock_file'\n";
unlink $lock_file, if( -e $lock_file );
$state = "none";
}
sub inthandler
{
release_lock() , if( $state eq "locked" );
exit( -1 );
}
sub quithandler
{
release_lock() , if( $state eq "locked" );
exit( 0 );
}
sub init
{
foreach my $file ( @file_names )
{
my $obj = new sdf_obj;
open my $FILEHANDLE , "<$file" or die "Can't open file '$file'";
$obj->FILEHANDLE ( $FILEHANDLE ) ;
getNextSdfObj( $obj );
push @files, $obj ;
print "Open file '$file'\n";
}
}
# get the next module/file
sub getNextIdentifier
{
my @sorted = sort {
return $a->module.$a->dir cmp $b->module.$b->dir;
} @current ;
return shift @sorted;
}
# update the obj with the next line
sub getNextSdfObj
{
my $obj = shift;
my $line = readline ( $obj->FILEHANDLE );
if ( $line eq undef )
{
$obj->endoffile( "true" );
}
else
{
CWS-TOOLING: integrate CWS localization37 2009-11-20 17:34:04 +0100 ihi r277585 : not yet the best solution 2009-11-19 14:34:34 +0100 ihi r277560 : #i103247# updated Luxembourgish autocorrect data 2009-11-16 16:58:56 +0100 ihi r277525 : added ast to no_ms_lang 2009-11-16 16:57:23 +0100 ihi r277524 : added ast 2009-11-16 16:41:22 +0100 ihi r277523 : #i106900# updated identifier ShowAnnotation -> ShowAnnotations 2009-11-16 16:39:34 +0100 ihi r277522 : small helper script 2009-11-16 15:24:34 +0100 ihi r277520 : Fixed german and removed ln ti pap ur 2009-11-11 14:27:38 +0100 releng r277457 : added ug, om, si, oc, or, ml, as to non ms langs 2009-11-11 14:23:30 +0100 releng r277456 : Fix for merging more then just one 2009-11-11 14:12:52 +0100 ihi r277455 : #i106775# Merge of OOo 3.2 l10n cws localization37 nb nn he ga uk my bg ja uz fi bn kid fr nl vi ca pt-BR ru ka oc gl cs km kn ko sh si om gu sk sl zh-CN ku or da sr de sv hi-IN pa-IN ta te pl th hu dz lv pt tr en-GB id el ar as eo es ml et eu zh-TW is ug it mr 2009-11-05 23:07:09 +0100 ihi r277375 : added om kid , removed dupe ta-IN 2009-11-03 18:09:39 +0100 ihi r277327 : removed dupe 2009-11-02 19:02:55 +0100 ihi r277303 : #i105973 obsolete sdf files removed 2009-11-02 19:02:16 +0100 ihi r277302 : #i105973 obsolete sdf files removed 2009-10-13 19:19:06 +0200 ihi r276871 : CWS-TOOLING: rebase CWS localization37 to branches/OOO320@276773 (milestone: OOO320:m1) 2009-10-01 13:19:45 +0200 ihi r276598 : key -> ky ... this one triggered a bad crash in rsc 2009-09-09 17:02:20 +0200 ihi r276004 : added some langs 2009-09-09 13:17:16 +0200 ihi r275986 : lucky local cygwin fix 2009-09-03 18:47:45 +0200 ihi r275769 : #104328# deal with l10nless src files 2009-09-03 15:58:51 +0200 ihi r275760 : added some new langs 2009-09-03 15:54:16 +0200 ihi r275759 : old localize.pl tool used as a helper 2009-09-03 15:53:48 +0200 ihi r275758 : do not merge not wellformated sdf files 2009-09-03 15:51:59 +0200 ihi r275757 : old localize.pl tool used as a helper 2009-09-03 15:50:03 +0200 ihi r275756 : some small helpers added 2009-09-01 18:22:04 +0200 ihi r275681 : update DEV300 code line with OOO310 strings 2009-09-01 13:45:43 +0200 ihi r275658 : #i104680# prevent that self defined or dupe ms ids are merged
2009-11-24 08:40:24 -06:00
$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 ;
if( defined $1 && defined $2 && defined $3 )
{
$obj->line ( $1 );
$obj->module( $2 );
$obj->file ( $3 );
$obj->dir ( getDir( $3 ) );
}
else
{
$obj->line ( "" );
$obj->module( "" );
$obj->file ( "" );
$obj->dir ( "" );
}
}
return $obj;
}
sub getNextSdfObjModule
{
my $obj = shift;
while( !$obj->endoffile )
{
my $line = readline ( $obj->FILEHANDLE );
if ( $line eq undef )
{
$obj->endoffile( "true" );
}
else
{
$line =~ /^(([^\t]*)\t([^\t]*).*)/o ;
if( defined $1 && defined $2 && defined $3 )
{
$obj->line ( $1 );
$obj->module( $2 );
$obj->file ( $3 );
$obj->dir ( getDir( $3 ) );
}
else
{
$obj->line ( "" );
$obj->module( "" );
$obj->file ( "" );
$obj->dir ( "" );
}
return $obj , if( $obj->module eq $module_name )
}
}
#return $obj;
}
sub getDir
{
my $path = shift ;
$path =~ s/\//\\/g;
my @tmp_path = split /\\/ , $path;
pop @tmp_path;
$path = join '\\' , @tmp_path;
return $path;
}
sub hasLines
{
my $hasLines = "";
my @tmpfiles;
foreach ( @files )
{
push @tmpfiles , $_, if( !$_->endoffile );
}
@files = @tmpfiles;
return $#files+1;
}
sub make_paths
{
my $localizeFile = $merge_dir."\\".$current[ 0 ]->module."\\".$current[ 0 ]->file;
my $path = getDir( $localizeFile );
$path =~ s/\\/\//g;
$localizeFile = $path."/localize.sdf";
return ( $path , $localizeFile );
}
sub write_lines
{
if( $first_run ){
add_to_buffer();
my( $path , $localize_file ) = make_paths();
$last_path = $path;
$last_localize_file = $localize_file;
mkpath $path;
write_buffer( $path , $localize_file );
$first_run = '';
}
else
{
return , if ( $#current+1 eq 0 );
my( $path , $localize_file ) = make_paths();
if( $path eq $last_path )
{
add_to_buffer();
}
else
{
mkpath $path;
write_buffer( $last_path , $last_localize_file );
add_to_buffer();
$last_path = $path;
$last_localize_file = $localize_file;
}
}
}
sub add_to_buffer
{
my $plainline;
my $afile;
my $amodule;
foreach my $elem ( @current )
{
do {
$amodule=$elem->module;
$afile=$elem->file;
$plainline=$elem->line;
push @buffer, $plainline;
getNextSdfObj( $elem );
} while ( !$elem->endoffile && $amodule eq $elem->module && $afile eq $elem->file );
}
}
sub write_buffer
{
my $path = shift;
my $localize_file = shift;
my $cnt = $#buffer+1;
print "Write to $path $cnt lines\n";
open FILE , ">>$localize_file" or die "Can't open file '$localize_file'\n";
foreach ( @buffer )
{
print FILE $_."\n";
}
@buffer = ();
}
sub parse_options
{
my $success = GetOptions( 'sdf_files=s' => \$sdf_filename , 'merge_dir=s' => \$merge_dir ); #, 'module=s' => \$module_name );
if( ! ( $sdf_filename && $merge_dir && $success ) )
{
usage();
exit( -1 );
}
}
sub usage
{
print "Usage: fast_merge -sdf_files <file containing sdf file names> -merge_dir <directory>\n" ;
}
sub read_sdf_file_names
{
open FILE , "<$sdf_filename" or die "Can't open file '$sdf_filename'\n";
while ( <FILE> )
{
push @file_names , split " " , $_ ;
}
close ( FILE );
}