aboutsummaryrefslogtreecommitdiffstats
path: root/libwc/ambwidth_map.awk
blob: 8544f589aa12195bb5db1cb8ed6ca7a755d8d787 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
BEGIN {
    FS = "[; ]";
    i = 0;
}
$2 == "A" { 
    code = sprintf("0x%s", $1);
    if (strtonum(code) < 0x10000) {
	map[i] = code
	i++;
    }
}
END {
    n = 0;
    start = map[0]
    prev = strtonum(map[0]);
    for (j = 1; j < i; j++) {
	cur = strtonum(map[j]);
	if (match(map[j], "[.]+")) {
	    map2[n] = sprintf("%s, %s", start, map[j - 1]);
	    n++;
	    gsub("[.]+", ", 0x", map[j])
	    map2[n] = map[j];
	    n++;
	    start = map[j + 1];
	    cur = strtonum(start);
	} else {
	    if (cur - prev > 2) {
		map2[n] = sprintf("%s, %s", start, map[j - 1]);
		start = map[j];
		n++;
	    }

	    if (j == i - 1) {
		map2[n] = sprintf("%s, %s", start, map[j]);
		n++;
	    }
	}
	prev = cur;
    }

    printf("static wc_map ucs_ambwidth_map[] = {\n");
    for (j = 0; j < n; j++) {
	printf("   { %s },\n", map2[j]);
    }
    printf("};\n");
    printf("#define N_ucs_ambwidth_map (sizeof(ucs_ambwidth_map) / sizeof(*ucs_ambwidth_map))\n");
}