#!/opt/bin/perl # utility to convert the extracted dictionary to a perl hash for further use # use jcf-dump GroupChat.java and extract the longest constant string sans '"' use Encode; use Data::Dumper; local $/; binmode STDIN; binmode STDOUT, ":utf-8"; my $dictionary = <>; $dictionary =~ s% \\ (?: \\ | 0([0-9a-f]{2}) | u([0-9a-f]{4}) | ([rnt\x27\x22]) | (.) ) % if ($1 || $2) { chr hex "$1$2"; } elsif ($3 eq "r") { "\015" } elsif ($3 eq "n") { "\012" } elsif ($3 eq "t") { "\011" } elsif ($3 eq "'") { "'" } elsif ($3 eq '"') { '"' } elsif ($4) { die "<<<$4>>>\n"; } else { "\\"; } %sgex; my ($idx, $bit) = (0, -32); while (length $dictionary) { my $prefix = ord substr $dictionary, 0, 1, ""; $prefix = unpack "n", Encode::encode "iso-8859-1", substr $dictionary, 0, 2, "" if $prefix == 255; my ($len, $width) = (int $prefix / 21, $prefix % 21); my $string = substr $dictionary, 0, $len + 1, ""; # carry while ($idx & 1) { $idx >>= 1; $bit--; } $idx |= 1; # widen while ($bit < $width) { $idx &= 0x7fffffff; $idx <<= 1; $bit++; } my $code = reverse unpack "b$width", pack "V", $idx; #$string =~ s/([^\x20-\x7e])/sprintf "\\x{%x}", ord $1/ge; $code{$code} = $string; } "" eq delete $code{"0000000000"} or die "FATAL"; print "package Net::Knuddels::Dictionary;\n", "\n", "\$Net::Knuddels::Dictionary = "; print Data::Dumper->new([\%code])->Terse(1)->Useqq(0)->Quotekeys(1)->Sortkeys(0)->Dump; print ";\n1;\n";