From 0a876d27cab179928f6392fd14b453bf30829c51 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 5 Feb 2023 20:03:30 -0500 Subject: Fix what went wrong, part 3 --- complete.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'complete.c') 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); -- cgit 1.4.1