Tools for handling Bibliofile *.DB/*.DBD files
authorBen Ostrowsky <ben@esilibrary.com>
Thu, 18 Nov 2010 16:06:18 +0000 (16:06 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 16 Jul 2012 15:30:04 +0000 (11:30 -0400)
bibliofile/parse_dbd.pl [new file with mode: 0755]

diff --git a/bibliofile/parse_dbd.pl b/bibliofile/parse_dbd.pl
new file mode 100755 (executable)
index 0000000..0a16c3a
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+$/ = undef;
+
+my %coltypes = ( 
+  'A' => 'Text',
+  'N' => 'Numeric',
+  'S' => 'Integer'
+);
+my $startOfColumnTypes = 8;
+
+while (<>) {
+
+  my $dbd = $_;
+  my $rowlength = ord substr($dbd, 0, 1);
+  my $numcolumns = ord substr($dbd, 2, 1);
+  my $extra = sprintf(
+    "%02x %02x %02x", 
+    ord substr($dbd, 4, 1),
+    ord substr($dbd, 5, 1),
+    ord substr($dbd, 6, 1),
+  );
+  my $delimiter = sprintf(
+    "%02x",
+    ord substr($dbd, 7, 1),
+  );
+
+  my $colnames = substr($dbd, $startOfColumnTypes + 7*$numcolumns - 2);
+  my @col = split(/\x00/, $colnames);
+
+  #print "Row length: $rowlength\n";
+  #print "Columns:    $numcolumns\n";
+  #print "Extra data: $extra\n";
+  #print "Delimiter:  $delimiter\n";
+
+  for (my $i = 1; $i <= $numcolumns; $i++) {
+    my $coltype = substr($dbd, 7*($i-1)+$startOfColumnTypes, 1);
+    my $collength = ord substr($dbd, 7*($i-1)+$startOfColumnTypes+1, 1);
+    printf ("Column %02d: %-8s %s (%d chars)\n", $i, $coltypes{$coltype}, $col[$i-1], $collength);
+  }
+
+}
+
+
+
+
+