diff --git a/include/api.h b/include/api.h index de83b98..b6fcf3b 100644 --- a/include/api.h +++ b/include/api.h @@ -1,12 +1,12 @@ #ifndef API_H_ +VARDECL char const * db; + DECL int api_init(void); DECL void api_rope(void); DECL void rope(void); DECL char * remind(char * who); DECL char * raw(char const * const sql); -extern char const * db; - #define API_H_ #endif diff --git a/include/help.h b/include/help.h index 489434c..a1cdac6 100644 --- a/include/help.h +++ b/include/help.h @@ -2,8 +2,8 @@ /* (((git))) */ -extern char const * help_msg; -extern char const * fmsg; +VARDECL char const * help_msg; +VARDECL char const * fmsg; #define HELP_H_ #endif diff --git a/include/irc.h b/include/irc.h index deae888..7175220 100644 --- a/include/irc.h +++ b/include/irc.h @@ -4,10 +4,9 @@ #include "parse.h" -extern irc_session_t * session; -extern irc_callbacks_t callbacks; - -extern char * current_username; +VARDECL irc_session_t * session; +VARDECL irc_callbacks_t callbacks; +VARDECL char * current_username; DECL int init(void); diff --git a/include/parse.h b/include/parse.h index 961b4d6..c054c39 100644 --- a/include/parse.h +++ b/include/parse.h @@ -11,7 +11,7 @@ typedef struct int port; } creds_t; -extern creds_t creds; +VARDECL creds_t creds; DECL char * dump(void); DECL char * raw(char const * const sql); diff --git a/include/stmt.h b/include/stmt.h deleted file mode 100644 index 853bea5..0000000 --- a/include/stmt.h +++ /dev/null @@ -1,50 +0,0 @@ -#define stmt_prepare(stmt) \ - sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) - -static sqlite3_stmt* remind_stmt; -static const char remind_stmt_template[] = - "SELECT " - "title," - "body," - "difficulty," - "repo_link," - "trigger_date," - "started DATE," - "span" - " FROM assignment INNER JOIN project on assignment.project = project.rowid " - "WHERE who = ?;" -; - -static sqlite3_stmt* set_repo_stmt; -static const char set_repo_stmt_template[] = - "UPDATE assignment " - "SET " - "repo_link = ? " - "WHERE who = ?;" -; - -static const char dump_stmt[] = - "SELECT * FROM project;" -; - -static sqlite3_stmt* get_nth_id_stmt; -static const char get_nth_id_stmt_template[] = - "SELECT rowid " - "FROM project " - "LIMIT 1 " - "OFFSET ?;" -; - -static sqlite3_stmt* new_assignment_stmt; -static const char new_assignment_stmt_template[] = - "INSERT INTO assignment " - "(who, project)" - " VALUES " - "(?, ?);" -; - -static sqlite3_stmt* purge_assignments_stmt; -static const char purge_assignments_stmt_template[] = - "DELETE FROM assignment " - "WHERE who = ?;" -; diff --git a/src/api.c b/src/api.c index 9263d3b..b4f70ee 100644 --- a/src/api.c +++ b/src/api.c @@ -1,13 +1,3 @@ -#include -#include - -#include - -#include "error.h" -#include "irc.h" -#include "irccolors.h" -#include "stmt.h" - #define DBFILE "probotic_data.sqlite" #define DBERR(line) do { \ @@ -21,9 +11,60 @@ } \ } while (0) -char const * db = DBFILE; +#define stmt_prepare(stmt) \ + sqlite3_prepare_v2(connection, stmt ## _template, -1, &stmt, NULL) -static sqlite3 * connection = NULL; +VARDECL sqlite3_stmt * remind_stmt; +VARDECL char const remind_stmt_template[] = + "SELECT " + "title," + "body," + "difficulty," + "repo_link," + "trigger_date," + "started DATE," + "span" + " FROM assignment INNER JOIN project on assignment.project = project.rowid " + "WHERE who = ?;" +; + +VARDECL sqlite3_stmt * set_repo_stmt; +VARDECL char const set_repo_stmt_template[] = + "UPDATE assignment " + "SET " + "repo_link = ? " + "WHERE who = ?;" +; + +VARDECL char const dump_stmt[] = + "SELECT * FROM project;" +; + +VARDECL sqlite3_stmt * get_nth_id_stmt; +VARDECL char const get_nth_id_stmt_template[] = + "SELECT rowid " + "FROM project " + "LIMIT 1 " + "OFFSET ?;" +; + +VARDECL sqlite3_stmt * new_assignment_stmt; +VARDECL char const new_assignment_stmt_template[] = + "INSERT INTO assignment " + "(who, project)" + " VALUES " + "(?, ?);" +; + +VARDECL sqlite3_stmt * purge_assignments_stmt; +VARDECL char const purge_assignments_stmt_template[] = + "DELETE FROM assignment " + "WHERE who = ?;" +; + +VARDECL char const * db = DBFILE; + +VARDECL sqlite3 * connection = NULL; DECL int api_init(void) diff --git a/src/irc.c b/src/irc.c index 8805d46..d8d33e8 100644 --- a/src/irc.c +++ b/src/irc.c @@ -18,20 +18,7 @@ */ -#include -#include -#include -#include -#include -#include - -#include "api.h" -#include "error.h" -#include "irc.h" -#include "irccolors.h" -#include "parse.h" - -char const * help_msg = +VARDECL char const * help_msg = IRC_GREEN "!help " IRC_STOP " : This message\n" IRC_GREEN "!remind " IRC_STOP " : Dump current assignment\n" IRC_GREEN "!reroll " IRC_STOP " : Rerolls assignment\n" @@ -41,7 +28,7 @@ IRC_GREEN "!dump " IRC_STOP " : List all possible projects\n" IRC_GREEN "!request " IRC_STOP " : Request personal project\n" IRC_GREEN "!remind " IRC_STOP " : Prints your assignment\n"; -char const * fmsg = +VARDECL char const * fmsg = "%s\x2C\x20\x79\x6F\x75\x20\x61\x72\x65\x20\x66\x61\x67\x67" "\x6F\x74\x20\x66\x6F\x72\x20\x74\x68\x61\x74\x20\x6F\x70" "\x69\x6E\x69\x6F\x6E\x2E"; @@ -49,11 +36,12 @@ char const * fmsg = #define PREFIX_COMMAND_CHAR '!' #define PREFIX_CHANNEL_COMMAND_CHAR '%' -irc_session_t * session; -irc_callbacks_t callbacks; +VARDECL irc_session_t * session; +VARDECL irc_callbacks_t callbacks; -char * current_username = NULL; -int f = -1; +VARDECL char * current_username = NULL; +/* Do you have any idea how many things this breaks? */ +int stupid_shit = -1; #define IRCMSG(msg) irc_cmd_msg(session, creds.channel, msg) @@ -137,8 +125,9 @@ event_channel(irc_session_t * session, break; } if(!current_username || *(message+1) == '\00'){ return; } - --f; - if(f == 0){ ircmsg(fmsg, current_username); } + --stupid_shit; + if(stupid_shit == 0) + { ircmsg(fmsg, current_username); } parse_command(message+1); free(current_username); current_username = NULL; diff --git a/src/main.c b/src/main.c index a014f39..7c992f6 100644 --- a/src/main.c +++ b/src/main.c @@ -18,14 +18,6 @@ */ -#include -#include - -#include "api.h" -#include "error.h" -#include "free.h" -#include "irc.h" - #define VERSION_STRING "0.0" #define EQOP(var,val,off) \ @@ -91,7 +83,8 @@ main (int argc, else if (strcmp(arg, "password") == 0) { free(creds.password); creds.password = strdup(argv[1]); } else if (strcmp(arg, "admin") == 0) - { free(creds.admins); parse_admins(argv[1]); } /* argv isn't constant :> */ + /* argv isn't constant :>, this can make even valgrind shutter */ + { free(creds.admins); parse_admins(argv[1]); } else if (strcmp(arg, "auth") == 0) { authfile = argv[1]; diff --git a/src/parse.c b/src/parse.c index 028c325..5a2eab8 100644 --- a/src/parse.c +++ b/src/parse.c @@ -17,18 +17,10 @@ version 3 + NIGGER along with Probotic. */ -#include -#include -#include - -#include "error.h" -#include "free.h" -#include "help.h" -#include "parse.h" #define PARAMS_COUNT 6 -enum cred_param_ids_e +enum cred_names_map { USERNAME, PASSWORD, @@ -38,7 +30,7 @@ enum cred_param_ids_e ADMINS }; -char const * cred_names[] = +VARDECL char const * cred_names[] = { "username", "password", @@ -48,7 +40,7 @@ char const * cred_names[] = "admins" }; -size_t const cred_names_len[] = +VARDECL size_t const cred_names_len[] = { 8, 8, @@ -58,7 +50,7 @@ size_t const cred_names_len[] = 6 }; -creds_t creds = {0}; +VARDECL creds_t creds = {0}; DECL char * slurp(char const * fn) @@ -73,9 +65,11 @@ slurp(char const * fn) rewind(fp); b = malloc(len+2); if (b) - { fread(b, 1, len, fp); } + { + fread(b, 1, len, fp); + b[len+1] = '\0'; + } fclose(fp); - b[len+1] = '\0'; return b; } @@ -101,33 +95,29 @@ parse_command(char const * cmd) { exit(1); } if (strcmp(cmd, "remind") == 0) { - msgswp = remind(current_username); - ircmsg("%s: %s", current_username, msgswp); - } + msgswp = remind(current_username); + ircmsg("%s: %s", current_username, msgswp); + } // XXX: maybe no? //else if (strcmp(cmd, "next") == 0) // TODO: implement //{ ircmsg("%s: No future assignments", current_username); } else if (strcmp(cmd, "help") == 0) - { - ircmsg(help_msg); - } + { ircmsg(help_msg); } else if (strcmp(cmd, "magic") == 0) - { - f = 8 + (rand() % 100); - } + { stupid_shit = 8 + (rand() % 100); } else if (strcmp(cmd, "dump") == 0) { - ircmsg("%s: All projects:", current_username); - msgswp = dump(); - ircmsg(msgswp); - } + ircmsg("%s: All projects:", current_username); + msgswp = dump(); + ircmsg(msgswp); + } else if (strcmp(cmd, "reroll") == 0) // TODO: implement { - ircmsg("%s: Rerolling...", current_username); - purge_assignments(current_username); - random_assign(current_username); - ircmsg(remind(current_username)); - } + ircmsg("%s: Rerolling...", current_username); + purge_assignments(current_username); + random_assign(current_username); + ircmsg(remind(current_username)); + } } else { diff --git a/src/unity.c b/src/unity.c index a42a135..19a0a15 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1,4 +1,23 @@ #define DECL static +#define VARDECL static + +#include +#include +#include +#include +#include +#include + +#include + +#include "api.h" +#include "error.h" +#include "free.h" +#include "help.h" +#include "irc.h" +#include "irccolors.h" +#include "parse.h" + #include "irc.c" #include "parse.c" #include "api.c"