diff --git a/README.md b/README.md index 64262a0..d36c29b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ cross-platform. Its major disadvantage is that it mostly doesn't exist yet. [![Build Status](https://travis-ci.org/zellyn/diskii.svg?branch=master)](https://travis-ci.org/zellyn/diskii) +[![Report Card](https://goreportcard.com/badge/github.com/zellyn/diskii)](https://goreportcard.com/report/github.com/zellyn/diskii) + It rhymes with “whiskey”. diff --git a/cmd/catalog.go b/cmd/catalog.go index 1ea70e1..1820afd 100644 --- a/cmd/catalog.go +++ b/cmd/catalog.go @@ -8,8 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/zellyn/diskii/lib/disk" - _ "github.com/zellyn/diskii/lib/dos3" - _ "github.com/zellyn/diskii/lib/supermon" ) var shortnames bool // flag for whether to print short filenames diff --git a/cmd/delete.go b/cmd/delete.go index 7c1733c..a4df421 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -8,8 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/zellyn/diskii/lib/disk" - _ "github.com/zellyn/diskii/lib/dos3" - _ "github.com/zellyn/diskii/lib/supermon" ) var missingok bool // flag for whether to consider deleting a nonexistent file okay diff --git a/cmd/dump.go b/cmd/dump.go index 9955671..78b56a9 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -8,8 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/zellyn/diskii/lib/disk" - _ "github.com/zellyn/diskii/lib/dos3" - _ "github.com/zellyn/diskii/lib/supermon" ) // dumpCmd represents the dump command, used to dump the raw contents diff --git a/cmd/filetypes.go b/cmd/filetypes.go index 768b2ac..5138217 100644 --- a/cmd/filetypes.go +++ b/cmd/filetypes.go @@ -8,8 +8,6 @@ import ( "github.com/spf13/cobra" "github.com/zellyn/diskii/lib/disk" - _ "github.com/zellyn/diskii/lib/dos3" - _ "github.com/zellyn/diskii/lib/supermon" ) var all bool // flag for whether to show all filetypes diff --git a/cmd/put.go b/cmd/put.go index f281cc7..af6860b 100644 --- a/cmd/put.go +++ b/cmd/put.go @@ -8,9 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/zellyn/diskii/lib/disk" - _ "github.com/zellyn/diskii/lib/dos3" "github.com/zellyn/diskii/lib/helpers" - _ "github.com/zellyn/diskii/lib/supermon" ) var filetypeName string // flag for file type diff --git a/lib/disk/disk.go b/lib/disk/disk.go index 5df5d3b..fc4e3c9 100644 --- a/lib/disk/disk.go +++ b/lib/disk/disk.go @@ -11,8 +11,9 @@ import ( "strings" ) +// Various DOS33 disk characteristics. const ( - DOS33Tracks = 35 // Tracks per disk + DOS33Tracks = 35 DOS33Sectors = 16 // Sectors per track // DOS33DiskBytes is the number of bytes on a DOS 3.3 disk. DOS33DiskBytes = 143360 // 35 tracks * 16 sectors * 256 bytes @@ -39,6 +40,8 @@ type TrackSector struct { Sector byte } +// SectorDisk is the interface use to read and write disks by physical +// (matches sector header) sector number. type SectorDisk interface { // ReadPhysicalSector reads a single physical sector from the disk. It // always returns 256 byes. @@ -54,6 +57,8 @@ type SectorDisk interface { Write(io.Writer) (int, error) } +// LogicalSectorDisk is the interface used to read and write a disk by +// *logical* sector number. type LogicalSectorDisk interface { // ReadLogicalSector reads a single logical sector from the disk. It // always returns 256 byes. @@ -78,6 +83,8 @@ type MappedDisk struct { var _ LogicalSectorDisk = MappedDisk{} +// NewMappedDisk returns a MappedDisk with the given +// logical-to-physical sector mapping. func NewMappedDisk(sd SectorDisk, logicalToPhysical []byte) (MappedDisk, error) { if logicalToPhysical != nil && len(logicalToPhysical) != int(sd.Sectors()) { return MappedDisk{}, fmt.Errorf("NewMappedDisk called on a disk image with %d sectors per track, but a mapping of length %d", sd.Sectors(), len(logicalToPhysical)) diff --git a/lib/disk/dsk.go b/lib/disk/dsk.go index 8312786..015a712 100644 --- a/lib/disk/dsk.go +++ b/lib/disk/dsk.go @@ -29,7 +29,7 @@ func LoadDSK(filename string) (DSK, error) { } // TODO(zellyn): handle 13-sector disks. if len(bb) != DOS33DiskBytes { - return DSK{}, fmt.Errorf("Expected file %q to contain %d bytes, but got %d.", filename, DOS33DiskBytes, len(bb)) + return DSK{}, fmt.Errorf("expected file %q to contain %d bytes, but got %d", filename, DOS33DiskBytes, len(bb)) } return DSK{ data: bb, diff --git a/lib/disk/filetype.go b/lib/disk/filetype.go index 27ee6f8..92a662e 100644 --- a/lib/disk/filetype.go +++ b/lib/disk/filetype.go @@ -11,6 +11,7 @@ import "fmt" // the ProDOS/SOS filetype byte definitions in the range 00-FF. type Filetype int +// Filetypes. const ( FiletypeTypeless Filetype = 0x00 // | both | Typeless file FiletypeBadBlocks Filetype = 0x01 // | both | Bad blocks file diff --git a/lib/dos3/dos3.go b/lib/dos3/dos3.go index 3c311e9..67293e6 100644 --- a/lib/dos3/dos3.go +++ b/lib/dos3/dos3.go @@ -19,6 +19,7 @@ const ( VTOCSector = 0 ) +// DiskSector represents a track and sector. type DiskSector struct { Track byte Sector byte @@ -185,6 +186,8 @@ func (v *VTOC) FromSector(data []byte) error { return nil } +// DefaultVTOC returns a new, empty VTOC with values set to their +// defaults. func DefaultVTOC() VTOC { v := VTOC{ CatalogTrack: 0x11, @@ -253,9 +256,9 @@ func (cs *CatalogSector) FromSector(data []byte) error { // Filetype is the type for dos 3.3 filetype+locked status byte. type Filetype byte +// The DOS3 filetypes. const ( - // Hex 80+file type - file is locked, - // Hex 00+file type - file is not locked. + // FiletypeLocked is just setting the high bit on other file types. FiletypeLocked Filetype = 0x80 FiletypeText Filetype = 0x00 // Text file @@ -268,8 +271,10 @@ const ( FiletypeB Filetype = 0x40 // B type file ) +// FileDescStatus is the type used to mark file descriptor status. type FileDescStatus int +// The three actual file descriptor status values. const ( FileDescStatusNormal FileDescStatus = iota FileDescStatusDeleted diff --git a/lib/dos3/dos3_test.go b/lib/dos3/dos3_test.go index 8575b2f..a287053 100644 --- a/lib/dos3/dos3_test.go +++ b/lib/dos3/dos3_test.go @@ -85,6 +85,9 @@ func TestReadCatalog(t *testing.T) { t.Fatal(err) } fds, deleted, err := ReadCatalog(dsk) + if err != nil { + t.Fatal(err) + } fdsWant := []struct { locked bool diff --git a/lib/errors/errors.go b/lib/errors/errors.go index e313f84..315ee07 100644 --- a/lib/errors/errors.go +++ b/lib/errors/errors.go @@ -9,7 +9,8 @@ import ( "fmt" ) -// Copy of errors.New, so you this package can be imported instead. +// New is a copy of errors.New, so this package can be imported as a +// replacement. func New(text string) error { return errors.New(text) } diff --git a/lib/helpers/helpers.go b/lib/helpers/helpers.go index 6b41b32..1b85fe0 100644 --- a/lib/helpers/helpers.go +++ b/lib/helpers/helpers.go @@ -9,6 +9,8 @@ import ( "os" ) +// FileContentsOrStdIn returns the contents of a file, unless the file +// is "-", in which case it reads from stdin. func FileContentsOrStdIn(s string) ([]byte, error) { if s == "-" { return ioutil.ReadAll(os.Stdin) diff --git a/lib/supermon/supermon.go b/lib/supermon/supermon.go index 785ed82..226ebef 100644 --- a/lib/supermon/supermon.go +++ b/lib/supermon/supermon.go @@ -473,7 +473,7 @@ func (st SymbolTable) DeleteSymbol(name string) bool { // already exists with a different address, it deletes it first. func (st SymbolTable) AddSymbol(name string, address uint16) error { if address == 0 { - return fmt.Errorf("cannot set symbol %q to address 0") + return fmt.Errorf("cannot set symbol %q to address 0", name) } hash := addrHash(address) pos := -1 @@ -584,7 +584,7 @@ func (st SymbolTable) ParseCompoundSymbol(name string) (address uint16, symAddre if _, err := encodeSymbol(name); err != nil { return 0, 0, name, nil } - return 0, 0, "", fmt.Errorf("%q is not a valid symbol name or address") + return 0, 0, "", fmt.Errorf("%q is not a valid symbol name or address", name) } if parts[0] == "" { @@ -630,7 +630,7 @@ func (st SymbolTable) FilesForCompoundName(filename string) (numFile byte, named return 0, 0, "", fmt.Errorf("invalid file number: %q", parts[0]) } if numFile2 := parseAddressFilename(parts[1]); numFile2 != 0 { - return 0, 0, "", fmt.Errorf("cannot valid file number (%q) as a filename") + return 0, 0, "", fmt.Errorf("cannot use valid file number (%q) as a filename", parts[1]) } namedFile, err = st.FileForName(parts[1]) if err != nil { diff --git a/main.go b/main.go index 202f506..ca9cd99 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,13 @@ package main -import "github.com/zellyn/diskii/cmd" +import ( + "github.com/zellyn/diskii/cmd" + + // Import disk operator factories for DOS3 and Super-Mon + _ "github.com/zellyn/diskii/lib/dos3" + _ "github.com/zellyn/diskii/lib/supermon" +) func main() { cmd.Execute()