Skip to content

Commit

Permalink
Add go report card; fix vet, lint, etc. warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zellyn committed Dec 10, 2016
1 parent 34a26dd commit e376f8e
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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”.

Expand Down
2 changes: 0 additions & 2 deletions cmd/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/filetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lib/disk/dsk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/disk/filetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/dos3/dos3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
VTOCSector = 0
)

// DiskSector represents a track and sector.
type DiskSector struct {
Track byte
Sector byte
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/dos3/dos3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/supermon/supermon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] == "" {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e376f8e

Please sign in to comment.