From fbe50ac4c3ed53f55bfdafaf793eab5efc30d5d3 Mon Sep 17 00:00:00 2001
From: Joe <rbo@gmx.us>
Date: Tue, 26 Dec 2023 20:20:20 +0100
Subject: fine for now

---
 c_hardflip.go | 20 ++++++++++++++++----
 c_init.go     | 25 ++++++-------------------
 c_ldirs.go    |  9 +++++----
 c_lhosts.go   | 36 ++++++++++++++++++------------------
 c_parse.go    |  7 ++++---
 5 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/c_hardflip.go b/c_hardflip.go
index 1e5bed9..0e2269d 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
- * Tue Dec 26 11:11:55 2023
+ * Tue Dec 26 14:40:37 2023
  * Joe
  *
  * the main
@@ -49,7 +49,6 @@ package main
 
 import (
 	"fmt"
-	"os"
 )
 
 // the main data structure, holds up everything important
@@ -69,7 +68,20 @@ func main() {
 		HardOpts{true, true},
 		data_dir,
 	}
-	os.Exit(0)
-	fmt.Println(data)
+	dir := data.ldirs.head
+	for dir != nil {
+		spaces := ""
+		for i := 0; uint16(i) < dir.Depth; i++ {
+			spaces += "  "
+		}
+		fmt.Println(spaces, dir.ID, dir.Name)
+		host := dir.lhost.head
+		for host != nil {
+			fmt.Println(spaces, " ", host.ID, host.Name)
+			host = host.next
+		}
+		fmt.Println()
+		dir = dir.next
+	}
 	// i_ui(&data)
 }
diff --git a/c_init.go b/c_init.go
index 64576b8..3627e3c 100644
--- a/c_init.go
+++ b/c_init.go
@@ -57,32 +57,28 @@ 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
 func c_recurse_data_dir(dir, root string, ldirs *DirsList,
-		id uint64, name string, parent *DirsNode) {
+		id uint64, name string, parent *DirsNode, depth uint16) {
 	files, err := os.ReadDir(root + dir)
 	if err != nil {
 		c_die("could not read data directory", err)
 	}
 	dir_node := DirsNode{
-		// TODO - id is wrong
+		// TODO - ID wrong
 		id,
 		name,
-		&HostList{},
 		parent,
+		depth,
+		&HostList{},
 		nil,
 	}
 	ldirs.add_back(&dir_node)
 	for _, file := range files {
 		if file.IsDir() == true {
 			c_recurse_data_dir(dir + file.Name() + "/", root, ldirs,
-				dir_node.ID + 1, file.Name(), &dir_node)
+				id + 1, file.Name(), &dir_node, depth + 1)
 		} else if filepath.Ext(file.Name()) == ".yml" {
 			host := c_read_yaml_file(root + dir + file.Name())
 			if host == nil {
@@ -92,21 +88,12 @@ func c_recurse_data_dir(dir, root string, ldirs *DirsList,
 			host.Dir = &dir_node
 			dir_node.lhost.add_back(host)
 		}
-		// 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) *DirsList {
 	ldirs := DirsList{}
 
-	c_recurse_data_dir("", dir + "/", &ldirs, 0, "", nil)
+	c_recurse_data_dir("", dir + "/", &ldirs, 0, "", nil, 0)
 	return &ldirs
 }
diff --git a/c_ldirs.go b/c_ldirs.go
index f78ef97..096dd72 100644
--- a/c_ldirs.go
+++ b/c_ldirs.go
@@ -49,9 +49,10 @@ package main
 
 type DirsNode struct {
 	ID     uint64
-	name   string
+	Name   string
+	Parent *DirsNode
+	Depth  uint16
 	lhost  *HostList
-	parent *DirsNode
 	next   *DirsNode
 }
 
@@ -99,8 +100,8 @@ func (ldirs *DirsList) path(node *DirsNode) string {
 	}
 	curr := node
 	for curr != nil {
-		path = curr.name + "/" + path
-		curr = curr.parent
+		path = curr.Name + "/" + path
+		curr = curr.Parent
 	}
 	return path
 }
diff --git a/c_lhosts.go b/c_lhosts.go
index 6482ede..8486004 100644
--- a/c_lhosts.go
+++ b/c_lhosts.go
@@ -50,28 +50,28 @@ package main
 // 0: ssh
 // 1: rdp
 type HostNode struct {
-	ID       uint64
-	Type     int8   `yaml:"type"`
-	Name     string `yaml:"name"`
-	Host     string `yaml:"host"`
-	Port     uint16 `yaml:"port"`
-	User     string `yaml:"user"`
-	Pass     string `yaml:"pass"`
-	Priv     string `yaml:"priv"`
-	Jump     string `yaml:"jump"`
+	ID        uint64
+	Protocol  int8   `yaml:"type"`
+	Name      string `yaml:"name"`
+	Host      string `yaml:"host"`
+	Port      uint16 `yaml:"port"`
+	User      string `yaml:"user"`
+	Pass      string `yaml:"pass"`
+	Priv      string `yaml:"priv"`
+	Jump      string `yaml:"jump"`
 	JumpPort uint16 `yaml:"jump_port"`
 	JumpUser string `yaml:"jump_user"`
 	JumpPass string `yaml:"jump_pass"`
 	JumpPriv string `yaml:"jump_priv"`
-	Quality  uint8  `yaml:"quality"`
-	Domain   string `yaml:"domain"`
-	Width    uint16 `yaml:"width"`
-	Height   uint16 `yaml:"height"`
-	Dynamic  bool   `yaml:"dynamic"`
-	Note     string `yaml:"note"`
-	Filename string
-	Dir      *DirsNode
-	next     *HostNode
+	Quality   uint8  `yaml:"quality"`
+	Domain    string `yaml:"domain"`
+	Width     uint16 `yaml:"width"`
+	Height    uint16 `yaml:"height"`
+	Dynamic   bool   `yaml:"dynamic"`
+	Note      string `yaml:"note"`
+	Filename  string
+	Dir       *DirsNode
+	next      *HostNode
 }
 
 type HostList struct {
diff --git a/c_parse.go b/c_parse.go
index d2f1580..407809b 100644
--- a/c_parse.go
+++ b/c_parse.go
@@ -49,6 +49,7 @@ package main
 
 import (
 	"os"
+
 	"gopkg.in/yaml.v3"
 )
 
@@ -68,7 +69,7 @@ func c_read_yaml_file(file string) *HostNode {
 	if len(host.Host) == 0 {
 		return nil
 	}
-	if host.Type == 0 {
+	if host.Protocol == 0 {
 		if host.Port == 0 {
 			host.Port = 22
 		}
@@ -83,7 +84,7 @@ func c_read_yaml_file(file string) *HostNode {
 				host.JumpUser = "root"
 			}
 		}
-	} else if host.Type == 1 {
+	} else if host.Protocol == 1 {
 		if len(host.User) == 0 {
 			host.User = "Administrator"
 		}
@@ -96,7 +97,7 @@ func c_read_yaml_file(file string) *HostNode {
 		if host.Height == 0 {
 			host.Height = 1200
 		}
-	} else if host.Type > 1 {
+	} else if host.Protocol > 1 {
 		return nil
 	}
 	if host.Quality > 2 {
-- 
cgit v1.2.3