about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--chat.h4
-rw-r--r--command.c20
-rw-r--r--complete.c21
-rw-r--r--handle.c19
4 files changed, 40 insertions, 24 deletions
diff --git a/chat.h b/chat.h
index ef5779a..6753fcb 100644
--- a/chat.h
+++ b/chat.h
@@ -417,9 +417,11 @@ void completePull(uint id, const char *str, enum Color color);
 void completeReplace(const char *old, const char *new);
 void completeRemove(uint id, const char *str);
 enum Color completeColor(uint id, const char *str);
+uint *completeBits(uint id, const char *str);
 const char *completePrefix(struct Cursor *curs, uint id, const char *prefix);
 const char *completeSubstr(struct Cursor *curs, uint id, const char *substr);
-uint completeNextID(struct Cursor *curs, const char *str);
+const char *completeEach(struct Cursor *curs, uint id);
+uint completeEachID(struct Cursor *curs, const char *str);
 void completeAccept(struct Cursor *curs);
 void completeReject(struct Cursor *curs);
 
diff --git a/command.c b/command.c
index ea7400a..b09b342 100644
--- a/command.c
+++ b/command.c
@@ -226,16 +226,16 @@ static void commandOps(uint id, char *params) {
 		idColors[id], idNames[id]
 	);
 	bool first = true;
-	//struct Cursor curs = {0};
-	//for (const char *nick; (nick = cacheNextKey(&curs, id));) {
-	//	char prefix = bitPrefix(curs.entry->prefixBits);
-	//	if (!prefix || prefix == '+') continue;
-	//	ptr = seprintf(
-	//		ptr, end, "%s\3%02d%c%s\3",
-	//		(first ? "" : ", "), curs.entry->color, prefix, nick
-	//	);
-	//	first = false;
-	//}
+	struct Cursor curs = {0};
+	for (const char *nick; (nick = completeEach(&curs, id));) {
+		char prefix = bitPrefix(*completeBits(id, nick));
+		if (!prefix || prefix == '+') continue;
+		ptr = seprintf(
+			ptr, end, "%s\3%02d%c%s\3",
+			(first ? "" : ", "), completeColor(id, nick), prefix, nick
+		);
+		first = false;
+	}
 	if (first) {
 		uiFormat(
 			id, Warm, NULL, "\3%02d%s\3 is a lawless wasteland",
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);
diff --git a/handle.c b/handle.c
index 34ce6b0..5a2cf7c 100644
--- a/handle.c
+++ b/handle.c
@@ -459,7 +459,7 @@ static void handleNick(struct Message *msg) {
 		inputUpdate();
 	}
 	struct Cursor curs = {0};
-	for (uint id; (id = completeNextID(&curs, msg->nick));) {
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		if (!strcmp(idNames[id], msg->nick)) {
 			set(&idNames[id], msg->params[0]);
 		}
@@ -480,7 +480,7 @@ static void handleNick(struct Message *msg) {
 static void handleSetname(struct Message *msg) {
 	require(msg, true, 1);
 	struct Cursor curs = {0};
-	for (uint id; (id = completeNextID(&curs, msg->nick));) {
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		uiFormat(
 			id, filterCheck(Cold, id, msg), tagTime(msg),
 			"\3%02d%s\3\tis now known as \3%02d%s\3 (%s\17)",
@@ -493,7 +493,7 @@ static void handleSetname(struct Message *msg) {
 static void handleQuit(struct Message *msg) {
 	require(msg, true, 0);
 	struct Cursor curs = {0};
-	for (uint id; (id = completeNextID(&curs, msg->nick));) {
+	for (uint id; (id = completeEachID(&curs, msg->nick));) {
 		enum Heat heat = filterCheck(Cold, id, msg);
 		if (heat > Ice) urlScan(id, msg->nick, msg->params[0]);
 		uiFormat(
@@ -576,11 +576,7 @@ static void handleReplyNames(struct Message *msg) {
 			bits |= prefixBit(*p);
 		}
 		completePush(id, nick, color);
-		/*
-		struct Entry *entry = cacheInsert(false, id, nick);
-		if (user) entry->color = color;
-		entry->prefixBits = bits;
-		*/
+		*completeBits(id, nick) = bits;
 		if (!replies[ReplyNames] && !replies[ReplyNamesAuto]) continue;
 		ptr = seprintf(
 			ptr, end, "%s\3%02d%s\3", (ptr > buf ? ", " : ""), color, prefixes
@@ -867,13 +863,12 @@ static void handleMode(struct Message *msg) {
 			char prefix = network.prefixes[
 				strchr(network.prefixModes, *ch) - network.prefixModes
 			];
-			/*
+			completePush(id, nick, Default);
 			if (set) {
-				cacheInsert(false, id, nick)->prefixBits |= prefixBit(prefix);
+				*completeBits(id, nick) |= prefixBit(prefix);
 			} else {
-				cacheInsert(false, id, nick)->prefixBits &= ~prefixBit(prefix);
+				*completeBits(id, nick) &= ~prefixBit(prefix);
 			}
-			*/
 			uiFormat(
 				id, Cold, tagTime(msg),
 				"\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3",