about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-02 02:31:20 -0500
committerJune McEnroe <june@causal.agency>2020-02-02 02:31:20 -0500
commit3c824684e5f262c2b2fab3f8009b29382277d086 (patch)
tree9f2374cdbc130aab24098bad49779ab6b385e9a9
parentHandle nickname errors (diff)
downloadcatgirl-3c824684e5f262c2b2fab3f8009b29382277d086.tar.gz
catgirl-3c824684e5f262c2b2fab3f8009b29382277d086.zip
Add color hashing function
-rw-r--r--chat.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/chat.h b/chat.h
index be3952c..fc5043d 100644
--- a/chat.h
+++ b/chat.h
@@ -16,6 +16,7 @@
 
 #include <err.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <string.h>
 #include <sysexits.h>
 #include <time.h>
@@ -93,6 +94,16 @@ enum Color {
 	Yellow, LightGreen, Cyan, LightCyan, LightBlue, Pink, Gray, LightGray,
 	Default = 99,
 };
+static inline enum Color hash(const char *str) {
+	if (*str == '~') str++;
+	uint32_t hash = 0;
+	for (; *str; ++str) {
+		hash = (hash << 5) | (hash >> 27);
+		hash ^= *str;
+		hash *= 0x27220A95;
+	}
+	return 2 + hash % 14;
+}
 
 void ircConfig(bool insecure, const char *cert, const char *priv);
 int ircConnect(const char *host, const char *port);
375a8c48646417db75564f248&follow=1'>Remove rc.kfcgiJune McEnroe I sent a better version of it to the port maintainer and it is now in the ports tree. 2019-01-16Reformat index.html with explore linkJune McEnroe 2019-01-16Return false from keydown handler in exploreJune McEnroe 2019-01-08Draw lines to tile edgeJune McEnroe 2019-01-08Factor out default pathsJune McEnroe 2019-01-08Remove incorrect default coordinatesJune McEnroe 2019-01-07Set img src when explore fragment changesJune McEnroe 2019-01-07Compress PNG data in imageJune McEnroe kcgi never enables compression for FastCGI. 2019-01-07madvise MADV_NOCORE in imageJune McEnroe 2019-01-07Add license notice to explore JavaScriptJune McEnroe 2019-01-07Add Q/Home binding in exploreJune McEnroe 2019-01-07Fix explore image URLJune McEnroe 2019-01-07Add HOME button, ssh link, AGPL notice to exploreJune McEnroe 2019-01-06Add meta viewport to exploreJune McEnroe 2019-01-06Set background and max-width in exploreJune McEnroe 2019-01-06Swallow writes after the connection is closedJune McEnroe It was not okay. 2019-01-06Handle KCGI_HUPJune McEnroe I hope it's okay that I keep writing to the fwopen stream after streamWrite returns -1. 2019-01-06Install html filesJune McEnroe