mirror of
https://github.com/zellyn/diskii.git
synced 2024-11-24 12:31:32 +00:00
debug: made it a counter rather than boolean
This commit is contained in:
parent
b264fe8e96
commit
0b85248dde
@ -97,9 +97,10 @@ My rough TODO list (apart from anything marked (✗) in the disk
|
||||
operations matrix is listed below. Anything that an actual user needs
|
||||
will be likely to get priority.
|
||||
|
||||
- [ ] Make `put` accept load address for appropriate filetypes.
|
||||
- [ ] Fix `golint` errors
|
||||
- [x] Make `put` accept load address for appropriate filetypes.
|
||||
- [x] Fix `golint` errors
|
||||
- [ ] Implement `GetFile` for prodos
|
||||
- [ ] Implement `PutFile` for prodos
|
||||
- [ ] Implement `Delete` for Super-Mon
|
||||
- [ ] Implement `Delete` for DOS 3.3
|
||||
- [ ] Implement `Delete` for ProDOS
|
||||
|
@ -35,7 +35,7 @@ func (l *LsCmd) Run(globals *types.Globals) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", err, l.Image.Name())
|
||||
}
|
||||
if globals.Debug {
|
||||
if globals.Debug > 0 {
|
||||
fmt.Fprintf(os.Stderr, "Opened disk with order %q, system %q\n", order, op.Name())
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ type PutCmd struct {
|
||||
System string `kong:"default='auto',enum='auto,dos3',help='DOS system used for image.'"`
|
||||
FiletypeName string `kong:"default='B',help='Type of file (“diskii filetypes” to list).'"`
|
||||
Overwrite bool `kong:"short='f',help='Overwrite existing file?'"`
|
||||
Address uint16 `kong:"type='anybaseuint16',default='0x6000',help='For filetypes where it is appropriate, address to load the code at.'"`
|
||||
|
||||
DiskImage string `kong:"arg,required,type='existingfile',help='Disk image to modify.'"`
|
||||
TargetFilename string `kong:"arg,required,help='Filename to use on disk.'"`
|
||||
@ -56,7 +57,8 @@ func (p *PutCmd) Run(globals *types.Globals) error {
|
||||
Length: len(contents),
|
||||
Type: filetype,
|
||||
},
|
||||
Data: contents,
|
||||
Data: contents,
|
||||
StartAddress: p.Address,
|
||||
}
|
||||
_, err = op.PutFile(fileInfo, p.Overwrite)
|
||||
if err != nil {
|
||||
|
16
disk/open.go
16
disk/open.go
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// OpenFilename attempts to open a disk or device image, using the provided ordering and system type.
|
||||
func OpenFilename(filename string, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug bool) (types.Operator, types.DiskOrder, error) {
|
||||
func OpenFilename(filename string, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug int) (types.Operator, types.DiskOrder, error) {
|
||||
if filename == "-" {
|
||||
return OpenFile(os.Stdin, order, system, operatorFactories, debug)
|
||||
}
|
||||
@ -26,7 +26,7 @@ func OpenFilename(filename string, order types.DiskOrder, system string, operato
|
||||
|
||||
// OpenFile attempts to open a disk or device image, using the provided ordering and system type.
|
||||
// OpenFile will close the file.
|
||||
func OpenFile(file *os.File, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug bool) (types.Operator, types.DiskOrder, error) {
|
||||
func OpenFile(file *os.File, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug int) (types.Operator, types.DiskOrder, error) {
|
||||
bb, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@ -38,7 +38,7 @@ func OpenFile(file *os.File, order types.DiskOrder, system string, operatorFacto
|
||||
}
|
||||
|
||||
// OpenImage attempts to open a disk or device image, using the provided ordering and system type.
|
||||
func OpenImage(filebytes []byte, filename string, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug bool) (types.Operator, types.DiskOrder, error) {
|
||||
func OpenImage(filebytes []byte, filename string, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug int) (types.Operator, types.DiskOrder, error) {
|
||||
ext := strings.ToLower(path.Ext(filename))
|
||||
size := len(filebytes)
|
||||
if size == FloppyDiskBytes {
|
||||
@ -54,7 +54,7 @@ func OpenImage(filebytes []byte, filename string, order types.DiskOrder, system
|
||||
return nil, "", fmt.Errorf("can only open disk-sized images and .hdv files")
|
||||
}
|
||||
|
||||
func openHDV(rawbytes []byte, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug bool) (types.Operator, types.DiskOrder, error) {
|
||||
func openHDV(rawbytes []byte, order types.DiskOrder, system string, operatorFactories []types.OperatorFactory, debug int) (types.Operator, types.DiskOrder, error) {
|
||||
size := len(rawbytes)
|
||||
if size%512 > 0 {
|
||||
return nil, "", fmt.Errorf("can only open .hdv files that are a multiple of 512 bytes: %d %% 512 == %d", size, size%512)
|
||||
@ -80,7 +80,7 @@ func openHDV(rawbytes []byte, order types.DiskOrder, system string, operatorFact
|
||||
return nil, "", fmt.Errorf("unable to find prodos module to open .hdv file") // Should not happen.
|
||||
}
|
||||
|
||||
func openDoOrPo(rawbytes []byte, order types.DiskOrder, system string, ext string, operatorFactories []types.OperatorFactory, debug bool) (types.Operator, types.DiskOrder, error) {
|
||||
func openDoOrPo(rawbytes []byte, order types.DiskOrder, system string, ext string, operatorFactories []types.OperatorFactory, debug int) (types.Operator, types.DiskOrder, error) {
|
||||
var factories []types.OperatorFactory
|
||||
for _, factory := range operatorFactories {
|
||||
if system == "auto" || system == factory.Name() {
|
||||
@ -121,7 +121,7 @@ func openDoOrPo(rawbytes []byte, order types.DiskOrder, system string, ext strin
|
||||
}
|
||||
|
||||
if len(orders) == 1 && system != "auto" {
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "Attempting to open with order=%s, system=%s.\n", order, factory.Name())
|
||||
}
|
||||
op, err := factory.Operator(diskbytes, debug)
|
||||
@ -131,7 +131,7 @@ func openDoOrPo(rawbytes []byte, order types.DiskOrder, system string, ext strin
|
||||
return op, order, nil
|
||||
}
|
||||
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "Testing whether order=%s, system=%s seems to match.\n", order, factory.Name())
|
||||
}
|
||||
if factory.SeemsToMatch(diskbytes, debug) {
|
||||
@ -139,7 +139,7 @@ func openDoOrPo(rawbytes []byte, order types.DiskOrder, system string, ext strin
|
||||
if err == nil {
|
||||
return op, order, nil
|
||||
}
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "Got error opening with order=%s, system=%s: %v\n", order, factory.Name(), err)
|
||||
}
|
||||
}
|
||||
|
10
dos3/dos3.go
10
dos3/dos3.go
@ -490,7 +490,7 @@ func (tsl *TrackSectorList) FromSector(data []byte) error {
|
||||
|
||||
// readCatalogSectors reads the raw CatalogSector structs from a DOS
|
||||
// 3.3 disk.
|
||||
func readCatalogSectors(diskbytes []byte, debug bool) ([]CatalogSector, error) {
|
||||
func readCatalogSectors(diskbytes []byte, debug int) ([]CatalogSector, error) {
|
||||
v := &VTOC{}
|
||||
err := disk.UnmarshalLogicalSector(diskbytes, v, VTOCTrack, VTOCSector)
|
||||
if err != nil {
|
||||
@ -528,7 +528,7 @@ func readCatalogSectors(diskbytes []byte, debug bool) ([]CatalogSector, error) {
|
||||
}
|
||||
|
||||
// ReadCatalog reads the catalog of a DOS 3.3 disk.
|
||||
func ReadCatalog(diskbytes []byte, debug bool) (files, deleted []FileDesc, err error) {
|
||||
func ReadCatalog(diskbytes []byte, debug int) (files, deleted []FileDesc, err error) {
|
||||
css, err := readCatalogSectors(diskbytes, debug)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -553,7 +553,7 @@ func ReadCatalog(diskbytes []byte, debug bool) (files, deleted []FileDesc, err e
|
||||
// high-level operations on files and directories.
|
||||
type operator struct {
|
||||
data []byte
|
||||
debug bool
|
||||
debug int
|
||||
}
|
||||
|
||||
var _ types.Operator = operator{}
|
||||
@ -692,14 +692,14 @@ func (of OperatorFactory) Name() string {
|
||||
|
||||
// SeemsToMatch returns true if the []byte disk image seems to match the
|
||||
// system of this operator.
|
||||
func (of OperatorFactory) SeemsToMatch(diskbytes []byte, debug bool) bool {
|
||||
func (of OperatorFactory) SeemsToMatch(diskbytes []byte, debug int) bool {
|
||||
// For now, just return true if we can run Catalog successfully.
|
||||
_, _, err := ReadCatalog(diskbytes, debug)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Operator returns an Operator for the []byte disk image.
|
||||
func (of OperatorFactory) Operator(diskbytes []byte, debug bool) (types.Operator, error) {
|
||||
func (of OperatorFactory) Operator(diskbytes []byte, debug int) (types.Operator, error) {
|
||||
return operator{data: diskbytes, debug: debug}, nil
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ func TestReadCatalog(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fds, deleted, err := ReadCatalog(diskbytes, false)
|
||||
fds, deleted, err := ReadCatalog(diskbytes, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
var cli struct {
|
||||
Debug bool `kong:"short='v',help='Enable debug mode.'"`
|
||||
Debug int `kong:"short='v',type='counter',help='Enable debug mode.'"`
|
||||
|
||||
Ls cmd.LsCmd `cmd:"" aliases:"list,cat,catalog" help:"List files/directories on a disk."`
|
||||
Reorder cmd.ReorderCmd `cmd:"" help:"Convert between DOS-order and ProDOS-order disk images."`
|
||||
|
1
next
1
next
@ -4,3 +4,4 @@ set -euo pipefail
|
||||
set -x
|
||||
# go run . nakedos mkhello supermon-audit-new.dsk DF02
|
||||
# go run . put -f supermon-audit-new.dsk DF02:FWORLD audit.o
|
||||
go run . dump ./data/disks/ProDOS_2_4_2.po VIEW.README
|
||||
|
@ -666,7 +666,7 @@ func (v Volume) subdirDescriptors() []FileDescriptor {
|
||||
|
||||
// readVolume reads the entire volume and subdirectories from a device
|
||||
// into memory.
|
||||
func readVolume(devicebytes []byte, keyBlock uint16, debug bool) (Volume, error) {
|
||||
func readVolume(devicebytes []byte, keyBlock uint16, debug int) (Volume, error) {
|
||||
v := Volume{
|
||||
keyBlock: &VolumeDirectoryKeyBlock{},
|
||||
subdirsByBlock: make(map[uint16]*Subdirectory),
|
||||
@ -699,7 +699,7 @@ func readVolume(devicebytes []byte, keyBlock uint16, debug bool) (Volume, error)
|
||||
}
|
||||
v.blocks = append(v.blocks, &vdb)
|
||||
v.firstSubdirBlocks[block] = keyBlock
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, " firstSubdirBlocks[%d] → %d\n", block, keyBlock)
|
||||
}
|
||||
// if debug {
|
||||
@ -708,7 +708,7 @@ func readVolume(devicebytes []byte, keyBlock uint16, debug bool) (Volume, error)
|
||||
}
|
||||
|
||||
sdds := v.subdirDescriptors()
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "got %d top-level subdir descriptors\n", len(sdds))
|
||||
}
|
||||
|
||||
@ -719,24 +719,24 @@ func readVolume(devicebytes []byte, keyBlock uint16, debug bool) (Volume, error)
|
||||
return v, err
|
||||
}
|
||||
v.subdirsByBlock[sdd.KeyPointer] = &sub
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, " subdirsByBlock[%d] → %q\n", sdd.KeyPointer, sub.keyBlock.Header.Name())
|
||||
}
|
||||
sdds = append(sdds, sub.subdirDescriptors()...)
|
||||
for _, block := range sub.blocks {
|
||||
v.firstSubdirBlocks[block.block] = sdd.KeyPointer
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, " firstSubdirBlocks[%d] → %d\n", block.block, sdd.KeyPointer)
|
||||
}
|
||||
}
|
||||
}
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "got %d total subdir descriptors\n", len(sdds))
|
||||
}
|
||||
|
||||
for _, sd := range v.subdirsByBlock {
|
||||
name := sd.keyBlock.Header.Name()
|
||||
if debug {
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "processing subdir %q\n", name)
|
||||
}
|
||||
parentName, err := parentDirName(sd.keyBlock.Header.ParentPointer, keyBlock, v.subdirsByBlock, v.firstSubdirBlocks)
|
||||
@ -749,8 +749,11 @@ func readVolume(devicebytes []byte, keyBlock uint16, debug bool) (Volume, error)
|
||||
|
||||
v.subdirsByName[name] = sd
|
||||
}
|
||||
if debug {
|
||||
fmt.Fprintf(os.Stderr, "HERE2\n")
|
||||
if debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "subdirsByName:\n")
|
||||
for k := range v.subdirsByName {
|
||||
fmt.Fprintf(os.Stderr, " %s\n", k)
|
||||
}
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
@ -842,7 +845,7 @@ func copyBytes(dst, src []byte) int {
|
||||
// high-level operations on files and directories.
|
||||
type operator struct {
|
||||
data []byte
|
||||
debug bool
|
||||
debug int
|
||||
}
|
||||
|
||||
var _ types.Operator = operator{}
|
||||
@ -865,7 +868,7 @@ func (o operator) HasSubdirs() bool {
|
||||
// Catalog returns a catalog of disk entries. subdir should be empty
|
||||
// for operating systems that do not support subdirectories.
|
||||
func (o operator) Catalog(subdir string) ([]types.Descriptor, error) {
|
||||
if o.debug {
|
||||
if o.debug > 1 {
|
||||
fmt.Fprintf(os.Stderr, "Catalog of %q\n", subdir)
|
||||
}
|
||||
vol, err := readVolume(o.data, 2, o.debug)
|
||||
@ -936,14 +939,14 @@ func (of OperatorFactory) Name() string {
|
||||
|
||||
// SeemsToMatch returns true if the []byte disk image seems to match the
|
||||
// system of this operator.
|
||||
func (of OperatorFactory) SeemsToMatch(devicebytes []byte, debug bool) bool {
|
||||
func (of OperatorFactory) SeemsToMatch(devicebytes []byte, debug int) bool {
|
||||
// For now, just return true if we can run Catalog successfully.
|
||||
_, err := readVolume(devicebytes, 2, debug)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Operator returns an Operator for the []byte disk image.
|
||||
func (of OperatorFactory) Operator(devicebytes []byte, debug bool) (types.Operator, error) {
|
||||
func (of OperatorFactory) Operator(devicebytes []byte, debug int) (types.Operator, error) {
|
||||
return operator{data: devicebytes, debug: debug}, nil
|
||||
}
|
||||
|
||||
|
@ -646,7 +646,7 @@ type Operator struct {
|
||||
data []byte
|
||||
SM SectorMap
|
||||
ST SymbolTable
|
||||
debug bool
|
||||
debug int
|
||||
}
|
||||
|
||||
var _ types.Operator = Operator{}
|
||||
@ -806,7 +806,7 @@ func (of OperatorFactory) Name() string {
|
||||
|
||||
// SeemsToMatch returns true if the []byte disk image seems to match the
|
||||
// system of this operator.
|
||||
func (of OperatorFactory) SeemsToMatch(diskbytes []byte, debug bool) bool {
|
||||
func (of OperatorFactory) SeemsToMatch(diskbytes []byte, debug int) bool {
|
||||
// For now, just return true if we can run Catalog successfully.
|
||||
sm, err := LoadSectorMap(diskbytes)
|
||||
if err != nil {
|
||||
@ -819,7 +819,7 @@ func (of OperatorFactory) SeemsToMatch(diskbytes []byte, debug bool) bool {
|
||||
}
|
||||
|
||||
// Operator returns an Operator for the []byte disk image.
|
||||
func (of OperatorFactory) Operator(diskbytes []byte, debug bool) (types.Operator, error) {
|
||||
func (of OperatorFactory) Operator(diskbytes []byte, debug int) (types.Operator, error) {
|
||||
sm, err := LoadSectorMap(diskbytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -4,7 +4,6 @@ package supermon
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -46,20 +45,6 @@ func loadSectorMap(filename string) (SectorMap, []byte, error) {
|
||||
return sm, diskbytes, nil
|
||||
}
|
||||
|
||||
// getOperator gets a types.Operator for the given NakedOS disk, assumed to be
|
||||
// in "do" order.
|
||||
func getOperator(filename string) (types.Operator, error) {
|
||||
f, err := os.Open(filepath.Clean(filename))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
op, _, err := disk.OpenFile(f, "do", "nakedos", []types.OperatorFactory{OperatorFactory{}}, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return op, nil
|
||||
}
|
||||
|
||||
// TestReadSectorMap tests the reading of the sector map of a test
|
||||
// disk.
|
||||
func TestReadSectorMap(t *testing.T) {
|
||||
@ -147,7 +132,7 @@ func TestReadSymbolTable(t *testing.T) {
|
||||
// TestGetFile tests the retrieval of a file's contents, using the
|
||||
// Operator interface.
|
||||
func TestGetFile(t *testing.T) {
|
||||
op, err := getOperator(testDisk)
|
||||
op, _, err := disk.OpenFilename(testDisk, types.DiskOrderAuto, "nakedos", []types.OperatorFactory{OperatorFactory{}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -228,7 +213,7 @@ func TestReadWriteSymbolTable(t *testing.T) {
|
||||
// TestPutFile tests the creation of a file, using the Operator
|
||||
// interface.
|
||||
func TestPutFile(t *testing.T) {
|
||||
op, err := getOperator(testDisk)
|
||||
op, _, err := disk.OpenFilename(testDisk, types.DiskOrderAuto, "nakedos", []types.OperatorFactory{OperatorFactory{}}, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ type OperatorFactory interface {
|
||||
DiskOrder() DiskOrder
|
||||
// SeemsToMatch returns true if the []byte disk image seems to match the
|
||||
// system of this operator.
|
||||
SeemsToMatch(diskbytes []byte, debug bool) bool
|
||||
SeemsToMatch(diskbytes []byte, debug int) bool
|
||||
// Operator returns an Operator for the []byte disk image.
|
||||
Operator(diskbytes []byte, debug bool) (Operator, error)
|
||||
Operator(diskbytes []byte, debug int) (Operator, error)
|
||||
}
|
||||
|
||||
// Operator is the interface that can operate on disks.
|
||||
|
@ -4,7 +4,8 @@ package types
|
||||
|
||||
// Globals holds flags and configuration that are shared globally.
|
||||
type Globals struct {
|
||||
Debug bool
|
||||
|
||||
// Debug level (0 = no debugging, 1 = normal user debugging, 2+ is mostly for me)
|
||||
Debug int
|
||||
// DiskOperatorFactories holds the current list of registered OperatorFactory instances.
|
||||
DiskOperatorFactories []OperatorFactory
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user