// SDB-CGEN V2.6.2
#include <ctype.h>
#include <stdio.h>
#include <string.h>

struct kv { const char *name; const char *value; };
static const struct kv kvs[] = {
// gcc -DMAIN=1 chip8.c ; ./a.out > chip8.h
	{"add", "add src and dest, store result in dest"},
	{"and", "logical and"},
	{"call", "call subroutine"},
	{"cls", "clear display"},
	{"drw", "draw sprite using given coordinates"},
	{"exit", "stop interpreter"},
	{"high", "enter high-resolution mode"},
	{"jp", "jump"},
	{"ld", "copy data from src to dest"},
	{"low", "enter low-resolution mode"},
	{"or", "logical inclusive or"},
	{"ret", "return from subroutine"},
	{"rnd", "set dest to (random number & src)"},
	{"scd", "scroll down"},
	{"scl", "scroll left"},
	{"scr", "scroll right"},
	{"se", "skip next instruction if equal"},
	{"shl", "shift left by one"},
	{"shr", "shift right by one"},
	{"sknp", "skip next instruction if specified key is not pressed"},
	{"skp", "skip next instruction if specified key is pressed"},
	{"sne", "skip next instruction if not equal"},
	{"sub", "subtract src from dest, store result in dest"},
	{"subn", "subtract dest from src, store result in dest"},
	{"xor", "logical exclusive or"},
  {NULL, NULL}
};
typedef int (*GperfForeachCallback)(void *user, const char *k, const char *v);
int gperf_chip8_foreach(GperfForeachCallback cb, void *user) {
  int i = 0; while (kvs[i].name) {
  cb (user, kvs[i].name, kvs[i].value);
  i++;}
  return 0;
}
const char *gperf_chip8_get(const char *s) {
  int i = 0; while (kvs[i].name) {
  if (!strcmp (s, kvs[i].name)) return kvs[i].value;
  i++;}
  return NULL;
}
#define sdb_hash_c_chip8(x,y) gperf_chip8_hash(x)
const unsigned int gperf_chip8_hash(const char *s) {
  int sum = strlen (s);
  while (*s) { sum += *s; s++; }
  return sum;
}
struct {const char *name;void *get;void *hash;void *foreach;} gperf_chip8 = {
  .name = "chip8",
  .get = &gperf_chip8_get,
  .hash = &gperf_chip8_hash,
  .foreach = &gperf_chip8_foreach
};

#if MAIN
int main () {
	const char *s = ((char*(*)(char*))gperf_chip8.get)("foo");
	printf ("%s\n", s);
}
#endif
