| 1 |
root |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
# |
| 3 |
|
|
# Usage: dump-dinfo >main.tsv |
| 4 |
|
|
# dump the d-info database to stdout as tab-seperated lines. |
| 5 |
|
|
# find out the rest of the format yourself. |
| 6 |
|
|
# |
| 7 |
|
|
# COPYRIGHT: (c)2003 Marc Lehmann, Paul Bettinger |
| 8 |
|
|
# AUTHORS: Marc A. Lehmann <dinfo@plan9.de>, Paul Bettinger <dinfo@n8geil.de> |
| 9 |
|
|
# LICENSE: This file is licensed under the General Public License (GPL) |
| 10 |
|
|
# http://www.gnu.org/licenses/licenses.html#GPL |
| 11 |
|
|
# |
| 12 |
|
|
|
| 13 |
|
|
$PFX = "/opt/dinfo/data"; # the directory where the dinfo datafiles are |
| 14 |
|
|
|
| 15 |
|
|
use Compress::Zlib; |
| 16 |
|
|
|
| 17 |
|
|
sub inf($) { |
| 18 |
|
|
my ($inf, $status) = inflateInit -WindowBits => -15; |
| 19 |
|
|
die $status if $status < -1; |
| 20 |
|
|
|
| 21 |
|
|
my ($out, $status) = $inf->inflate ($_[0]); |
| 22 |
|
|
die $status if $status < -1; |
| 23 |
|
|
|
| 24 |
|
|
$out; |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
sub street_names { |
| 28 |
|
|
my (@res, @idx); |
| 29 |
|
|
|
| 30 |
|
|
open my $fh_dat, "<", "$PFX/street.dat" |
| 31 |
|
|
or die "$PFX/street.dat: $!"; |
| 32 |
|
|
open my $fh_idx, "<", "$PFX/street.idx" |
| 33 |
|
|
or die "$PFX/street.idx: $!"; |
| 34 |
|
|
|
| 35 |
|
|
push @idx, unpack "x10 V", $idx |
| 36 |
|
|
while 32 == sysread $fh_idx, my $idx, 32; |
| 37 |
|
|
push @idx, -s "$PFX/street.dat"; |
| 38 |
|
|
|
| 39 |
|
|
for (0 .. $#idx - 1) { |
| 40 |
|
|
my ($ofs, $end) = ($idx[$_], $idx[$_+1]); |
| 41 |
|
|
|
| 42 |
|
|
sysseek $fh_dat, $ofs, 0 |
| 43 |
|
|
or die "seek_street.dat: $!"; |
| 44 |
|
|
$end - $ofs == sysread $fh_dat, my $buf, $end - $ofs |
| 45 |
|
|
or die "read_street.dat: short read ($!)"; |
| 46 |
|
|
|
| 47 |
|
|
push @res, split /\x00/, inf $buf; |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
|
\@res; |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
sub dump_dinfo { |
| 54 |
|
|
my $street = street_names; |
| 55 |
|
|
|
| 56 |
|
|
push @$street, ""; |
| 57 |
|
|
|
| 58 |
|
|
open my $fh_idx, "<", "$PFX/main.idx" |
| 59 |
|
|
or die "$PFX/main.dat: $!"; |
| 60 |
|
|
open my $fh_dat, "<", "$PFX/main.dat" |
| 61 |
|
|
or die "$PFX/main.dat: $!"; |
| 62 |
|
|
|
| 63 |
|
|
my @idx; |
| 64 |
|
|
push @idx, unpack "V", $idx |
| 65 |
|
|
while (24 == sysread $fh_idx, my $idx, 24) { |
| 66 |
|
|
push @idx, (-s "$PFX/main.dat") - 26; |
| 67 |
|
|
|
| 68 |
|
|
for (0 .. $#idx - 1) { |
| 69 |
|
|
print STDERR "\r$_ ($#idx)"; |
| 70 |
|
|
|
| 71 |
|
|
my ($ofs, $end) = ($idx[$_], $idx[$_+1]); |
| 72 |
|
|
|
| 73 |
|
|
sysseek $fh_dat, $ofs + 26, 0 |
| 74 |
|
|
or die "seek_main.dat: $!"; |
| 75 |
|
|
$end - $ofs == sysread $fh_dat, my $buf, $end - $ofs |
| 76 |
|
|
or die "read_main.dat: short read ($!)"; |
| 77 |
|
|
|
| 78 |
|
|
my @data = map inf $buf, 0 .. 12; |
| 79 |
|
|
|
| 80 |
|
|
$_ = [split /\x00/, $_, -1] for @data[0..5, 7..12]; |
| 81 |
|
|
|
| 82 |
|
|
$data[6] = [ |
| 83 |
|
|
map { $_ < $#$street ? $_ : $#street } |
| 84 |
|
|
map { unpack "V", "$_\x00" } |
| 85 |
|
|
split /(...)/s, $data[6] |
| 86 |
|
|
]; |
| 87 |
|
|
|
| 88 |
|
|
for (0 .. $#{$data[0]} - 1) { |
| 89 |
|
|
print +(join "\t", |
| 90 |
|
|
$data[0][$_], $data[1][$_], $data[2][$_], |
| 91 |
|
|
$data[3][$_*2+0], $data[3][$_*2+1], |
| 92 |
|
|
$data[4][$_], $data[5][$_], |
| 93 |
|
|
$street->[$data[6][$_]], |
| 94 |
|
|
$data[7][$_], $data[8][$_], $data[9][$_], $data[10][$_], $data[11][$_], |
| 95 |
|
|
), "\n"; |
| 96 |
|
|
} |
| 97 |
|
|
} |
| 98 |
|
|
} |
| 99 |
|
|
|
| 100 |
|
|
dump_dinfo; |