Mercurial > garten
annotate main.c @ 20:17b2bcc42d72 default tip
added check for empty result; minor stuff
author | meillo@marmaro.de |
---|---|
date | Sun, 27 Jul 2008 21:34:54 +0200 |
parents | eb8db0d906de |
children |
rev | line source |
---|---|
13 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include "db.h" | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
4 #include "modules.h" |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
5 |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
6 |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
7 void init(void) { |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
8 db_connect(); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
9 read_time(); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
10 } |
13 | 11 |
12 | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
13 void cleanup(void) { |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
14 db_close(); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
15 } |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
16 |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
17 |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
18 void run_module(char* name, int (*module)(void)) { |
13 | 19 printf(" --> %s\n", name); |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
20 if (!module()) { |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
21 fprintf(stderr, "failure in module '%s'\n", name); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
22 cleanup(); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
23 exit(2); |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
24 } |
13 | 25 printf(" --< %s\n", name); |
26 } | |
27 | |
28 | |
29 int main(int argc, char* argv[]) { | |
30 if (argc != 2) { | |
31 printf("usage: %s <database>\n", argv[0]); | |
32 exit(1); | |
33 } | |
34 database = argv[1]; | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
35 init(); |
13 | 36 |
37 /* modules */ | |
38 run_module("clock", worldclock); | |
39 run_module("weather", weather); | |
40 run_module("environment", environment); | |
41 /* run_module("market", market); */ | |
42 run_module("growth", growth); | |
43 /* run_module("orderexec", orderexec); */ | |
44 | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
13
diff
changeset
|
45 cleanup(); |
13 | 46 return 0; |
47 } |