[go: up one dir, main page]

File: dat2h.awk

package info (click to toggle)
sxiv 1.3.2-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 392 kB
  • ctags: 482
  • sloc: ansic: 3,693; makefile: 55; sh: 44; awk: 30
file content (35 lines) | stat: -rw-r--r-- 512 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/awk -f

function printchars() {
  while (n > 0) {
    x = n / 16 >= 1 ? 16 : n;
    printf("0x%x%x,%s", x - 1, ref[c] - 1, ++i % 12 == 0 ? "\n" : " ");
    n -= x;
  }
}

/^$/ {
  printchars();
  printf("\n\n");
  c = "";
  i = 0;
}

/./ {
  if (!ref[$0]) {
    col[cnt++] = $0;
    ref[$0] = cnt;
  }
  if ($0 != c) {
    if (c != "")
      printchars();
    c = $0;
    n = 0;
  }
  n++;
}

END {
  for (i = 0; i < cnt; i++)
    printf("%s,%s", col[i], ++j % 4 == 0 || i + 1 == cnt ? "\n" : " ");
}