Repaired and merge

This commit is contained in:
Emil 2023-08-03 21:39:15 -06:00
commit aed88c3521
6 changed files with 74 additions and 73 deletions

2
docs/formatting.txt Normal file
View File

@ -0,0 +1,2 @@
/*--------------------------------------------------------------------------------*/
/* Lines shouldn't be longer than 80 characters, which is this long ^ */

View File

@ -1,33 +0,0 @@
#ifndef CRED_DATA_H_
#define PARAMS_COUNT 5
enum cred_param_ids_e
{
USERNAME,
PASSWORD,
CHANNEL,
SERVER,
PORT
};
char const * cred_names[] =
{
"username",
"password",
"channel",
"server",
"port"
};
size_t const cred_names_len[] =
{
8,
8,
7,
6,
4
};
#define CRED_DATA_H_
#endif

View File

@ -1,29 +1,7 @@
#ifndef HELP_H_
/*--------------------------------------------------------------------------------*/
/* Lines shouldn't be longer than 80 characters, which is this long ^ */
/* note that this is a really terrible way to do this. there should be an
implementation file (help.c) and this file should simply expose that file to
the linker, but this also makes the codegen larger by being duplicated
(prossiby optimized?) I've moved the header to the unity.c rather than move
those definitions away from here. And because this file was included twice
this issue couldn't be so simply overlooked. */
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"
IRC_GREEN "!set_repo <link>" IRC_STOP " : Sets project repository link\n"
IRC_GREEN "!raw <sql> " IRC_STOP " : Execute raw SQL\n"
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 =
"%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";
extern char const * help_msg;
extern char const * fmsg;
#define HELP_H_
#endif

View File

@ -75,7 +75,8 @@ remind(char * who)
repo = (char *) sqlite3_column_text(remind_stmt, 3);
if (repo) { repo = strdup(repo); } else { repo = "<no link available>"; }
asprintf(&r,
IRC_RED "%s: " IRC_YELLOW "%s" IRC_GREEN " (@" IRC_BLUE "%s" IRC_GREEN ")" IRC_STOP,
IRC_RED "%s: " IRC_YELLOW "%s" IRC_GREEN
" (@" IRC_BLUE "%s" IRC_GREEN ")" IRC_STOP,
title, desc, repo);
}
else
@ -120,9 +121,11 @@ rtos(void * data,
}
DECL char *
dump(){
dump()
{
char* errmsg;
char* r = (char*)calloc(sizeof(char), 10000); // TODO: allow for reallocing in rtos, start with a smaller value
/* TODO: allow for reallocing in rtos, start with a smaller value */
char* r = (char*)calloc(sizeof(char), 10000);
DBERR(sqlite3_exec(connection, dump_stmt, rtos, &r, &errmsg));
return r;
}
@ -131,7 +134,8 @@ DECL char *
raw(char const * const sql)
{
char* errmsg;
char *r = (char*)calloc(sizeof(char), 10000); // TODO: allow for reallocing in rtos, start with a smaller value
/* TODO: allow for reallocing in rtos, start with a smaller value */
char *r = (char*)calloc(sizeof(char), 10000);
sqlite3_exec(connection, sql, rtos, &r, &errmsg);
if (errmsg){
free(r);
@ -142,7 +146,8 @@ raw(char const * const sql)
DECL int
get_project_count_callback(void* data, int argc, char** argv, char** colname) {
get_project_count_callback(void* data, int argc, char** argv, char** colname)
{
(void)argc;
(void)colname;
int* count = (int*)data;
@ -151,17 +156,19 @@ get_project_count_callback(void* data, int argc, char** argv, char** colname) {
}
DECL int
get_project_count(){
get_project_count()
{
int r = 0;
char const* sql = "SELECT COUNT(*) FROM project;";
char const * sql = "SELECT COUNT(*) FROM project;";
DBERR(sqlite3_exec(connection, sql, get_project_count_callback, &r, NULL));
return r;
}
DECL int
get_nth_id(const int i){
get_nth_id(const int i)
{
int r;
DBERR(sqlite3_reset(get_nth_id_stmt));
DBERR(sqlite3_bind_int(get_nth_id_stmt, 1, i));
@ -171,7 +178,8 @@ get_nth_id(const int i){
}
DECL void
new_assignment(char const * const who, const int project){
new_assignment(char const * const who, const int project)
{
DBERR(sqlite3_reset(new_assignment_stmt));
DBERR(sqlite3_bind_text(new_assignment_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_bind_int(new_assignment_stmt, 2, project));
@ -179,15 +187,17 @@ new_assignment(char const * const who, const int project){
}
DECL void
random_assign(char const * const who){
random_assign(char const * const who)
{
int i = rand() % get_project_count();
i = get_nth_id(i);
new_assignment(who, i);
}
DECL void
purge_assignments(char const * const who){
purge_assignments(char const * const who)
{
DBERR(sqlite3_reset(purge_assignments_stmt));
DBERR(sqlite3_bind_text(purge_assignments_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_step(purge_assignments_stmt));
DBERR(sqlite3_bind_text(purge_assignments_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_step(purge_assignments_stmt));
}

View File

@ -25,11 +25,26 @@
#include <time.h>
#include <stdlib.h>
#include "irc.h"
#include "parse.h"
#include "api.h"
#include "error.h"
#include "irc.h"
#include "irccolors.h"
#include "parse.h"
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"
IRC_GREEN "!set_repo <link>" IRC_STOP " : Sets project repository link\n"
IRC_GREEN "!raw <sql> " IRC_STOP " : Execute raw SQL\n"
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 =
"%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";
#define PREFIX_COMMAND_CHAR '!'
#define PREFIX_CHANNEL_COMMAND_CHAR '%'

View File

@ -21,9 +21,38 @@
#include <stdlib.h>
#include <string.h>
#include "cred_data.h"
#include "parse.h"
#include "error.h"
#include "help.h"
#define PARAMS_COUNT 5
enum cred_param_ids_e
{
USERNAME,
PASSWORD,
CHANNEL,
SERVER,
PORT
};
char const * cred_names[] =
{
"username",
"password",
"channel",
"server",
"port"
};
size_t const cred_names_len[] =
{
8,
8,
7,
6,
4
};
creds_t creds = {0};
char ** admins = NULL;