From fde340dda9ded520959d7d431757d5654241c60c Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 29 Dec 2023 20:20:20 +0100 Subject: cleaner --- c_hardflip.go | 22 ++++++++++++++++------ c_init.go | 53 ++++++++++++++++++++--------------------------------- c_ldirs.go | 7 ++++--- c_lhosts.go | 6 +++--- c_litems.go | 6 +++--- i_ui.go | 1 - 6 files changed, 46 insertions(+), 49 deletions(-) diff --git a/c_hardflip.go b/c_hardflip.go index 6f575eb..8965cdc 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -69,12 +69,22 @@ func main() { opts, data_dir, } - for dir := ldirs.head; dir != nil ; dir = dir.next { - for host := ldirs.head.lhost.head; host != nil; host = host.next { - fmt.Println(host.ID, host.Filename) - } - fmt.Println("next dir") - } + // for dir := ldirs.head; dir != nil ; dir = dir.next { + // fmt.Println(dir.ID, dir.Name) + // } + // for dir := ldirs.head; dir != nil ; dir = dir.next { + // for host := dir.lhost.head; host != nil; host = host.next { + // fmt.Println(host.ID, host.Name) + // } + // } + // for item := litems.head; item != nil ; item = item.next { + // if item.Dirs != nil { + // fmt.Println(item.ID, item.Dirs.Name) + // } else { + // fmt.Println(item.ID, item.Host.Name) + // } + // } + return i_ui(&data) } diff --git a/c_init.go b/c_init.go index 30b022c..7852e75 100644 --- a/c_init.go +++ b/c_init.go @@ -61,32 +61,31 @@ 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, root string, opts HardOpts, - litems *ItemsList, ldirs *DirsList, dir_node *DirsNode, - id *uint64, name string, parent *DirsNode, depth uint16) { + litems *ItemsList, ldirs *DirsList, + 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{ - // *id, - // name, - // parent, - // depth, - // &HostList{}, - // opts.FoldAll, - // nil, - // } - // item_node := ItemsNode{} - // item_node.Dirs = dir_node - // item_node.Host = nil - *id++ - // ldirs.add_back(&dir_node) - // litems.add_back(&item_node) + dir_node := DirsNode{ + 0, + name, + parent, + depth, + &HostList{}, + opts.FoldAll, + nil, + } + item_node := ItemsNode{} + item_node.Dirs = &dir_node + item_node.Host = nil + ldirs.add_back(&dir_node) + litems.add_back(&item_node) for _, file := range files { filename := file.Name() if file.IsDir() == true { - c_recurse_data_dir(dir + filename + "/", root, opts, litems, ldirs, dir_node, - id, file.Name(), dir_node, depth + 1) + c_recurse_data_dir(dir + filename + "/", root, opts, litems, ldirs, + file.Name(), &dir_node, depth + 1) } else if filepath.Ext(filename) == ".yml" { host_node := c_read_yaml_file(root + dir + filename) if host_node == nil { @@ -97,7 +96,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, item_node.Host = host_node litems.add_back(&item_node) host_node.Filename = filename - host_node.Dir = dir_node + host_node.Dir = &dir_node dir_node.lhost.add_back(host_node) } } @@ -106,19 +105,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, func c_load_data_dir(dir string, opts HardOpts) (*ItemsList, *DirsList) { litems := ItemsList{} ldirs := DirsList{} - var id uint64 - dir_node := DirsNode{ - 0, - "qwe", - nil, - 0, - &HostList{}, - opts.FoldAll, - nil, - } - ldirs.add_back(&dir_node) - id = 0 - c_recurse_data_dir("", dir + "/", opts, &litems, &ldirs, &dir_node, &id, "", nil, 1) + c_recurse_data_dir("", dir + "/", opts, &litems, &ldirs, "", nil, 1) return &litems, &ldirs } diff --git a/c_ldirs.go b/c_ldirs.go index 199927a..601d074 100644 --- a/c_ldirs.go +++ b/c_ldirs.go @@ -72,9 +72,10 @@ func (ldirs *DirsList) add_back(node *DirsNode) { return } curr := ldirs.last - for curr.next != nil { - curr = curr.next - } + // for curr.next != nil { + // curr = curr.next + // } + new_node.ID = curr.ID + 1 curr.next = new_node ldirs.last = curr.next } diff --git a/c_lhosts.go b/c_lhosts.go index fe8f7a0..46ba85c 100644 --- a/c_lhosts.go +++ b/c_lhosts.go @@ -89,9 +89,9 @@ func (lhost *HostList) add_back(node *HostNode) { return } curr := lhost.last - for curr.next != nil { - curr = curr.next - } + // for curr.next != nil { + // curr = curr.next + // } new_node.ID = curr.ID + 1 curr.next = new_node lhost.last = curr.next diff --git a/c_litems.go b/c_litems.go index 05ffbe2..5b211fb 100644 --- a/c_litems.go +++ b/c_litems.go @@ -68,9 +68,9 @@ func (litems *ItemsList) add_back(node *ItemsNode) { return } curr := litems.last - for curr.next != nil { - curr = curr.next - } + // for curr.next != nil { + // curr = curr.next + // } new_node.ID = curr.ID + 1 curr.next = new_node litems.last = curr.next diff --git a/i_ui.go b/i_ui.go index 4e8583c..a26dbee 100644 --- a/i_ui.go +++ b/i_ui.go @@ -533,7 +533,6 @@ func i_ui(data *HardData) { } if ui.mode == DELETE_MODE { // TODO: delete mode - // host := data.lhost.sel(ui.sel) // i_draw_delete_box(*ui, host) } -- cgit v1.2.3