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 diff
     1.1 --- a/main.c	Wed Jul 23 17:14:38 2008 +0200
     1.2 +++ b/main.c	Wed Jul 23 17:40:55 2008 +0200
     1.3 @@ -1,12 +1,29 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6  #include "db.h"
     1.7 -#include "game.h"
     1.8 +#include "modules.h"
     1.9  
    1.10  
    1.11 -void run_module(char* name, void (*module)(void)) {
    1.12 +void init(void) {
    1.13 +	/* echo "started backend cycle at `date +%F\ %H:%M:%S`" */
    1.14 +	db_connect();
    1.15 +	read_time();
    1.16 +}
    1.17 +
    1.18 +
    1.19 +void cleanup(void) {
    1.20 +	db_close();
    1.21 +	/* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */
    1.22 +}
    1.23 +
    1.24 +
    1.25 +void run_module(char* name, int (*module)(void)) {
    1.26  	printf("  --> %s\n", name);
    1.27 -	module();
    1.28 +	if (!module()) {
    1.29 +		fprintf(stderr, "failure in module '%s'\n", name);
    1.30 +		cleanup();
    1.31 +		exit(2);
    1.32 +	}
    1.33  	printf("  --< %s\n", name);
    1.34  }
    1.35  
    1.36 @@ -18,11 +35,7 @@
    1.37  	}
    1.38  	database = argv[1];
    1.39  	printf("database '%s'\n", database);
    1.40 -
    1.41 -	/* echo "started backend cycle at `date +%F\ %H:%M:%S`" */
    1.42 -	db_connect();
    1.43 -	read_time();
    1.44 -
    1.45 +	init();
    1.46  
    1.47  	/* modules */
    1.48  	run_module("clock", worldclock);
    1.49 @@ -32,9 +45,6 @@
    1.50  	run_module("growth", growth);
    1.51  	/* run_module("orderexec", orderexec); */
    1.52  
    1.53 -
    1.54 -	db_close();
    1.55 -	/* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */
    1.56 -
    1.57 +	cleanup();
    1.58  	return 0;
    1.59  }