annotate clock.c @ 11:176ee28e7464

switched from mysql to sqlite; (+ some cleanups)
author meillo@marmaro.de
date Wed, 23 Jul 2008 11:41:38 +0200
parents 8369454d4ec9
children 8db6497d6065
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
1 #include <stdio.h>
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
2 #include <stdlib.h>
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
3
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
4 #include "db.h"
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
5 #include "game.h"
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
6
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
7
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
8
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
9 void inc_time() {
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
10 /* get current time */
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
11 sprintf(query, "select time from game;");
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
12 db_query(query);
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
13 if (sqlite3_step(stmt) == SQLITE_ROW) {
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
14 gametime = sqlite3_column_int(stmt, 0);
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
15 printf("gametime: %d\n", gametime);
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
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
18 }
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
19 sqlite3_finalize(stmt);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
20
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
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);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
23 db_query(query);
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
24 if (sqlite3_step(stmt) == SQLITE_DONE) {
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
25 printf("time update successful\n");
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
26 printf("virtual time: %d\n", gametime);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
27 } else {
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
28 printf("error: time update failed: %s\n", sqlite3_errmsg(db));
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
29 }
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
30 sqlite3_finalize(stmt);
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
31 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
32
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
33
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
34 int main(int argc, char* argv[]) {
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
35 printf(" --> clock\n");
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
36
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
37 /* init */
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
38 if (argc != 2) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
39 printf("usage: %s <game>\n", argv[0]);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
40 exit(1);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
41 }
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
42 database = argv[1];
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
43
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
44 db_connect();
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 2
diff changeset
45 read_time();
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
46
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
47 inc_time();
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
48
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
49 /*
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
50 while ((row = mysql_fetch_row(result)) != NULL) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
51 for (i = 0; i < mysql_num_fields(result); i++) {
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
52 printf("%10s ", row[i]);
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
53 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
54 printf("\n");
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
55 }
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
56 */
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
57
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
58
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
59
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
60
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
61 db_close();
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
62
2
8369454d4ec9 with outsourced gamecheck and minor stuff
meillo@marmaro.de
parents: 0
diff changeset
63 printf(" --< clock\n");
0
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
64 return 0;
831599184108 inital commit
meillo@marmaro.de
parents:
diff changeset
65 }