mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 12:31:04 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43fcf43d1f | |||
| 3a9d753720 | |||
| 5afe1275bc | |||
|
|
41b38191a5 | ||
| 8f2b6955ff | |||
| 9b244fc170 |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -7,7 +7,7 @@ assignees: TLINDEN
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Describtion**
|
**Description**
|
||||||
<!-- Please provide a clear and concise description of the issue: -->
|
<!-- Please provide a clear and concise description of the issue: -->
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: build
|
- name: build
|
||||||
run: make
|
run: make buildlocal
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: make test
|
run: make test
|
||||||
|
|||||||
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()
|
||||||
|
|||||||
10
calc_test.go
10
calc_test.go
@@ -78,7 +78,7 @@ func TestCommentsAndWhitespace(t *testing.T) {
|
|||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
for _, line := range test.cmd {
|
for _, line := range test.cmd {
|
||||||
if err := calc.Eval(line); err != nil {
|
if err := calc.Eval(line); err != nil {
|
||||||
t.Errorf(err.Error())
|
t.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
got := calc.stack.Last()
|
got := calc.stack.Last()
|
||||||
@@ -292,7 +292,7 @@ func TestCalc(t *testing.T) {
|
|||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
calc.batch = test.batch
|
calc.batch = test.batch
|
||||||
if err := calc.Eval(test.cmd); err != nil {
|
if err := calc.Eval(test.cmd); err != nil {
|
||||||
t.Errorf(err.Error())
|
t.Error(err.Error())
|
||||||
}
|
}
|
||||||
got := calc.Result()
|
got := calc.Result()
|
||||||
calc.stack.Clear()
|
calc.stack.Clear()
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,10 @@ func (c *Calc) SetCommands() {
|
|||||||
c.SettingsCommands["b"] = c.SettingsCommands["batch"]
|
c.SettingsCommands["b"] = c.SettingsCommands["batch"]
|
||||||
c.SettingsCommands["s"] = c.SettingsCommands["showstack"]
|
c.SettingsCommands["s"] = c.SettingsCommands["showstack"]
|
||||||
|
|
||||||
|
c.SettingsCommands["togglebatch"] = c.SettingsCommands["batch"]
|
||||||
|
c.SettingsCommands["toggledebug"] = c.SettingsCommands["debug"]
|
||||||
|
c.SettingsCommands["toggleshowstack"] = c.SettingsCommands["showstack"]
|
||||||
|
|
||||||
c.ShowCommands["h"] = c.ShowCommands["history"]
|
c.ShowCommands["h"] = c.ShowCommands["history"]
|
||||||
c.ShowCommands["p"] = c.ShowCommands["dump"]
|
c.ShowCommands["p"] = c.ShowCommands["dump"]
|
||||||
c.ShowCommands["v"] = c.ShowCommands["vars"]
|
c.ShowCommands["v"] = c.ShowCommands["vars"]
|
||||||
|
|||||||
6
go.mod
6
go.mod
@@ -4,12 +4,12 @@ go 1.22
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/chzyer/readline v1.5.1
|
github.com/chzyer/readline v1.5.1
|
||||||
github.com/rogpeppe/go-internal v1.11.0
|
github.com/rogpeppe/go-internal v1.13.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/yuin/gopher-lua v1.1.1
|
github.com/yuin/gopher-lua v1.1.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
golang.org/x/sys v0.21.0 // indirect
|
||||||
golang.org/x/tools v0.1.12 // indirect
|
golang.org/x/tools v0.22.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
17
go.sum
17
go.sum
@@ -1,18 +1,17 @@
|
|||||||
|
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
|
||||||
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
|
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
|
||||||
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
|
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
|
||||||
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
|
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
|
||||||
|
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
|
||||||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
||||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
|
|
||||||
github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
|
||||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
|
|
||||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
|
||||||
|
|||||||
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.1"
|
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