From 03cb0d7c04d287ba95b26924620ece0855002ad5 Mon Sep 17 00:00:00 2001
From: C. McEnroe
Date: Sat, 1 Feb 2020 02:33:17 -0500
Subject: Add IDs and names
---
chat.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
(limited to 'chat.h')
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 .
*/
+#include
#include
+#include
+#include
+#include
#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) \
--
cgit 1.4.1-2-gfad0