Skip to content

Commit

Permalink
util submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Nov 27, 2024
1 parent abed437 commit d42da2f
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 160 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ on:
jobs:

build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.20.x'

- name: Build utilities
run: |
Expand Down
4 changes: 2 additions & 2 deletions cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"log"
"os"

"github.com/schwarzlichtbezirk/wpk"
lw "github.com/schwarzlichtbezirk/wpk/luawpk"
"github.com/schwarzlichtbezirk/wpk/util"
)

func main() {
for _, fpath := range os.Args[1:] {
if err := lw.RunLuaVM(wpk.Envfmt(fpath, nil)); err != nil {
if err := lw.RunLuaVM(util.Envfmt(fpath, nil)); err != nil {
log.Println(err.Error())
return
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/schwarzlichtbezirk/wpk/bulk"
"github.com/schwarzlichtbezirk/wpk/fsys"
"github.com/schwarzlichtbezirk/wpk/mmap"
"github.com/schwarzlichtbezirk/wpk/util"
)

// command line settings
Expand Down Expand Up @@ -49,7 +50,7 @@ func checkargs() int {
if fpath == "" {
continue
}
fpath = wpk.ToSlash(wpk.Envfmt(fpath, nil))
fpath = util.ToSlash(util.Envfmt(fpath, nil))
if ok, _ := wpk.FileExists(fpath); !ok {
log.Printf("source file #%d '%s' does not exist", i+1, fpath)
ec++
Expand All @@ -62,7 +63,7 @@ func checkargs() int {
ec++
}

DstPath = wpk.ToSlash(wpk.Envfmt(DstPath, nil))
DstPath = util.ToSlash(util.Envfmt(DstPath, nil))
if DstPath == "" {
log.Println("destination path does not specified")
ec++
Expand Down Expand Up @@ -133,7 +134,7 @@ func readpackage() (err error) {
next = err == nil
}()

var fullpath = wpk.JoinPath(DstPath, fkey)
var fullpath = util.JoinPath(DstPath, fkey)
if err = os.MkdirAll(path.Dir(fullpath), os.ModePerm); err != nil {
return
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/pack/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/schwarzlichtbezirk/wpk"
"github.com/schwarzlichtbezirk/wpk/util"
)

// command line settings
Expand Down Expand Up @@ -41,7 +42,7 @@ func checkargs() (ec int) { // returns error counter
if fpath == "" {
continue
}
fpath = wpk.ToSlash(wpk.Envfmt(fpath, nil))
fpath = util.ToSlash(util.Envfmt(fpath, nil))
if !strings.HasSuffix(fpath, "/") {
fpath += "/"
}
Expand All @@ -57,7 +58,7 @@ func checkargs() (ec int) { // returns error counter
ec++
}

DstFile = wpk.ToSlash(wpk.Envfmt(DstFile, nil))
DstFile = util.ToSlash(util.Envfmt(DstFile, nil))
if DstFile == "" {
log.Println("destination file does not specified")
ec++
Expand Down Expand Up @@ -118,7 +119,7 @@ func writepackage() (err error) {
return nil // file is directory
}

var fpath = wpk.JoinPath(srcpath, fkey)
var fpath = util.JoinPath(srcpath, fkey)
var file wpk.RFile
var ts wpk.TagsetRaw
if file, err = os.Open(fpath); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"path"
"strings"

"github.com/schwarzlichtbezirk/wpk/util"
)

// MakeTagsPath receives file path and returns it with ".wpt" extension.
Expand Down Expand Up @@ -76,13 +78,13 @@ func FileExists(fpath string) (bool, error) {

// TempPath returns filename located at temporary directory.
func TempPath(fname string) string {
return JoinPath(ToSlash(os.TempDir()), fname)
return util.JoinPath(util.ToSlash(os.TempDir()), fname)
}

// ReadDirN returns fs.DirEntry array with nested into given package directory presentation.
// It's core function for ReadDirFile and ReadDirFS structures.
func (ftt *FTT) ReadDirN(fulldir string, n int) (list []fs.DirEntry, err error) {
fulldir = ToSlash(fulldir)
fulldir = util.ToSlash(fulldir)
var found = map[string]fs.DirEntry{}
var prefix string
if fulldir != "." && fulldir != "" {
Expand All @@ -97,7 +99,7 @@ func (ftt *FTT) ReadDirN(fulldir string, n int) (list []fs.DirEntry, err error)
found[suffix] = ts
n--
} else { // dir detected
var subdir = JoinPath(prefix, suffix[:sp])
var subdir = util.JoinPath(prefix, suffix[:sp])
if _, ok := found[subdir]; !ok {
var dts = TagsetRaw{}.
Put(TIDpath, StrTag(subdir))
Expand Down Expand Up @@ -128,7 +130,7 @@ func (ftt *FTT) ReadDirN(fulldir string, n int) (list []fs.DirEntry, err error)
// OpenDir returns PackDirFile structure associated with group of files in package
// pooled with common directory prefix. Usable to implement fs.FileSystem interface.
func (ftt *FTT) OpenDir(fulldir string) (fs.ReadDirFile, error) {
fulldir = ToSlash(fulldir)
fulldir = util.ToSlash(fulldir)
var prefix string
if fulldir != "." && fulldir != "" {
prefix = fulldir + "/" // set terminated slash
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/schwarzlichtbezirk/wpk
go 1.20

require (
github.com/edsrzf/mmap-go v1.1.0
github.com/edsrzf/mmap-go v1.2.0
github.com/h2non/filetype v1.1.3
github.com/yuin/gopher-lua v1.1.1
gopkg.in/djherbis/times.v1 v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/edsrzf/mmap-go v1.2.0 h1:hXLYlkbaPzt1SaQk+anYwKSRNhufIDCchSPkUD6dD84=
github.com/edsrzf/mmap-go v1.2.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
Expand Down
4 changes: 3 additions & 1 deletion luawpk/adjusttags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"path"

"github.com/h2non/filetype"

"github.com/schwarzlichtbezirk/wpk"
"github.com/schwarzlichtbezirk/wpk/util"
)

func adjustmime(ts wpk.TagsetRaw, r io.ReadSeeker, skip bool) (wpk.TagsetRaw, error) {
Expand All @@ -22,7 +24,7 @@ func adjustmime(ts wpk.TagsetRaw, r io.ReadSeeker, skip bool) (wpk.TagsetRaw, er
if skip || ts.Has(wpk.TIDmime) {
return ts, err
}
var ext = wpk.ToLower(path.Ext(ts.Path()))
var ext = util.ToLower(path.Ext(ts.Path()))
var ctype string
if ctype = mime.TypeByExtension(ext); ctype == "" {
if ctype, ok = MimeExt[ext]; !ok {
Expand Down
11 changes: 6 additions & 5 deletions luawpk/luapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"path"
"path/filepath"

"github.com/schwarzlichtbezirk/wpk"
lua "github.com/yuin/gopher-lua"

"github.com/schwarzlichtbezirk/wpk/util"
)

// RegPath registers "path" namespace into Lua virtual machine.
Expand Down Expand Up @@ -34,7 +35,7 @@ var pathfuncs = map[string]lua.LGFunction{
func pathtoslash(ls *lua.LState) int {
var fpath = ls.CheckString(1)

ls.Push(lua.LString(wpk.ToSlash(fpath)))
ls.Push(lua.LString(util.ToSlash(fpath)))
return 1
}

Expand Down Expand Up @@ -73,7 +74,7 @@ func pathbase(ls *lua.LState) int {
func pathname(ls *lua.LState) int {
var fpath = ls.CheckString(1)

var name = wpk.PathName(fpath)
var name = util.PathName(fpath)
ls.Push(lua.LString(name))
return 1
}
Expand Down Expand Up @@ -128,7 +129,7 @@ func pathglob(ls *lua.LState) int {
return 0
}
for _, dir := range matches {
ls.Push(lua.LString(wpk.ToSlash(dir)))
ls.Push(lua.LString(util.ToSlash(dir)))
}
return len(matches)
}
Expand Down Expand Up @@ -160,7 +161,7 @@ func pathenum(ls *lua.LState) int {

func pathenvfmt(ls *lua.LState) int {
var fpath = ls.CheckString(1)
ls.Push(lua.LString(wpk.Envfmt(fpath, nil)))
ls.Push(lua.LString(util.Envfmt(fpath, nil)))
return 1
}

Expand Down
3 changes: 2 additions & 1 deletion luawpk/luawpk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"path"
"strings"

"github.com/schwarzlichtbezirk/wpk"
lua "github.com/yuin/gopher-lua"

"github.com/schwarzlichtbezirk/wpk"
)

// Package writer errors.
Expand Down
3 changes: 2 additions & 1 deletion luawpk/nametid.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"strconv"
"time"

"github.com/schwarzlichtbezirk/wpk"
lua "github.com/yuin/gopher-lua"

"github.com/schwarzlichtbezirk/wpk"
)

const (
Expand Down
15 changes: 8 additions & 7 deletions luawpk/runlvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"path"
"time"

"github.com/schwarzlichtbezirk/wpk"
lua "github.com/yuin/gopher-lua"

"github.com/schwarzlichtbezirk/wpk/util"
)

var (
Expand Down Expand Up @@ -51,7 +52,7 @@ func luacheckfile(ls *lua.LState) int {

func luabin2hex(ls *lua.LState) int {
var arg = ls.CheckString(1)
ls.Push(lua.LString(hex.EncodeToString(wpk.S2B(arg))))
ls.Push(lua.LString(hex.EncodeToString(util.S2B(arg))))
return 1
}

Expand All @@ -67,7 +68,7 @@ func luahex2bin(ls *lua.LState) int {
if b, err = hex.DecodeString(arg); err != nil {
return 0
}
ls.Push(lua.LString(wpk.B2S(b)))
ls.Push(lua.LString(util.B2S(b)))
return 1
}

Expand Down Expand Up @@ -106,17 +107,17 @@ func InitLuaVM(ls *lua.LState) {

var bindir = func() string {
if str, err := os.Executable(); err == nil {
return path.Dir(wpk.ToSlash(str))
return path.Dir(util.ToSlash(str))
} else {
return path.Dir(wpk.ToSlash(os.Args[0]))
return path.Dir(util.ToSlash(os.Args[0]))
}
}()

// global variables
ls.SetGlobal("buildvers", lua.LString(BuildVers))
ls.SetGlobal("buildtime", lua.LString(BuildTime))
ls.SetGlobal("bindir", lua.LString(bindir))
ls.SetGlobal("tmpdir", lua.LString(wpk.ToSlash(os.TempDir())))
ls.SetGlobal("tmpdir", lua.LString(util.ToSlash(os.TempDir())))
// global functions
ls.SetGlobal("log", ls.NewFunction(lualog))
ls.SetGlobal("checkfile", ls.NewFunction(luacheckfile))
Expand All @@ -132,7 +133,7 @@ func RunLuaVM(fpath string) (err error) {
defer ls.Close()
InitLuaVM(ls)

var scrdir = path.Dir(wpk.ToSlash(fpath))
var scrdir = path.Dir(util.ToSlash(fpath))
ls.SetGlobal("scrdir", lua.LString(scrdir))

if err = ls.DoFile(fpath); err != nil {
Expand Down
Loading

0 comments on commit d42da2f

Please sign in to comment.