2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
21 fn spctab(b : byte) : bool := b = ' ' or b = ' ' or b = '-';
23 fn main(implicit w : world, d : dhandle, h : list(handle), args : list(bytes), env : treemap(bytes, bytes)) : world
25 var dh := dopen(d, "scripts/charset", 0);
26 var lz := dread_lazy(dh);
29 if not list_ends_with(name, ".cp") then
31 //write(h[1], name + nl);
32 var cpx_name := name[ .. len(name) - 3] + ".cpx";
33 var cpx := list_break_to_lines(read_lazy(ropen_lazy(d, path_append("scripts/charset", cpx_name), 0)));
35 var mime_name := cpx[1];
36 var normalized_name := charset_name_normalize(mime_name);
37 var file_name := normalized_name;
38 if len(file_name) > 8 then
39 file_name := file_name[ .. 3] + "_" + file_name[len(file_name) - 4 .. ];
42 var table := array_fill(char, 0, [256]);
43 var chs := list_break_to_lines(read_lazy(ropen_lazy(d, path_append("scripts/charset", name), 0)));
45 if line = "" or line[0] = '#' or line[0] = 26 then
47 var broken := list_break_whitespace(line);
48 if broken[0][ .. 2] <> "0x" then
50 if list_search(broken[0], '-') >= 0 then
52 var ccode := ston_base(broken[0][2 .. ], 16);
56 if broken[1] = "0" or broken[1][0] = '#' then
58 if broken[1][ .. 2] <> "0x" then
60 var ucode := ston_base(broken[1][2 .. ], 16);
61 if ucode >= #80, ucode < #a0 then
63 table[ccode] := ucode;
67 tstr += label + bytes.[0];
68 tstr += mime_name + bytes.[0];
69 for i := 128 to 256 do [
70 tstr +<= table[i] and #ff;
71 tstr +<= (table[i] shr 8) and #ff;
72 tstr +<= (table[i] shr 16) and #ff;
75 var wh := wopen(d, path_append("charsets", file_name), open_flag_create, open_mode_default);