add concept of full and short filenames

This commit is contained in:
Zellyn Hunter 2016-11-30 22:12:01 -05:00
parent 10d2a1e027
commit b9a838400c
3 changed files with 29 additions and 11 deletions

View File

@ -12,6 +12,8 @@ import (
_ "github.com/zellyn/diskii/lib/supermon" _ "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 // catalogCmd represents the cat command, used to catalog a disk or
// directory. // directory.
var catalogCmd = &cobra.Command{ var catalogCmd = &cobra.Command{
@ -29,6 +31,7 @@ var catalogCmd = &cobra.Command{
func init() { func init() {
RootCmd.AddCommand(catalogCmd) 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. // runCat performs the actual catalog logic.
@ -56,7 +59,11 @@ func runCat(args []string) error {
return err return err
} }
for _, fd := range fds { for _, fd := range fds {
fmt.Println(fd.Name) if !shortnames && fd.Fullname != "" {
fmt.Println(fd.Fullname)
} else {
fmt.Println(fd.Name)
}
} }
return nil return nil
} }

View File

@ -15,11 +15,12 @@ import (
// Descriptor describes a file's characteristics. // Descriptor describes a file's characteristics.
type Descriptor struct { type Descriptor struct {
Name string Name string
Sectors int Fullname string // If there's a more complete filename (eg. Super-Mon), put it here.
Length int Sectors int
Locked bool Length int
Type Filetype Locked bool
Type Filetype
} }
// Operator is the interface that can operate on disks. // Operator is the interface that can operate on disks.

View File

@ -490,6 +490,15 @@ func NameForFile(file byte, symbols []Symbol) string {
return fmt.Sprintf("DF%02X", file) 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 // parseAddressFilename parses filenames of the form DFxx and returns
// the xx part. Invalid filenames result in 0. // the xx part. Invalid filenames result in 0.
func parseAddressFilename(filename string) byte { func parseAddressFilename(filename string) byte {
@ -596,11 +605,12 @@ func (o operator) Catalog(subdir string) ([]disk.Descriptor, error) {
} }
fileAddr := 0xDF00 + uint16(file) fileAddr := 0xDF00 + uint16(file)
descs = append(descs, disk.Descriptor{ descs = append(descs, disk.Descriptor{
Name: NameForFile(file, o.symbols[fileAddr]), Name: NameForFile(file, o.symbols[fileAddr]),
Sectors: l, Fullname: FullnameForFile(file, o.symbols[fileAddr]),
Length: l * 256, Sectors: l,
Locked: false, Length: l * 256,
Type: disk.FiletypeBinary, Locked: false,
Type: disk.FiletypeBinary,
}) })
} }
return descs, nil return descs, nil