-
Notifications
You must be signed in to change notification settings - Fork 7
/
prg.go
76 lines (66 loc) · 1002 Bytes
/
prg.go
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
65
66
67
68
69
70
71
72
73
74
75
76
package ciqdb
import (
"fmt"
"io"
"os"
)
//go:generate stringer -type=DataType
type DataType uint8
const (
Null DataType = iota
Int
Float
String
Object
Array
Method
ClassDefinition
Symbol
Bool
ModuleDef
Hash
Resource // then resourceBITMAP=0, FONT=1
PrimitiveObj
Long
Double
WeakPointer
PrimitiveMod
SysPointer
Char
)
type Section interface {
getLength() int
getName() string
getLabel() string
getType() SecType
fmt.Stringer // String() string
}
type PRG struct {
Filename string
Sections []Section
}
func (p *PRG) Parse(r io.Reader) error {
for {
s, err := readSection(p, r)
if err == io.EOF {
break
} else if err != nil {
return err
}
p.Sections = append(p.Sections, s)
}
return nil
}
func NewPRG(filename string) (*PRG, error) {
prg := PRG{}
prg.Filename = filename
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
if err := prg.Parse(file); err != nil {
return nil, err
}
return &prg, nil
}