Ajla 0.1.5
[ajla.git] / scripts / charset / widechar_width.c
bloba237a38c717aed812e26cb323255f359114c41ba
1 /*
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
9 * version.
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/>.
19 #include <stdio.h>
20 #include <limits.h>
22 #include "widechar_width.h"
24 #define class_combining -1
25 #define class_zero 0
26 #define class_one 1
27 #define class_two 2
29 static int char_class(int c)
31 int w = widechar_wcwidth(c);
32 switch (w) {
33 case 1: return class_one;
34 case 2: return class_two;
35 case widechar_nonprint: return class_zero;
36 case widechar_combining: return class_combining;
37 case widechar_ambiguous: return class_one;
38 case widechar_private_use: return class_one;
39 case widechar_unassigned: return class_one;
40 case widechar_widened_in_9: return class_two;
41 case widechar_non_character: return class_zero;
42 default: abort();
47 int main(void)
49 int i;
50 int last_cls;
51 printf("{*\n");
52 printf(" * No-copyright\n");
53 printf(" * A table of numbers, generated by a script, is supposedly not copyrightable.\n");
54 printf(" *}\n");
55 printf("\n");
56 printf("private unit uni_table;\n");
57 printf("\n");
58 printf("const uni_table~cache : list(char);\n");
59 printf("\n");
60 printf("implementation\n");
61 printf("\n");
62 printf("const uni_table~cache : list(char) := list(char).[\n");
63 last_cls = INT_MAX;
64 for (i = 0; i < 0x110000; i++) {
65 int cls = char_class(i);
66 if (cls != last_cls) {
67 printf("\t#%x, %d,\n", i, cls);
68 last_cls = cls;
71 if (last_cls != class_zero)
72 printf("\t#%x, %d,\n", i, class_zero);
73 printf("];\n");
74 return 0;