[Add] Made progress with config file system

This commit is contained in:
Ritchie Cunningham 2024-11-23 20:03:28 +00:00
parent 170f543b5c
commit c0ba7e6bed
6 changed files with 68 additions and 1 deletions

View File

@ -1,6 +1,7 @@
default:
mkdir -p bin
mkdir -p bin/base
cp skel/* bin/base
cd base && make
clean:

View File

@ -1,10 +1,52 @@
#include "config.h"
void configProcess(const char* command, const char* arg1, const char* arg2) {
if(strcmp(command, "plugin") == 0) {
if(strcmp(arg1, "scan") == 0)
pluginCrawl(arg2);
}
return;
}
int configRead(const char* path) {
FILE* fp;
char command[64], arg1[128], arg2[128], buff[512];
if((fp = fopen(path, "r")) == NULL) {
fprintf(stderr, "[CONFIG] Unable to open configuration file %s. We're screwed\n", path);
return -1;
}
while(!feof(fp)) {
*buff = 0;
*command = 0;
*arg1 = 0;
*arg2 = 0;
fgets(buff, 512, fp);
sscanf(buff, "%s %s %s\n", command, arg1, arg2);
configProcess(command, arg1, arg2);
}
return 0;
}
void configErrorPush(const char* error) {
/* TODO: Make queue. */
fprintf(stderr, error);
return;
}
void* init() {
if((config = malloc(sizeof(CONFIG))) == NULL) {
fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n");
return NULL;
}
pluginInit();
configRead("base/c3po.conf");
return NULL;
}

View File

@ -120,7 +120,8 @@ void pluginCrawl(const char* path) {
DIR* dir;
struct dirent* file;
dir = opendir(path);
if((dir = opendir(path)) == NULL)
return;
do {
file = readdir(dir);

View File

@ -26,3 +26,6 @@ typedef struct {
struct PLUGIN_NETWORK_ENTRY* network_plug;
struct PLUGIN_FILTER_ENTRY* filter_plug;
} PLUGIN;
void pluginInit();
void pluginCrawl(const char* path);

10
bin/base/c3po.conf Normal file
View File

@ -0,0 +1,10 @@
plugin scan base
plugin scan extra
network Libera {
server irc.libera.chat
port 6667
nick C-3PO
channel #hackers
}

10
skel/c3po.conf Normal file
View File

@ -0,0 +1,10 @@
plugin scan base
plugin scan extra
network Libera {
server irc.libera.chat
port 6667
nick C-3PO
channel #hackers
}