File: gaptab.awk

package info (click to toggle)
glibc 2.28-8
  • links: PTS, VCS
  • area: main
  • in suites: buster, experimental, sid
  • size: 271,788 kB
  • sloc: ansic: 1,008,637; asm: 259,607; makefile: 11,271; sh: 10,477; python: 6,910; cpp: 4,992; perl: 2,258; awk: 2,005; yacc: 290; pascal: 182; sed: 73
file content (48 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (20)
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
BEGIN { hv["0"] =  0; hv["1"] =  1; hv["2"] =  2; hv["3"] =  3;
	hv["4"] =  4; hv["5"] =  5; hv["6"] =  6; hv["7"] =  7;
	hv["8"] =  8; hv["9"] =  9; hv["A"] = 10; hv["B"] = 11;
	hv["C"] = 12; hv["D"] = 13; hv["E"] = 14; hv["F"] = 15;
	hv["a"] = 10; hv["b"] = 11; hv["c"] = 12; hv["d"] = 13;
	hv["e"] = 14; hv["f"] = 15;

	first = 0; last = 0; idx = 0; f = 0;
}

function tonum(str)
{
  num=0;
  cnt=1;
  while (cnt <= length(str)) {
    num *= 16;
    num += hv[substr(str,cnt,1)];
    ++cnt;
  }
  return num;
}

function fmt(val)
{
  if (f++ % 8 == 0)
    { printf ("\n  '\\x%02x',", val); }
  else
    { printf (" '\\x%02x',", val); }
}

{
  u = tonum($1); c = tonum($2);

  if (u - last > 6)
    {
      if (last) { idx += last - first + 1; }
      first = u;
    }
  else
    {
      for (m = last+1; m < u; m++) { fmt(0); }
    }

  fmt(c);
  last = u;
}

END { print "" }