mirror of
https://github.com/garraflavatra/go-fmp.git
synced 2025-06-27 20:15:11 +00:00
Debug prints
This commit is contained in:
@ -5,6 +5,10 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func debug(str string, args ...interface{}) {
|
||||
fmt.Printf(str+"\n", args...)
|
||||
}
|
||||
|
||||
func (f *FmpFile) ToDebugFile(fname string) {
|
||||
f_sectors, err := os.Create(fname + ".sectors")
|
||||
if err != nil {
|
||||
|
@ -100,7 +100,7 @@ func (ctx *FmpFile) readHeader() error {
|
||||
}
|
||||
|
||||
func (ctx *FmpFile) readSector() (*FmpSector, error) {
|
||||
println("---------- Reading sector", ctx.currentSectorID)
|
||||
debug("---------- Reading sector %d", ctx.currentSectorID)
|
||||
buf := make([]byte, sectorHeaderSize)
|
||||
n, err := ctx.stream.Read(buf)
|
||||
|
||||
|
@ -2,7 +2,6 @@ package fmp
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
@ -19,22 +18,20 @@ func (sect *FmpSector) readChunks() error {
|
||||
|
||||
chunk, err := sect.readChunk(sect.Payload)
|
||||
if chunk == nil {
|
||||
fmt.Printf("0x%02x (pos %v, unknown)\n", sect.Payload[0], pos)
|
||||
debug("0x%02x (pos %v, unknown)\n", sect.Payload[0], pos)
|
||||
} else {
|
||||
fmt.Printf("0x%02x (pos %v, type %v)\n", sect.Payload[0], pos, int(chunk.Type))
|
||||
debug("0x%02x (pos %v, type %v)\n", sect.Payload[0], pos, int(chunk.Type))
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
println("break1")
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
println(hex.EncodeToString(sect.Payload))
|
||||
println("break2")
|
||||
debug("chunk error at sector %d", sect.ID)
|
||||
debug(hex.EncodeToString(sect.Payload))
|
||||
return err
|
||||
}
|
||||
if chunk == nil {
|
||||
println("break3")
|
||||
break
|
||||
}
|
||||
if chunk.Length == 0 {
|
||||
@ -92,14 +89,6 @@ func (sect *FmpSector) processChunks(dict *FmpDict, currentPath *[]uint64) error
|
||||
case FMP_CHUNK_NOOP:
|
||||
// noop
|
||||
}
|
||||
|
||||
if chunk.Delayed {
|
||||
if len(*currentPath) == 0 {
|
||||
println("warning: delayed pop without path")
|
||||
} else {
|
||||
*currentPath = (*currentPath)[:len(*currentPath)-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -112,11 +101,6 @@ func (sect *FmpSector) readChunk(payload []byte) (*FmpChunk, error) {
|
||||
chunk := &FmpChunk{}
|
||||
chunkCode := payload[0]
|
||||
|
||||
if (chunkCode & 0xC0) == 0xC0 {
|
||||
chunkCode &= 0x3F
|
||||
chunk.Delayed = true
|
||||
}
|
||||
|
||||
switch chunkCode {
|
||||
case 0x00:
|
||||
chunk.Length = 2
|
||||
|
@ -7,19 +7,19 @@ func (ctx *FmpFile) Tables() []*FmpTable {
|
||||
if key != 3 {
|
||||
continue
|
||||
}
|
||||
println("Found a 3")
|
||||
debug("Found a 3")
|
||||
|
||||
for key, ent = range *ent.Children {
|
||||
if key != 16 {
|
||||
continue
|
||||
}
|
||||
println("Found a 3.16")
|
||||
debug("Found a 3.16")
|
||||
|
||||
for key, ent = range *ent.Children {
|
||||
if key != 5 {
|
||||
continue
|
||||
}
|
||||
println("Found a 3.16.5")
|
||||
debug("Found a 3.16.5")
|
||||
|
||||
for tablePath := range *ent.Children {
|
||||
if key >= 128 {
|
||||
@ -27,7 +27,7 @@ func (ctx *FmpFile) Tables() []*FmpTable {
|
||||
}
|
||||
|
||||
// Found a table!
|
||||
println("Found a table at 3.16.5.", tablePath)
|
||||
debug("Found a table at 3.16.5.%d", tablePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,11 @@ type FmpSector struct {
|
||||
}
|
||||
|
||||
type FmpChunk struct {
|
||||
Type FmpChunkType
|
||||
Length uint64
|
||||
Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE
|
||||
Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA
|
||||
Value []byte
|
||||
Delayed bool
|
||||
Type FmpChunkType
|
||||
Length uint64
|
||||
Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE
|
||||
Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA
|
||||
Value []byte
|
||||
}
|
||||
|
||||
type FmpDict map[uint64]*FmpDictEntry
|
||||
|
Reference in New Issue
Block a user