File: ambwidth_map.awk

package info (click to toggle)
w3m 0.5.3%2Bgit20230121-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,520 kB
  • sloc: ansic: 59,204; sh: 4,331; perl: 4,217; javascript: 2,315; makefile: 913; cpp: 869; ruby: 776; awk: 78; sed: 16
file content (39 lines) | stat: -rw-r--r-- 905 bytes parent folder | download | duplicates (7)
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
BEGIN {
    FS = "[; ]";
    i = 0;
}
$2 == "A" { 
    code = code2 = strtonum(sprintf("0x%s", $1))
    if (match($1, /[.]+[0-9A-Fa-f]+/)) {
	s = substr($1, RSTART, RLENGTH)
	sub(/[.]+/, "0x", s)
	code2 = strtonum(s)
    }
    for (; code <= code2; code++) {
	if (code >= 0x10000) { break }
	map[i] = sprintf("0x%04X", code)
	i++;
    }
}
END {
    n = 0;
    start = map[0]
    prev = strtonum(map[0]);
    for (j = 1; j < i; j++) {
	cur = strtonum(map[j]);
	if (cur - prev > 1) {
	    map2[n] = sprintf("%s, %s", start, map[j - 1]);
	    n++;
	    start = map[j];
	}
	prev = cur;
    }
    if (i > 0) { map2[n] = sprintf("%s, %s", start, map[i - 1]); n++ }

    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");
}