/**
 *  String switching for ANSI C idea - example program
 *  Copyright (C) 2009 Matous Jan Fialka, <http://mjf.cz/>
 *  Released under the terms of The MIT License
 *
 *  $ cc hc.c -o hc
 *  $ ./hc foo
 *  $ ./hc oof
 *  $ ./hc 'very long string'
 */

#include <stdio.h>

/* Simplest hashing function I could write */

unsigned int hash(char *s)
{
	unsigned int h = 0;

	while (*s++) {
		h = h << 7 ^ (*s);
	}
	return h;
}

/* Example program */

int main(int argc, char *argv[])
{
	unsigned int h = argv[1] ? hash(argv[1]) : '\0';

	printf("Matched ");
	switch (h) {
	case 0x001bf780:
		printf("foo");
		break;
	case 0x2d3bb380:
		printf("very long string");
		break;
	default:
		printf("nothing");
	}
	printf(".\n");

	return 0;
}
