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