Merge branch 'master' into magic-number 116/head
authorPeje Nilsson <peje66@gmail.com>
Mon, 19 Jun 2017 22:06:49 +0000 (00:06 +0200)
committerPeje Nilsson <peje66@gmail.com>
Mon, 19 Jun 2017 22:06:49 +0000 (00:06 +0200)
advent.h
misc.c

index ff62476379a7f16dda8212109ef28a52cbc02cb5..2b7f761ac4c3b7ba9a1c06c65181f5dff5d540bb 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -90,6 +90,7 @@ extern bool oldstyle, editline, prompt;
 extern void* xmalloc(size_t size);
 extern char* xstrdup(const char*);
 extern void packed_to_token(long, char token[]);
+extern void token_to_packed(char token[], long*);
 extern void speak(const char*);
 extern bool wordeq(token_t, token_t);
 extern bool wordempty(token_t);
diff --git a/misc.c b/misc.c
index ba834fdffd44b84cef98268a2e2cbadc8dea63b2..29846e23f6a5aef4aef9320ea180e8a0797a5800 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -50,6 +50,18 @@ void packed_to_token(long packed, char token[6])
     }
 }
 
+void token_to_packed(char token[6], long* packed)
+{
+  *packed = 0;
+  for (size_t i = 0; i < 5; ++i)
+    {
+      if (token[4 - i] == '\0')
+       continue;       
+      char mapped = ascii_to_advent[(int) token[4 - i]];
+      *packed |= (mapped << (6 * i));
+    }
+}
+
 /* Hide the fact that wods are corrently packed longs */
 
 bool wordeq(token_t a, token_t b)