Mercurial > garten
annotate clock.c @ 13:f1d43b52ed36
and here now is the main program
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 15:20:35 +0200 |
parents | 8db6497d6065 |
children | 5e6c9260913a |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "db.h" | |
2 | 5 #include "game.h" |
0 | 6 |
7 | |
8 | |
12 | 9 |
2 | 10 void inc_time() { |
0 | 11 /* get current time */ |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
12 sprintf(query, "select time from game;"); |
0 | 13 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
14 if (sqlite3_step(stmt) == SQLITE_ROW) { |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
15 gametime = sqlite3_column_int(stmt, 0); |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
16 } else { |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db)); |
0 | 18 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
19 sqlite3_finalize(stmt); |
0 | 20 |
21 /* increment time */ | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
22 sprintf(query, " update game set time = '%d';", ++gametime); |
12 | 23 if (!db_update(query)) { |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
24 printf("error: time update failed: %s\n", sqlite3_errmsg(db)); |
0 | 25 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
26 sqlite3_finalize(stmt); |
0 | 27 } |
28 | |
29 | |
12 | 30 void worldclock(void) { |
2 | 31 inc_time(); |
12 | 32 printf("gametime: %d\n", gametime); |
0 | 33 } |