tools: Do not hardcode path to perl.
[dragonfly.git] / tools / tools / locale / tools / UTF82encoding.pl
CommitLineData
344be199 1#!/usr/bin/env perl -w
252345eb
JM
2
3use strict;
4use Data::Dumper;
5
6if ($#ARGV != 1) {
7 print "Usage: $0 <cldr dir> <input file>\n";
8 exit;
9}
10
11open(FIN, "$ARGV[0]/posix/UTF-8.cm");
12my @lines = <FIN>;
13chomp(@lines);
14close(FIN);
15
16my %cm = ();
17foreach my $line (@lines) {
18 next if ($line =~ /^#/);
19 next if ($line eq "");
20 next if ($line !~ /^</);
21
22 my @a = split(" ", $line);
23 next if ($#a != 1);
24
25 $a[1] =~ s/\\x//g;
26 $a[0] =~ s/_/ /g;
27 $cm{$a[1]} = $a[0] if (!defined $cm{$a[1]});
28}
29
30open(FIN, $ARGV[1]);
31@lines = <FIN>;
32chomp(@lines);
33close(FIN);
34
35foreach my $line (@lines) {
36 if ($line =~ /^#/) {
37 print "$line\n";
38 next;
39 }
40
41 my @l = split(//, $line);
42 for (my $i = 0; $i <= $#l; $i++) {
43 my $hex = sprintf("%X", ord($l[$i]));
44
45 if (( $l[$i] gt "\x20")
46 && ($l[$i] lt "a" || $l[$i] gt "z")
47 && ($l[$i] lt "A" || $l[$i] gt "Z")
48 && ($l[$i] lt "0" || $l[$i] gt "9")
49 && ($l[$i] lt "\x80")) {
50 print $l[$i];
51 next;
52 }
53
54 if (defined $cm{$hex}) {
55 print $cm{$hex};
56 next;
57 }
58
59 $hex = sprintf("%X%X", ord($l[$i]), ord($l[$i + 1]));
60 if (defined $cm{$hex}) {
61 $i += 1;
62 print $cm{$hex};
63 next;
64 }
65
66 $hex = sprintf("%X%X%X",
67 ord($l[$i]), ord($l[$i + 1]), ord($l[$i + 2 ]));
68 if (defined $cm{$hex}) {
69 $i += 2;
70 print $cm{$hex};
71 next;
72 }
73
74 print "\n--$hex--\n";
75 }
76 print "\n";
77
78}