files
Table/MODULES.C
Mikhail Frolov b3981d174a Table: All editor code files have been added from the flash drive.
The start date of development is September 12, 2024.
2025-03-30 22:56:32 +05:00

127 lines
4.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* this file description of the modules API and included functions for
loading, initializing, closing and calling functions of modules.
Файл - Реализация загрузки всех модулей, их инициалиазция.
Данный файл обеспечивает загрузку модулей и вызов функций проверки и
инициализации модулей формул и форматов.
Описание поведения программы при работе с модулями:
После загрузки конфигурации программа провеяет наличие в параметрах
командной строки пути к файлу таблицчного документа.
Если такого файла нет, то создаётся новый объект table_DOM и доступны
к использованию формулы из всех модулей.
Если файл является табличным документом и загружается каким-либо модулем,
то всплывает окно с выбором доступных данному документу формул модулей.
Каждый документ должен предоставить информацию об использованных модулях.
Если это евозможно ввиду особенностей формата(csv), то всплывает окно с
выбором модулей формул.
;-----------------------------------------------------------------------------
- Для расширения функционала()
;-----------------------------------------------------------------------------
Для формул модуль должен предоставить таблицу описания формулы
*/
#include <sys/ksys.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "modules.h"
static table_exports_t table_exports = {
.version = 0x0102, // 0.1.2
};
static module_t* modules_list = NULL;
int module_init(char* dll_name, char* cmdline, char* namespace){
module_t* this = (module_t*)malloc(sizeof(module_t));
if (!this)
return ENOMEM;
// clear flags
this -> flags = 0;
// copy dll name
this -> dll_path = strdup(dll_name);
// copy namespae
strncpy(this -> namespace, namespace, sizeof(this -> namespace) - 1);
this -> namespace[sizeof(this -> namespace) - 1] = '\0';
// load dll
this -> dll = _ksys_dlopen(dll_name);
if (this -> dll == NULL)
return -1;// not load dll
this -> fn_init = _ksys_dlsym(this -> dll, "tmodule_init");
this -> fn_close = _ksys_dlsym(this -> dll, "tmodule_close");
// call 'tmodule_init'
if (!(this -> fn_init || this -> fn_close))
return -1;// not found standarted function
this -> pdata = this -> fn_init(&table_exports, cmdline, namespace);
if (this -> pdata == NULL)
return -1; // not init module
// call formats_init
import_format_t* __stdcall (*module_get_formats)(uint32_t);
module_get_formats = _ksys_dlsym(this -> dll, "tmodule_formats");
if (module_get_formats)
this -> formats = module_get_formats(this -> pdata);
else
this -> formats = NULL;
// call formulas_init
import_formula_t* __stdcall (*module_get_formulas)(uint32_t);
module_get_formulas = _ksys_dlsym(this -> dll, "tmodule_formulas");
if (module_get_formulas)
this -> formulas = module_get_formulas(this -> pdata);
else
this -> formulas = NULL;
// add_list_item this
this -> next = modules_list;
modules_list = this;
return 0;
}
void modules_exit(){
module_t* this = modules_list;
while (modules_list == NULL ) {
this -> fn_close(this -> pdata);
// del_list_item this
modules_list = this -> next;
if (this -> flags & MODULE_FLAG_EMMBEDED == NULL){
// free module_t.dll_path
free(this -> dll_path);
// free this
free(this);
};
};
return;
}
module_t* find_module_namespace(const char* namespace, uint32_t len){
return NULL;
}
int call_module_formula(module_t* this, const char* func_name, uint32_t len){
return 0;
}
int modules_save_file(char* path){
return;
}
int modules_load_file(char* path){
return;
}