aboutsummaryrefslogtreecommitdiff
path: root/src/util.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-11 20:27:48 +0200
committerlemon <lsof@mailbox.org>2022-08-11 20:27:48 +0200
commit19f1093f0929b989a06cdee2e7d175e6db15559c (patch)
treeacf82e3cb1b8e81ff132978b7656c178249c5f15 /src/util.cff
parentc7961d732e5d67e8ea1b0be05e979bf24361f794 (diff)
things
Diffstat (limited to 'src/util.cff')
-rw-r--r--src/util.cff35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util.cff b/src/util.cff
index 36a0c13..33bce84 100644
--- a/src/util.cff
+++ b/src/util.cff
@@ -12,3 +12,38 @@ extern fn xrealloc(p *void, n usize) *void {
return p;
}
+
+extern fn fnv1a(h u32, d [#]const u8) u32 {
+ foreach(i, x, d,
+ h ^= x;
+ h *= 0x01000193;
+ )
+ return h;
+}
+
+extern fn fnv1a_s(h u32, str *const u8) u32 {
+ while *str != 0 {
+ h ^= *str++;
+ h *= 0x01000193;
+ }
+ return h;
+}
+
+static filepaths [64]*const u8 = {};
+static nfilepaths int = 0;
+
+extern fn addfilepath(s *const u8) int {
+ let i0 = fnv1a_s(FNV1A_INI, s) % filepaths.#len;
+ let i int = i0;
+ do {
+ if filepaths[i] == #null {
+ break;
+ } else if streq(filepaths[i], s) {
+ return i;
+ }
+ } while ++i != i0;
+
+ assert(nfilepaths++ < filepaths.#len, "too many files");
+ filepaths[i] = s;
+ return i;
+}