Mercurial > garten
diff 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 diff
--- a/main.c Wed Jul 23 17:14:38 2008 +0200 +++ b/main.c Wed Jul 23 17:40:55 2008 +0200 @@ -1,12 +1,29 @@ #include <stdio.h> #include <stdlib.h> #include "db.h" -#include "game.h" +#include "modules.h" + + +void init(void) { + /* echo "started backend cycle at `date +%F\ %H:%M:%S`" */ + db_connect(); + read_time(); +} -void run_module(char* name, void (*module)(void)) { +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); - module(); + if (!module()) { + fprintf(stderr, "failure in module '%s'\n", name); + cleanup(); + exit(2); + } printf(" --< %s\n", name); } @@ -18,11 +35,7 @@ } database = argv[1]; printf("database '%s'\n", database); - - /* echo "started backend cycle at `date +%F\ %H:%M:%S`" */ - db_connect(); - read_time(); - + init(); /* modules */ run_module("clock", worldclock); @@ -32,9 +45,6 @@ run_module("growth", growth); /* run_module("orderexec", orderexec); */ - - db_close(); - /* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */ - + cleanup(); return 0; }