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"
)
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
}

View File

@ -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.

View File

@ -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