aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2023-12-26 20:20:20 +0100
committerJoe <rbo@gmx.us>2023-12-26 20:20:20 +0100
commitda0196ddaeb1de894efbb12c86a7741d3ba1e856 (patch)
treecad0936e7794609bcdd8cb75a8745488a47313d7
parentmust rewrite inti (diff)
downloadhardflip-da0196ddaeb1de894efbb12c86a7741d3ba1e856.tar.gz
hardflip-da0196ddaeb1de894efbb12c86a7741d3ba1e856.tar.bz2
hardflip-da0196ddaeb1de894efbb12c86a7741d3ba1e856.tar.xz
hardflip-da0196ddaeb1de894efbb12c86a7741d3ba1e856.tar.zst
hardflip-da0196ddaeb1de894efbb12c86a7741d3ba1e856.zip
its fucked
Diffstat (limited to '')
-rw-r--r--c_hardflip.go15
-rw-r--r--c_init.go54
-rw-r--r--c_ldirs.go34
3 files changed, 72 insertions, 31 deletions
diff --git a/c_hardflip.go b/c_hardflip.go
index 3243a3c..b0dcfeb 100644
--- a/c_hardflip.go
+++ b/c_hardflip.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_hardflip.go
- * Thu Dec 21 18:12:49 2023
+ * Tue Dec 26 11:11:55 2023
* Joe
*
* the main
@@ -47,25 +47,26 @@
package main
+import "fmt"
+
// the main data structure, holds up everything important
type HardData struct {
- lhost *HostList
ldirs *DirsList
- ui HardUI
+ // ui HardUI
opts HardOpts
data_dir string
}
func main() {
data_dir := c_get_data_dir()
- lhosts, ldirs := c_load_data_dir(data_dir)
+ ldirs := c_load_data_dir(data_dir)
data := HardData{
- lhosts,
ldirs,
- HardUI{},
+ // HardUI{},
HardOpts{true, true},
data_dir,
}
- i_ui(&data)
+ fmt.Println(data)
+ // i_ui(&data)
}
diff --git a/c_init.go b/c_init.go
index 5a9bc21..ec3ae11 100644
--- a/c_init.go
+++ b/c_init.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_init.go
- * Wed Dec 20 10:47:33 2023
+ * Tue Dec 26 11:51:10 2023
* Joe
*
* init functions
@@ -49,7 +49,7 @@ package main
import (
"os"
- "path/filepath"
+ // "path/filepath"
)
type HardOpts struct {
@@ -57,40 +57,48 @@ type HardOpts struct {
loop bool
}
+// TODO
+func c_read_dir_hosts() *HostList {
+ return nil
+}
+
// this function recurses into the specified root directory in order to load
// every yaml file into memory
-// TODO - must rewrite this function entirely
func c_recurse_data_dir(dir string, root string,
- lhost *HostList, ldirs *DirsList) {
+ ldirs *DirsList, parent *DirsNode) {
files, err := os.ReadDir(root + dir)
if err != nil {
c_die("could not read data directory", err)
}
+ var dir_node *DirsNode
+ if parent == nil {
+ dir_node.ID = parent.ID + 1
+ } else {
+ dir_node.ID = 0
+ }
+ dir_node.name = file.Name()
+ dir_node.parent = parent
+ ldirs.add_back(dir_node)
for _, file := range files {
if file.IsDir() == true {
- var dir_node *DirsNode
- dir_node.name = file.Name()
- dir_node.parent = dont_know
- ldirs.add_back(dir_node)
- c_recurse_data_dir(dir + file.Name() + "/", root, lhost, ldirs)
- } else if filepath.Ext(file.Name()) == ".yml" {
- host := c_read_yaml_file(root + dir + file.Name())
- if host == nil {
- return
- }
- host.Filename = file.Name()
- host.Folder = dir
- lhost.add_back(host)
+ c_recurse_data_dir(dir + file.Name() + "/", root, ldirs, dir_node)
+ } else {
}
+ // else if filepath.Ext(file.Name()) == ".yml" {
+ // host := c_read_yaml_file(root + dir + file.Name())
+ // if host == nil {
+ // return
+ // }
+ // host.Filename = file.Name()
+ // host.Folder = dir
+ // lhost.add_back(host)
+ // }
}
}
-func c_load_data_dir(dir string) (*HostList, *DirsList) {
- lhost := HostList{}
+func c_load_data_dir(dir string) *DirsList {
ldirs := DirsList{}
- var root_dir DirsNode
- ldirs.add_back(&root_dir)
- c_recurse_data_dir("", dir + "/", &lhost, &ldirs)
- return &lhost, &ldirs
+ c_recurse_data_dir("", dir + "/", &ldirs, nil)
+ return &ldirs
}
diff --git a/c_ldirs.go b/c_ldirs.go
index 03d5657..f78ef97 100644
--- a/c_ldirs.go
+++ b/c_ldirs.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_ldirs.go
- * Thu Dec 21 18:06:00 2023
+ * Tue Dec 26 11:09:27 2023
* Joe
*
* the directories linked list
@@ -48,6 +48,7 @@
package main
type DirsNode struct {
+ ID uint64
name string
lhost *HostList
parent *DirsNode
@@ -72,3 +73,34 @@ func (ldirs *DirsList) add_back(node *DirsNode) {
}
curr.next = new_node
}
+
+// return the list node with the according id
+func (ldirs *DirsList) sel(id uint64) *DirsNode {
+ curr := ldirs.head
+
+ if curr == nil {
+ return nil
+ }
+ for curr.next != nil && curr.ID != id {
+ curr = curr.next
+ }
+ if curr.ID != id {
+ return nil
+ }
+ return curr
+}
+
+// returns a string with the full path of the dir
+func (ldirs *DirsList) path(node *DirsNode) string {
+ var path string
+
+ if node == nil {
+ return ""
+ }
+ curr := node
+ for curr != nil {
+ path = curr.name + "/" + path
+ curr = curr.parent
+ }
+ return path
+}