Compare commits

..

8 Commits

5 changed files with 90 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
1.12.0 53
1.14.0 35
+29 -5
View File
@@ -14,7 +14,7 @@ function usage() {
msgln "USAGE:"
#msgln " ${prog} <program-name> <program-version> <os>/<platform>..."
msgln " ${prog} <os>/<platform>..."
msgln " ${prog} --dev Build the local exec"
msgln " ${prog} --local Build the local exec"
msgln " ${prog} --init Create the resource file in the current directory"
msgln
if [ -r "${RESOURCE_FILE}" ]; then
@@ -64,8 +64,8 @@ platform=("linux/amd64" "darwin/arm64")
#--- end of file ---
eot
msgln "Resource file '${RESOURCE_FILE}' create"
${EDITOR-vi} "${RESOURCE_FILE}"
msgln "Resource file '${RESOURCE_FILE}' create. Edit it to set valid values."
#${EDITOR-vi} "${RESOURCE_FILE}"
exit
fi
@@ -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
}
@@ -173,7 +197,7 @@ eot
## -- MAIN -- ##
createVersionSource
if [ "${1}" == "--dev" ]; then
if [ "${1}" == "--local" ]; then
buildLocal
exit
fi
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
GO_SRC="/go/src"
PKG_PATTERN="git\.portale-stac\.it/[^ ]*"
PKG_BRANCH=main
#cd "${GO_SRC}"
#git clone -b main https://git.portale-stac.it/go/dev-expr.git
#cd "dev-expr"
for pkg in $(grep -o "${PKG_PATTERN}" go.mod); do
go get "${pkg}@${PKG_BRANCH}"
done
./build.bash --local
+47 -2
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() {
+1 -1
View File
@@ -1 +1 @@
1.12.0
1.14.0