Skip to content

Commit

Permalink
Added examine and deposit to memory and registers commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcornwell committed Jul 23, 2024
1 parent d62aa2f commit 3ecf969
Show file tree
Hide file tree
Showing 15 changed files with 1,231 additions and 227 deletions.
2 changes: 1 addition & 1 deletion command/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import "errors"
type CmdOption struct {
Name string // Name of option.
EqualOpt string // Value of string after =.
Value int // Numberic value.
Value uint32 // Numberic value.
}

// List of option types.
Expand Down
31 changes: 16 additions & 15 deletions command/parser/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
var cmdList = []cmd{
{Name: "attach", Min: 2, Process: attach, Complete: attachComplete},
{Name: "detach", Min: 2, Process: detach, Complete: func(line *cmdLine) []string {
return matchDevice(true, *line, command.ValidAttach, false)
return line.matchDevice(command.ValidAttach, false)
}},
{Name: "set", Min: 3, Process: set, Complete: setComplete},
{Name: "unset", Min: 4, Process: unset, Complete: setComplete},
Expand All @@ -49,11 +49,13 @@ var cmdList = []cmd{
{Name: "continue", Min: 1, Process: cont},
{Name: "start", Min: 3, Process: start},
{Name: "show", Min: 2, Process: show, Complete: showComplete},
{Name: "examine", Min: 2, Process: examine},
{Name: "deposit", Min: 2, Process: deposit},
{Name: "ipl", Min: 1, Process: ipl, Complete: func(line *cmdLine) []string {
return matchDevice(true, *line, command.ValidIPL, false)
return line.matchDevice(command.ValidIPL, false)
}},
{Name: "rewind", Min: 3, Process: rewind, Complete: func(line *cmdLine) []string {
return matchDevice(true, *line, command.ValidRewind, false)
return line.matchDevice(command.ValidRewind, false)
}},
{Name: "reset", Min: 5, Process: reset, Complete: DeviceComplete},
}
Expand Down Expand Up @@ -179,8 +181,8 @@ func show(line *cmdLine, _ *core.Core) (bool, error) {
// Get device number make sure it is valid.
devNum, err := line.getHex()
if err != nil || line.isEOL() {
name, last := line.getWord(false)
if last != 0 || name != "all" {
name := line.getWord(false)
if name != "all" {
return false, errors.New("set must be device number, empty or all")
}

Expand All @@ -191,13 +193,13 @@ func show(line *cmdLine, _ *core.Core) (bool, error) {
continue
}

device, err := ch.GetCommand(uint16(devNum))
if err != nil {
device, nfnd := ch.GetCommand(uint16(devNum))
if nfnd != nil {
continue
}

out, err := device.Show(optList)
if err != nil {
out, noOpt := device.Show(optList)
if noOpt != nil {
continue
}
fmt.Println(out)
Expand Down Expand Up @@ -227,13 +229,12 @@ func show(line *cmdLine, _ *core.Core) (bool, error) {

// Set/Unset command completion.
func showComplete(line *cmdLine) []string {
devices := matchDevice(true, *line, command.ValidShow, false)
devices := line.matchDevice(command.ValidShow, false)
if len(devices) != 1 {
return devices
}

device, err := line.getDevice()

if err != nil {
return devices
}
Expand Down Expand Up @@ -269,17 +270,17 @@ func reset(line *cmdLine, _ *core.Core) (bool, error) {
// Get device number make sure it is valid.
devNum, err := line.getHex()
if err != nil || line.isEOL() {
name, last := line.getWord(false)
if last != 0 || name != "all" {
name := line.getWord(false)
if name != "all" {
return false, errors.New("set must be device number, empty or all")
}

// If no unit number of all reset all devices.
for _, str := range config.ModelList {
devNum, ok := strconv.ParseUint(str, 16, 12)
if ok == nil {
device, err := ch.GetCommand(uint16(devNum))
if err == nil {
device, deverr := ch.GetCommand(uint16(devNum))
if deverr == nil {
_ = device.Reset()
}
}
Expand Down
95 changes: 58 additions & 37 deletions command/parser/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import (
// Called to complete a command line, during line editing.
func CompleteCmd(commandLine string) []string {
line := cmdLine{line: commandLine}
name, last := line.getWord(false)
name := line.getWord(false)

// We have a command, let it try and complete it.
if unicode.IsSpace(rune(last)) {
if !line.isEOL() && !unicode.IsSpace(rune(line.getCurrent())) {
// See if there is a completer for this command.
match := matchList(name)
if len(match) == 0 || len(match) > 1 {
Expand All @@ -66,13 +66,10 @@ func CompleteCmd(commandLine string) []string {
}

// Match for device address.
func matchDevice(appendStart bool, line cmdLine, cmdType int, all bool) []string {
leading := ""
func (line *cmdLine) matchDevice(cmdType int, all bool) []string {
device := ""
pos := line.pos
if appendStart {
leading = line.line[:pos]
}
leading := line.line[:pos]

// Collect device.
for pos < len(line.line) {
Expand Down Expand Up @@ -124,24 +121,52 @@ outer:
return devices
}

// Scan a word.
// Scan a number.
func (line *cmdLine) scanNumber() (string, bool) {
line.skipSpace()

// Check if end of line.
if line.isEOL() {
return "", true
return "", false
}

pos := line.pos
// Characters must be alphabetic
// Characters must be numeric
value := ""
by := line.line[line.pos]
for {
if !unicode.IsDigit(rune(by)) {
line.pos = pos
return "", false
}
value += string([]byte{by})
by = line.getNext()
if line.isEOL() || unicode.IsSpace(rune(by)) {
break
}
}

return value, true
}

// Scan a hexnumber.
func (line *cmdLine) scanHex() (string, bool) {
line.skipSpace()

// Check if end of line.
if line.isEOL() {
return "", false
}

pos := line.pos
// Characters must be numeric
value := ""
by := line.line[line.pos]
for {
if strings.Contains(hex, strings.ToLower(string(by))) {
line.pos = pos
return "", false
}
value += string([]byte{by})
by = line.getNext()
if line.isEOL() || unicode.IsSpace(rune(by)) {
Expand Down Expand Up @@ -276,12 +301,11 @@ func (line *cmdLine) scanOption(opt command.Options) ([]string, bool) {
str, skip = line.scanQuoteString()

case command.OptionNumber:
str = line.scanWord(false)
skip = str != ""
str, skip = line.scanNumber()

case command.OptionHex:
str = line.scanWord(false)
skip = str != ""
str, skip = line.scanHex()

case command.OptionList:
modName := line.scanList()
mods := []string{}
Expand Down Expand Up @@ -355,43 +379,40 @@ func (line *cmdLine) scanOptions(device command.Command, cmdType int) []string {
func (line *cmdLine) scanOpts(device command.Command, cmdType int) []string {
opts := device.Options("")
matches := []string{}
for {
line.skipSpace()
leading := ""
if line.pos == (len(line.line) - 1) {
leading = line.line
} else {
leading = line.line[:line.pos]
}
name := line.scanWord(true)

matchOpts := scanOpt(name, opts, cmdType)
line.skipSpace()
if len(matchOpts) > 1 {
leading = line.line[:line.pos-len(name)]
for _, opt := range matchOpts {
matches = append(matches, leading+opt.Name)
}
return matches
}
// for {
line.skipSpace()
// leading := line.line
// if line.pos < (len(line.line) - 1) {
// leading = line.line[:line.pos]
// }
name := line.scanWord(true)

leading = line.line[:line.pos]
matchOpts := scanOpt(name, opts, cmdType)
line.skipSpace()
if len(matchOpts) > 1 {
leading := line.line[:line.pos-len(name)]
for _, opt := range matchOpts {
matches = append(matches, leading+opt.Name)
}
return matches
}

leading := line.line[:line.pos]
for _, opt := range matchOpts {
matches = append(matches, leading+opt.Name)
}
return matches
// }
}

// Scan device style commands.
func (line *cmdLine) scanDevice(cmdType int) []string {
devices := matchDevice(true, *line, cmdType, false)
devices := line.matchDevice(cmdType, false)
if len(devices) != 1 {
return devices
}

device, err := line.getDevice()

if err != nil {
return devices
}
Expand All @@ -401,5 +422,5 @@ func (line *cmdLine) scanDevice(cmdType int) []string {

// Complete commands that only need device number.
func DeviceComplete(line *cmdLine) []string {
return matchDevice(true, *line, 0, true)
return line.matchDevice(0, true)
}
Loading

0 comments on commit 3ecf969

Please sign in to comment.