[Add] Made progress with config file system
This commit is contained in:
parent
170f543b5c
commit
c0ba7e6bed
1
Makefile
1
Makefile
@ -1,6 +1,7 @@
|
|||||||
default:
|
default:
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
mkdir -p bin/base
|
mkdir -p bin/base
|
||||||
|
cp skel/* bin/base
|
||||||
cd base && make
|
cd base && make
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -1,10 +1,52 @@
|
|||||||
#include "config.h"
|
#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() {
|
void* init() {
|
||||||
if((config = malloc(sizeof(CONFIG))) == NULL) {
|
if((config = malloc(sizeof(CONFIG))) == NULL) {
|
||||||
fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n");
|
fprintf(stderr, "[CONFIG] First malloc failed. Let's just give up :D\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginInit();
|
||||||
|
configRead("base/c3po.conf");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,8 @@ void pluginCrawl(const char* path) {
|
|||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* file;
|
struct dirent* file;
|
||||||
|
|
||||||
dir = opendir(path);
|
if((dir = opendir(path)) == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
file = readdir(dir);
|
file = readdir(dir);
|
||||||
|
@ -26,3 +26,6 @@ typedef struct {
|
|||||||
struct PLUGIN_NETWORK_ENTRY* network_plug;
|
struct PLUGIN_NETWORK_ENTRY* network_plug;
|
||||||
struct PLUGIN_FILTER_ENTRY* filter_plug;
|
struct PLUGIN_FILTER_ENTRY* filter_plug;
|
||||||
} PLUGIN;
|
} PLUGIN;
|
||||||
|
|
||||||
|
void pluginInit();
|
||||||
|
void pluginCrawl(const char* path);
|
||||||
|
10
bin/base/c3po.conf
Normal file
10
bin/base/c3po.conf
Normal 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
10
skel/c3po.conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
plugin scan base
|
||||||
|
plugin scan extra
|
||||||
|
|
||||||
|
network Libera {
|
||||||
|
server irc.libera.chat
|
||||||
|
port 6667
|
||||||
|
nick C-3PO
|
||||||
|
|
||||||
|
channel #hackers
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user