summaryrefslogtreecommitdiff
path: root/Veni_Creator_Spiritus/parse-str-comments
blob: 05d97937ac3ad0277fc4fe9be01b3a509c8dd0fc (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
34
35
36
37
38
39
40
41
#!/bin/bash

cnt=$(cat)

printf '%s\n' "${cnt}" \
| sed "$(
  printf '%s\n' "${cnt}" \
  | sed '
    s,^.*%STR_\(MIX\|MAX\|NOT\)\(\( [0-9]\+\)*\)%.*$,\2,
    t
    d
  ' \
  | sort -u \
  | while read -r l; do
    found_missing=0
    found_present=0
    for i in $(seq 1 "$1"); do
      if ! printf '%s\n' "${i}" \
        | grep -xq "$2"; then
        continue
      fi
      if printf '%s\n' "${l}" \
        | grep -wqF "${i}"; then
        found_present=1
      else
        found_missing=1
      fi
    done
    printf '%s %s %s\n' "${found_present}" "${found_missing}" "${l}"
  done \
  | sed '
    s/^1 1/MIX/
    s/^0 1/NOT/
    s/^1 0/MAX/
    t
    d
  ' \
  | sed '
    s/^.*$/s@%STR_\0%@@/
  '
)"