Skip to content

Commit

Permalink
add concept of full and short filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
zellyn committed Dec 1, 2016
1 parent 10d2a1e commit b9a8384
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
9 changes: 8 additions & 1 deletion cmd/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
_ "github.com/zellyn/diskii/lib/supermon"
)

var shortnames bool // flag for whether to print short filenames

// catalogCmd represents the cat command, used to catalog a disk or
// directory.
var catalogCmd = &cobra.Command{
Expand All @@ -29,6 +31,7 @@ var catalogCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(catalogCmd)
catalogCmd.Flags().BoolVarP(&shortnames, "shortnames", "s", false, "whether to print short filenames (only makes a difference on Super-Mon disks)")
}

// runCat performs the actual catalog logic.
Expand Down Expand Up @@ -56,7 +59,11 @@ func runCat(args []string) error {
return err
}
for _, fd := range fds {
fmt.Println(fd.Name)
if !shortnames && fd.Fullname != "" {
fmt.Println(fd.Fullname)
} else {
fmt.Println(fd.Name)
}
}
return nil
}
11 changes: 6 additions & 5 deletions lib/disk/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (

// Descriptor describes a file's characteristics.
type Descriptor struct {
Name string
Sectors int
Length int
Locked bool
Type Filetype
Name string
Fullname string // If there's a more complete filename (eg. Super-Mon), put it here.
Sectors int
Length int
Locked bool
Type Filetype
}

// Operator is the interface that can operate on disks.
Expand Down
20 changes: 15 additions & 5 deletions lib/supermon/supermon.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ func NameForFile(file byte, symbols []Symbol) string {
return fmt.Sprintf("DF%02X", file)
}

// FullnameForFile returns a string representation of a filename:
// either DFxx, or a DFxx:symbol, if one exists for that value.
func FullnameForFile(file byte, symbols []Symbol) string {
if len(symbols) > 0 {
return fmt.Sprintf("DF%02X:%s", file, symbols[0].Name)
}
return fmt.Sprintf("DF%02X", file)
}

// parseAddressFilename parses filenames of the form DFxx and returns
// the xx part. Invalid filenames result in 0.
func parseAddressFilename(filename string) byte {
Expand Down Expand Up @@ -596,11 +605,12 @@ func (o operator) Catalog(subdir string) ([]disk.Descriptor, error) {
}
fileAddr := 0xDF00 + uint16(file)
descs = append(descs, disk.Descriptor{
Name: NameForFile(file, o.symbols[fileAddr]),
Sectors: l,
Length: l * 256,
Locked: false,
Type: disk.FiletypeBinary,
Name: NameForFile(file, o.symbols[fileAddr]),
Fullname: FullnameForFile(file, o.symbols[fileAddr]),
Sectors: l,
Length: l * 256,
Locked: false,
Type: disk.FiletypeBinary,
})
}
return descs, nil
Expand Down

0 comments on commit b9a8384

Please sign in to comment.