summaryrefslogtreecommitdiff
path: root/Unicode/tr7bit.awk
blob: dc2256a5c49ba2269e537104cf88a60d4803ae3f (plain)
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
#!/bin/awk -f
function hex2dec(xx) {
	nn = 0;
	while (xx != "") {
		aa = substr(xx, 1, 1);
		ii = index("0123456789ABCDEF", aa);
		if (!ii) ii = index("0123456789abcdef", aa);
		if (!ii) return -1;
		nn = nn * 16 + ii - 1;
		xx = substr(xx, 2);
	}
	return nn;
}
		
/^U/{
	gsub("\\\\", "\\\\");
	printf("0x%s\n", substr($0, 3));
}
/^0x[0-9a-fA-F]*[	 ]/{
	c = hex2dec(substr($1, 3));
	for (i = 2; i <= NF; i++) {
		if (substr($i, 1, 1) == "#") break;
		if (p = index($i, "-")) {
			p1 = hex2dec(substr($i, 3, p - 3));
			p2 = hex2dec(substr($i, p + 3));
		} else {
			p1 = hex2dec(substr($i, 3));
			p2 = p1;
		}
		for (p = p1; p <= p2; p++) printf("0x%04x:%c\n", p, c);
	}
}
BEGIN{
	printf("0x00a0:\\001\n0x00ad:\n");
}