ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/dinfo/dump-dinfo
Revision: 1.2
Committed: Fri Aug 29 04:15:01 2003 UTC (20 years, 8 months ago) by root
Branch: MAIN
Changes since 1.1: +24 -13 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 #!/opt/bin/perl
2 root 1.1 #
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     $PFX = "/opt/dinfo/data"; # the directory where the dinfo datafiles are
13 root 1.2 $VERSION = 0.01;
14 root 1.1
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 root 1.2 my (@res, @idx, $idx);
29 root 1.1
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 root 1.2 while 32 == sysread $fh_idx, $idx, 32;
37 root 1.1 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 root 1.2 my (@idx, $idx);
56    
57     my @cols = qw(name vorname zusatz1 zusatz2 zusatz3 vorwahl nummer strasse hausnr plz ort ortsteil branche);
58    
59     open $_, ">", "data/dump/$_" for @cols;
60 root 1.1
61     push @$street, "";
62    
63     open my $fh_idx, "<", "$PFX/main.idx"
64     or die "$PFX/main.dat: $!";
65     open my $fh_dat, "<", "$PFX/main.dat"
66     or die "$PFX/main.dat: $!";
67    
68     push @idx, unpack "V", $idx
69 root 1.2 while 24 == sysread $fh_idx, $idx, 24;
70 root 1.1 push @idx, (-s "$PFX/main.dat") - 26;
71    
72     for (0 .. $#idx - 1) {
73     print STDERR "\r$_ ($#idx)";
74    
75     my ($ofs, $end) = ($idx[$_], $idx[$_+1]);
76    
77     sysseek $fh_dat, $ofs + 26, 0
78     or die "seek_main.dat: $!";
79     $end - $ofs == sysread $fh_dat, my $buf, $end - $ofs
80     or die "read_main.dat: short read ($!)";
81    
82     my @data = map inf $buf, 0 .. 12;
83    
84     $_ = [split /\x00/, $_, -1] for @data[0..5, 7..12];
85    
86     $data[6] = [
87     map { $_ < $#$street ? $_ : $#street }
88     map { unpack "V", "$_\x00" }
89     split /(...)/s, $data[6]
90     ];
91    
92     for (0 .. $#{$data[0]} - 1) {
93 root 1.2 print {$cols[0]} $data[0][$_], "\0";
94     print {$cols[1]} $data[1][$_], "\0";
95     print {$cols[2]} $data[2][$_], "\0";
96     print {$cols[3]} $data[3][$_*2+0], "\0";
97     print {$cols[4]} $data[3][$_*2+1], "\0";
98     print {$cols[5]} $data[4][$_], "\0";
99     print {$cols[6]} $data[5][$_], "\0";
100     print {$cols[7]} $street->[$data[6][$_]], "\0";
101     print {$cols[8]} $data[7][$_], "\0";
102     print {$cols[9]} $data[8][$_], "\0";
103     print {$cols[10]} $data[9][$_], "\0";
104     print {$cols[11]} $data[10][$_], "\0";
105     print {$cols[12]} $data[11][$_], "\0";
106 root 1.1 }
107     }
108     }
109    
110     dump_dinfo;
111 root 1.2