92 lines
2.6 KiB
C
92 lines
2.6 KiB
C
|
|
#include <sys/ksys.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "system/libini.h"
|
|
#include "modules.h"
|
|
|
|
#include "config.h"
|
|
|
|
config_data_t config_data;
|
|
|
|
static char* config_section_table = "table";
|
|
static char* config_section_modules = "table_modules";
|
|
|
|
static char* config_key_doc_f = "doc_formula";
|
|
static char* config_key_doc_g = "doc_graph";
|
|
static char* config_key_doc_k = "doc_hotkeys";
|
|
static char* config_key_doc_d = "doc_modules";
|
|
|
|
static char* config_key_mdules_dir = "modules_dir";
|
|
//static char* config_key_table = "table_lib";
|
|
|
|
static config_error = -1;
|
|
|
|
static int __stdcall ini_callback(char* f_name, char* sec_name, char* key_name, char* key_value){
|
|
char* cmdline = strchr(key_value, ',');
|
|
if (cmdline != NULL) {
|
|
cmdline[0] = 0;
|
|
cmdline++;
|
|
};
|
|
|
|
if (key_value[0] != '/') {
|
|
char dll_name [4096];
|
|
strcpy(dll_name, config_data.modules_dir);
|
|
strcat(dll_name, "/");
|
|
strcat(dll_name, key_value);
|
|
config_error = module_init(dll_name, cmdline, key_name);
|
|
free(dll_name);
|
|
}else
|
|
config_error = module_init(key_value, cmdline, key_name);
|
|
return !config_error;
|
|
}
|
|
|
|
|
|
int config_load(const char* path){
|
|
_ksys_debug_puts("table: config >");
|
|
_ksys_debug_puts(path);
|
|
_ksys_debug_puts("\n");
|
|
|
|
config_data.config_path = path;
|
|
|
|
// alloc buffer on 5 path to file of documetation
|
|
char* buff = malloc(INI_VALUE_LEN*5);
|
|
if (buff == 0) return -1;
|
|
|
|
if (ini_get_str(path, config_section_table, config_key_doc_f, buff, INI_VALUE_LEN, 0) == 0)
|
|
config_data.doc_formulas = buff;
|
|
else config_data.doc_formulas = NULL;
|
|
|
|
if (ini_get_str(path, config_section_table, config_key_doc_g, buff + INI_VALUE_LEN*1, INI_VALUE_LEN, 0) == 0)
|
|
config_data.doc_graph = buff + INI_VALUE_LEN*1;
|
|
else config_data.doc_graph = NULL;
|
|
|
|
if (ini_get_str(path, config_section_table, config_key_doc_k, buff + INI_VALUE_LEN*2, INI_VALUE_LEN, 0) == 0)
|
|
config_data.doc_hotkeys = buff + INI_VALUE_LEN*2;
|
|
else config_data.doc_hotkeys = NULL;
|
|
|
|
if (ini_get_str(path, config_section_table, config_key_doc_d, buff + INI_VALUE_LEN*3, INI_VALUE_LEN, 0) == 0)
|
|
config_data.doc_module_api = buff + INI_VALUE_LEN*3;
|
|
else config_data.doc_module_api = NULL;
|
|
|
|
ini_get_str(path, config_section_table, config_key_mdules_dir, buff + INI_VALUE_LEN*4, INI_VALUE_LEN, 0);
|
|
config_data.modules_dir = buff + INI_VALUE_LEN*4;
|
|
|
|
// loading modules
|
|
ini_enum_keys(path, config_section_modules, &ini_callback);
|
|
|
|
if (config_error != 0) {
|
|
_ksys_debug_puts("table: error config\n");
|
|
return -1;
|
|
} else {
|
|
_ksys_debug_puts("table: good config\n");
|
|
return 0;
|
|
};
|
|
}
|
|
|
|
|
|
void config_save(){
|
|
|
|
return ;
|
|
} |