mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 20:41:01 +01:00
Compare commits
4 Commits
feature/ad
...
internal/u
| Author | SHA1 | Date | |
|---|---|---|---|
| d9a0d61efc | |||
|
|
d2db420837 | ||
|
|
b4f53d2dd6 | ||
| 4c6caa7114 |
26
calc.go
26
calc.go
@@ -261,7 +261,7 @@ func (c *Calc) Eval(line string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := c.Funcalls[item]; ok {
|
||||
if exists(c.Funcalls, item) {
|
||||
if err := c.DoFuncall(item); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
@@ -270,8 +270,12 @@ func (c *Calc) Eval(line string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if c.batch {
|
||||
if _, ok := c.BatchFuncalls[item]; ok {
|
||||
if exists(c.BatchFuncalls, item) {
|
||||
if !c.batch {
|
||||
fmt.Println("only supported in batch mode")
|
||||
continue
|
||||
}
|
||||
|
||||
if err := c.DoFuncall(item); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
@@ -279,12 +283,6 @@ func (c *Calc) Eval(line string) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if _, ok := c.BatchFuncalls[item]; ok {
|
||||
fmt.Println("only supported in batch mode")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if contains(c.LuaFunctions, item) {
|
||||
// user provided custom lua functions
|
||||
@@ -304,22 +302,22 @@ func (c *Calc) Eval(line string) {
|
||||
}
|
||||
|
||||
// internal commands
|
||||
if _, ok := c.Commands[item]; ok {
|
||||
if exists(c.Commands, item) {
|
||||
c.Commands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := c.ShowCommands[item]; ok {
|
||||
if exists(c.ShowCommands, item) {
|
||||
c.ShowCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := c.StackCommands[item]; ok {
|
||||
if exists(c.StackCommands, item) {
|
||||
c.StackCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := c.SettingsCommands[item]; ok {
|
||||
if exists(c.SettingsCommands, item) {
|
||||
c.SettingsCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
@@ -507,7 +505,7 @@ func (c *Calc) PutVar(name string) {
|
||||
}
|
||||
|
||||
func (c *Calc) GetVar(name string) {
|
||||
if _, ok := c.Vars[name]; ok {
|
||||
if exists(c.Vars, name) {
|
||||
c.Debug(fmt.Sprintf("retrieve %.2f from %s", c.Vars[name], name))
|
||||
c.stack.Backup()
|
||||
c.stack.Push(c.Vars[name])
|
||||
|
||||
28
rpn.go
28
rpn.go
@@ -178,17 +178,27 @@ DESCRIPTION
|
||||
[no]debug toggle debug output (nodebug turns it off)
|
||||
[no]showstack show the last 5 items of the stack (noshowtack turns it off)
|
||||
|
||||
Show commands: dump display the stack contents hex show last stack item
|
||||
in hex form (converted to int) history display calculation history vars
|
||||
show list of variables
|
||||
Show commands:
|
||||
|
||||
Stack manipulation commands: clear clear the whole stack shift remove
|
||||
the last element of the stack reverse reverse the stack elements swap
|
||||
exchange the last two stack elements dup duplicate last stack item undo
|
||||
undo last operation edit edit the stack interactively using vi or
|
||||
$EDITOR
|
||||
dump display the stack contents
|
||||
hex show last stack item in hex form (converted to int)
|
||||
history display calculation history
|
||||
vars show list of variables
|
||||
|
||||
Other commands: help|? show this message manual show manual
|
||||
Stack manipulation commands:
|
||||
|
||||
clear clear the whole stack
|
||||
shift remove the last element of the stack
|
||||
reverse reverse the stack elements
|
||||
swap exchange the last two stack elements
|
||||
dup duplicate last stack item
|
||||
undo undo last operation
|
||||
edit edit the stack interactively using vi or $EDITOR
|
||||
|
||||
Other commands:
|
||||
|
||||
help|? show this message
|
||||
manual show manual
|
||||
quit|exit|c-d|c-c exit program
|
||||
|
||||
Register variables:
|
||||
|
||||
3
rpn.pod
3
rpn.pod
@@ -186,12 +186,14 @@ Configuration Commands:
|
||||
[no]showstack show the last 5 items of the stack (noshowtack turns it off)
|
||||
|
||||
Show commands:
|
||||
|
||||
dump display the stack contents
|
||||
hex show last stack item in hex form (converted to int)
|
||||
history display calculation history
|
||||
vars show list of variables
|
||||
|
||||
Stack manipulation commands:
|
||||
|
||||
clear clear the whole stack
|
||||
shift remove the last element of the stack
|
||||
reverse reverse the stack elements
|
||||
@@ -201,6 +203,7 @@ Stack manipulation commands:
|
||||
edit edit the stack interactively using vi or $EDITOR
|
||||
|
||||
Other commands:
|
||||
|
||||
help|? show this message
|
||||
manual show manual
|
||||
quit|exit|c-d|c-c exit program
|
||||
|
||||
16
util.go
16
util.go
@@ -23,16 +23,24 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// find an item in a list
|
||||
func contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
// find an item in a list, generic variant
|
||||
func contains[E comparable](s []E, v E) bool {
|
||||
for _, vs := range s {
|
||||
if v == vs {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// look if a key in a map exists, generic variant
|
||||
func exists[K comparable, V any](m map[K]V, v K) bool {
|
||||
if _, ok := m[v]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func const2num(name string) float64 {
|
||||
switch name {
|
||||
case "Pi":
|
||||
|
||||
Reference in New Issue
Block a user