#!/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); 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 +(join "\t", $data[0][$_], $data[1][$_], $data[2][$_], $data[3][$_*2+0], $data[3][$_*2+1], $data[4][$_], $data[5][$_], $street->[$data[6][$_]], $data[7][$_], $data[8][$_], $data[9][$_], $data[10][$_], $data[11][$_], ), "\n"; } } } dump_dinfo;