#!/usr/bin/perl if ($#ARGV < 0) { print STDERR "Usage: getsource sourcefile.pdb\n"; exit -1; } open(IN, "< $ARGV[0]") || die($ARGV[0]); # Read the header read(IN, $buf, 78); ($name, $attributes, $version, $creationDate, $modificationDate, $lastBackupDate, $modificationNumber, $appInfoID, $sortInfoID, $type, $creator, $uniqueIDSeed, $nextRecordListID, $numRecords) = unpack("A32 n n N N N N N N a4 a4 N N n", $buf); # Print out information from the header if (0) { print STDERR "name $name\n"; print STDERR "attributes $attributes\n"; print STDERR "version $version\n"; print STDERR "creationDate $creationDate\n"; print STDERR "modificationDate $modificationDate\n"; print STDERR "lastBackupDate $lastBackupDate\n"; print STDERR "modificationNumber $modificationNumber\n"; print STDERR "appInfoID $appInfoID\n"; print STDERR "sortInfoID $sortInfoID\n"; print STDERR "type $type\n"; print STDERR "creator $creator\n"; print STDERR "uniqueIDSeed $uniqueIDSeed\n"; print STDERR "nextRecordListID $nextRecordListID\n"; print STDERR "numRecords $numRecords\n"; } if ($creator ne "KSla") { print STDERR "Expecting creator to be KSla: file may be wrong type\n"; } if ($appInfoID) { print STDERR "Wasn't expecting appInfoID, things may go wrong\n"; } if ($numRecords != 1) { print STDERR "Expected one record, not $numRecords\n"; } # Read record info read(IN, $buf, 10); ($localChunkID, $attributes, $uniqueID) = unpack("N c a3", $buf); # Now read application header read(IN, $buf, 20); ($magic, $num, $xsize, $ysize, $charsize) = unpack("N5", $buf); if ($magic != 1234) { print STDERR "Warning: Magic number $magic not 1234\n"; } print "$name\n"; # Each bitmap is $ysize*$charsize bytes # Read bitmaps for ($i= 0 ; $i < $num; $i++) { read(IN, $bitmap[$i], $ysize*$charsize); } # Process strings and print out the bitmaps for ($i= 0 ; $i < $num; $i++) { $str = ""; while (1) { $got = read(IN, $buf, 1); if ($buf eq "\0" || ! defined $got) { last; } $str .= $buf; } print "$str\n"; # Unpack the bitmap into bits $nbytes = $ysize*$charsize; @bytes = unpack("C$nbytes", $bitmap[$i]); for ($line = 0; $line < $ysize; $line++) { for ($x = 0; $x < $xsize; $x++) { $byte = $bytes[($x>>3) + $line*$charsize]; $bit = 1<<(7-($x&7)); if ($byte & $bit) { print "*"; } else { print "."; } } print "\n"; } print "###\n"; }