だいぶ前に作った _CATALOG.VIX を分割して jpg に出力する Perl スクリプト。不完全。Linux では動かない。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
C:\>perl --version This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 817 [257965] provided by ActiveState http://www.ActiveState.com Built Mar 20 2006 17:54:25 Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
$fn = $ARGV[0]; $count = 1; mkdir 'data'; if ($fn) { print "fn = $fn\n"; &vixsplit; } else { opendir(DH, "."); @fs = readdir(DH); closedir(DH); for $fn (@fs) { unless ($fn =~ m/\.vix$/i) { next; } print "************************** fn = $fn\n"; &vixsplit; } } sub vixsplit { open(IN, "< $fn") || die "$0: can't open: $fn\n"; binmode(IN); $b = &B4; # ID printf("%s\n", $b); &splitVix; close(IN); } sub splitVix { $b = &B2; printf("%s\n", $b); if ($b eq "ff00") { print "file head start marker\n"; } $b = &B2; while ($b ne "ff01") { $len = &B4; $len = hex($len); printf("len = %d bytes\n", $len); read(IN, $buf, $len); $b = &B2; printf("%s\n", $b); } $b = &B2; printf("%s\n", $b); while (1) { $m = &B2; if ($m eq "0002") { $m = &B2; # 0001 next; } $l = &B4; $l = hex($l); unless (read(IN, $data, $l)) { return; } if ($m eq "0003") { $fname =~ s/^\s+//; $fname =~ s/\s+$//; do { $fname = sprintf("./data/%d_%s.jpg", $count++, $data); } while ( -f $fname ); printf("fname = $fname\n"); } elsif ($m eq "000d") { open(OUT, "> $fname") || die "Cannot open $fname\n"; binmode(OUT); print OUT $data; close(OUT); } } } sub field { local($marker, $len, $data); $marker = &B2; printf("%s\n", $marker); printf("marker = %s, ", $marker); $len = &B4; printf("%s\n", $len); $len = hex($len); printf("len = %d bytes, \n", $len); return ($marker, $len); } sub B4 { $b2 = &B2; $b1 = &B2; return $b1 . $b2; } sub B2 { local($buf, $b2, $b1); read(IN, $buf, 1); $b2 = unpack("C*", $buf); read(IN, $buf, 1); $b1 = unpack("C*", $buf); return sprintf("%02x%02x", $b1, $b2); } 1; |