-
Notifications
You must be signed in to change notification settings - Fork 29
/
nwn_key_shadows.nim
40 lines (31 loc) · 1.13 KB
/
nwn_key_shadows.nim
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
import shared, terminal
let Args = DOC """
This utility walks a set of keyfiles and and prints out statistics on how much
data is shadowed.
Usage:
$0 [options] <key>...
$USAGE
$OPT
"""
# Load keytables in order.
let keyTables = @(Args["<key>"]).map() do (key: string) -> KeyTable:
let keyRoot = key.expandFilename.splitFile().dir
result = readKeyTable(openFileStream(key, fmRead), key) do (bif: string) -> Stream:
result = openFileStream(keyRoot / bif.extractFilename)
# Holds all resrefs per key table (idx) that are shadowed by later key tables.
let shadowed = keyTables.map() do (keyIdx: int, key: KeyTable) -> seq[ResRef]:
result = newSeq[ResRef]()
for o in key.contents:
if keyTables[keyIdx+1..keyTables.high].anyIt(it.contains(o)):
result.add(o)
const Padding = 12
echo "Shadowed:"
echo align("bytes", Padding), " ",
align("files", Padding), " ",
"in"
echo repeat("-", terminalWidth())
for keyIdx, key in keyTables:
let shadowedBytes = foldl(shadowed[keyIdx], a + key.demand(b).ioSize, 0i64)
echo align(shadowedBytes.formatSize, Padding), " ",
align($shadowed[keyIdx].len, Padding), " ",
key