Adjust patch to use dlist_pop()
diff --git a/lib/llist.c b/lib/llist.c
index 596da40..71a187d 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -37,8 +37,11 @@
{
struct double_list **pdlist = (struct double_list **)list, *dlist = *pdlist;
- dlist->next->prev = dlist->prev;
- dlist->prev->next = *pdlist = dlist->next;
+ if (dlist->next == dlist) *pdlist = 0;
+ else {
+ dlist->next->prev = dlist->prev;
+ dlist->prev->next = *pdlist = dlist->next;
+ }
return dlist;
}
diff --git a/scripts/test/test.test b/scripts/test/test.test
index a66dd3c..f501157 100755
--- a/scripts/test/test.test
+++ b/scripts/test/test.test
@@ -61,3 +61,7 @@
testing "test -ge" "arith_test -ge" "e\ng\n" "" ""
testing "test -lt" "arith_test -lt" "l\n" "" ""
testing "test -le" "arith_test -le" "l\ne\n" "" ""
+
+# test ! = -o a
+# test ! \( = -o a \)
+# test \( ! = \) -o a
diff --git a/toys/posix/patch.c b/toys/posix/patch.c
index bb44348..7fb6add 100644
--- a/toys/posix/patch.c
+++ b/toys/posix/patch.c
@@ -204,18 +204,12 @@
if (PATCH_DEBUG) fprintf(stderr, "NOT: %s\n", plist->data);
TT.state = 3;
- check = llist_pop(&buf);
- check->prev->next = buf;
- buf->prev = check->prev;
- do_line(check);
+ do_line(check = dlist_pop(&buf));
plist = TT.current_hunk;
// If we've reached the end of the buffer without confirming a
// match, read more lines.
- if (check==buf) {
- buf = 0;
- break;
- }
+ if (!buf) break;
check = buf;
} else {
if (PATCH_DEBUG) fprintf(stderr, "MAYBE: %s\n", plist->data);