lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | BEGIN { hv["0"] = 0; hv["1"] = 1; hv["2"] = 2; hv["3"] = 3; |
| 2 | hv["4"] = 4; hv["5"] = 5; hv["6"] = 6; hv["7"] = 7; |
| 3 | hv["8"] = 8; hv["9"] = 9; hv["A"] = 10; hv["B"] = 11; |
| 4 | hv["C"] = 12; hv["D"] = 13; hv["E"] = 14; hv["F"] = 15; |
| 5 | hv["a"] = 10; hv["b"] = 11; hv["c"] = 12; hv["d"] = 13; |
| 6 | hv["e"] = 14; hv["f"] = 15; |
| 7 | |
| 8 | first = 0; last = 0; idx = 0; f = 0; |
| 9 | } |
| 10 | |
| 11 | function tonum(str) |
| 12 | { |
| 13 | num=0; |
| 14 | cnt=1; |
| 15 | while (cnt <= length(str)) { |
| 16 | num *= 16; |
| 17 | num += hv[substr(str,cnt,1)]; |
| 18 | ++cnt; |
| 19 | } |
| 20 | return num; |
| 21 | } |
| 22 | |
| 23 | function fmt(val) |
| 24 | { |
| 25 | if (f++ % 8 == 0) |
| 26 | { printf ("\n '\\x%02x',", val); } |
| 27 | else |
| 28 | { printf (" '\\x%02x',", val); } |
| 29 | } |
| 30 | |
| 31 | { |
| 32 | u = tonum($1); c = tonum($2); |
| 33 | |
| 34 | if (u - last > 6) |
| 35 | { |
| 36 | if (last) { idx += last - first + 1; } |
| 37 | first = u; |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | for (m = last+1; m < u; m++) { fmt(0); } |
| 42 | } |
| 43 | |
| 44 | fmt(c); |
| 45 | last = u; |
| 46 | } |
| 47 | |
| 48 | END { print "" } |