aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2023-12-21 20:20:20 +0100
committerJoe <rbo@gmx.us>2023-12-21 20:20:20 +0100
commit3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f (patch)
treec7983a4d1fe26c2de0398dc18d15b374e530a219
parenticon option (diff)
downloadhardflip-3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f.tar.gz
hardflip-3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f.tar.bz2
hardflip-3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f.tar.xz
hardflip-3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f.tar.zst
hardflip-3edca0fd3c5b0411ef2dc95bfe9f34865b5fb55f.zip
must rewrite inti
-rw-r--r--c_hardflip.go2
-rw-r--r--c_init.go15
-rw-r--r--c_ldirs.go17
3 files changed, 29 insertions, 5 deletions
diff --git a/c_hardflip.go b/c_hardflip.go
index 5351593..3243a3c 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
- * Wed Dec 20 16:34:51 2023
+ * Thu Dec 21 18:12:49 2023
* Joe
*
* the main
diff --git a/c_init.go b/c_init.go
index ca26683..5a9bc21 100644
--- a/c_init.go
+++ b/c_init.go
@@ -59,14 +59,20 @@ type HardOpts struct {
// this function recurses into the specified root directory in order to load
// every yaml file into memory
-func c_recurse_data_dir(dir string, root string, lhost *HostList) {
+// TODO - must rewrite this function entirely
+func c_recurse_data_dir(dir string, root string,
+ lhost *HostList, ldirs *DirsList) {
files, err := os.ReadDir(root + dir)
if err != nil {
c_die("could not read data directory", err)
}
for _, file := range files {
if file.IsDir() == true {
- c_recurse_data_dir(dir + file.Name() + "/", root, lhost)
+ 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 {
@@ -82,6 +88,9 @@ func c_recurse_data_dir(dir string, root string, lhost *HostList) {
func c_load_data_dir(dir string) (*HostList, *DirsList) {
lhost := HostList{}
ldirs := DirsList{}
- c_recurse_data_dir("", dir + "/", &lhost)
+ var root_dir DirsNode
+
+ ldirs.add_back(&root_dir)
+ c_recurse_data_dir("", dir + "/", &lhost, &ldirs)
return &lhost, &ldirs
}
diff --git a/c_ldirs.go b/c_ldirs.go
index df2e373..03d5657 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 14:03:40 2023
+ * Thu Dec 21 18:06:00 2023
* Joe
*
* the directories linked list
@@ -57,3 +57,18 @@ type DirsNode struct {
type DirsList struct {
head *DirsNode
}
+
+// adds a directory node to the list
+func (ldirs *DirsList) add_back(node *DirsNode) {
+ new_node := node
+
+ if ldirs.head == nil {
+ ldirs.head = new_node
+ return
+ }
+ curr := ldirs.head
+ for curr.next != nil {
+ curr = curr.next
+ }
+ curr.next = new_node
+}