adding deletion of surveys to remove ou scripts
[migration-tools.git] / bibliofile / parse_dbd.pl
1 #!/usr/bin/perl -w
2
3 # Copyright 2009-2012, Equinox Software, Inc.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 use strict;
20
21 $/ = undef;
22
23 my %coltypes = ( 
24   'A' => 'Text',
25   'N' => 'Numeric',
26   'S' => 'Integer'
27 );
28 my $startOfColumnTypes = 8;
29
30 while (<>) {
31
32   my $dbd = $_;
33   my $rowlength = ord(substr($dbd, 0, 1)) + (256 * (ord(substr($dbd, 1, 1))));
34   my $numcolumns = ord substr($dbd, 2, 1);
35   my $extra = sprintf(
36     "%02x %02x %02x", 
37     ord substr($dbd, 4, 1),
38     ord substr($dbd, 5, 1),
39     ord substr($dbd, 6, 1),
40   );
41   my $delimiter = sprintf(
42     "%02x",
43     ord substr($dbd, 7, 1),
44   );
45
46   my $colnames = substr($dbd, $startOfColumnTypes + 7*$numcolumns - 2);
47   my @col = split(/\x00/, $colnames);
48
49   print "Row length: $rowlength\n";
50   print "Columns:    $numcolumns\n";
51   print "Extra data: $extra\n";
52   print "Delimiter:  $delimiter\n";
53
54   for (my $i = 1; $i <= $numcolumns; $i++) {
55     my $coltype = substr($dbd, 7*($i-1)+$startOfColumnTypes, 1);
56     my $collength = ord substr($dbd, 7*($i-1)+$startOfColumnTypes+1, 1);
57     printf ("Column %02d: %-8s %s (%d chars)\n", $i, $coltypes{$coltype}, $col[$i-1], $collength);
58   }
59
60 }
61
62
63
64
65