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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
1 #include <stdio.h>
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
2 #include <stdlib.h>
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
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 /* echo "started backend cycle at `date +%F\ %H:%M:%S`" */
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
9 db_connect();
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
10 read_time();
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
11 }
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
12
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
13
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
14 void cleanup(void) {
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
15 db_close();
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
16 /* echo "finished backend cycle at `date +%F\ %H:%M:%S`" */
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
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
19
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
20 void run_module(char* name, int (*module)(void)) {
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
21 printf(" --> %s\n", name);
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
22 if (!module()) {
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
23 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
24 cleanup();
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
25 exit(2);
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
26 }
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
27 printf(" --< %s\n", name);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
28 }
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
29
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
30
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
31 int main(int argc, char* argv[]) {
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
32 if (argc != 2) {
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
33 printf("usage: %s <database>\n", argv[0]);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
34 exit(1);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
35 }
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
36 database = argv[1];
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
37 printf("database '%s'\n", database);
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
38 init();
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
39
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
40 /* modules */
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
41 run_module("clock", worldclock);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
42 run_module("weather", weather);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
43 run_module("environment", environment);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
44 /* run_module("market", market); */
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
45 run_module("growth", growth);
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
46 /* run_module("orderexec", orderexec); */
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
47
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 13
diff changeset
48 cleanup();
13
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
49 return 0;
f1d43b52ed36 and here now is the main program
meillo@marmaro.de
parents:
diff changeset
50 }