add options, that sometimes work, to print desc and md5sum from .xwd

files.  Still need to figure out how to parse binary into UTF-8.
This commit is contained in:
Eric House 2012-09-08 13:20:12 -07:00
parent 047f68aafd
commit 1957ad3dbe

View file

@ -26,6 +26,10 @@ use Encode 'from_to';
use Encode; use Encode;
my $gInFile; my $gInFile;
my $gSumOnly = 0;
my $gSum;
my $gDescOnly = 0;
my $gDesc;
my $gDoRaw = 0; my $gDoRaw = 0;
my $gDoJSON = 0; my $gDoJSON = 0;
my $gFileType; my $gFileType;
@ -35,9 +39,11 @@ use Fcntl 'SEEK_CUR';
sub systell { sysseek($_[0], 0, SEEK_CUR) } sub systell { sysseek($_[0], 0, SEEK_CUR) }
sub usage() { sub usage() {
print STDERR "USAGE: $0 " print STDERR "USAGE: $0"
. "[-raw | -json] " . " [-raw | -json] "
. "-dict <xwdORpdb>" . " [-get-sum]"
. " [-get-desc]"
. " -dict <xwdORpdb>"
. "\n" . "\n"
. "\t(Takes a .pdb or .xwd and prints its words to stdout)\n"; . "\t(Takes a .pdb or .xwd and prints its words to stdout)\n";
exit 1; exit 1;
@ -52,6 +58,10 @@ sub parseARGV() {
$gDoJSON = 1; $gDoJSON = 1;
} elsif ( $parm eq "-dict" ) { } elsif ( $parm eq "-dict" ) {
$gInFile = shift(@ARGV); $gInFile = shift(@ARGV);
} elsif ( $parm eq "-get-sum" ) {
$gSumOnly = 1;
} elsif ( $parm eq "-get-desc" ) {
$gDescOnly = 1;
} else { } else {
usage(); usage();
} }
@ -161,6 +171,10 @@ sub printHeader($$) {
printf STDERR "skipped %d bytes of header:\n", $len + 2; printf STDERR "skipped %d bytes of header:\n", $len + 2;
my $asStr = Encode::decode_utf8($buf); my $asStr = Encode::decode_utf8($buf);
my @strs = split( '\0', $asStr ); my @strs = split( '\0', $asStr );
# There are variable numbers of strings showing up in this thing.
# Need to figure out the right way to unpack the thing.
$gDesc = $strs[1];
$gSum = $strs[2];
foreach my $str (@strs) { foreach my $str (@strs) {
if ( 0 < length($str) ) { if ( 0 < length($str) ) {
print STDERR 'Got: ', $str, "\n"; print STDERR 'Got: ', $str, "\n";
@ -204,6 +218,7 @@ sub mergeSpecials($$) {
sub prepXWD($$$$) { sub prepXWD($$$$) {
my ( $fh, $facRef, $nodesRef, $startRef ) = @_; my ( $fh, $facRef, $nodesRef, $startRef ) = @_;
my $done = 1;
printf STDERR "at 0x%x at start\n", systell($fh); printf STDERR "at 0x%x at start\n", systell($fh);
my $buf; my $buf;
@ -212,6 +227,15 @@ sub prepXWD($$$$) {
$gNodeSize = nodeSizeFromFlags( $fh, $flags ); $gNodeSize = nodeSizeFromFlags( $fh, $flags );
if ( $gSumOnly ) {
print STDOUT $gSum, "\n";
} elsif( $gDescOnly ) {
print STDOUT $gDesc, "\n";
} else {
$done = 0;
}
if ( !$done ) {
my $nSpecials; my $nSpecials;
my $faceCount = readXWDFaces( $fh, $facRef, \$nSpecials ); my $faceCount = readXWDFaces( $fh, $facRef, \$nSpecials );
@ -238,7 +262,9 @@ sub prepXWD($$$$) {
my @nodes = readNodesToEnd( $fh ); my @nodes = readNodesToEnd( $fh );
@$nodesRef = @nodes; @$nodesRef = @nodes;
}
print STDERR "prepXWD done\n"; print STDERR "prepXWD done\n";
return $done;
} # prepXWD } # prepXWD
sub readPDBSpecials($$$$$) { sub readPDBSpecials($$$$$) {
@ -448,17 +474,20 @@ binmode INFILE;
my @faces; my @faces;
my @nodes; my @nodes;
my $startIndex; my $startIndex;
my $done;
if ( $gFileType eq "xwd" ){ if ( $gFileType eq "xwd" ){
prepXWD( *INFILE, \@faces, \@nodes, \$startIndex ); $done = prepXWD( *INFILE, \@faces, \@nodes, \$startIndex );
} elsif ( $gFileType eq "pdb" ) { } elsif ( $gFileType eq "pdb" ) {
prepPDB( *INFILE, \@faces, \@nodes, \$startIndex ); $done = prepPDB( *INFILE, \@faces, \@nodes, \$startIndex );
} }
close INFILE; close INFILE;
die "no nodes!!!" if 0 == @nodes; die "no nodes!!!" if 0 == @nodes;
if ( $gDoRaw ) { if ( $done ) {
# we're done...
} elsif ( $gDoRaw ) {
printNodes( \@nodes, \@faces ); printNodes( \@nodes, \@faces );
} elsif ( $gDoJSON ) { } elsif ( $gDoJSON ) {
print "dict = {\n"; print "dict = {\n";