File: tr7bit.awk

package info (click to toggle)
elinks 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,352 kB
  • sloc: ansic: 156,569; cpp: 30,139; sh: 7,719; python: 4,031; perl: 2,183; pascal: 1,670; makefile: 995; javascript: 904; yacc: 295; lisp: 125; awk: 79; ruby: 70
file content (49 lines) | stat: -rwxr-xr-x 1,015 bytes parent folder | download | duplicates (12)
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
48
49
#!/bin/awk -f

function join(array, start, sep, end, result, i)
{
	if (sep == "")
		sep = " "
	else if (sep == SUBSEP) # magic value
		sep = ""
	result = array[start]
	for (i = start + 1; i <= end; i++)
		result = result sep array[i]
	return result
}

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("\\\\", "\\\\");
	split(substr($0, 3), z, ":")
	printf("0x%08x:%s\n", hex2dec(z[1]), join(z, 2, ":"));
}
/^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%08x:%c\n", p, c);
	}
}
BEGIN{
	printf("0x000000a0:\\001\n0x000000ad:\n");
}