From b9a838400caf83b48721ff3f920b0f56335976b5 Mon Sep 17 00:00:00 2001 From: Zellyn Hunter Date: Wed, 30 Nov 2016 22:12:01 -0500 Subject: [PATCH] add concept of full and short filenames --- cmd/catalog.go | 9 ++++++++- lib/disk/ops.go | 11 ++++++----- lib/supermon/supermon.go | 20 +++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cmd/catalog.go b/cmd/catalog.go index af1010e..1ea70e1 100644 --- a/cmd/catalog.go +++ b/cmd/catalog.go @@ -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{ @@ -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. @@ -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 } diff --git a/lib/disk/ops.go b/lib/disk/ops.go index d4860c2..2e82b23 100644 --- a/lib/disk/ops.go +++ b/lib/disk/ops.go @@ -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. diff --git a/lib/supermon/supermon.go b/lib/supermon/supermon.go index 0fe26fc..98347e2 100644 --- a/lib/supermon/supermon.go +++ b/lib/supermon/supermon.go @@ -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 { @@ -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