feat: moving to VULTRAS

This commit is contained in:
Andrey Parhomenko 2024-01-23 18:20:00 +03:00
parent af7fd31a47
commit 64b1dd2f02
9 changed files with 90 additions and 112 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.exe

3
go.mod
View file

@ -1,4 +1,5 @@
module utf8tmpl
module vultras.su/util/combo
go 1.16
require vultras.su/core/cli v0.0.0-20240104195345-5d79542278a0 // indirect

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
vultras.su/core/cli v0.0.0-20240104195345-5d79542278a0 h1:acA77oEg7hDuUchyBvw7scG9gayVLFAC9/CGuqyfLSA=
vultras.su/core/cli v0.0.0-20240104195345-5d79542278a0/go.mod h1:rYu/sFWE3vUkDSSJCZt+K1aVaso0MYcZ+tmxQd4whdQ=

View file

@ -1,4 +0,0 @@
#!/bin/sh
exec go install

41
main.go
View file

@ -1,40 +1,17 @@
package main
import(
"fmt"
"os"
"utf8tmpl/tmpl"
"utf8tmpl/pin"
"vultras.su/util/combo/tmpl"
"vultras.su/util/combo/pin"
"vultras.su/core/cli/mtool"
)
var root = mtool.T("combo").Subs(
tmpl.Tool,
pin.Tool,
)
func main() {
var(
utilName string
args []string
)
utilsMap := map[string] interface{} {
"tmpl" : tmpl.Run,
"pin" : pin.Run,
}
if len(os.Args)<2 {
for k, _ := range utilsMap {
fmt.Printf("%s\n", k)
}
os.Exit(0)
} else {
utilName = os.Args[1]
args = os.Args[1:]
}
if _, ok := utilsMap[utilName] ; !ok {
fmt.Printf("%s: %s: no such util\n", os.Args[0], utilName )
os.Exit(1)
}
status := utilsMap[utilName].(func([]string) int )(args)
os.Exit(status)
root.Run(os.Args[1:])
}

View file

@ -1,25 +1,27 @@
package pin
import(
"os"
import (
"fmt"
"strconv"
"log"
"flag"
//"strconv"
//"log"
"vultras.su/core/cli/mtool"
"os"
)
var(
var (
Lflag bool
lval int
arg0 string
delim rune = '\n'
status int = 0
nVal int
chrs []rune
Tool = mtool.T("pin").Func(Run).Desc(
"print all the possible PIN combinations made of custom characters",
).Usage(
"<tmpl_chars>",
)
)
func
Pow(x, p int) int {
func Pow(x, p int) int {
ret := 1
for i:=0 ; i<p ; i++ {
ret *= x
@ -27,8 +29,7 @@ Pow(x, p int) int {
return ret
}
func
GetPin(s []rune, l int, i int) string {
func GetPin(s []rune, l int, i int) string {
ret := ""
slen := len(s)
for j:=0 ; j<l ; j++ {
@ -37,8 +38,7 @@ GetPin(s []rune, l int, i int) string {
return ret
}
func
printPins(s []rune, l int) {
func printPins(s []rune, l int) {
n := Pow(len(s), l)
for i:=0 ; i<n ; i++ {
pin := GetPin(s, l, i)
@ -48,8 +48,7 @@ printPins(s []rune, l int) {
}
}
func
Fits(s []rune) bool {
func Fits(s []rune) bool {
a := make([]int, len(chrs))
for i, v1 := range chrs {
for _, v2 := range s {
@ -64,57 +63,58 @@ Fits(s []rune) bool {
return true
}
func
Run(args []string) int {
arg0 = args[0]
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
flagSet.IntVar(&lval, "l", 0,
"Add combinations with less number of chars starting with arg.")
flagSet.BoolVar(&Lflag, "L", false,
"Set less number to 1. Overrides l flag.")
flagSet.IntVar(&nVal, "n", 1, "Max repeats of the rune." )
flagSet.Parse(args[1:])
args = flagSet.Args()
flagSet.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] <tmpl_chars> [len]\n", arg0)
flagSet.PrintDefaults()
func Run(flags *mtool.Flags) {
var (
length int
rFlag bool
)
flags.IntVar(
&lval, "min", 0,
"min length of the output pins",
)
flags.BoolVar(
&Lflag, "m", false,
"set the '-min' flag value to 1 (overrides it)",
)
flags.IntVar(
&length, "max", 0,
"max length of the output pins",
)
flags.IntVar(&nVal, "rep", 1, "max repeats of the rune." )
flags.BoolVar(&rFlag, "R", false, "make the maximum repeat equal to the length of input chars" )
args := flags.Parse()
if len(args) == 0 {
flags.Usage()
os.Exit(1)
}
var(
err error
n int
)
if len(args) == 0 {
flagSet.Usage()
}
chrs = []rune(args[0])
if len(args) == 2 {
n, err = strconv.Atoi(args[1])
} else if len(args) == 1 {
n = len(chrs)
}
if err!=nil {
log.Fatal(err)
if length == 0 {
length = len(chrs)
}
if Lflag {
lval = 1
}
if lval != 0 {
if lval > n {
flagSet.Usage()
if rFlag {
nVal = len(chrs)
}
for i := lval ; i<=n ; i++ {
if lval != 0 {
if lval > length {
flags.Usage()
os.Exit(1)
}
for i := lval ; i<=length ; i++ {
printPins(chrs, i)
}
} else {
printPins(chrs, n)
printPins(chrs, length)
}
return status
}

View file

@ -1,4 +1,5 @@
# utf8tmpl
# combo
## Description
Set of utils to implement templates based on UTF-8 characters.

7
taskfile.yml Normal file
View file

@ -0,0 +1,7 @@
version: 3
tasks:
build:
desc: build the binary
cmds:
- go build

View file

@ -5,33 +5,30 @@ import (
"fmt"
"bufio"
"io"
"vultras.su/core/cli/mtool"
)
var(
arg0 string
delim rune
status int
Tool = mtool.T("tmpl").Func(Run).Desc(
"substitute the inputted runes with the specified words",
).Usage(
"[n_utf8_chars] [n_strings]",
)
)
func
usage() {
fmt.Fprintf(os.Stderr, "usage: %s [n_utf8_chars] [n_strings]\n", arg0)
os.Exit(1)
}
func
Run(args []string) int {
status = 0
func Run(flags *mtool.Flags) {
delim = '\n'
arg0 = args[0]
args := flags.Parse()
if len(args)<3 || len(args[1]) != len(args)-2 {
usage()
if len(args)<2 || len(args[0]) != len(args)-1 {
flags.Usage()
os.Exit(1)
}
chrs := []rune(args[1])
args = args[2:]
chrs := []rune(args[0])
args = args[1:]
tmpl := make(map[rune] string)
for i, s := range args {
@ -45,18 +42,13 @@ Run(args []string) int {
break
}
s = s[:len(s)-1]
for _, c := range []rune(s) {
for _, c := range s {
s, ok := tmpl[c]
if !ok {
/*fmt.Fprintf(os.Stderr, "%s: '%s': no such character in template string\n",
arg0, string(c) )*/
s = string(c)
}
fmt.Printf("%s", s)
}
fmt.Printf("%s", string(delim))
}
return status
}