From 43523c458a6f974a60355d7e3e87a80699303604 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Thu, 12 Jun 2025 10:53:31 +0200 Subject: [PATCH] Dict debug output --- fmp/fmp_debug.go | 28 ++++++++++++++++++++++++---- fmp/fmp_test.go | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fmp/fmp_debug.go b/fmp/fmp_debug.go index ed4f3cd..6e4846a 100644 --- a/fmp/fmp_debug.go +++ b/fmp/fmp_debug.go @@ -3,24 +3,44 @@ package fmp import ( "fmt" "os" + "strings" ) func (f *FmpFile) ToDebugFile(fname string) { - fo, err := os.Create(fname) + f_chunks, err := os.Create(fname + ".chunks") if err != nil { panic(err) } defer func() { - if err := fo.Close(); err != nil { + if err := f_chunks.Close(); err != nil { panic(err) } }() - 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 { 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 +} diff --git a/fmp/fmp_test.go b/fmp/fmp_test.go index 191457a..21f7642 100644 --- a/fmp/fmp_test.go +++ b/fmp/fmp_test.go @@ -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")) } - f.ToDebugFile("../private/output.txt") + f.ToDebugFile("../private/output") }