about summary refs log tree commit diff
path: root/chat.h
diff options
context:
space:
mode:
Diffstat (limited to 'chat.h')
-rw-r--r--chat.h52
1 files changed, 30 insertions, 22 deletions
diff --git a/chat.h b/chat.h
index 628d416..369747c 100644
--- a/chat.h
+++ b/chat.h
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>
-#include <sysexits.h>
 #include <time.h>
 #include <wchar.h>
 
@@ -131,7 +130,7 @@ static inline uint idFor(const char *name) {
 	if (idNext == IDCap) return Network;
 	idNames[idNext] = strdup(name);
 	idColors[idNext] = Default;
-	if (!idNames[idNext]) err(EX_OSERR, "strdup");
+	if (!idNames[idNext]) err(1, "strdup");
 	return idNext++;
 }
 
@@ -168,6 +167,19 @@ extern struct Network {
 	char invex;
 } network;
 
+static inline uint prefixBit(char p) {
+	char *s = strchr(network.prefixes, p);
+	if (!s) return 0;
+	return 1 << (s - network.prefixes);
+}
+
+static inline char bitPrefix(uint p) {
+	for (uint i = 0; network.prefixes[i]; ++i) {
+		if (p & (1 << i)) return network.prefixes[i];
+	}
+	return '\0';
+}
+
 #define ENUM_CAP \
 	X("causal.agency/consumer", CapConsumer) \
 	X("chghost", CapChghost) \
@@ -189,7 +201,6 @@ enum Cap {
 
 extern struct Self {
 	bool debug;
-	bool kiosk;
 	bool restricted;
 	size_t pos;
 	enum Cap caps;
@@ -209,7 +220,7 @@ extern struct Self {
 static inline void set(char **field, const char *value) {
 	free(*field);
 	*field = strdup(value);
-	if (!*field) err(EX_OSERR, "strdup");
+	if (!*field) err(1, "strdup");
 }
 
 #define ENUM_TAG \
@@ -261,7 +272,7 @@ static inline void utilPush(struct Util *util, const char *arg) {
 	if (1 + util->argc < UtilCap) {
 		util->argv[util->argc++] = arg;
 	} else {
-		errx(EX_CONFIG, "too many utility arguments");
+		errx(1, "too many utility arguments");
 	}
 }
 
@@ -278,7 +289,6 @@ enum Reply {
 	ReplyNamesAuto,
 	ReplyTopic,
 	ReplyTopicAuto,
-	ReplyWho,
 	ReplyWhois,
 	ReplyWhowas,
 	ReplyCap,
@@ -292,7 +302,7 @@ const char *commandIsPrivmsg(uint id, const char *input);
 const char *commandIsNotice(uint id, const char *input);
 const char *commandIsAction(uint id, const char *input);
 size_t commandWillSplit(uint id, const char *input);
-void commandCache(void);
+void commandCompletion(void);
 
 enum Heat {
 	Ice,
@@ -334,7 +344,7 @@ void inputWait(void);
 void inputUpdate(void);
 bool inputPending(uint id);
 void inputRead(void);
-void inputCache(void);
+void inputCompletion(void);
 int inputSave(FILE *file);
 void inputLoad(FILE *file, size_t version);
 
@@ -396,24 +406,22 @@ int bufferReflow(
 	struct Buffer *buffer, int cols, enum Heat thresh, size_t tail
 );
 
-struct Entry {
-	enum Color color;
-	uint prefixBits;
-};
 struct Cursor {
 	uint gen;
 	struct Node *node;
 };
-struct Entry *cacheInsert(bool touch, uint id, const char *key);
-const struct Entry *cacheGet(uint id, const char *key);
-void cacheReplace(bool touch, const char *old, const char *new);
-const char *cacheComplete(struct Cursor *curs, uint id, const char *prefix);
-const char *cacheSearch(struct Cursor *curs, uint id, const char *substr);
-uint cacheID(struct Cursor *curs, const char *key);
-void cacheAccept(struct Cursor *curs);
-void cacheReject(struct Cursor *curs);
-void cacheRemove(uint id, const char *key);
-void cacheClear(uint id);
+void completePush(uint id, const char *str, enum Color color);
+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);
+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);
 
 extern struct Util urlOpenUtil;
 extern struct Util urlCopyUtil;