projects
/
open-adventure.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9c88649
)
Add token_to_packed() utility function.
author
Jason S. Ninneman
<jsn@mbar.us>
Mon, 19 Jun 2017 21:45:32 +0000
(14:45 -0700)
committer
Jason S. Ninneman
<jsn@mbar.us>
Mon, 19 Jun 2017 21:45:32 +0000
(14:45 -0700)
advent.h
patch
|
blob
|
history
misc.c
patch
|
blob
|
history
diff --git
a/advent.h
b/advent.h
index ff62476379a7f16dda8212109ef28a52cbc02cb5..1a6ab089f2838c19ee762fd3eade3e60ceca9fb0 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* 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);
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..64c05ceb1fa8c636b2b4659c33ffba8a3d85da90 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[token[4 - i]];
+ *packed |= (mapped << (6 * i));
+ }
+}
+
/* Hide the fact that wods are corrently packed longs */
bool wordeq(token_t a, token_t b)
/* Hide the fact that wods are corrently packed longs */
bool wordeq(token_t a, token_t b)