summaryrefslogtreecommitdiff
path: root/number-to-name.awk
blob: ba9a7332d4c04ef3f30fe763f26e208e907ec8d9 (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
#!/usr/bin/awk -f
# Tries to map a number to name (or a question mark if not found)
# Author: Peter Wu <lekensteyn@gmail.com>

BEGIN {
	if (!cmd) cmd = "openssl ciphers -V";
	# alternative: cat suites.txt

	while ((cmd | getline) > 0) {
		if ($1 ~ /^[0-9]+/) {
			# suites.txt format: <decimal-number> <name>
			num = $1;
			name = $2;
			number_to_name[num] = name;
		} else if (split($0, a, / +- +|[, ]+/) >= 2) {
			# `openssl ciphers -V` format:
			# 0xHH,0xHH - <name> ...
			num = strtonum(a[2]) * 256 + strtonum(a[3]);
			name = a[4];
			number_to_name[num] = name;
		}
	}
}
{
	for (i = 1; i <= NF; i++) {
		if ($i ~ /^[0-9]+$/) {
			name = number_to_name[$i];
			if (!name) name = "?";
			$i = $i " " name;
		}
	}
	print;
}