1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 04:25:11 +00:00
Files
go-fmp/fmp/fmp_debug.go

74 lines
1.5 KiB
Go
Raw Normal View History

2025-06-12 09:41:46 +02:00
package fmp
import (
"fmt"
"os"
)
2025-06-14 14:24:35 +02:00
func debug(str string, args ...interface{}) {
fmt.Printf(str+"\n", args...)
}
2025-06-12 09:41:46 +02:00
func (f *FmpFile) ToDebugFile(fname string) {
2025-06-13 12:09:39 +02:00
f_sectors, err := os.Create(fname + ".sectors")
if err != nil {
panic(err)
}
defer func() {
if err := f_sectors.Close(); err != nil {
panic(err)
}
}()
for _, sect := range f.Sectors {
fmt.Fprintf(f_sectors, "%s\n", sect.String())
}
2025-06-12 10:53:31 +02:00
f_chunks, err := os.Create(fname + ".chunks")
2025-06-12 09:41:46 +02:00
if err != nil {
panic(err)
}
defer func() {
2025-06-12 10:53:31 +02:00
if err := f_chunks.Close(); err != nil {
2025-06-12 09:41:46 +02:00
panic(err)
}
}()
for _, chunk := range f.Chunks {
2025-06-12 10:53:31 +02:00
fmt.Fprintf(f_chunks, "%s, %s\n", chunk.String(), string(chunk.Value))
}
f_dicts, err := os.Create(fname + ".dicts")
if err != nil {
panic(err)
2025-06-12 09:41:46 +02:00
}
2025-06-12 10:53:31 +02:00
defer func() {
if err := f_dicts.Close(); err != nil {
panic(err)
}
}()
fmt.Fprint(f_dicts, f.Dictionary.String())
2025-06-12 09:41:46 +02:00
}
2025-06-13 12:09:39 +02:00
func (sect *FmpSector) String() string {
2025-06-13 13:01:25 +02:00
return fmt.Sprintf("<Sector, id=%20v, del=%5v, lev=%1v, prevID=%20v, nextID=%20v>", sect.ID, sect.Deleted, sect.Level, sect.PrevID, sect.NextID)
2025-06-13 12:09:39 +02:00
}
2025-06-12 09:41:46 +02:00
func (c *FmpChunk) String() string {
2025-06-13 13:01:25 +02:00
return fmt.Sprintf("<Chunk, type=%v, len=%v>", c.Type, c.Length)
2025-06-12 09:41:46 +02:00
}
2025-06-12 10:53:31 +02:00
2025-06-12 21:21:55 +02:00
func (dict *FmpDict) string(parentPath string) string {
2025-06-12 10:53:31 +02:00
s := ""
for k, v := range *dict {
2025-06-12 21:21:55 +02:00
s += fmt.Sprintf("%v%v: %v\n", parentPath, k, string(v.Value))
if v.Children != nil {
s += v.Children.string(fmt.Sprintf("%v%v.", parentPath, k))
}
2025-06-12 10:53:31 +02:00
}
return s
}
2025-06-12 21:21:55 +02:00
func (dict *FmpDict) String() string {
return dict.string("")
}