-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdoidentify.go
More file actions
64 lines (47 loc) · 1.08 KB
/
doidentify.go
File metadata and controls
64 lines (47 loc) · 1.08 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"os"
"github.com/itchio/wizardry/wizardry/wizinterpreter"
"github.com/itchio/wizardry/wizardry/wizparser"
"github.com/itchio/wizardry/wizardry/wizutil"
)
func doIdentify() error {
magdir := *identifyArgs.magdir
NoLogf := func(format string, args ...any) {}
Logf := func(format string, args ...any) {
fmt.Println(fmt.Sprintf(format, args...))
}
pctx := &wizparser.ParseContext{
Logf: NoLogf,
}
if *appArgs.debugParser {
pctx.Logf = Logf
}
book := make(wizparser.Spellbook)
err := pctx.ParseAll(magdir, book)
if err != nil {
return err
}
target := *identifyArgs.target
targetReader, err := os.Open(target)
if err != nil {
panic(err)
}
defer targetReader.Close()
stat, _ := targetReader.Stat()
ictx := &wizinterpreter.InterpretContext{
Logf: NoLogf,
Book: book,
}
if *appArgs.debugInterpreter {
ictx.Logf = Logf
}
sr := wizutil.NewSliceReader(targetReader, 0, stat.Size())
result, err := ictx.Identify(sr)
if err != nil {
panic(err)
}
fmt.Printf("%s: %s\n", target, wizutil.MergeStrings(result))
return nil
}