2 # Copyright (C) 2020 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 $0: generate code page tables from ICU encoding list
24 usage: $0 < convrtrs.txt > sys-file-encoding.c
26 To regenerate the encoding data, get the latest ICU encoding data from:
27 http://source.icu-project.org/repos/icu/icu/trunk/source/data/mappings/convrtrs.txt
28 then convert it with this script using the command above.
30 exit (@ARGV && $ARGV[0] eq '--help' ? 0 : 1);
33 open (CONVERTERS, '<', 'convrtrs.txt')
34 or die "convrtrs.txt: open failed ($!)\n";
36 our $WINDOWS = 3; # Windows code pages.
37 our $IBM = 2; # IBM code pages.
38 our $CP = 1; # Java (?) code pages.
39 our %sources = ($WINDOWS => "windows", $IBM => "ibm", $CP => "cp");
42 while (<CONVERTERS>) {
48 process_converter ($converter);
52 process_converter ($converter);
58 /* -*- mode: c; buffer-read-only: t -*-
60 Generated by sys-file-encoding.pl. Do not modify!
64 PSPP - a program for statistical analysis.
65 Copyright (C) 2017 Free Software Foundation, Inc.
67 This program is free software: you can redistribute it and/or modify
68 it under the terms of the GNU General Public License as published by
69 the Free Software Foundation, either version 3 of the License, or
70 (at your option) any later version.
72 This program is distributed in the hope that it will be useful,
73 but WITHOUT ANY WARRANTY; without even the implied warranty of
74 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 GNU General Public License for more details.
77 You should have received a copy of the GNU General Public License
78 along with this program. If not, see <http://www.gnu.org/licenses/>.
83 #include "data/sys-file-private.h"
85 struct sys_encoding sys_codepage_number_to_name[] = {
87 for my $cpnumber (sort { $a <=> $b } (keys (%codepages))) {
88 my $source = max (keys (%{$codepages{$cpnumber}}));
89 my $name = ${$codepages{$cpnumber}{$source}}[0];
90 print " { $cpnumber, \"$name\" },\n";
92 print " { 0, NULL }\n";
96 for my $cpnumber (sort { $a <=> $b } (keys (%codepages))) {
97 for my $source (keys (%{$codepages{$cpnumber}})) {
98 for my $name (@{$codepages{$cpnumber}{$source}}) {
99 push(@{$names{$name}{$source}}, $cpnumber);
103 print "struct sys_encoding sys_codepage_name_to_number[] = {\n";
104 for my $name (sort (keys (%names))) {
105 for my $source (reverse (sort (keys (%sources)))) {
106 next if !exists ($names{$name}{$source});
107 my (@numbers) = @{$names{$name}{$source}};
109 # The only two encodings that currently print this are KSC_5601
110 # and KS_C_5601-1987, for code pages 949 and 51949. It looks to
111 # me like the correct code page number is 949, which is the one
112 # chosen (because the numbers are in sorted order).
113 print " /* $name has multiple numbers for $sources{$source}: @numbers */\n"
116 print " { $numbers[0], \"$name\" },\n";
120 print " { 0, NULL }\n";
123 sub process_converter {
124 my ($converter) = @_;
125 return if $converter =~ /^\s*$/;
126 return if $converter =~ /^\s*\{/;
132 my @fields = split (' ', $converter);
134 my $name = shift (@fields);
135 if (@fields && $fields[0] eq '{') {
140 my $standard = shift (@fields);
141 last if $standard eq '}';
142 $standards{$standard} = 1;
144 if (exists $standards{'IANA*'}) {
145 unshift (@iana, $name);
146 } elsif (exists $standards{'IANA'}) {
148 } elsif (grep (/\*$/, keys %standards)) {
149 unshift (@other, $name);
151 push (@other, $name);
154 # Untagged names are completely nonstandard.
159 if (($number) = $name =~ /^cp([0-9]+)$/) {
160 $cps{$CP} = int ($number);
161 } elsif (($number) = $name =~ /^windows-([0-9]+)$/) {
162 $cps{$WINDOWS} = int ($number);
163 } elsif (($number) = $name =~ /^ibm-([0-9]+)$/) {
164 $cps{$IBM} = int ($number);
170 # If there are no tagged names then this is completely nonstandard.
171 return if !@iana && !@other;
173 $codepages{$cps{$_}}{$_} = [@iana, @other] for keys (%cps);
179 $best = $x if !defined ($best) || $x > $best;