44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
/*
|
|
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <cllexer.h>
|
|
#include <clcomp.h>
|
|
#include <vmapper.h>
|
|
#include <clconfig.h>
|
|
|
|
void clconfig_init(clconfig_t * clconfig, int argc, char** argv) {
|
|
clconfig->errstr = NULL;
|
|
vmapper_init(&(clconfig->vmapper));
|
|
clcomp_init(&(clconfig->comp), &(clconfig->vmapper), argv, argc);
|
|
}
|
|
|
|
int clconfig_bind(clconfig_t * clconfig, int type, char* name, void* ptr) {
|
|
vmapper_t* vmapper = &(clconfig->vmapper);
|
|
|
|
return vmapper_bind(vmapper, type, name, ptr);
|
|
}
|
|
|
|
int clconfig_parse(clconfig_t * clconfig) {
|
|
int res = clcomp_parse(&(clconfig->comp));
|
|
|
|
if (res < 0) {
|
|
if ((clconfig->errstr = clcomp_geterr(&(clconfig->comp))) == NULL) {
|
|
clconfig->errstr = "Undefined command line error";
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
char* clconfig_geterr(clconfig_t * clconfig) {
|
|
return clconfig->errstr;
|
|
}
|
|
|
|
void clconfig_destroy(clconfig_t * clconfig) {
|
|
clcomp_destroy(&(clconfig->comp));
|
|
vmapper_destroy(&(clconfig->vmapper));
|
|
}
|