Updated to pure unity build and fixes some other gripes
This commit is contained in:
commit
8f1f476fcb
@ -2,7 +2,3 @@ server=irc.rizon.net
|
||||
username=probotic
|
||||
port=6667
|
||||
admins=anon8697 emilemilemil fa11_1eaf
|
||||
|
||||
; provide channel yourself
|
||||
; lines without an equal sign are dropped
|
||||
; prefix comments with a semicolon for future compat
|
||||
|
@ -1,5 +1,7 @@
|
||||
#ifndef API_H_
|
||||
|
||||
VARDECL char const * db;
|
||||
|
||||
DECL int api_init(void);
|
||||
DECL void api_rope(void);
|
||||
DECL void rope(void);
|
||||
@ -7,7 +9,5 @@ DECL char * remind(char * who);
|
||||
DECL char * raw(char const * const sql);
|
||||
DECL int is_no_assignment(char const * const who);
|
||||
|
||||
extern char const * db;
|
||||
|
||||
#define API_H_
|
||||
#endif
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -1,56 +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 = ?;"
|
||||
;
|
||||
|
||||
static sqlite3_stmt* is_no_assignment_stmt;
|
||||
static const char is_no_assignment_stmt_template[] =
|
||||
"SELECT * FROM assignment "
|
||||
"WHERE who = ?;"
|
||||
;
|
69
src/api.c
69
src/api.c
@ -1,18 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "irc.h"
|
||||
#include "irccolors.h"
|
||||
#include "stmt.h"
|
||||
|
||||
#define DBFILE "probotic_data.sqlite"
|
||||
|
||||
#define DBERR(line) do { \
|
||||
const int e = line; \
|
||||
if(e != SQLITE_OK && e != SQLITE_ROW && e != SQLITE_DONE) \
|
||||
#define DBERR(l) do { \
|
||||
if(l != SQLITE_OK && l != SQLITE_ROW && l != SQLITE_DONE) \
|
||||
{ \
|
||||
fprintf(stderr, \
|
||||
"sqlite (%d): %s\n", \
|
||||
@ -21,9 +10,59 @@
|
||||
} \
|
||||
} 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 sqlite3_stmt* is_no_assignment_stmt;
|
||||
VARDECL const char is_no_assignment_stmt_template[] =
|
||||
"SELECT * FROM assignment "
|
||||
"WHERE who = ?;" ;
|
||||
|
||||
VARDECL char const * db = DBFILE;
|
||||
|
||||
VARDECL sqlite3 * connection = NULL;
|
||||
|
||||
DECL int
|
||||
api_init(void)
|
||||
|
31
src/irc.c
31
src/irc.c
@ -18,20 +18,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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)
|
||||
|
||||
@ -142,8 +130,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;
|
||||
|
11
src/main.c
11
src/main.c
@ -18,14 +18,6 @@
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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];
|
||||
|
70
src/parse.c
70
src/parse.c
@ -17,18 +17,10 @@
|
||||
version 3 + NIGGER along with Probotic.
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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,30 +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)
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -143,8 +136,8 @@ parse_command(char const * cmd)
|
||||
msgswp = remind(creds.channel);
|
||||
ircmsg("%s: %s", current_username, msgswp);
|
||||
}
|
||||
// XXX: what is this suppose to do?
|
||||
else if (strncmp(cmd, "submit", i) == 0) // TODO: implement
|
||||
/* XXX: what is this suppose to do? */
|
||||
else if (strncmp(cmd, "submit", i) == 0) /* TODO: implement */
|
||||
{
|
||||
ircmsg("%s: Submitting project link '%s' to <random janny>",
|
||||
current_username, arg);
|
||||
@ -171,8 +164,8 @@ parse_pair(char const * buf, size_t len)
|
||||
/* X macro for handling this data may be better */
|
||||
if (strncmp(buf, cred_names[f], cred_names_len[f]) == 0)
|
||||
{
|
||||
/* fprintf(stderr, "f%ld:len%ld:%s\n", f, cred_names_len[f], */
|
||||
/* cred_names[f]); fflush(stderr); */
|
||||
fprintf(stderr, "f%ld:len%ld:%s\n", f, cred_names_len[f],
|
||||
cred_names[f]); fflush(stderr);
|
||||
buf += i;
|
||||
while (buf[x] != '\0')
|
||||
{
|
||||
@ -189,7 +182,10 @@ parse_pair(char const * buf, size_t len)
|
||||
case CHANNEL: creds.channel = strndup(buf,x); break;
|
||||
case SERVER: creds.server = strndup(buf,x); break;
|
||||
case PORT: creds.port = atoi(buf); break;
|
||||
case ADMINS: adm = strndup(buf,x); parse_admins(adm); free(adm); break;
|
||||
case ADMINS: adm = strndup(buf,x);
|
||||
parse_admins(adm);
|
||||
free(adm);
|
||||
break;
|
||||
}
|
||||
if (x + 2 < len)
|
||||
{ buf += x + 1; }
|
||||
|
19
src/unity.c
19
src/unity.c
@ -1,4 +1,23 @@
|
||||
#define DECL static
|
||||
#define VARDECL static
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#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"
|
||||
|
Reference in New Issue
Block a user