Added Windows support
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-07-01 13:37:40 +02:00
parent dbc865ee67
commit 562c839835
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
37 changed files with 742 additions and 45 deletions

6
src/dll/Library.go Normal file
View file

@ -0,0 +1,6 @@
package dll
type Library struct {
Name string
Functions []string
}

55
src/dll/List.go Normal file
View file

@ -0,0 +1,55 @@
package dll
import "slices"
// List is a slice of DLLs.
type List []Library
// Append adds a function for the given DLL if it doesn't exist yet.
func (list List) Append(dllName string, funcName string) List {
for i, dll := range list {
if dll.Name != dllName {
continue
}
if slices.Contains(dll.Functions, funcName) {
return list
}
list[i].Functions = append(list[i].Functions, funcName)
return list
}
return append(list, Library{Name: dllName, Functions: []string{funcName}})
}
// Contains returns true if the library exists.
func (list List) Contains(dllName string) bool {
for _, dll := range list {
if dll.Name == dllName {
return true
}
}
return false
}
// Index returns the position of the given function name.
func (list List) Index(dllName string, funcName string) int {
index := 0
for _, dll := range list {
if dll.Name != dllName {
index += len(dll.Functions) + 1
continue
}
for i, fn := range dll.Functions {
if fn == funcName {
return index + i
}
}
}
return -1
}

34
src/dll/List_test.go Normal file
View file

@ -0,0 +1,34 @@
package dll_test
import (
"testing"
"git.urbach.dev/cli/q/src/dll"
"git.urbach.dev/go/assert"
)
func TestList(t *testing.T) {
libs := dll.List{}
assert.False(t, libs.Contains("kernel32"))
assert.Equal(t, -1, libs.Index("kernel32", "ExitProcess"))
libs = libs.Append("kernel32", "ExitProcess")
assert.True(t, libs.Contains("kernel32"))
assert.Equal(t, 0, libs.Index("kernel32", "ExitProcess"))
libs = libs.Append("user32", "MessageBox")
assert.True(t, libs.Contains("kernel32"))
assert.True(t, libs.Contains("user32"))
assert.Equal(t, 0, libs.Index("kernel32", "ExitProcess"))
assert.Equal(t, 2, libs.Index("user32", "MessageBox"))
libs = libs.Append("kernel32", "SetConsoleCP")
assert.Equal(t, 0, libs.Index("kernel32", "ExitProcess"))
assert.Equal(t, 1, libs.Index("kernel32", "SetConsoleCP"))
assert.Equal(t, 3, libs.Index("user32", "MessageBox"))
libs = libs.Append("kernel32", "ExitProcess")
assert.Equal(t, 0, libs.Index("kernel32", "ExitProcess"))
assert.Equal(t, 1, libs.Index("kernel32", "SetConsoleCP"))
assert.Equal(t, 3, libs.Index("user32", "MessageBox"))
}