aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_lhosts.go31
-rw-r--r--c_litems.go39
-rw-r--r--i_events.go27
3 files changed, 68 insertions, 29 deletions
diff --git a/c_lhosts.go b/c_lhosts.go
index 791e885..74726d8 100644
--- a/c_lhosts.go
+++ b/c_lhosts.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_lhosts.go
- * Fri Jan 05 12:29:56 2024
+ * Tue Jan 09 11:16:59 2024
* Joe
*
* the hosts linked list
@@ -103,20 +103,31 @@ func (lhost *HostList) del(host *HostNode) {
}
if lhost.head == host {
lhost.head = lhost.head.next
- for curr:= lhost.head; curr != nil; curr = curr.next {
- curr.ID -= 1
+ if lhost.head == nil {
+ lhost.last = nil
+ return
+ }
+ for ptr := lhost.head; ptr != nil; ptr = ptr.next {
+ ptr.ID -= 1
}
return
}
- curr := lhost.head
- for curr.next != nil && curr.next != host {
- curr = curr.next
+ ptr := lhost.head
+ for ptr.next != nil && ptr.next != host {
+ ptr = ptr.next
}
- if curr.next == host {
- curr.next = curr.next.next
+ if ptr.next == host {
+ ptr.next = ptr.next.next
}
- for curr := curr.next; curr != nil; curr = curr.next {
- curr.ID -= 1
+ for ptr := ptr.next; ptr != nil; ptr = ptr.next {
+ ptr.ID -= 1
+ }
+ if lhost.last == host {
+ ptr := lhost.head
+ for ptr.next != nil {
+ ptr = ptr.next
+ }
+ lhost.last = ptr
}
}
diff --git a/c_litems.go b/c_litems.go
index df20520..c5e93ff 100644
--- a/c_litems.go
+++ b/c_litems.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_litems.go
- * Mon Jan 08 13:36:49 2024
+ * Tue Jan 09 10:51:22 2024
* Joe
*
* the dir and hosts linked list
@@ -87,22 +87,39 @@ func (litems *ItemsList) del(item *ItemsNode) {
}
if litems.head == item {
litems.head = litems.head.next
+ if litems.head == nil {
+ litems.last = nil
+ litems.curr = nil
+ litems.draw_start = nil
+ return
+ }
litems.head.prev = nil
- for curr := litems.head; curr != nil; curr = curr.next {
- curr.ID -= 1
+ litems.curr = litems.head
+ litems.draw_start = litems.head
+ for ptr := litems.head; ptr != nil; ptr = ptr.next {
+ ptr.ID -= 1
}
return
}
- curr := litems.head
- for curr.next != nil && curr.next != item {
- curr = curr.next
+ if litems.last == item {
+ litems.last = litems.last.prev
+ litems.last.next = nil
+ litems.curr = litems.last
+ if litems.draw_start == item {
+ litems.draw_start = litems.last
+ }
+ return
+ }
+ ptr := litems.head
+ for ptr.next != nil && ptr.next != item {
+ ptr = ptr.next
}
- if curr.next == item {
- curr.next = curr.next.next
- curr.next.prev = curr
+ if ptr.next == item {
+ ptr.next = ptr.next.next
+ ptr.next.prev = ptr
}
- for curr := curr.next; curr != nil; curr = curr.next {
- curr.ID -= 1
+ for ptr := ptr.next; ptr != nil; ptr = ptr.next {
+ ptr.ID -= 1
}
}
diff --git a/i_events.go b/i_events.go
index ca68e90..2484f28 100644
--- a/i_events.go
+++ b/i_events.go
@@ -84,21 +84,32 @@ func i_delete_host(data *HardData) {
return
}
host := curr.Host
- file_path := data.data_dir + host.Parent.path() + host.Filename
-
- if err := os.Remove(file_path); err != nil {
- c_die("can't remove " + file_path, err)
+ if host == nil {
+ return
}
+ // FIX: uncomment this after fix
+ // file_path := data.data_dir + host.Parent.path() + host.Filename
+ //
+ // if err := os.Remove(file_path); err != nil {
+ // c_die("can't remove " + file_path, err)
+ // }
+ var tmp *ItemsNode
host.Parent.lhost.del(host)
- prev := data.litems.curr.prev
+ if data.litems.curr != nil {
+ tmp = data.litems.curr.prev
+ }
data.litems.del(curr)
- if prev == nil {
- prev = data.litems.head
+ if tmp == nil {
+ tmp = data.litems.head
}
- data.litems.curr = prev
+ data.litems.curr = tmp
if data.litems.last != nil {
data.ui.sel_max = data.litems.last.ID
+ } else {
+ data.ui.sel_max = 0
}
+ // FIX: segv if only one host
+ // FIX: segv if del last host <- this is new, fuck
// FIX: doesn't del the first one visually
}