diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2008-07-01 13:51:08 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2008-07-01 13:51:08 +0000 |
commit | 4c89a79c70182005ed00b80c1a0db44683e602f6 (patch) | |
tree | e51a0e567dc2c40bc7465630c67d9eaeab5c1e00 /transex3 | |
parent | e1d727ae685d5a31b0a111635fa963cf8a5f3ae6 (diff) |
INTEGRATION: CWS newkeyid1 (1.1.2); FILE ADDED
2008/05/28 15:24:07 gh 1.1.2.5: #i90075#hardcode one KeyID to keyid1
2008/05/21 12:30:28 gh 1.1.2.4: #i89720 implement new KeyIDs
2008/04/16 09:34:02 gh 1.1.2.3: change delimiter of KeyID from . (dot) to | (pipe)
2008/04/03 10:44:23 gh 1.1.2.2: force KeyIDs to 6 Digits and generate keyIDs for fileds containing a zero
2008/03/13 12:20:15 gh 1.1.2.1: calculate KeyIDs for KeyID Build and Database import
Diffstat (limited to 'transex3')
-rw-r--r-- | transex3/scripts/keyidGen.pl | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/transex3/scripts/keyidGen.pl b/transex3/scripts/keyidGen.pl new file mode 100644 index 000000000000..6f543695b819 --- /dev/null +++ b/transex3/scripts/keyidGen.pl @@ -0,0 +1,193 @@ +: +eval 'exec perl -S $0 ${1+"$@"}' + if 0; +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: keyidGen.pl,v $ +# +# $Revision: 1.2 $ +# +# last change: $Author: vg $ $Date: 2008-07-01 14:51:08 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2007 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* +# +# add keyids to sdf file +# + +use Compress::Zlib(); + +print "\nkeyidGen version 1.0 \n\n"; + +my ( $infile,$outfile,$dbimport ); +get_options(); + +print_help() if ( !defined $infile || $help ); +exit 1 if ( !defined $infile ); +if ( ! defined $outfile ) +{ + $outfile = $infile; + $outfile =~ s/\.sdf$//i; + $outfile .= "_KeyID.sdf"; +} + +$collisions = 0; +%hashcodes = (); +$count = 0; +print "writing to $outfile\n"; +open INFILE,"<$infile" || die "could not open $infile $! $^E\n"; +open OUTFILE,">$outfile" || die "could not open $outfile $! $^E\n"; + +while ( <INFILE> ) +{ + $line = $_; + chomp $line; + $hash = 0; + if ( $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]*)$/ ) + { + $string="$1 $2 $4 $5 $6 $7 $8"; + $hashp = makeID( $string ); + + if ( defined ($hashcodes{ $hashp } ) ) + { + $collisions ++ unless $hashcodes{ $hashp } eq $string; + } + $hashcodes{ $hashp } = $string; + $count++; + if ( $dbimport ) + { + my ( $pre, $post, $old ); + $pre = "$1\t$2\t"; + $post = "\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t$11\t$12\t$13\t$14\t$15\n"; + $old = $3; + $old =~ s/;{0,1}keyid:......;{0,1}//; + $old =~ s/^0$//; + if ( $old ne "" ) { $old .= ";"; } + print OUTFILE "$pre${old}keyid:$hashp$post"; + } + else + { + print OUTFILE "$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t$10\t".makekidstr($hashp,$11)."\t".makekidstr($hashp,$12)."\t$13\t".makekidstr($hashp,$14)."\t$15\n"; + } + } +} +print "$count entries\n"; +print "$collisions collisions\n"; + +close INFILE; +close OUTFILE; + +sub makeID +{ + my ( $String ) = shift; + my ( $hash ); + # hardcoded to prevent windows installer to choke on bad directoryname :-(( + if ( $String eq "scp2 source\\ooo\\directory_ooo.ulf LngText STR_DIR_KAPITEL " ) + { + return "keyid1"; + } + + $hash = Compress::Zlib::crc32( $String, undef ); + return makenumber( $hash ); +} + +sub makenumber +{ + $h = shift; + # 1 2 3 4 + # 1234567890123456789012345678901234567890 + $symbols="0123456789abcdefghijklmnopqrstuvwxyz+-<=>"; + $order = length($symbols); + $result = ""; + while ( length( $result ) < 6 ) + { + $result .= substr( $symbols, ($h % $order), 1 ); + $h = int( $h / $order ); + } + die "makenumber failed because number is too big (this cannot be so this is a strange error)" if $h > 0; + + return reverse $result; +} + + +sub makekidstr +{ + $kid = shift; + $str = shift; + + if ( $str ne "" ) + { + # special handling for strings starting with font descriptions like {&Tahoma8} (win system integration) + if ( $str =~ s/^(\{\&[^\}]+\})// ) + { + return "$1$kid‖$str"; + } + else + { + return "$kid‖$str"; + } + } + else + { + return ""; + } +# return "default"; +} + +sub print_help +{ + print "\n\n"; + print "keyidGen 0.5 for sdf files\n"; + print "--------------------------\n"; + print "Usage:\n"; + print "keyidGen <infile> [<outfile>] [-dbimport]\n"; + print " add keyids to the entries and write them to a file with\n"; + print " _KeyID added to the name\n"; + print " -dbimport Add KeyID to a new column instead of to the strings.\n"; + print " This is needed to import the IDs into tha database.\n"; + print "\n\n"; +} + + +sub get_options { + my ($arg,$has_infile); + + while ($arg = shift @ARGV) { + $arg =~ /^-dbimport$/ and $dbimport = 1 and next; + $arg =~ /^-help$/ and $help = 1 and next; #show help + + if ( !$has_infile ) + { + $infile = $arg; + $has_infile = 1; + } + else + { + $outfile = $arg; + } + } +} |