if (true || '\'); then exec perl -CI "$0" "$@"; fi # ') {}
# The above uses the fact that backslash isn't special in single quotes in
# shell script, whereas in perl it escapes the following single quote.
#
# The problem it tries to solve is that we want perl to be run with -CI flag
# (to have stdin interpreted as utf-8), so we would use `#! /usr/bin/perl -CI',
# except that if we do that then perl 5.10 complains about it being too late
# to apply -CI if the script is run with `perl -CI ./utf8-to-roff', as we want
# to do from the Makefile. The reason we don't do `./utf8-to-roff' from the makefile
# is that then we require the #! line to have the right location of perl instead of
# just consulting the path. (Similarly, we could use `#! /usr/bin/env perl -CI',
# though that still requires that /usr/bin/env exist.) The reason we don't just
# remove the `-CI' from the #! line is that then the script couldn't be run correctly
# with ./utf8-to-roff.
# Converts a man page from utf8 (not understood by groff 1.18) to groff escapes.
# I couldn't find any existing tool to convert from utf8 to groff, though I
# seem to recall seeing some code to do so somewhere.
#
# Hereby released into public domain by Peter Moulder.
use warnings;
use strict;
# Table generated automatically using:
# zcat /usr/share/man/man7/groff_char.7.gz |groff -man -Tutf8| col -pb | grep '\\\['|
# perl -CI -nae 'my ($ch, $seq) = @F; if (ord($ch) >= 128) { printf(" 0x\%x, q{\%s},\n", ord($ch), $seq); }'
# with č (0x10d) manually translated as cˇ (c\[ah]). (Anyone have a better translation, e.g. using
# overprint? \[vc] doesn't work, btw.)
# Similarly, ć (0x107) has been manually translated as c´ (c\[aa]), and ń (0x144) as n´ (n\[aa]).
my %map = (
0xd0, q{\[-D]},
0xf0, q{\[Sd]},
0xde, q{\[TP]},
0xfe, q{\[Tp]},
0xdf, q{\[ss]},
0xfb00, q{\[ff]},
0xfb01, q{\[fi]},
0xfb02, q{\[fl]},
0xfb03, q{\[Fi]},
0xfb04, q{\[Fl]},
0xc6, q{\[AE]},
0xe6, q{\[ae]},
0x152, q{\[OE]},
0x153, q{\[oe]},
0x131, q{\[.i]},
0xc1, q{\['A]},
0xc9, q{\['E]},
0xcd, q{\['I]},
0xd3, q{\['O]},
0xda, q{\['U]},
0xdd, q{\['Y]},
0xe1, q{\['a]},
0xe9, q{\['e]},
0xed, q{\['i]},
0xf3, q{\['o]},
0xfa, q{\['u]},
0xfd, q{\['y]},
0xc4, q{\[:A]},
0xcb, q{\[:E]},
0xcf, q{\[:I]},
0xd6, q{\[:O]},
0xdc, q{\[:U]},
0x178, q{\[:Y]},
0xe4, q{\[:a]},
0xeb, q{\[:e]},
0xef, q{\[:i]},
0xf6, q{\[:o]},
0xfc, q{\[:u]},
0xff, q{\[:y]},
0xc2, q{\[^A]},
0xca, q{\[^E]},
0xce, q{\[^I]},
0xd4, q{\[^O]},
0xdb, q{\[^U]},
0xe2, q{\[^a]},
0xea, q{\[^e]},
0xee, q{\[^i]},
0xf4, q{\[^o]},
0xfb, q{\[^u]},
0xc0, q{\[`A]},
0xc8, q{\[`E]},
0xcc, q{\[`I]},
0xd2, q{\[`O]},
0xd9, q{\[`U]},
0xe0, q{\[`a]},
0xe8, q{\[`e]},
0xec, q{\[`i]},
0xf2, q{\[`o]},
0xf9, q{\[`u]},
0xc3, q{\[~A]},
0xd1, q{\[~N]},
0xd5, q{\[~O]},
0xe3, q{\[~a]},
0xf1, q{\[~n]},
0xf5, q{\[~o]},
0x107, q{c\[aa]}, # Added manually; see above.
0x10d, q{c\[ah]}, # Added manually; see above.
0x160, q{\[vS]},
0x161, q{\[vs]},
0x17d, q{\[vZ]},
0x17e, q{\[vz]},
0xc7, q{\[,C]},
0xe7, q{\[,c]},
0x141, q{\[/L]},
0x142, q{\[/l]},
0x144, q{n\[aa]}, # Added manually; see above.
0xd8, q{\[/O]},
0xf8, q{\[/o]},
0xc5, q{\[oA]},
0xe5, q{\[oa]},
0x2dd, q{\[a"]},
0xaf, q{\[a-]},
0x2d9, q{\[a.]},
0xb4, q{\[aa]},
0x2d8, q{\[ab]},
0xb8, q{\[ac]},
0xa8, q{\[ad]},
0x2c7, q{\[ah]},
0x2da, q{\[ao]},
0x2db, q{\[ho]},
0x223c, q{\[ti]},
0x201e, q{\[Bq]},
0x201a, q{\[bq]},
0x201c, q{\[lq]},
0x201d, q{\[rq]},
0x2018, q{\[oq]},
0x2019, q{\[cq]},
0xab, q{\[Fo]},
0xbb, q{\[Fc]},
0x2039, q{\[fo]},
0x203a, q{\[fc]},
0xa1, q{\[r!]},
0xbf, q{\[r?]},
0x2014, q{\[em]},
0x2013, q{\[en]},
0x2010, q{\[hy]},
0x2329, q{\[la]},
0x232a, q{\[ra]},
0x2190, q{\[<-]},
0x2192, q{\[->]},
0x2194, q{\[<>]},
0x2193, q{\[da]},
0x21d1, q{\[ua]},
0x21d0, q{\[lA]},
0x21d2, q{\[rA]},
0x21d4, q{\[hA]},
0x21d3, q{\[dA]},
0x21d1, q{\[uA]},
0x2500, q{\[an]},
0x2502, q{\[br]},
0x2502, q{\[bv]},
0xa6, q{\[bb]},
0x25ef, q{\[ci]},
0xb7, q{\[bu]},
0x2021, q{\[dd]},
0x2020, q{\[dg]},
0x25ca, q{\[lz]},
0x25a1, q{\[sq]},
0xb6, q{\[ps]},
0xa7, q{\[sc]},
0x261c, q{\[lh]},
0x261e, q{\[rh]},
0x240d, q{\[CR]},
0xa9, q{\[co]},
0xae, q{\[rg]},
0x2122, q{\[tm]},
0x21d1, q{\[Do]},
0xa2, q{\[ct]},
0x20ac, q{\[eu]},
0x20ac, q{\[Eu]},
0xa5, q{\[Ye]},
0xa3, q{\[Po]},
0xa4, q{\[Cs]},
0x192, q{\[Fn]},
0xb0, q{\[de]},
0x2030, q{\[%0]},
0x2032, q{\[fm]},
0x2033, q{\[sd]},
0xb5, q{\[mc]},
0xaa, q{\[Of]},
0xba, q{\[Om]},
0x2227, q{\[AN]},
0x2228, q{\[OR]},
0xac, q{\[no]},
0x2203, q{\[te]},
0x2200, q{\[fa]},
0x220b, q{\[st]},
0x2234, q{\[3d]},
0x2234, q{\[tf]},
0xbd, q{\[12]},
0xbc, q{\[14]},
0xbe, q{\[34]},
0xb9, q{\[S1]},
0xb2, q{\[S2]},
0xb3, q{\[S3]},
0xb1, q{\[+-]},
0xb1, q{\[t+-]},
0xb7, q{\[pc]},
0x22c5, q{\[md]},
0xd7, q{\[mu]},
0xd7, q{\[tmu]},
0x2297, q{\[c*]},
0x2295, q{\[c+]},
0xf7, q{\[di]},
0xf7, q{\[tdi]},
0x2044, q{\[f/]},
0x2217, q{\[**]},
0x2264, q{\[<=]},
0x2265, q{\[>=]},
0x2260, q{\[!=]},
0x2261, q{\[==]},
0x2245, q{\[=~]},
0x223c, q{\[ap]},
0x2248, q{\[~~]},
0x2248, q{\[~=]},
0x221d, q{\[pt]},
0x2205, q{\[es]},
0x2208, q{\[mo]},
0x2209, q{\[nm]},
0x2284, q{\[nb]},
0x2282, q{\[sb]},
0x2283, q{\[sp]},
0x2286, q{\[ib]},
0x2287, q{\[ip]},
0x2229, q{\[ca]},
0x222a, q{\[cu]},
0x2220, q{\[/_]},
0x22a5, q{\[pp]},
0x222b, q{\[is]},
0x2211, q{\[sum]},
0x220f, q{\[product]},
0x2207, q{\[gr]},
0x221a, q{\[sr]},
0x203e, q{\[rn]},
0x221e, q{\[if]},
0x2135, q{\[Ah]},
0x2111, q{\[Im]},
0x211c, q{\[Re]},
0x2118, q{\[wp]},
0x2202, q{\[pd]},
0x391, q{\[*A]},
0x392, q{\[*B]},
0x39e, q{\[*C]},
0x394, q{\[*D]},
0x395, q{\[*E]},
0x3a6, q{\[*F]},
0x393, q{\[*G]},
0x398, q{\[*H]},
0x399, q{\[*I]},
0x39a, q{\[*K]},
0x39b, q{\[*L]},
0x39c, q{\[*M]},
0x39d, q{\[*N]},
0x39f, q{\[*O]},
0x3a0, q{\[*P]},
0x3a8, q{\[*Q]},
0x3a1, q{\[*R]},
0x3a3, q{\[*S]},
0x3a4, q{\[*T]},
0x3a5, q{\[*U]},
0x3a9, q{\[*W]},
0x3a7, q{\[*X]},
0x397, q{\[*Y]},
0x396, q{\[*Z]},
0x3b1, q{\[*a]},
0x3b2, q{\[*b]},
0x3be, q{\[*c]},
0x3b4, q{\[*d]},
0x3b5, q{\[*e]},
0x3c6, q{\[*f]},
0x3d5, q{\[+f]},
0x3b3, q{\[*g]},
0x3b8, q{\[*h]},
0x3d1, q{\[+h]},
0x3b9, q{\[*i]},
0x3ba, q{\[*k]},
0x3bb, q{\[*l]},
0x3bc, q{\[*m]},
0x3bd, q{\[*n]},
0x3bf, q{\[*o]},
0x3c0, q{\[*p]},
0x3d6, q{\[+p]},
0x3c8, q{\[*q]},
0x3c1, q{\[*r]},
0x3c3, q{\[*s]},
0x3c4, q{\[*t]},
0x3c5, q{\[*u]},
0x3c9, q{\[*w]},
0x3c7, q{\[*x]},
0x3b7, q{\[*y]},
0x3b6, q{\[*z]},
0x3c2, q{\[ts]},
0x2663, q{\[CL]},
0x2660, q{\[SP]},
0x2665, q{\[HE]},
0x2666, q{\[DI]},
);
#while(<>) {
# s/([^ -~])/(ord($1) < 128 ? $1 : defined($map{$1}) ? $map{$1} : sprintf("\\u%4x", $1))/ge;
# print;
#}
#exit 0;
my $ch;
while(defined($ch = getc(STDIN))) {
my $ord = ord($ch);
if ($ord < 128) {
print $ch;
} else {
my $out = $map{$ord};
if (defined($out)) {
print $out;
} else {
die "Untranslatable character \\u" . sprintf("%X", ord($ch)) . " / `$ch'";
}
}
}