mirror of
https://github.com/garraflavatra/go-fmp.git
synced 2025-06-28 04:25:11 +00:00
Dict debug output
This commit is contained in:
@ -3,24 +3,44 @@ package fmp
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FmpFile) ToDebugFile(fname string) {
|
func (f *FmpFile) ToDebugFile(fname string) {
|
||||||
fo, err := os.Create(fname)
|
f_chunks, err := os.Create(fname + ".chunks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := fo.Close(); err != nil {
|
if err := f_chunks.Close(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for _, chunk := range f.Chunks {
|
for _, chunk := range f.Chunks {
|
||||||
fmt.Fprintf(fo, "%s, %s\n", chunk.String(), string(chunk.Value))
|
fmt.Fprintf(f_chunks, "%s, %s\n", chunk.String(), string(chunk.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f_dicts, err := os.Create(fname + ".dicts")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := f_dicts.Close(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fmt.Fprint(f_dicts, f.Dictionary.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FmpChunk) String() string {
|
func (c *FmpChunk) String() string {
|
||||||
return fmt.Sprintf("<%v(%v)>", c.Type, c.Length)
|
return fmt.Sprintf("<%v(%v)>", c.Type, c.Length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dict *FmpDict) String() string {
|
||||||
|
s := ""
|
||||||
|
for k, v := range *dict {
|
||||||
|
ns := strings.ReplaceAll(v.Children.String(), "\n", "\n\t")
|
||||||
|
s += fmt.Sprintf("%v: %v\n%v\n", k, string(v.Value), ns)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
@ -20,5 +20,5 @@ func TestOpenFile(t *testing.T) {
|
|||||||
t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
|
t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
|
||||||
}
|
}
|
||||||
|
|
||||||
f.ToDebugFile("../private/output.txt")
|
f.ToDebugFile("../private/output")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user