about summary refs log tree commit diff
path: root/complete.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-02-05 20:03:30 -0500
committerJune McEnroe <june@causal.agency>2023-02-05 20:03:30 -0500
commit0a876d27cab179928f6392fd14b453bf30829c51 (patch)
treefa61ae03449ebd3e3ca0980ad760c2c59a1647cc /complete.c
parentFix what went wrong, part 2 (diff)
downloadcatgirl-0a876d27cab179928f6392fd14b453bf30829c51.tar.gz
catgirl-0a876d27cab179928f6392fd14b453bf30829c51.zip
Fix what went wrong, part 3
Diffstat (limited to 'complete.c')
-rw-r--r--complete.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/complete.c b/complete.c
index 4536401..3552c7c 100644
--- a/complete.c
+++ b/complete.c
@@ -36,6 +36,7 @@ struct Node {
 	uint id;
 	char *str;
 	enum Color color;
+	uint bits;
 	struct Node *prev;
 	struct Node *next;
 };
@@ -51,6 +52,7 @@ static struct Node *alloc(uint id, const char *str, enum Color color) {
 	node->str = strdup(str);
 	if (!node->str) err(EX_OSERR, "strdup");
 	node->color = color;
+	node->bits = 0;
 	return node;
 }
 
@@ -138,6 +140,11 @@ enum Color completeColor(uint id, const char *str) {
 	return (node ? node->color : Default);
 }
 
+uint *completeBits(uint id, const char *str) {
+	struct Node *node = find(id, str);
+	return (node ? &node->bits : NULL);
+}
+
 const char *completePrefix(struct Cursor *curs, uint id, const char *prefix) {
 	size_t len = strlen(prefix);
 	if (curs->gen != gen) curs->node = NULL;
@@ -165,7 +172,19 @@ const char *completeSubstr(struct Cursor *curs, uint id, const char *substr) {
 	return NULL;
 }
 
-uint completeNextID(struct Cursor *curs, const char *str) {
+const char *completeEach(struct Cursor *curs, uint id) {
+	if (curs->gen != gen) curs->node = NULL;
+	for (
+		curs->gen = gen, curs->node = (curs->node ? curs->node->next : head);
+		curs->node;
+		curs->node = curs->node->next
+	) {
+		if (curs->node->id == id) return curs->node->str;
+	}
+	return NULL;
+}
+
+uint completeEachID(struct Cursor *curs, const char *str) {
 	if (curs->gen != gen) curs->node = NULL;
 	for (
 		curs->gen = gen, curs->node = (curs->node ? curs->node->next : head);