X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/1e3cacf005302b9d4812fc9fe690e4e09b8a330b..4cccd0f03b54ed366c5de96fb40cea688c6482e9:/rfc1345convert diff --git a/rfc1345convert b/rfc1345convert index c1b3861..412bac1 100644 --- a/rfc1345convert +++ b/rfc1345convert @@ -46,9 +46,45 @@ for (@t) { $di{$mnem} = hex $char; } +# personal addendums +my @extra; +if (-r 'shiar.inc.txt') { + open my $include, '<:utf8', 'shiar.inc.txt'; + for (readline $include) { + m{^([!"%'-Z_a-z]{2}) (.)} or next; + warn("$1 already defined"), next if defined $di{$1}; + $di{$1} = ord $2; + push @extra, $1; + } +} +warn $@ if $@; + +# optionally get unicode character information +my %info = eval { + require Unicode::UCD; + map { + $_ => Unicode::UCD::charinfo($di{$_}) + || { block => '?', category => 'Xn', name => '', script => '' } + } keys %di; +}; + +# add custom categories for certain blocks +for (values %info) { + $_->{category} .= ' Xa' if $_->{block} eq 'Basic Latin'; + $_->{category} .= ' Xl' if $_->{block} eq 'Latin-1 Supplement'; +} + +# mark unofficial extras as such +$info{$_}->{category} .= ' Xz' for @extra; + # 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; +printf "q{%s}=>[%s],\n", $_, join(',', + $di{$_}, # glyph code point + $info{$_} # optional additional arguments + ? map {"'$_'"} @{ $info{$_} }{qw/name category script/} + : () +) for sort keys %di; print "}\n";