wm: glendy

Download patch

ref: 8ad7cd5f89d4f0135a8f48834ac49f7d4b090b13
parent: 4a95885ae014e351a8acb3168c3cb7d8ff508faa
author: mkf <mkf@cloud9p.org>
date: Sun Jun 9 00:38:41 EDT 2024

util.c: add qdel

--- a/util.c
+++ b/util.c
@@ -137,9 +137,8 @@
 	
 		last->next = temp;
 		temp->data = data;
+		return 1;
 	}
-	return 1;
-	
 }
 
 void
@@ -252,4 +251,39 @@
 	
 	q->len--;
 	free(tmp);
+}
+
+/* we don't free items, free stuff elsewhere */
+void
+qdel(Quene *q, List *item)
+{
+	List *prev = nil, *next = nil;
+
+	if(q->len == 0 || item == nil
+	|| q->head == nil || q->tail == nil)
+		return;
+
+	
+	/* we can't use lldel, because we can't update q->tail if l == q->tail */
+	for(List *t = q->head;
+	t->next != nil  && t != t->next;
+	t = t->next)
+	{
+		/* maybe we should use memcmp */
+		if(t == item)
+		{
+		next = t->next;
+
+		/* these may be nil and that's fine */
+		if(item == q->head)
+			q->head = q->head->next;
+		if(item == q->tail)
+			q->tail = q->tail->next;
+
+		if(prev != nil)
+			prev->next = next;
+		}
+
+		prev = t;
+	}
 }