Remodels repository to be a strict unity build

This commit is contained in:
Emil 2023-08-04 04:31:16 -06:00
parent 8e8299ff15
commit 5953430b92
10 changed files with 114 additions and 133 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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 = ?;"
;

View File

@ -1,13 +1,3 @@
#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 { \
@ -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)

View File

@ -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)
@ -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;

View File

@ -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];

View File

@ -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,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
{

View File

@ -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"