#!/usr/bin/env perl use 5.010; use strict; use warnings; use utf8; use open OUT => ':utf8', ':std'; use Data::Dump 'pp'; our $VERSION = '1.01'; # translation table for deprecated code points my %replace = ( 0xE001 => 0, # join lines: not accepted 0xE004 => 0, # umlaut is no different from diaeresis 0x0308 0xE005 => "\x{0344}", # discouraged 0xE006 => "\x{0300}", 0xE007 => "\x{0301}", 0xE008 => "\x{0302}", 0xE009 => "\x{0303}", 0xE00A => "\x{0304}", 0xE00B => "\x{0306}", 0xE00C => "\x{0307}", 0xE00D => "\x{0308}", 0xE00E => "\x{030A}", 0xE00F => "\x{030B}", 0xE010 => "\x{030C}", 0xE011 => "\x{0327}", 0xE012 => "\x{0328}", 0xE013 => "\x{0332}", 0xE014 => "\x{0333}", 0xE015 => "\x{0338}", 0xE016 => "\x{0345}", 0xE017 => "\x{0314}", 0xE018 => "\x{0313}", 0xE019 => "\x{1FFE}", 0xE01A => "\x{1FBF}", 0xE01B => "\x{03D0}", # middle beta = curled beta? 0xE01C => "\x{25CB}", 0xE01D => "\x{0192}", 0xE01E => "\x{0292}", 0xE01F => "\x{33C2}", # am, compatibility char 0xE020 => "\x{33D8}", # pm, compatibility char 0xE021 => "\x{2121}", 0xE022 => "\x{FE8E}", 0xE023 => 0, # dutch guilder 0192 is already encoded, and not very useful anyway 0xE024 => "\x{0393}", 0xE025 => "\x{20D7}", # also 20D1; non-spacing 0xE026 => "\x{1FEF}", 0xE027 => "\x{1FC0}", 0xE028 => "\x{01F0}", #but uppercase ); # expect input data source at command line @ARGV or die "Specify input source file or - for STDIN\n"; # skip everything until a character indented by 1 space (table start) do { $_ = readline; defined or die "Premature input end"; } until s/^\s(?=\S)//; chomp; my @line = $_; # add first line (already read, assume it's ok) # read the rest of the character table while ($_ = readline) { # check for table end (chapter 4) last if /^\d/; # parse table lines (ignore (unindented) page break) next unless s/^ //; chomp; # append line contents if (s/^ {15}/ /) { # continuation line (add to last entry) $line[-1] .= $_; } else { # add a new entry push @line, $_; } } # output perl code of hash # (assume no backslashes or curlies, so we can just q{} w/o escaping) say "# automatically generated by $0"; say 'use utf8;'; say '+{'; for (@line) { my ($mnem, $chrhex, $name) = split / +/, $_, 3; next if length $mnem != 2; my $chrnum = hex $chrhex; my $chr = $replace{$chrnum} // chr $chrnum or next; my $chrstr = pp $chr; say "q{$mnem} => $chrstr, # $name"; } say '}'; __END__ =head1 NAME mkdigraphs-rfc - Output digraph data from RFC-1345 =head1 SYNOPSIS Extract digraphs from text specifications as a perl hash: mkdigraphs-rfc rfc1345.txt >digraphs-rfc.inc.pl Input can be the literal RFC (or similar) document: curl http://www.ietf.org/rfc/rfc1345.txt | mkdigraphlist - Test by printing the character for DO (should be a dollar sign): perl -e'$di = do "digraphs-rfc.inc.pl"; print chr $di->{DO}' =head1 DESCRIPTION Parses the official RFC-1345 document, searching the 'character mnemonic table' for all digraph definitions. If successful, Perl code is output resulting in a hash with Unicode code points keyed by digraph. Obsolete values (references to private use area) are converted to modern alternatives. Any errors and warnings are given at STDERR. =head1 AUTHOR Mischa POSLAWSKY =head1 LICENSE Licensed under the GNU Affero General Public License version 3.