5 usage: mkutable [-n] [-f#] type... [--] [<] UnicodeData.txt
6 -n = take non-matching types
7 -f = zero-based type field (default 2)
10 use vars qw( $opt_f $opt_n );
14 # Override Unicode tables for certain control chars
15 # that are expected to be found in normal text files.
17 0x08 => 1, # backspace
20 0x0c => 1, # form feed
21 0x0d => 1, # carriage return
24 exit (main() ? 0 : 1);
29 my $args = join ' ', @ARGV;
30 my $header = "/* Generated by \"$0 $args\" on $date */\n";
32 die $USAGE if not getopts('f:n');
33 $type_field = $opt_f if $opt_f;
36 while ($arg = shift @ARGV) {
40 my %out = ( 'types' => \%types );
47 my @fields = split /;/;
49 my ($lo_code, $hi_code);
50 my $codes = $fields[0];
51 if ($codes =~ /(\w+)\.\.(\w+)/) {
55 $lo_code = $hi_code = hex $fields[0];
57 my $type = $fields[$type_field];
59 for ($last_code = $lo_code; $last_code <= $hi_code; ++$last_code) {
60 $type = 'Zs' if $force_space{$last_code};
61 output(\%out, $last_code, $type);
64 output(\%out, $last_code);
69 my ($out, $code, $type) = @_;
70 my $type_ok = ($type and ${${$out}{types}}{$type});
71 $type_ok = not $type_ok if $opt_n;
72 my $prev_code = $$out{prev_code};
75 end_run($out, $prev_code);
76 } elsif (not $$out{in_run} or $type ne $$out{run_type} or $code != $prev_code+1) {
77 end_run($out, $prev_code);
78 start_run($out, $code, $type);
80 $$out{prev_code} = $code;
84 my ($out, $code, $type) = @_;
85 $$out{start_code} = $code;
86 $$out{prev_code} = $code;
87 $$out{run_type} = $type;
92 my ($out, $code) = @_;
93 return if not $$out{in_run};
94 printf "\t{ 0x%04x, 0x%04x }, /* %s */\n", $$out{start_code}, $code, $$out{run_type};