1 #!/usr/local/bin/perl -w
3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright 2009 Edwin Groothuis <edwin@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 open(FIN, "$etcdir/charmaps.xml");
47 my $xml = new XML::Parser(Handlers => {
52 $xml->parse(join("", @xml));
63 while ($#attrs >= 0) {
64 $attrs{$attrs[0]} = $attrs[1];
69 $data{element}{++$index} = $element;
72 && $data{element}{1} eq "languages"
73 && $element eq "language") {
74 my $name = $attrs{name};
75 my $countries = $attrs{countries};
76 my $encoding = $attrs{encoding};
77 my $family = $attrs{family};
78 my $f = defined $attrs{family} ? $attrs{family} : "x";
79 my $nc_link = $attrs{namecountry_link};
80 my $e_link = $attrs{encoding_link};
81 my $fallback = $attrs{fallback};
82 my $definitions = $attrs{definitions};
84 $d{L}{$name}{$f}{fallback} = $fallback;
85 $d{L}{$name}{$f}{e_link} = $e_link;
86 $d{L}{$name}{$f}{nc_link} = $nc_link;
87 $d{L}{$name}{$f}{family} = $family;
88 $d{L}{$name}{$f}{encoding} = $encoding;
89 $d{L}{$name}{$f}{definitions} = $definitions;
90 $d{L}{$name}{$f}{countries} = $countries;
91 foreach my $c (split(" ", $countries)) {
92 if (defined $encoding) {
93 foreach my $e (split(" ", $encoding)) {
94 $d{L}{$name}{$f}{data}{$c}{$e} = undef;
95 $d{E}{$e} = 0; # not read
98 $d{L}{$name}{$f}{data}{$c}{"UTF-8"} = undef;
104 && $data{element}{1} eq "translations"
105 && $element eq "translation") {
106 foreach my $e (split(" ", $attrs{encoding})) {
107 if (defined $attrs{hex}) {
108 my $k = $attrs{cldr};
109 my $hs = $attrs{hex};
110 $d{T}{$e}{$k}{hex} = $hs;
112 if (defined $attrs{string}) {
114 for (my $i = 0; $i < length($attrs{string}); $i++) {
115 $s .= sprintf("%02x",
116 ord(substr($attrs{string}, $i, 1)));
118 $d{T}{$e}{$attrs{cldr}}{hex} = $s;
120 if (defined $attrs{unicode}) {
121 my $k = $attrs{cldr};
122 my $uc = $attrs{unicode};
123 $d{T}{$e}{$k}{unicode} = $uc;
125 if (defined $attrs{ucc}) {
126 my $k = $attrs{cldr};
127 my $uc = $attrs{ucc};
128 $d{T}{$e}{$k}{ucc} = $uc;
135 && $data{element}{1} eq "alternativemonths"
136 && $element eq "language") {
137 my $name = $attrs{name};
138 my $countries = $attrs{countries};
140 $data{fields}{name} = $name;
141 $data{fields}{countries} = $countries;
142 $data{fields}{text} = "";
153 if ($data{element}{1} eq "alternativemonths"
154 && $data{element}{2} eq "language") {
155 foreach my $c (split(/,/, $data{fields}{countries})) {
156 my $m = $data{fields}{text};
160 $d{AM}{$data{fields}{name}}{$c} = $m;
174 if ($data{element}{1} eq "alternativemonths"
175 && $data{element}{2} eq "language") {
176 $data{fields}{text} .= $string;
182 #my %D = get_xmldata();