mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 12:31:04 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43fcf43d1f |
11
calc.go
11
calc.go
@@ -272,9 +272,18 @@ func (c *Calc) EvalItem(item string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try time
|
||||||
|
var hour, min int
|
||||||
|
_, err = fmt.Sscanf(item, "%d:%d", &hour, &min)
|
||||||
|
if err == nil {
|
||||||
|
c.stack.Backup()
|
||||||
|
c.stack.Push(float64(hour) + float64(min)/60)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// try hex
|
// try hex
|
||||||
var i int
|
var i int
|
||||||
|
|
||||||
_, err = fmt.Sscanf(item, "0x%x", &i)
|
_, err = fmt.Sscanf(item, "0x%x", &i)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.stack.Backup()
|
c.stack.Backup()
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ func FuzzEval(f *testing.F) {
|
|||||||
|
|
||||||
calc := NewCalc()
|
calc := NewCalc()
|
||||||
|
|
||||||
var hexnum int
|
var hexnum, hour, min int
|
||||||
|
|
||||||
f.Fuzz(func(t *testing.T, line string) {
|
f.Fuzz(func(t *testing.T, line string) {
|
||||||
t.Logf("Stack:\n%v\n", calc.stack.All())
|
t.Logf("Stack:\n%v\n", calc.stack.All())
|
||||||
@@ -391,6 +391,7 @@ func FuzzEval(f *testing.F) {
|
|||||||
if !contains(legal, line) && len(line) > 0 {
|
if !contains(legal, line) && len(line) > 0 {
|
||||||
item := strings.TrimSpace(calc.Comment.ReplaceAllString(line, ""))
|
item := strings.TrimSpace(calc.Comment.ReplaceAllString(line, ""))
|
||||||
_, hexerr := fmt.Sscanf(item, "0x%x", &hexnum)
|
_, hexerr := fmt.Sscanf(item, "0x%x", &hexnum)
|
||||||
|
_, timeerr := fmt.Sscanf(item, "%d:%d", &hour, &min)
|
||||||
// no comment?
|
// no comment?
|
||||||
if len(item) > 0 {
|
if len(item) > 0 {
|
||||||
// no known command or function?
|
// no known command or function?
|
||||||
@@ -405,7 +406,8 @@ func FuzzEval(f *testing.F) {
|
|||||||
!exists(calc.StackCommands, item) &&
|
!exists(calc.StackCommands, item) &&
|
||||||
!calc.Register.MatchString(item) &&
|
!calc.Register.MatchString(item) &&
|
||||||
item != "?" && item != "help" &&
|
item != "?" && item != "help" &&
|
||||||
hexerr != nil {
|
hexerr != nil &&
|
||||||
|
timeerr != nil {
|
||||||
t.Errorf("Fuzzy input accepted: <%s>", line)
|
t.Errorf("Fuzzy input accepted: <%s>", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -30,7 +30,7 @@ import (
|
|||||||
lua "github.com/yuin/gopher-lua"
|
lua "github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION string = "2.1.2"
|
const VERSION string = "2.1.3"
|
||||||
|
|
||||||
const Usage string = `This is rpn, a reverse polish notation calculator cli.
|
const Usage string = `This is rpn, a reverse polish notation calculator cli.
|
||||||
|
|
||||||
|
|||||||
3
rpn.go
3
rpn.go
@@ -108,7 +108,8 @@ DESCRIPTION
|
|||||||
is enabled automatically, see last example.
|
is enabled automatically, see last example.
|
||||||
|
|
||||||
You can enter integers, floating point numbers (positive or negative) or
|
You can enter integers, floating point numbers (positive or negative) or
|
||||||
hex numbers (prefixed with 0x).
|
hex numbers (prefixed with 0x). Time values in hh::mm format are
|
||||||
|
possible as well.
|
||||||
|
|
||||||
STACK MANIPULATION
|
STACK MANIPULATION
|
||||||
There are lots of stack manipulation commands provided. The most
|
There are lots of stack manipulation commands provided. The most
|
||||||
|
|||||||
3
rpn.pod
3
rpn.pod
@@ -112,7 +112,8 @@ If the first parameter to rpn is a math operator or function, batch
|
|||||||
mode is enabled automatically, see last example.
|
mode is enabled automatically, see last example.
|
||||||
|
|
||||||
You can enter integers, floating point numbers (positive or negative)
|
You can enter integers, floating point numbers (positive or negative)
|
||||||
or hex numbers (prefixed with 0x).
|
or hex numbers (prefixed with 0x). Time values in hh::mm format are
|
||||||
|
possible as well.
|
||||||
|
|
||||||
=head2 STACK MANIPULATION
|
=head2 STACK MANIPULATION
|
||||||
|
|
||||||
|
|||||||
2
t/cmdlinecalc-time.txtar
Normal file
2
t/cmdlinecalc-time.txtar
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
exec testrpn 09:55 4:15 -
|
||||||
|
stdout '5.67\n'
|
||||||
Reference in New Issue
Block a user