3 # Parses Bibliofile files.
4 # Usage: parse_db.pl TITLE.DB [--ignore-indexes]
5 # Choosing --ignore-indexes will find data you'd otherwise miss, but also grabs a lot of junk you'll need to filter out.
11 my $ignoreIndexes = '';
13 my $opts = GetOptions('ignore-indexes' => \$ignoreIndexes);
17 my $startOfColumnTypes = 8;
18 my $startOfRealData = 4096;
20 my $initialOffset = 6;
41 $rowLength = ord(substr($data, 0, 1)) + (256 * (ord(substr($data, 1, 1))));
42 #print STDERR "Row length: $rowLength\n";
44 my $numColumns = ord substr($data, 2, 1);
45 #print STDERR "Columns: $numColumns\n";
47 my $namedata = substr($data, $startOfColumnTypes + ($numColumns * 7) - 2);
48 @fieldNames = split(/\x00/, $namedata);
50 for (my $i = 0; $i < $numColumns; $i++) {
51 $fieldTypes[$i] = substr($data, ($i * 7) + $startOfColumnTypes, 1);
52 $fieldLengths[$i] = ord substr($data, ($i * 7) + $startOfColumnTypes + 1, 1);
59 print join("\t", @fieldNames) . "\n";
65 while (read DB, my $data, $blockSize) {
67 next if ($blocks == 1);
68 my $maxRecords = POSIX::floor($blockSize / $rowLength);
69 unless $ignoreIndexes {
70 my $indexIndicator1 = ord substr($data, 1, 1);
71 next if ($indexIndicator1 != 0);
72 my $indexIndicator2 = ord substr($data, 7, 1);
73 next if ($indexIndicator2 == 0);
76 for (my $r = 0; $r < $maxRecords; $r++) {
81 #print STDERR "Record " . ($r+1) . " of $maxRecords\n";
83 for (my $f = 0; $f < scalar(@fieldLengths); $f++) {
84 $field[$f] = substr($data, $initialOffset + ($r * $rowLength) + $pos, $fieldLengths[$f]);
85 if ($fieldTypes[$f] eq 'S') { $field[$f] = ord $field[$f]; }
86 $pos += $fieldLengths[$f];
89 if ($field[0] =~ m/[^\x00]/) {
90 print join("\t", @field) . "\n";