5 if($ARGV[0] eq "--help")
8 usage: ucstoany.pl [-f][+u|-u]|[+f[+g|-g]] [+o|-o OUTPUT]
9 [+[CHAR]] [--] INPUT REGISTRY ENCODING [TABLE...]
11 -f Filter mode - don't output characters with unicode
12 FFFF. This is the default.
13 +u Unicode mode - encode characters with index >= 32 with
14 their unicodes. Default for ISO10646-1 output.
15 -u Index mode - encode the characters with their indexes
16 (FFFF counts). Default for any other output.
18 +f Fillout mode - encode with unicodes, output characters
19 with unicode FFFF as the default character.
20 +g Exchange the characters in range 00...1F with these at
21 C0...DF. Default for 8-pixel wide 256-character fonts
22 not starting with FFFD.
23 -g Do not exchange. Default for all other fonts.
25 +o Output to INPUT-REGISTRY-ENCODING (using the same name
26 as ucs2any, but preserving the INPUT directory).
27 -o NAME Output to NAME.
29 +b Use binary mode for output. Only affects the systems
30 that distinguish between text and binary files.
31 -b Use text mode for output. This is the default.
33 +[CHAR] Set the default character to CHAR. If no CHAR is
34 specified, the one from INPUT is used.
36 -- Terminate the option list.
40 TABLE An unicode table. Each line must either be blank or
41 contain exactly one hexadecimal unicode consisting of
42 maximum 4 digits. If no TABLE(s) are specified, the
43 standard input is read.
45 If no output is specified, the standard output is used.
47 If no default character is specified, 65533 (FFFD) is used for
48 unicode and fillout modes, 46 (period) for index mode.
50 Any options not specified in the above order are treated as
56 if($ARGV[0] eq "--version")
59 ucstoany.pl 0.1.0, Copyright (C) 2005 Dimitar Toshkov Zhekov
61 This program is free software; you can redistribute it and/or
62 modify it under the terms of the GNU General Public License as
63 published by the Free Software Foundation; either version 2 of
64 the License, or (at your option) any later version.
66 This program is distributed in the hope that it will be useful,
67 but WITHOUT ANY WARRANTY; without even the implied warranty of
68 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 GNU General Public License for more details.
71 Report bugs to jimmy\@is-vn.bg
86 elsif($ARGV[0] eq "-g")
95 if($ARGV[0] eq "-f") { shift @ARGV; }
102 elsif($ARGV[0] eq "-u")
114 elsif($ARGV[0] eq "-o")
118 $ARGV[0] ne "" || die("$0: -o requires a non-empty argument\n");
131 if($ARGV[0] eq "-b") { shift @ARGV; }
141 if($ARGV[0] eq '--') { shift @ARGV; }
142 elsif($ARGV[0] =~ /^([-+][0-9a-z])$/) { print STDERR
"$0: suspicuous $1, use -- to terminate the option list\n"; }
145 if($#ARGV == 2) { $ARGV[3] = "-"; }
146 elsif($#ARGV < 2) { die("$0: invalid arguments, try --help\n"); }
148 open(BDF
, "<$ARGV[0]") || die("$0: $ARGV[0]: $!\n");
158 if(/^STARTCHAR\s+(.+)$/) { $startchar = $1; }
159 elsif(/^ENCODING\s+(.+)$/) { $encoding = $1; }
163 $startchar ne "" || die("$0: $ARGV[0]: ENDCHAR without STARTCHAR\n");
164 $encoding ne "" || die("$0: $ARGV[0]: no ENCODING for $startchar\n");
165 $bitmap{$encoding} = $buffer;
166 $buffer = $startchar = $encoding = "";
168 elsif(!defined($exchange) && /^BBX\s+([0-9]+)/ && $1 != 8) { $exchange = 0; }
173 $charset = $_ = "-$ARGV[1]-$ARGV[2]";
174 if(!defined($control)) { $control = /^-iso10646-1$/i ?
32 : 65536; }
177 for($index = 3; $index <= $#ARGV; $index++)
179 open(UNI
, "<$ARGV[$index]") || die("$0: $ARGV[$index]: $!\n");
183 /^([0-9a-fA-F]{1,4})$/ || die("$0: $ARGV[$index]: invalid unicode $_\n");
184 push @unimap, hex($1);
185 if(!$control || hex($1) != 65535) { $chars++; }
190 if(!defined($exchange)) { $exchange = $chars == 256 && $unimap[0] != 65533; }
193 @unimap >= 0xE0 || die("$0: not enough characters for exchange\n");
194 for($index = 0x00; $index < 0x20; $index++)
196 $_ = $unimap[$index];
197 $unimap[$index] = $unimap[$index + 0xC0];
198 $unimap[$index + 0xC0] = $_;
202 if(!defined($default)) { $default = $control == 65536 ?
46 : 65533; }
203 elsif($default eq "")
206 /^DEFAULT_CHAR\s(.+)$/m || die("$0: $ARGV[0]: unable to obtain DEFAULT_CHAR\n");
210 if(!defined($output)) { $output = "-"; }
211 elsif($output eq "") { if($ARGV[0] =~ /^(.*).bdf$/) { $output = "$1$charset.bdf" ; } else { $output = "$ARGV[0]$charset"; } }
213 $header =~ s/^(FONT\s.*)-.*-.*$/$1$charset/m || die("$0: $output: unable to change FONT registry-encoding\n");
214 $header =~ s/^(CHARSET_REGISTRY\s).*$/$1"$ARGV[1]"/m || die("$0: $output: unable to change CHARSET_REGISTRY\n");
215 $header =~ s/^(CHARSET_ENCODING\s).*$/$1"$ARGV[2]"/m || die("$0: $output: unable to change CHARSET_ENCODING\n");
216 $header =~ s/^(DEFAULT_CHAR\s).*$/$1$default/m || die("$0: $output: unable to change DEFAULT_CHAR\n");
217 $header =~ s/^(CHARS\s).*$/$1$chars/m || die("$0: $output: unable to change CHARS\n");
219 sub int { $int = $!; }
223 $output ne "-" && unlink($output) != 1 && print STDERR
"$0: $output: $!\n";
227 open(OUT
, ">$output") || die("$0: $output: $!\n");
229 if($binary) { binmode(OUT
) || bye
("$0: $output: $!\n"); }
232 for($index = 0; $index < @unimap; $index++)
234 $_ = $unimap[$index];
235 $encoding = $index >= $control ?
$_ : $index;
236 if($_ == 65535) { if($control) { next; } else { $_ = $default ; } }
237 $bitmap{$_} =~ s/^(ENCODING\s).*$/$1$encoding/m || bye
("$0: $output: unable to change encoding for $_\n");
238 print OUT
$bitmap{$_};
242 close OUT
|| bye
("$0: $output: $!\n");
243 defined($int) && bye
("$0: $int\n");