(cosmetic) Adjust digits in column numbers to fit data
[migration-tools.git] / bibliofile / parse_dbd.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 $/ = undef;
6
7 my %coltypes = ( 
8   'A' => 'Text',
9   'N' => 'Numeric',
10   'S' => 'Integer'
11 );
12 my $startOfColumnTypes = 8;
13
14 while (<>) {
15
16   my $dbd = $_;
17   my $rowlength = ord substr($dbd, 0, 1);
18   my $numcolumns = ord substr($dbd, 2, 1);
19   my $extra = sprintf(
20     "%02x %02x %02x", 
21     ord substr($dbd, 4, 1),
22     ord substr($dbd, 5, 1),
23     ord substr($dbd, 6, 1),
24   );
25   my $delimiter = sprintf(
26     "%02x",
27     ord substr($dbd, 7, 1),
28   );
29
30   my $colnames = substr($dbd, $startOfColumnTypes + 7*$numcolumns - 2);
31   my @col = split(/\x00/, $colnames);
32
33   #print "Row length: $rowlength\n";
34   #print "Columns:    $numcolumns\n";
35   #print "Extra data: $extra\n";
36   #print "Delimiter:  $delimiter\n";
37
38   for (my $i = 1; $i <= $numcolumns; $i++) {
39     my $coltype = substr($dbd, 7*($i-1)+$startOfColumnTypes, 1);
40     my $collength = ord substr($dbd, 7*($i-1)+$startOfColumnTypes+1, 1);
41     printf ("Column %0" . length($numcolumns) . "d: %-8s %s (%d chars)\n", $i, $coltypes{$coltype}, $col[$i-1], $collength);
42   }
43
44 }
45
46
47
48
49