10 die "Usage: $0 filename.kbd charset [EURO|YEN]\n"
13 my $inputfile = shift; # first command argument
14 my $converter = Text::Iconv->new(shift, "UTF-8"); # second argument
20 while (my $arg = shift) {
25 die "Unknown encoding option '$arg'\n";
29 sub local_to_UCS_string
33 return $converter->convert($string);
40 return "'" . chr($ucs_char) . "'"
41 if 32 <= $ucs_char and $ucs_char <= 126; # print as ASCII if possible
42 # return sprintf "%d", $ucs_char; # <---- temporary decimal
43 return sprintf "0x%02x", $ucs_char
44 if $ucs_char <= 255; # print as hex number, else
45 return sprintf "0x%04x", $ucs_char;
52 my $ucs_char = ord(Encode::decode("UTF-8", local_to_UCS_string($char)));
54 $current_char = lc(chr($ucs_char))
55 if $current_char eq "";
57 $ucs_char = 0x20ac # replace with Euro character
58 if $ucs_char == 0xa4 and $use_euro and $current_char eq "e";
60 $ucs_char = 0xa5 # replace with Jap. Yen character on PC kbd
61 if $ucs_char == ord('\\') and $use_yen and $current_scancode == 125;
63 return prettyprint_token($ucs_char);
66 sub malformed_to_UCS_code
70 return prettyprint_token(ord(Encode::decode("UTF-8", $char)));
78 if $C =~ m/^([a-z][a-z0-9]*)$/; # key token
79 return local_to_UCS_code(chr($1))
80 if $C =~ m/^(\d+)$/; # decimal number
81 return local_to_UCS_code(chr(hex($1)))
82 if $C =~ m/^0x([0-9a-f]+)$/i; # hex number
83 return local_to_UCS_code(chr(ord($1)))
84 if $C =~ m/^'(.)'$/; # character
85 return malformed_to_UCS_code($1)
86 if $C =~ m/^'(.+)'$/; # character
87 return "<?$C?>"; # uncovered case
90 sub tokenize { # split on white space and parentheses (but not within token)
93 $line =~ s/'\('/ _lpar_ /g; # prevent splitting of '('
94 $line =~ s/'\)'/ _rpar_ /g; # prevent splitting of ')'
95 $line =~ s/'''/'_squote_'/g; # remove quoted single quotes from matches below
96 $line =~ s/([()])/ $1 /g; # insert blanks around remaining parentheses
99 $matches = ($line =~ s/^([^']*)'([^']+)'/$1_squoteL_$2_squoteR_/g);
101 $line =~ s/_squoteL_ _squoteR_/ _spc_ /g; # prevent splitting of ' '
102 my @KEYTOKEN = split (" ", $line);
103 grep(s/_squote[LR]?_/'/g, @KEYTOKEN);
104 grep(s/_spc_/' '/, @KEYTOKEN);
105 grep(s/_lpar_/'('/, @KEYTOKEN);
106 grep(s/_rpar_/')'/, @KEYTOKEN);
111 open FH, "<$inputfile";
114 print local_to_UCS_string($_);
118 my @KEYTOKEN = tokenize($_);
121 foreach $C (@KEYTOKEN) {
124 $current_scancode = -1;
125 if ($C =~ m/^\s*\d/) { # line begins with key code number
126 $current_scancode = $C;
128 } elsif ($C =~ m/^[a-z]/) { # line begins with accent name or paren
129 printf " %-4s ", $C; # accent name starts accent definition
130 } elsif ($C eq "(") {
131 printf "%17s", "( "; # paren continues accent definition
133 print "Unknown input line format: $_";
137 if ($C =~ m/^([BCNO])$/) {
138 print " $1"; # special case: effect of Caps Lock/Num Lock
139 } elsif ($C eq "(") {
142 } elsif ($C eq ")") {
145 printf "%-6s ", convert_token($C);