garten

annotate 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
rev   line source
meillo@13 1 #include <stdio.h>
meillo@13 2 #include <stdlib.h>
meillo@13 3 #include "db.h"
meillo@18 4 #include "modules.h"
meillo@13 5
meillo@13 6
meillo@18 7 void init(void) {
meillo@18 8 /* echo "started backend cycle at `date +%F\ %H:%M:%S`" */
meillo@18 9 db_connect();
meillo@18 10 read_time();
meillo@18 11 }
meillo@18 12
meillo@18 13
meillo@18 14 void cleanup(void) {
meillo@18 15 db_close();
meillo@18 16 /* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */
meillo@18 17 }
meillo@18 18
meillo@18 19
meillo@18 20 void run_module(char* name, int (*module)(void)) {
meillo@13 21 printf(" --> %s\n", name);
meillo@18 22 if (!module()) {
meillo@18 23 fprintf(stderr, "failure in module '%s'\n", name);
meillo@18 24 cleanup();
meillo@18 25 exit(2);
meillo@18 26 }
meillo@13 27 printf(" --< %s\n", name);
meillo@13 28 }
meillo@13 29
meillo@13 30
meillo@13 31 int main(int argc, char* argv[]) {
meillo@13 32 if (argc != 2) {
meillo@13 33 printf("usage: %s <database>\n", argv[0]);
meillo@13 34 exit(1);
meillo@13 35 }
meillo@13 36 database = argv[1];
meillo@13 37 printf("database '%s'\n", database);
meillo@18 38 init();
meillo@13 39
meillo@13 40 /* modules */
meillo@13 41 run_module("clock", worldclock);
meillo@13 42 run_module("weather", weather);
meillo@13 43 run_module("environment", environment);
meillo@13 44 /* run_module("market", market); */
meillo@13 45 run_module("growth", growth);
meillo@13 46 /* run_module("orderexec", orderexec); */
meillo@13 47
meillo@18 48 cleanup();
meillo@13 49 return 0;
meillo@13 50 }