Files
helmetc/libxtools/tconfig.c
2025-10-18 16:31:44 +02:00

53 lines
1.4 KiB
C

/*
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
*/
#include <stdio.h>
#include <tclexer.h>
#include <tccomp.h>
#include <bstream.h>
#include <vmapper.h>
#include <tconfig.h>
void tconfig_init(tconfig_t * tconfig) {
tconfig->errstr = NULL;
bstream_init(&(tconfig->stream));
vmapper_init(&(tconfig->mapper));
tclexer_init(&(tconfig->lexer), &(tconfig->stream));
tccomp_init(&(tconfig->comp), &(tconfig->lexer), &(tconfig->mapper));
}
int tconfig_bind(tconfig_t * tconfig, int type, char* name, void* ptr) {
vmapper_t* vmapper = &(tconfig->mapper);
return vmapper_bind(vmapper, type, name, ptr);
}
ssize_t tconfig_read(tconfig_t * tconfig, char* filename) {
bstream_t* stream = &(tconfig->stream);
return bstream_fread(stream, filename);
}
char* tconfig_geterr(tconfig_t * tconfig) {
return tconfig->errstr;
}
int tconfig_parse(tconfig_t * tconfig) {
int res = 0;
if ((res = tccomp_parse(&(tconfig->comp))) < 0) {
if ((tconfig->errstr = tccomp_geterr(&(tconfig->comp))) == NULL) {
tconfig->errstr = "Unknown config parsing errror";
}
return res;
};
return 0;
}
void tconfig_destroy(tconfig_t * tconfig) {
tccomp_destroy(&(tconfig->comp));
tclexer_destroy(&(tconfig->lexer));
bstream_destroy(&(tconfig->stream));
vmapper_destroy(&(tconfig->mapper));
}