#include "db.h" #include #include #include #include #define FNAME "xbot.db" int main() { struct db_table *db; int i; if (access(FNAME, F_OK) == -1) { printf("Creating db\n"); db = (struct db_table *)malloc(sizeof(struct db_table)); db->count = 0; db->hashes = NULL; } else { db = read_db(FNAME); } // write some data if db is empty if (db->count == 0) { db_add_hash_char(db, "lua.scripts", "hello.lua,test.lua,youtube.lua"); db_add_hash_int(db, "lua.scriptcount", 2); write_db(db, FNAME); return 0; } for (i = 0; i < db->count; i++) { if (db->hashes[i].type == DB_TYPE_INT) { printf("Key: %s, Value: %d\n", db->hashes[i].key, get_hash_int(db, db->hashes[i].key)); } else { printf("Key: %s, Value: %s\n", db->hashes[i].key, get_hash_char(db, db->hashes[i].key)); } } free(db); return 0; }