2 eval 'exec perl -S $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: keyidGen.pl,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 # add keyids to sdf file
40 print "\nkeyidGen version 1.0 \n\n";
42 my ( $infile,$outfile,$dbimport );
45 print_help
() if ( !defined $infile || $help );
46 exit 1 if ( !defined $infile );
47 if ( ! defined $outfile )
50 $outfile =~ s/\.sdf$//i;
51 $outfile .= "_KeyID.sdf";
57 print "writing to $outfile\n";
58 open INFILE
,"<$infile" || die "could not open $infile $! $^E\n";
59 open OUTFILE
,">$outfile" || die "could not open $outfile $! $^E\n";
66 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]*)$/ )
68 $string="$1 $2 $4 $5 $6 $7 $8";
69 $hashp = makeID
( $string );
71 if ( defined ($hashcodes{ $hashp } ) )
73 $collisions ++ unless $hashcodes{ $hashp } eq $string;
75 $hashcodes{ $hashp } = $string;
79 my ( $pre, $post, $old );
81 $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";
83 $old =~ s/;{0,1}keyid:......;{0,1}//;
85 if ( $old ne "" ) { $old .= ";"; }
86 print OUTFILE
"$pre${old}keyid:$hashp$post";
90 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";
94 print "$count entries\n";
95 print "$collisions collisions\n";
102 my ( $String ) = shift;
104 # hardcoded to prevent windows installer to choke on bad directoryname :-((
105 if ( $String eq "scp2 source\\ooo\\directory_ooo.ulf LngText STR_DIR_KAPITEL " )
110 $hash = Compress
::Zlib
::crc32
( $String, undef );
111 return makenumber
( $hash );
118 # 1234567890123456789012345678901234567890
119 $symbols="0123456789abcdefghijklmnopqrstuvwxyz+-<=>";
120 $order = length($symbols);
122 while ( length( $result ) < 6 )
124 $result .= substr( $symbols, ($h % $order), 1 );
125 $h = int( $h / $order );
127 die "makenumber failed because number is too big (this cannot be so this is a strange error)" if $h > 0;
129 return reverse $result;
140 # special handling for strings starting with font descriptions like {&Tahoma8} (win system integration)
141 if ( $str =~ s/^(\{\&[^\}]+\})// )
143 return "$1$kid‖$str";
160 print "keyidGen 0.5 for sdf files\n";
161 print "--------------------------\n";
163 print "keyidGen <infile> [<outfile>] [-dbimport]\n";
164 print " add keyids to the entries and write them to a file with\n";
165 print " _KeyID added to the name\n";
166 print " -dbimport Add KeyID to a new column instead of to the strings.\n";
167 print " This is needed to import the IDs into tha database.\n";
173 my ($arg,$has_infile);
175 while ($arg = shift @ARGV) {
176 $arg =~ /^-dbimport$/ and $dbimport = 1 and next;
177 $arg =~ /^-help$/ and $help = 1 and next; #show help