diff options
Diffstat (limited to 'contrib/less/mkutable')
-rwxr-xr-x | contrib/less/mkutable | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/contrib/less/mkutable b/contrib/less/mkutable index 803335b924eb..ff107b51f007 100755 --- a/contrib/less/mkutable +++ b/contrib/less/mkutable @@ -4,14 +4,14 @@ use strict; my $USAGE = <<__EOF__; usage: mkutable [-n] [-f#] type... [--] [<] UnicodeData.txt -n = take non-matching types - -f = zero-based type field (default 2) + -f = zero-based type field (default 2) __EOF__ use vars qw( $opt_f $opt_n ); use Getopt::Std; my $type_field = 2; -exit (main() ? 1 : 0); +exit (main() ? 0 : 1); sub main { my $date = `date`; @@ -28,48 +28,58 @@ sub main { $types{$arg} = 1; } my %out = ( 'types' => \%types ); - my $last_code = 0; print $header; + my $last_code = 0; while (<>) { chomp; s/#.*//; my @fields = split /;/; next if not @fields; - my $code = hex $fields[0]; + my ($lo_code, $hi_code); + my $codes = $fields[0]; + if ($codes =~ /(\w+)\.\.(\w+)/) { + $lo_code = hex $1; + $hi_code = hex $2; + } else { + $lo_code = $hi_code = hex $fields[0]; + } my $type = $fields[$type_field]; $type =~ s/\s//g; - while (++$last_code < $code) { - output(\%out, $last_code, '?'); + for ($last_code = $lo_code; $last_code <= $hi_code; ++$last_code) { + output(\%out, $last_code, $type); } - output(\%out, $code, $type); } - output(\%out, $last_code+1, '?'); + output(\%out, $last_code); + return 1; } sub output { my ($out, $code, $type) = @_; - my $match = ${${$out}{types}}{$type}; - my $type_change = (not $$out{start_type} or $type ne $$out{start_type}); - $match = not $match if $opt_n; - if ($match and (not $$out{in_run} or $type_change)) { - end_run($out, $code-1); + my $type_ok = ($type and ${${$out}{types}}{$type}); + $type_ok = not $type_ok if $opt_n; + my $prev_code = $$out{prev_code}; + + if (not $type_ok) { + end_run($out, $prev_code); + } elsif (not $$out{in_run} or $type ne $$out{run_type} or $code != $prev_code+1) { + end_run($out, $prev_code); start_run($out, $code, $type); - } elsif (not $match and $$out{in_run}) { - end_run($out, $code-1); } + $$out{prev_code} = $code; } sub start_run { my ($out, $code, $type) = @_; $$out{start_code} = $code; - $$out{start_type} = $type; + $$out{prev_code} = $code; + $$out{run_type} = $type; $$out{in_run} = 1; } sub end_run { my ($out, $code) = @_; return if not $$out{in_run}; - printf "\t{ 0x%04x, 0x%04x }, /* %s */\n", $$out{start_code}, $code, $$out{start_type}; + printf "\t{ 0x%04x, 0x%04x }, /* %s */\n", $$out{start_code}, $code, $$out{run_type}; $$out{in_run} = 0; } |