Skip to content

Commit 4cc0ff3

Browse files
committed
Move dump functions to gork-ztools
1 parent 1fe61ae commit 4cc0ff3

File tree

3 files changed

+88
-71
lines changed

3 files changed

+88
-71
lines changed

gork-ztools/main.go

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ func dumpStoryInfo(story string, conf *config) {
5454
}
5555

5656
if conf.showObjects {
57-
gork.DumpAllZObjects(mem, header)
57+
DumpAllZObjects(mem, header)
5858
}
5959

6060
if conf.showObjectTree {
61-
gork.DumpZObjectsTree(mem, header)
61+
DumpZObjectsTree(mem, header)
6262
}
6363

6464
if conf.showAbbreviations {
65-
gork.DumpAbbreviations(mem, header)
65+
DumpAbbreviations(mem, header)
6666
}
6767

6868
if conf.showDictionary {
@@ -71,3 +71,68 @@ func dumpStoryInfo(story string, conf *config) {
7171

7272
fmt.Println("")
7373
}
74+
75+
func DumpAbbreviations(mem *gork.ZMemory, header *gork.ZHeader) {
76+
fmt.Print("\n **** Abbreviations ****\n\n")
77+
78+
abbrs := gork.GetAbbreviations(mem, header)
79+
80+
if len(abbrs) == 0 {
81+
fmt.Printf(" No abbreviation information.\n")
82+
return
83+
}
84+
85+
for i, abbr := range abbrs {
86+
fmt.Printf(" [%2d] \"%s\"\n", i, abbr)
87+
}
88+
}
89+
90+
func DumpAllZObjects(mem *gork.ZMemory, header *gork.ZHeader) {
91+
total := gork.ZObjectsCount(mem, header)
92+
93+
fmt.Print("\n **** Objects ****\n\n")
94+
fmt.Printf(" Object count = %d\n\n", total)
95+
96+
for i := uint8(1); i <= total; i++ {
97+
fmt.Printf("%3d. %s", i, gork.NewZObject(mem, i, header))
98+
}
99+
}
100+
101+
func DumpZObjectsTree(mem *gork.ZMemory, header *gork.ZHeader) {
102+
103+
fmt.Print("\n **** Object tree ****\n\n")
104+
105+
total := gork.ZObjectsCount(mem, header)
106+
107+
var printObject func(obj *gork.ZObject, depth int)
108+
printObject = func(obj *gork.ZObject, depth int) {
109+
for {
110+
111+
for j := 0; j < depth; j++ {
112+
fmt.Print(" . ")
113+
}
114+
fmt.Printf("[%3d] ", obj.Id())
115+
fmt.Printf("\"%s\"\n", obj.Name())
116+
117+
if obj.ChildId() != 0 {
118+
childobj := gork.NewZObject(mem, obj.ChildId(), header)
119+
printObject(childobj, depth+1)
120+
}
121+
122+
if obj.SiblingId() == 0 {
123+
break
124+
}
125+
obj = gork.NewZObject(mem, obj.SiblingId(), header)
126+
}
127+
}
128+
129+
for i := uint8(1); i <= total; i++ {
130+
zobj := gork.NewZObject(mem, i, header)
131+
132+
// root
133+
if zobj.ParentId() == 0 {
134+
printObject(zobj, 0)
135+
break
136+
}
137+
}
138+
}

gork/zabbreviations.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package gork
22

3-
import (
4-
"fmt"
5-
)
6-
73
// v3 3 tables * 32 entries each
84
const abbrCount = 32 * 3
95

@@ -20,18 +16,3 @@ func GetAbbreviations(mem *ZMemory, header *ZHeader) []string {
2016

2117
return ret
2218
}
23-
24-
func DumpAbbreviations(mem *ZMemory, header *ZHeader) {
25-
fmt.Print("\n **** Abbreviations ****\n\n")
26-
27-
abbrs := GetAbbreviations(mem, header)
28-
29-
if len(abbrs) == 0 {
30-
fmt.Printf(" No abbreviation information.\n")
31-
return
32-
}
33-
34-
for i, abbr := range abbrs {
35-
fmt.Printf(" [%2d] \"%s\"\n", i, abbr)
36-
}
37-
}

gork/zobject.go

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,26 @@ func (obj *ZObject) PropertiesIds() []byte {
304304
return ret
305305
}
306306

307+
func (obj *ZObject) Id() uint8 {
308+
return obj.number
309+
}
310+
311+
func (obj *ZObject) Name() string {
312+
return obj.name
313+
}
314+
315+
func (obj *ZObject) ParentId() uint8 {
316+
return obj.parent
317+
}
318+
319+
func (obj *ZObject) SiblingId() uint8 {
320+
return obj.sibling
321+
}
322+
323+
func (obj *ZObject) ChildId() uint8 {
324+
return obj.child
325+
}
326+
307327
func (obj *ZObject) String() string {
308328
ret := ""
309329

@@ -341,52 +361,3 @@ func (obj *ZObject) String() string {
341361

342362
return ret
343363
}
344-
345-
func DumpAllZObjects(mem *ZMemory, header *ZHeader) {
346-
total := ZObjectsCount(mem, header)
347-
348-
fmt.Print("\n **** Objects ****\n\n")
349-
fmt.Printf(" Object count = %d\n\n", total)
350-
351-
for i := uint8(1); i <= total; i++ {
352-
fmt.Printf("%3d. %s", i, NewZObject(mem, i, header))
353-
}
354-
}
355-
356-
func DumpZObjectsTree(mem *ZMemory, header *ZHeader) {
357-
358-
fmt.Print("\n **** Object tree ****\n\n")
359-
360-
total := ZObjectsCount(mem, header)
361-
362-
var printObject func(obj *ZObject, depth int)
363-
printObject = func(obj *ZObject, depth int) {
364-
for {
365-
366-
for j := 0; j < depth; j++ {
367-
fmt.Print(" . ")
368-
}
369-
fmt.Printf("[%3d] ", obj.number)
370-
fmt.Printf("\"%s\"\n", obj.name)
371-
372-
if obj.child != 0 {
373-
childobj := NewZObject(mem, obj.child, header)
374-
printObject(childobj, depth+1)
375-
}
376-
377-
if obj.sibling == 0 {
378-
break
379-
}
380-
obj = NewZObject(mem, obj.sibling, header)
381-
}
382-
}
383-
384-
for i := uint8(1); i <= total; i++ {
385-
zobj := NewZObject(mem, i, header)
386-
387-
// root
388-
if zobj.parent == 0 {
389-
printObject(zobj, 0)
390-
}
391-
}
392-
}

0 commit comments

Comments
 (0)