2 eval 'exec perl -S $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 #*************************************************************************
31 # add keyids to sdf file
36 print "\nkeyidGen version 1.0 \n\n";
38 my ( $infile,$outfile,$dbimport );
41 print_help
() if ( !defined $infile || $help );
42 exit 1 if ( !defined $infile );
43 if ( ! defined $outfile )
46 $outfile =~ s/\.sdf$//i;
47 $outfile .= "_KeyID.sdf";
53 print "writing to $outfile\n";
54 open INFILE
,"<$infile" || die "could not open $infile $! $^E\n";
55 open OUTFILE
,">$outfile" || die "could not open $outfile $! $^E\n";
62 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]*)$/ )
64 $string="$1 $2 $4 $5 $6 $7 $8";
65 $hashp = makeID
( $string );
67 if ( defined ($hashcodes{ $hashp } ) )
69 $collisions ++ unless $hashcodes{ $hashp } eq $string;
71 $hashcodes{ $hashp } = $string;
75 my ( $pre, $post, $old );
77 $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";
79 $old =~ s/;{0,1}keyid:......;{0,1}//;
81 if ( $old ne "" ) { $old .= ";"; }
82 print OUTFILE
"$pre${old}keyid:$hashp$post";
86 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";
90 print "$count entries\n";
91 print "$collisions collisions\n";
98 my ( $String ) = shift;
100 # hardcoded to prevent windows installer to choke on bad directoryname :-((
101 if ( $String eq "scp2 source\\ooo\\directory_ooo.ulf LngText STR_DIR_KAPITEL " )
106 $hash = Compress
::Zlib
::crc32
( $String, undef );
107 return makenumber
( $hash );
114 # 1234567890123456789012345678901234567890
115 $symbols="0123456789abcdefghijklmnopqrstuvwxyz+-[=]";
116 $order = length($symbols);
118 while ( length( $result ) < 6 )
120 $result .= substr( $symbols, ($h % $order), 1 );
121 $h = int( $h / $order );
123 die "makenumber failed because number is too big (this cannot be so this is a strange error)" if $h > 0;
125 return reverse $result;
136 # special handling for strings starting with font descriptions like {&Tahoma8} (win system integration)
137 if ( $str =~ s/^(\{\&[^\}]+\})// )
139 return "$1$kid‖$str";
156 print "keyidGen 0.5 for sdf files\n";
157 print "--------------------------\n";
159 print "keyidGen <infile> [<outfile>] [-dbimport]\n";
160 print " add keyids to the entries and write them to a file with\n";
161 print " _KeyID added to the name\n";
162 print " -dbimport Add KeyID to a new column instead of to the strings.\n";
163 print " This is needed to import the IDs into tha database.\n";
169 my ($arg,$has_infile);
171 while ($arg = shift @ARGV) {
172 $arg =~ /^-dbimport$/ and $dbimport = 1 and next;
173 $arg =~ /^-help$/ and $help = 1 and next; #show help