view main.c @ 18:5937504619f2

rename game.h -> modules.h; added some error handling; and more
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:40:55 +0200
parents f1d43b52ed36
children eb8db0d906de
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include "db.h"
#include "modules.h"


void init(void) {
	/* echo "started backend cycle at `date +%F\ %H:%M:%S`" */
	db_connect();
	read_time();
}


void cleanup(void) {
	db_close();
	/* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */
}


void run_module(char* name, int (*module)(void)) {
	printf("  --> %s\n", name);
	if (!module()) {
		fprintf(stderr, "failure in module '%s'\n", name);
		cleanup();
		exit(2);
	}
	printf("  --< %s\n", name);
}


int main(int argc, char* argv[]) {
	if (argc != 2) {
		printf("usage: %s <database>\n", argv[0]);
		exit(1);
	}
	database = argv[1];
	printf("database '%s'\n", database);
	init();

	/* modules */
	run_module("clock", worldclock);
	run_module("weather", weather);
	run_module("environment", environment);
	/* run_module("market", market); */
	run_module("growth", growth);
	/* run_module("orderexec", orderexec); */

	cleanup();
	return 0;
}