summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-01 02:33:17 -0500
committerJune McEnroe <june@causal.agency>2020-02-01 02:33:17 -0500
commit03cb0d7c04d287ba95b26924620ece0855002ad5 (patch)
tree1906bd93e28d13b03b31da2e06ef70b1729b7252
parentAdd -v flag (diff)
downloadcatgirl-03cb0d7c04d287ba95b26924620ece0855002ad5.tar.gz
catgirl-03cb0d7c04d287ba95b26924620ece0855002ad5.zip
Add IDs and names
Diffstat (limited to '')
-rw-r--r--chat.c7
-rw-r--r--chat.h22
2 files changed, 29 insertions, 0 deletions
diff --git a/chat.c b/chat.c
index 5796085..462faa0 100644
--- a/chat.c
+++ b/chat.c
@@ -23,6 +23,13 @@
 
 #include "chat.h"
 
+char *idNames[IDCap] = {
+	[None] = "<none>",
+	[Debug] = "<debug>",
+	[Network] = "<network>",
+};
+size_t idNext = Network + 1;
+
 struct Self self;
 
 int main(int argc, char *argv[]) {
diff --git a/chat.h b/chat.h
index 4dd4732..8c13d49 100644
--- a/chat.h
+++ b/chat.h
@@ -14,13 +14,35 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <err.h>
 #include <stdbool.h>
+#include <string.h>
+#include <sysexits.h>
+#include <time.h>
 
 #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
 #define BIT(x) x##Bit, x = 1 << x##Bit, x##Bit_ = x##Bit
 
 typedef unsigned char byte;
 
+enum { None, Debug, Network, IDCap = 256 };
+extern char *idNames[IDCap];
+extern size_t idNext;
+
+static inline size_t idFind(const char *name) {
+	for (size_t id = 0; id < idNext; ++id) {
+		if (!strcmp(idNames[id], name)) return id;
+	}
+	return None;
+}
+static inline size_t idFor(const char *name) {
+	size_t id = idFind(name);
+	if (id) return id;
+	idNames[idNext] = strdup(name);
+	if (!idNames[idNext]) err(EX_OSERR, "strdup");
+	return idNext++;
+}
+
 #define ENUM_CAP \
 	X("sasl", CapSASL) \
 	X("server-time", CapServerTime) \
9-07-27 13:27:13 -0400'>2019-07-27Reference png.h in bin.7June McEnroe 2019-07-27Revert "Use scheme to style HTMLs"June McEnroe This reverts commit 46237a457ff3c9a813a56f2a442c115bf8610cbc. I don't know why but I don't like it. 2019-07-27Remove scheme text linkJune McEnroe No standard base64 encoder so no way to maintain it. 2019-07-26Update Dark.terminalJune McEnroe Why are the blobs so much bigger now? 2019-07-26Lighten dark whiteJune McEnroe 2019-07-25Add png.3 man pageJune McEnroe 2019-07-25Use scheme to style HTMLsJune McEnroe 2019-07-25Don't match comments in strings in makeJune McEnroe 2019-07-25Generate index.html with links from bin.7June McEnroe 2019-07-24Warn when date has changedJune McEnroe 2019-07-24Add whenJune McEnroe When? Now. 2019-07-24Remove histedit from bitJune McEnroe