#!/opt/bin/perl # # Usage: dump-dinfo >main.tsv # dump the d-info database to stdout as tab-seperated lines. # find out the rest of the format yourself. # # COPYRIGHT: (c)2003 Marc Lehmann, Paul Bettinger # AUTHORS: Marc A. Lehmann , Paul Bettinger # LICENSE: This file is licensed under the General Public License (GPL) # http://www.gnu.org/licenses/licenses.html#GPL $PFX = "/opt/dinfo/data"; # the directory where the dinfo datafiles are $VERSION = 0.01; use Compress::Zlib; sub inf($) { my ($inf, $status) = inflateInit -WindowBits => -15; die $status if $status < -1; my ($out, $status) = $inf->inflate ($_[0]); die $status if $status < -1; $out; } sub street_names { my (@res, @idx, $idx); open my $fh_dat, "<", "$PFX/street.dat" or die "$PFX/street.dat: $!"; open my $fh_idx, "<", "$PFX/street.idx" or die "$PFX/street.idx: $!"; push @idx, unpack "x10 V", $idx while 32 == sysread $fh_idx, $idx, 32; push @idx, -s "$PFX/street.dat"; for (0 .. $#idx - 1) { my ($ofs, $end) = ($idx[$_], $idx[$_+1]); sysseek $fh_dat, $ofs, 0 or die "seek_street.dat: $!"; $end - $ofs == sysread $fh_dat, my $buf, $end - $ofs or die "read_street.dat: short read ($!)"; push @res, split /\x00/, inf $buf; } \@res; } sub dump_dinfo { my $street = street_names; my (@idx, $idx); my @cols = qw(name vorname zusatz1 zusatz2 zusatz3 vorwahl nummer strasse hausnr plz ort ortsteil branche); open $_, ">", "data/dump/$_" for @cols; push @$street, ""; open my $fh_idx, "<", "$PFX/main.idx" or die "$PFX/main.dat: $!"; open my $fh_dat, "<", "$PFX/main.dat" or die "$PFX/main.dat: $!"; push @idx, unpack "V", $idx while 24 == sysread $fh_idx, $idx, 24; push @idx, (-s "$PFX/main.dat") - 26; for (0 .. $#idx - 1) { print STDERR "\r$_ ($#idx)"; my ($ofs, $end) = ($idx[$_], $idx[$_+1]); sysseek $fh_dat, $ofs + 26, 0 or die "seek_main.dat: $!"; $end - $ofs == sysread $fh_dat, my $buf, $end - $ofs or die "read_main.dat: short read ($!)"; my @data = map inf $buf, 0 .. 12; $_ = [split /\x00/, $_, -1] for @data[0..5, 7..12]; $data[6] = [ map { $_ < $#$street ? $_ : $#street } map { unpack "V", "$_\x00" } split /(...)/s, $data[6] ]; for (0 .. $#{$data[0]} - 1) { print {$cols[0]} $data[0][$_], "\0"; print {$cols[1]} $data[1][$_], "\0"; print {$cols[2]} $data[2][$_], "\0"; print {$cols[3]} $data[3][$_*2+0], "\0"; print {$cols[4]} $data[3][$_*2+1], "\0"; print {$cols[5]} $data[4][$_], "\0"; print {$cols[6]} $data[5][$_], "\0"; print {$cols[7]} $street->[$data[6][$_]], "\0"; print {$cols[8]} $data[7][$_], "\0"; print {$cols[9]} $data[8][$_], "\0"; print {$cols[10]} $data[9][$_], "\0"; print {$cols[11]} $data[10][$_], "\0"; print {$cols[12]} $data[11][$_], "\0"; } } } dump_dinfo;