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