1#!/usr/bin/awk -f 2# 3# Description: a script to generate east asian width table. 4# 5 6BEGIN { 7 prev = -1 8 comma = 0 9 ORS = "" 10 FS = "[;.|# ]" 11 print "static const struct {\n\tint begin;\n\tint end;\n} " TABLE_NAME "[] = {\n\t" 12} 13 14/^#/ { 15} 16 17/^[0-9a-fA-F]+;/ { 18 if ($2 == "W" || $2 == "F") { 19 20 v = strtonum( "0x" $1 ) 21 if (prev < 0) { 22 first = v 23 } else if (v - prev > 1) { 24 if (comma) { 25 print ",\n\t" 26 } 27 printf("{ 0x%04x, 0x%04x }", first, prev) 28 first = v 29 comma = 1 30 } 31 prev = v 32 } else { 33 if (prev >= 0) { 34 if (comma) { 35 print ",\n\t" 36 } 37 printf("{ 0x%04x, 0x%04x }", first, prev) 38 prev = -1 39 comma = 1 40 } 41 } 42} 43 44/^[0-9a-fA-F]+\.\./ { 45 if ($4 == "W" || $4 == "F") { 46 vs = strtonum( "0x" $1 ) 47 ve = strtonum( "0x" $3 ) 48 if (prev < 0) { 49 first = vs 50 } else if (vs - prev > 1) { 51 if (comma) { 52 print ",\n\t" 53 } 54 printf("{ 0x%04x, 0x%04x }", first, prev) 55 first = vs 56 comma = 1 57 } 58 prev = ve 59 } else { 60 if (prev >= 0) { 61 if (comma) { 62 print ",\n\t" 63 } 64 printf("{ 0x%04x, 0x%04x }", first, prev) 65 prev = -1 66 comma = 1 67 } 68 } 69} 70 71END { 72 if (prev >= 0) { 73 if (comma) { 74 print ",\n\t" 75 } 76 printf("{ 0x%04x, 0x%04x }", first, prev) 77 } 78 print "\n};\n" 79} 80