X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/e84402a9c62d8b57f9fd78a81d639692108a46e3..1e3cacf005302b9d4812fc9fe690e4e09b8a330b:/rfc1345convert diff --git a/rfc1345convert b/rfc1345convert new file mode 100644 index 0000000..c1b3861 --- /dev/null +++ b/rfc1345convert @@ -0,0 +1,54 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Data::Dumper; + +our $VERSION = '1.00'; + +if (0) { + #TODO: automatic download if not specified on stdin + require LWP::Simple; + LWP::Simple::get('http://www.ietf.org/rfc/rfc1345.txt'); +} + +# skip everything until a character indented by 1 space (table start) +do {$_ = <>} until /^\s\S/; + +my @t = $_; # add first line (already read, assume it's ok) + +# read the rest of the character table +while ($_ = <>) { + # check for table end (chapter 4) + last if /^4/; + + # parse table lines (ignore (unindented) page break) + next unless s/^ //; + chomp; + + # add the line to @t + if (s/^ {15}/ /) { + # continuation line (add to last entry) + $t[-1] .= $_; + } + else { + # add a new entry + push @t, $_; + } +} + +# create a hash of desired input +my %di; +for (@t) { + my ($mnem, $char, $name) = split / +/, $_, 3; + next if length $mnem != 2; + $di{$mnem} = hex $char; +} + +# output perl code of hash +# (assume no backslashes or curlies, so we can just q{} w/o escaping) +print "{\n"; +print "q{$_}=>$di{$_},\n" for sort keys %di; +print "}\n"; +