1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-27 20:15:11 +00:00
Files
go-fmp/fmp/fmp_debug.go
2025-06-15 21:09:39 +02:00

96 lines
1.8 KiB
Go

package fmp
import (
"fmt"
"os"
)
const debugging = false
func debug(str string, args ...interface{}) {
if debugging {
fmt.Printf(str+"\n", args...)
}
}
func dump(data []byte) {
if debugging {
for _, b := range data {
fmt.Printf("%02x ", b)
}
fmt.Println()
}
}
func dumpPath(path []uint64) {
if debugging {
for _, p := range path {
fmt.Printf("%v. ", p)
}
fmt.Println()
}
}
func (f *FmpFile) ToDebugFile(fname string) {
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())
}
f_chunks, err := os.Create(fname + ".chunks")
if err != nil {
panic(err)
}
defer func() {
if err := f_chunks.Close(); err != nil {
panic(err)
}
}()
for _, chunk := range f.Chunks {
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 (sect *FmpSector) String() string {
return fmt.Sprintf("<Sector, id=%20v, del=%5v, lev=%1v, prevID=%20v, nextID=%20v>", sect.ID, sect.Deleted, sect.Level, sect.PrevID, sect.NextID)
}
func (c *FmpChunk) String() string {
return fmt.Sprintf("<Chunk, type=%v, len=%v>", c.Type, c.Length)
}
func (dict *FmpDict) string(parentPath string) string {
s := ""
for k, v := range *dict {
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))
}
}
return s
}
func (dict *FmpDict) String() string {
return dict.string("")
}