diff --git a/lib/db.h b/lib/db.h index ca686af..8c577f2 100755 --- a/lib/db.h +++ b/lib/db.h @@ -1,6 +1,8 @@ #ifndef DB_H #define DB_H +#include "util.h" + #define DB_MAGIC 0xdeadbeef #define DB_VER 0x10 @@ -30,21 +32,21 @@ struct db_table struct db_hash *hashes; }; -int db_write(struct db_table *db, char *fname); -struct db_table *db_read(char *fname); +MY_API int db_write(struct db_table *db, char *fname); +MY_API struct db_table *db_read(char *fname); -int db_set_hash(struct db_table *db, char *key, void *value); -int db_set_hash_char(struct db_table *db, char *key, char *value); -int db_set_hash_int(struct db_table *db, char *key, int value); -int db_set_hash_float(struct db_table *db, char *key, float value); +MY_API int db_set_hash(struct db_table *db, char *key, void *value); +MY_API int db_set_hash_char(struct db_table *db, char *key, char *value); +MY_API int db_set_hash_int(struct db_table *db, char *key, int value); +MY_API int db_set_hash_float(struct db_table *db, char *key, float value); -int db_del_hash(struct db_table *db, char *key); +MY_API int db_del_hash(struct db_table *db, char *key); -void *db_get_hash(struct db_table *db, char *key); -int db_get_hash_type(struct db_table *db, char *key); +MY_API void *db_get_hash(struct db_table *db, char *key); +MY_API int db_get_hash_type(struct db_table *db, char *key); -char *db_get_hash_char(struct db_table *db, char *key); -int db_get_hash_int(struct db_table *db, char *key); -float db_get_hash_float(struct db_table *db, char *key); +MY_API char *db_get_hash_char(struct db_table *db, char *key); +MY_API int db_get_hash_int(struct db_table *db, char *key); +MY_API float db_get_hash_float(struct db_table *db, char *key); #endif diff --git a/lib/irc.h b/lib/irc.h index 6867419..d68d085 100755 --- a/lib/irc.h +++ b/lib/irc.h @@ -9,6 +9,7 @@ #include +#include "util.h" #include "db.h" #ifdef _WIN32 @@ -42,16 +43,6 @@ struct irc_conn typedef struct handler event_handler; -#ifdef _WIN32 -#ifdef MY_DLL_EXPORTS -#define MY_API __declspec(dllexport) -#else -#define MY_API __declspec(dllimport) -#endif -#else -#define MY_API -#endif - void irc_connect(struct irc_conn *bot); void irc_auth(struct irc_conn *bot); diff --git a/lib/util.h b/lib/util.h index 4060d49..db8986e 100755 --- a/lib/util.h +++ b/lib/util.h @@ -12,17 +12,27 @@ #define false FALSE #endif +#ifdef _WIN32 +#ifdef MY_DLL_EXPORTS +#define MY_API __declspec(dllexport) +#else +#define MY_API __declspec(dllimport) +#endif +#else +#define MY_API +#endif + void eprint(char *fmt, ...); #if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 38)) || defined(_WIN32) -void strlcpy(char *to, const char *from, int len); +MY_API void strlcpy(char *to, const char *from, int len); #endif #ifdef _WIN32 -char *basename(char *path); +MY_API char *basename(char *path); #endif -char *skip(char *s, char c); -void trim(char *s); +MY_API char *skip(char *s, char c); +MY_API void trim(char *s); #endif diff --git a/mods/lua/lua.c b/mods/lua/lua.c index a8039fb..f1972e1 100755 --- a/mods/lua/lua.c +++ b/mods/lua/lua.c @@ -95,10 +95,6 @@ int remove_script(char *fname) struct script_list get_scripts() { char *scriptlist = db_get_hash_char(get_bot_db(), "lua.scripts"); - printf("dbug: scriptlist: %s\n", scriptlist); - - // dbug: scriptlist: hello.lua,test.lua,youtube.lua - struct script_list list = {0}; char *p = scriptlist; int i = 0; diff --git a/mods/lua/scripts b/mods/lua/scripts new file mode 100755 index 0000000..b150a42 --- /dev/null +++ b/mods/lua/scripts @@ -0,0 +1,2 @@ +test.lua +hello.lua diff --git a/mods/lua/scripts.tmp b/mods/lua/scripts.tmp index d7a1022..b150a42 100755 --- a/mods/lua/scripts.tmp +++ b/mods/lua/scripts.tmp @@ -1,2 +1,2 @@ -hello.lua test.lua +hello.lua diff --git a/src/db.c b/src/db.c index cebfcb0..d067d18 100755 --- a/src/db.c +++ b/src/db.c @@ -10,6 +10,7 @@ int db_write(struct db_table *db, char *fname) { FILE *fp; int i; + char *fullpath; if ((fp = fopen(fname, "wb")) == NULL) { @@ -19,6 +20,15 @@ int db_write(struct db_table *db, char *fname) db->db_magic = DB_MAGIC; db->db_ver = DB_VER; + // get the full path to the db file +#ifdef _WIN32 + fullpath = _fullpath(NULL, fname, 0); +#else + fullpath = realpath(fname, NULL); +#endif + + printf("Writing db to file: %s\n", fullpath); + // write the header fwrite(db, sizeof(struct db_table), 1, fp); diff --git a/src/main.c b/src/main.c index 95b9a4f..03f099d 100755 --- a/src/main.c +++ b/src/main.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "config.h" #include "irc.h" @@ -24,6 +23,7 @@ #include #else #include +#include #endif static time_t trespond; @@ -51,11 +51,14 @@ int main() init_timers(); init_mods(); // Read the config - bot = read_config(bot, "xbot.cfg"); // check if the db exists, if not, create it +#ifdef _WIN32 + if (access(bot.db_file, 0) == -1) +#else if (access(bot.db_file, F_OK) == -1) +#endif { printf("Creating database file: %s\n", bot.db_file); bot.db = (struct db_table *)malloc(sizeof(struct db_table)); diff --git a/src/util.c b/src/util.c index f80e7a7..79de657 100755 --- a/src/util.c +++ b/src/util.c @@ -11,7 +11,7 @@ #include #include -#include "irc.h" +#include "util.h" void eprint(char *fmt, ...) { @@ -30,7 +30,7 @@ void eprint(char *fmt, ...) } #if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 38)) || defined(_WIN32) -MY_API void strlcpy(char *to, const char *from, int len) +void strlcpy(char *to, const char *from, int len) { memccpy(to, from, '\0', len); to[len-1] = '\0'; @@ -38,14 +38,14 @@ MY_API void strlcpy(char *to, const char *from, int len) #endif #ifdef _WIN32 -MY_API char *basename(char *path) +char *basename(char *path) { char *p = strrchr(path, '\\'); return p ? p + 1 : path; } #endif -MY_API char *skip(char *s, char c) +char *skip(char *s, char c) { while (*s != c && *s != '\0') { diff --git a/xbot.vcxproj b/xbot.vcxproj index a628870..83b66f6 100755 --- a/xbot.vcxproj +++ b/xbot.vcxproj @@ -105,6 +105,7 @@ + @@ -114,6 +115,7 @@ +