mirror of https://github.com/zellyn/diskii.git
Add go report card; fix vet, lint, etc. warnings
This commit is contained in:
parent
34a26dd1d6
commit
e376f8ee41
|
@ -15,6 +15,8 @@ cross-platform.
|
||||||
Its major disadvantage is that it mostly doesn't exist yet.
|
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)
|
[![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”.
|
It rhymes with “whiskey”.
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zellyn/diskii/lib/disk"
|
"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
|
var shortnames bool // flag for whether to print short filenames
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zellyn/diskii/lib/disk"
|
"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
|
var missingok bool // flag for whether to consider deleting a nonexistent file okay
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zellyn/diskii/lib/disk"
|
"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
|
// dumpCmd represents the dump command, used to dump the raw contents
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zellyn/diskii/lib/disk"
|
"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
|
var all bool // flag for whether to show all filetypes
|
||||||
|
|
|
@ -8,9 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zellyn/diskii/lib/disk"
|
"github.com/zellyn/diskii/lib/disk"
|
||||||
_ "github.com/zellyn/diskii/lib/dos3"
|
|
||||||
"github.com/zellyn/diskii/lib/helpers"
|
"github.com/zellyn/diskii/lib/helpers"
|
||||||
_ "github.com/zellyn/diskii/lib/supermon"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var filetypeName string // flag for file type
|
var filetypeName string // flag for file type
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Various DOS33 disk characteristics.
|
||||||
const (
|
const (
|
||||||
DOS33Tracks = 35 // Tracks per disk
|
DOS33Tracks = 35
|
||||||
DOS33Sectors = 16 // Sectors per track
|
DOS33Sectors = 16 // Sectors per track
|
||||||
// DOS33DiskBytes is the number of bytes on a DOS 3.3 disk.
|
// DOS33DiskBytes is the number of bytes on a DOS 3.3 disk.
|
||||||
DOS33DiskBytes = 143360 // 35 tracks * 16 sectors * 256 bytes
|
DOS33DiskBytes = 143360 // 35 tracks * 16 sectors * 256 bytes
|
||||||
|
@ -39,6 +40,8 @@ type TrackSector struct {
|
||||||
Sector byte
|
Sector byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SectorDisk is the interface use to read and write disks by physical
|
||||||
|
// (matches sector header) sector number.
|
||||||
type SectorDisk interface {
|
type SectorDisk interface {
|
||||||
// ReadPhysicalSector reads a single physical sector from the disk. It
|
// ReadPhysicalSector reads a single physical sector from the disk. It
|
||||||
// always returns 256 byes.
|
// always returns 256 byes.
|
||||||
|
@ -54,6 +57,8 @@ type SectorDisk interface {
|
||||||
Write(io.Writer) (int, error)
|
Write(io.Writer) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogicalSectorDisk is the interface used to read and write a disk by
|
||||||
|
// *logical* sector number.
|
||||||
type LogicalSectorDisk interface {
|
type LogicalSectorDisk interface {
|
||||||
// ReadLogicalSector reads a single logical sector from the disk. It
|
// ReadLogicalSector reads a single logical sector from the disk. It
|
||||||
// always returns 256 byes.
|
// always returns 256 byes.
|
||||||
|
@ -78,6 +83,8 @@ type MappedDisk struct {
|
||||||
|
|
||||||
var _ LogicalSectorDisk = MappedDisk{}
|
var _ LogicalSectorDisk = MappedDisk{}
|
||||||
|
|
||||||
|
// NewMappedDisk returns a MappedDisk with the given
|
||||||
|
// logical-to-physical sector mapping.
|
||||||
func NewMappedDisk(sd SectorDisk, logicalToPhysical []byte) (MappedDisk, error) {
|
func NewMappedDisk(sd SectorDisk, logicalToPhysical []byte) (MappedDisk, error) {
|
||||||
if logicalToPhysical != nil && len(logicalToPhysical) != int(sd.Sectors()) {
|
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))
|
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))
|
||||||
|
|
|
@ -29,7 +29,7 @@ func LoadDSK(filename string) (DSK, error) {
|
||||||
}
|
}
|
||||||
// TODO(zellyn): handle 13-sector disks.
|
// TODO(zellyn): handle 13-sector disks.
|
||||||
if len(bb) != DOS33DiskBytes {
|
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{
|
return DSK{
|
||||||
data: bb,
|
data: bb,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import "fmt"
|
||||||
// the ProDOS/SOS filetype byte definitions in the range 00-FF.
|
// the ProDOS/SOS filetype byte definitions in the range 00-FF.
|
||||||
type Filetype int
|
type Filetype int
|
||||||
|
|
||||||
|
// Filetypes.
|
||||||
const (
|
const (
|
||||||
FiletypeTypeless Filetype = 0x00 // | both | Typeless file
|
FiletypeTypeless Filetype = 0x00 // | both | Typeless file
|
||||||
FiletypeBadBlocks Filetype = 0x01 // | both | Bad blocks file
|
FiletypeBadBlocks Filetype = 0x01 // | both | Bad blocks file
|
||||||
|
|
|
@ -19,6 +19,7 @@ const (
|
||||||
VTOCSector = 0
|
VTOCSector = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DiskSector represents a track and sector.
|
||||||
type DiskSector struct {
|
type DiskSector struct {
|
||||||
Track byte
|
Track byte
|
||||||
Sector byte
|
Sector byte
|
||||||
|
@ -185,6 +186,8 @@ func (v *VTOC) FromSector(data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultVTOC returns a new, empty VTOC with values set to their
|
||||||
|
// defaults.
|
||||||
func DefaultVTOC() VTOC {
|
func DefaultVTOC() VTOC {
|
||||||
v := VTOC{
|
v := VTOC{
|
||||||
CatalogTrack: 0x11,
|
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.
|
// Filetype is the type for dos 3.3 filetype+locked status byte.
|
||||||
type Filetype byte
|
type Filetype byte
|
||||||
|
|
||||||
|
// The DOS3 filetypes.
|
||||||
const (
|
const (
|
||||||
// Hex 80+file type - file is locked,
|
// FiletypeLocked is just setting the high bit on other file types.
|
||||||
// Hex 00+file type - file is not locked.
|
|
||||||
FiletypeLocked Filetype = 0x80
|
FiletypeLocked Filetype = 0x80
|
||||||
|
|
||||||
FiletypeText Filetype = 0x00 // Text file
|
FiletypeText Filetype = 0x00 // Text file
|
||||||
|
@ -268,8 +271,10 @@ const (
|
||||||
FiletypeB Filetype = 0x40 // B type file
|
FiletypeB Filetype = 0x40 // B type file
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FileDescStatus is the type used to mark file descriptor status.
|
||||||
type FileDescStatus int
|
type FileDescStatus int
|
||||||
|
|
||||||
|
// The three actual file descriptor status values.
|
||||||
const (
|
const (
|
||||||
FileDescStatusNormal FileDescStatus = iota
|
FileDescStatusNormal FileDescStatus = iota
|
||||||
FileDescStatusDeleted
|
FileDescStatusDeleted
|
||||||
|
|
|
@ -85,6 +85,9 @@ func TestReadCatalog(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
fds, deleted, err := ReadCatalog(dsk)
|
fds, deleted, err := ReadCatalog(dsk)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
fdsWant := []struct {
|
fdsWant := []struct {
|
||||||
locked bool
|
locked bool
|
||||||
|
|
|
@ -9,7 +9,8 @@ import (
|
||||||
"fmt"
|
"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 {
|
func New(text string) error {
|
||||||
return errors.New(text)
|
return errors.New(text)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"os"
|
"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) {
|
func FileContentsOrStdIn(s string) ([]byte, error) {
|
||||||
if s == "-" {
|
if s == "-" {
|
||||||
return ioutil.ReadAll(os.Stdin)
|
return ioutil.ReadAll(os.Stdin)
|
||||||
|
|
|
@ -473,7 +473,7 @@ func (st SymbolTable) DeleteSymbol(name string) bool {
|
||||||
// already exists with a different address, it deletes it first.
|
// already exists with a different address, it deletes it first.
|
||||||
func (st SymbolTable) AddSymbol(name string, address uint16) error {
|
func (st SymbolTable) AddSymbol(name string, address uint16) error {
|
||||||
if address == 0 {
|
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)
|
hash := addrHash(address)
|
||||||
pos := -1
|
pos := -1
|
||||||
|
@ -584,7 +584,7 @@ func (st SymbolTable) ParseCompoundSymbol(name string) (address uint16, symAddre
|
||||||
if _, err := encodeSymbol(name); err != nil {
|
if _, err := encodeSymbol(name); err != nil {
|
||||||
return 0, 0, name, 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] == "" {
|
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])
|
return 0, 0, "", fmt.Errorf("invalid file number: %q", parts[0])
|
||||||
}
|
}
|
||||||
if numFile2 := parseAddressFilename(parts[1]); numFile2 != 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])
|
namedFile, err = st.FileForName(parts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
8
main.go
8
main.go
|
@ -2,7 +2,13 @@
|
||||||
|
|
||||||
package main
|
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() {
|
func main() {
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
|
|
Loading…
Reference in New Issue