7 Commits

Author SHA1 Message Date
433c5ede91 bump version 2025-02-01 18:15:37 +01:00
dependabot[bot]
b77ef061e6 Bump actions/checkout from 2 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-01 17:57:18 +01:00
dependabot[bot]
2a5e70279e Bump github.com/spf13/pflag from 1.0.5 to 1.0.6
Bumps [github.com/spf13/pflag](https://github.com/spf13/pflag) from 1.0.5 to 1.0.6.
- [Release notes](https://github.com/spf13/pflag/releases)
- [Commits](https://github.com/spf13/pflag/compare/v1.0.5...v1.0.6)

---
updated-dependencies:
- dependency-name: github.com/spf13/pflag
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-01 17:45:24 +01:00
dependabot[bot]
6c56ed9508 Bump actions/setup-go from 1 to 5
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 1 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v1...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-01 17:44:55 +01:00
ff76137986 build release binaries using ci workflow 2025-01-18 10:55:04 +01:00
e5dfad1e35 better switch 2025-01-15 10:28:35 +01:00
43fcf43d1f add time support 2024-11-18 13:18:51 +01:00
11 changed files with 61 additions and 18 deletions

32
.github/workflows/release.yaml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: build-and-test
on:
push:
tags:
- "*"
jobs:
release:
name: Build Release Assets
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.11
- name: Build the executables
run: ./mkrel.sh rpnc ${{ github.ref_name}}
- name: List the executables
run: ls -l ./releases
- name: Upload the binaries
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
file: ./releases/*
file_glob: true

View File

@@ -81,8 +81,8 @@ goupdate:
buildall: buildall:
./mkrel.sh $(tool) $(VERSION) ./mkrel.sh $(tool) $(VERSION)
release: buildall release:
gh release create v$(VERSION) --generate-notes releases/* gh release create v$(VERSION) --generate-notes
show-versions: buildlocal show-versions: buildlocal
@echo "### rpn version:" @echo "### rpn version:"

15
calc.go
View File

@@ -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()
@@ -361,9 +370,7 @@ func (c *Calc) EvalItem(item string) error {
} }
switch item { switch item {
case "?": case "?", "help":
fallthrough
case "help":
c.PrintHelp() c.PrintHelp()
default: default:

View File

@@ -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
go.mod
View File

@@ -5,7 +5,7 @@ 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.13.1 github.com/rogpeppe/go-internal v1.13.1
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.6
github.com/yuin/gopher-lua v1.1.1 github.com/yuin/gopher-lua v1.1.1
) )

4
go.sum
View File

@@ -6,8 +6,8 @@ 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.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= 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.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View File

@@ -116,9 +116,7 @@ func (i *Interpreter) CallLuaFunc(funcname string, items []float64) (float64, er
funcname, LuaFuncs[funcname].numargs)) funcname, LuaFuncs[funcname].numargs))
switch LuaFuncs[funcname].numargs { switch LuaFuncs[funcname].numargs {
case 0: case 0, 1:
fallthrough
case 1:
// 1 arg variant // 1 arg variant
if err := LuaInterpreter.CallByParam(lua.P{ if err := LuaInterpreter.CallByParam(lua.P{
Fn: LuaInterpreter.GetGlobal(funcname), Fn: LuaInterpreter.GetGlobal(funcname),

View File

@@ -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.4"
const Usage string = `This is rpn, a reverse polish notation calculator cli. const Usage string = `This is rpn, a reverse polish notation calculator cli.
@@ -50,7 +50,7 @@ Options:
When <operator> is given, batch mode ist automatically enabled. Use When <operator> is given, batch mode ist automatically enabled. Use
this only when working with stdin. E.g.: echo "2 3 4 5" | rpn + this only when working with stdin. E.g.: echo "2 3 4 5" | rpn +
Copyright (c) 2023-2024 T.v.Dein` Copyright (c) 2023-2025 T.v.Dein`
func main() { func main() {
os.Exit(Main()) os.Exit(Main())

3
rpn.go
View File

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

View File

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

@@ -0,0 +1,2 @@
exec testrpn 09:55 4:15 -
stdout '5.67\n'