chiark / gitweb /
ubuntu-daily: DVDs are not usefully jigdoable any more
[bin.git] / revod
1 #! /usr/bin/perl -w
2 use strict;
3
4 # Convert the output of 'od -tx1 -Ax' back to binary. The input is expected
5 # to look like this:
6 #
7 # 000000 eb 58 90 4d 41 4b 45 42 4f 4f 54 00 02 08 40 00
8 # 000010 01 00 00 00 00 f8 00 00 20 00 40 00 00 00 00 00
9 # [...]
10
11 binmode STDOUT;
12
13 my $index = 0;
14 my $prevblock;
15 while (<>) {
16     chomp;
17     next if $_ eq '*';
18     if (s/^([a-z0-9]+)(?:\s+|$)//) {
19         my $lineindex = hex($1);
20         while ($lineindex > $index) {
21             die "no previous block!" unless defined $prevblock;
22             for my $hex (split ' ', $prevblock) {
23                 print chr(hex($hex));
24                 ++$index;
25             }
26         }
27     }
28     for my $hex (split) {
29         print chr(hex($hex));
30         ++$index;
31     }
32     $prevblock = $_;
33 }