Compare commits

...

3 Commits

4 changed files with 74 additions and 5 deletions

View File

@ -1 +1 @@
1.12.0 53
1.14.0 35

View File

@ -148,11 +148,34 @@ function gitTag() {
echo ${tag}
}
function gitTagDate() {
local tag_name=${1}
local expr_path gopath gopkg mod
local tag_date
expr_path=$(exprPath)
if [[ "${expr_path}" ]]; then
tag_date=$(git -C "${expr_path}" show --no-patch --format=%ci "${tag_name}")
else
tag_date="n/a"
# gopath=$(go env GOPATH)
# gopkg="${gopath}/pkg/mod/git.portale-stac.it/go-pkg"
# if cd "${gopkg}" 2>/dev/null; then
# mod=$(ls -1v |grep expr@|tail -1)
# tag=${mod##*@}
# cd - >/dev/null
# fi
fi
echo ${tag_date}
}
function createVersionSource() {
local tag
local tag tag_date
tag=$(gitTag)
if [ -z "${tag}" ]; then
tag="n/a"
else
tag_date=$(gitTagDate "${tag}")
fi
cat >version.go <<eot
@ -166,6 +189,7 @@ const (
PROGNAME = "${PROGRAM_NAME}"
VERSION = "v${PROGRAM_VERSION}(build $(getBuildCount)),$(date +"%Y/%m/%d") (celestino.amoroso@portale-stac.it)"
EXPR_VERSION = "${tag}"
EXPR_DATE = "${tag_date}"
)
eot
}

49
main.go
View File

@ -20,7 +20,7 @@ import (
const (
intro = PROGNAME + ` -- Expressions calculator ` + VERSION + `
Based on the Expr package ` + EXPR_VERSION + `
Based on the Expr package ` + EXPR_VERSION + ` (` + EXPR_DATE + `)
Type help to get the list of available commands
See also https://git.portale-stac.it/go-pkg/expr/src/branch/main/README.adoc
`
@ -243,7 +243,8 @@ func isReaderTerminal(r io.Reader) bool {
func registerLocalFunctions(ctx expr.ExprContext) {
const (
devParamProp = "prop"
devParamProp = "prop"
devParamDigits = "digits"
)
aboutFunc := func(ctx expr.ExprContext, name string, args map[string]any) (result any, err error) {
@ -300,6 +301,46 @@ func registerLocalFunctions(ctx expr.ExprContext) {
return
}
binFunc := func(ctx expr.ExprContext, name string, args map[string]any) (result any, err error) {
var value, digits int64
var ok bool
var sb strings.Builder
if value, ok = args[expr.ParamValue].(int64); !ok {
err = expr.ErrExpectedGot(name, expr.TypeInt, args[expr.ParamValue])
return
}
if digits, ok = args[devParamDigits].(int64); !ok {
err = expr.ErrExpectedGot(name, expr.TypeInt, args[devParamDigits])
return
}
if digits != 64 && digits != 32 && digits != 16 && digits != 8 {
err = fmt.Errorf("%s param allows 8, 16, 32, or 64 values only", devParamDigits)
return
}
mask := uint64(0)
for i := 0; i < int(digits); i++ {
mask |= (1 << i)
}
maskedValue := uint64(value) & mask
// if maskedValue != uint64(value) {
// err = fmt.Errorf("%s param (%d) is not compatible with the value (%d) of %s param", expr.ParamValue, value, digits, devParamDigits)
// return
// }
for i := int(digits) - 1; i >= 0; i-- {
if maskedValue&(1<<i) == 0 {
sb.WriteByte('0')
} else {
sb.WriteByte('1')
}
}
result = sb.String()
return
}
ctx.RegisterFunc("about", expr.NewGolangFunctor(aboutFunc), expr.TypeString, []expr.ExprFuncParam{})
ctx.RegisterFunc("ctrlList", expr.NewGolangFunctor(ctrlListFunc), expr.TypeListOfStrings, []expr.ExprFuncParam{})
ctx.RegisterFunc("ctrl", expr.NewGolangFunctor(ctrlFunc), expr.TypeAny, []expr.ExprFuncParam{
@ -314,6 +355,10 @@ func registerLocalFunctions(ctx expr.ExprContext) {
expr.NewFuncParam(expr.ParamName),
})
ctx.RegisterFunc("bin", expr.NewGolangFunctor(binFunc), expr.TypeInt, []expr.ExprFuncParam{
expr.NewFuncParam(expr.ParamValue),
expr.NewFuncParamFlagDef(devParamDigits, expr.PfOptional|expr.PfDefault, int64(8)),
})
}
func main() {

View File

@ -1 +1 @@
1.12.0
1.14.0