work in progess

This commit is contained in:
Олег Бородин
2025-10-16 16:09:55 +02:00
parent 05f845a444
commit dfd504328d
5 changed files with 25 additions and 19 deletions

View File

@@ -12,6 +12,12 @@
#include <cllexer.h> #include <cllexer.h>
#include <clcomp.h> #include <clcomp.h>
#ifdef DEBUG
#define DPRINTF(str, ...) printf(str, __VA_ARGS__)
#else
#define DPRINTF(str, ...) ((void)0)
#endif
static char* strcopy(char* src) { static char* strcopy(char* src) {
size_t srcsize = strlen(src) + 1; size_t srcsize = strlen(src) + 1;
char* dst = malloc(srcsize); char* dst = malloc(srcsize);
@@ -37,6 +43,8 @@ char* clcomp_geterr(clcomp_t * comp) {
return comp->errstr; return comp->errstr;
} }
#define SPACE_TOKEN "space"
int clcomp_gettok(clcomp_t * comp, char* token) { int clcomp_gettok(clcomp_t * comp, char* token) {
if (comp->argn > comp->argc) { if (comp->argn > comp->argc) {
strcpy(token, "EOF"); strcpy(token, "EOF");
@@ -48,7 +56,7 @@ int clcomp_gettok(clcomp_t * comp, char* token) {
if (toktype == TOKEN_ENDF && comp->argn != comp->argc) { if (toktype == TOKEN_ENDF && comp->argn != comp->argc) {
comp->argn++; comp->argn++;
cllexer_init(&(comp->lexer), comp->argv[comp->argn]); cllexer_init(&(comp->lexer), comp->argv[comp->argn]);
strcpy(token, "space"); strcpy(token, SPACE_TOKEN);
return TOKEN_SPACE; return TOKEN_SPACE;
} }
return toktype; return toktype;
@@ -65,12 +73,12 @@ int clcomp_parse(clcomp_t * comp) {
while (toktype != TOKEN_ENDF) { while (toktype != TOKEN_ENDF) {
toktype = clcomp_gettok(comp, token); toktype = clcomp_gettok(comp, token);
i++; i++;
printf("cllexer_parse res: %d: %d [%s]\n", i, toktype, token); DPRINTF("cllexer_parse res: %d: %d [%s]\n", i, toktype, token);
switch (comp->pos) { switch (comp->pos) {
case 0:{ case 0:{
if (toktype == TOKEN_PREF) { if (toktype == TOKEN_PREF) {
comp->pos = 1; comp->pos = 1;
printf("pos %d: TOKEN_PREF %s\n", comp->pos, token); DPRINTF("pos %d: TOKEN_PREF %s\n", comp->pos, token);
} }
continue; continue;
} }
@@ -78,7 +86,7 @@ int clcomp_parse(clcomp_t * comp) {
if (toktype == TOKEN_WORD) { if (toktype == TOKEN_WORD) {
comp->pos = 2; comp->pos = 2;
key = strcopy(token); key = strcopy(token);
printf("pos %d: TOKEN_WORD %s\n", comp->pos, token); DPRINTF("pos %d: TOKEN_WORD %s\n", comp->pos, token);
continue; continue;
} else { } else {
comp->errstr = "Unknown key token"; comp->errstr = "Unknown key token";
@@ -86,9 +94,9 @@ int clcomp_parse(clcomp_t * comp) {
} }
} }
case 2:{ case 2:{
if (toktype == TOKEN_DELIM || toktype == TOKEN_SPACE) { if (toktype == TOKEN_DELIM) {
comp->pos = 3; comp->pos = 3;
printf("pos %d: TOKEN_DELIM %s\n", comp->pos, token); DPRINTF("pos %d: TOKEN_DELIM %s\n", comp->pos, token);
continue; continue;
} else { } else {
comp->errstr = "Unknown delimeter token"; comp->errstr = "Unknown delimeter token";
@@ -100,7 +108,7 @@ int clcomp_parse(clcomp_t * comp) {
comp->pos = 0; comp->pos = 0;
printf("pos %d: TOKEN_WORD %s\n", comp->pos, token); printf("pos %d: TOKEN_WORD %s\n", comp->pos, token);
val = strcopy(token); val = strcopy(token);
printf("keyval = [%s], [%s]\n", key, val); DPRINTF("keyval = [%s], [%s]\n", key, val);
vmapper_set(comp->vmapper, key, val); vmapper_set(comp->vmapper, key, val);
free(key); free(key);
free(val); free(val);
@@ -110,7 +118,6 @@ int clcomp_parse(clcomp_t * comp) {
goto error; goto error;
} }
} }
} }
} }
return 0; return 0;

View File

@@ -27,11 +27,9 @@ int main(int argc, char** argv) {
clconfig_bind(&clconfig, GCONF_STR, "strkey", &strkey); clconfig_bind(&clconfig, GCONF_STR, "strkey", &strkey);
int res = clconfig_parse(&clconfig); int res = clconfig_parse(&clconfig);
if (res < 0) { if (res < 0) {
printf("error: %s\n", clconfig_geterr(&clconfig)); printf("error: %s\n", clconfig_geterr(&clconfig));
} }
MASSERT(res == 0); MASSERT(res == 0);
clconfig_destroy(&clconfig); clconfig_destroy(&clconfig);

View File

@@ -21,6 +21,7 @@
#define LCONTEXT_ENDFL 5 #define LCONTEXT_ENDFL 5
#define LCONTEXT_UNDEF 7 #define LCONTEXT_UNDEF 7
static int get_ltype(char newletter) { static int get_ltype(char newletter) {
switch (newletter) { switch (newletter) {
case '-': case '-':

View File

@@ -26,7 +26,7 @@ int main(int argc, char** argv) {
while (toktype != TOKEN_ENDF) { while (toktype != TOKEN_ENDF) {
toktype = cllexer_gettok(&lex, token); toktype = cllexer_gettok(&lex, token);
printf("cllexer_gettok res: %d: %d [%s]\n", i, toktype, token); printf("test cllexer_gettok res: %d: %d [%s]\n", i, toktype, token);
i++; i++;
} }

View File

@@ -9,30 +9,25 @@
int server_init(void) { int server_init(void) {
logger_dprintf("server init"); logger_dprintf("server inited");
return 0; return 0;
} }
#define SERVER_CONFIG_ERROR -1 #define SERVER_CONFIG_ERROR -1
int server_config(void) { int server_config(void) {
logger_dprintf("server config"); logger_dprintf("server configi");
tconfig_t tconfig; tconfig_t tconfig;
tconfig_init(&tconfig); tconfig_init(&tconfig);
char* logpath = NULL; char* logpath = NULL;
tconfig_bind(&tconfig, TCONF_STR, "logpath", &logpath); tconfig_bind(&tconfig, TCONF_STR, "logpath", &logpath);
ssize_t rsize = tconfig_read(&tconfig, "helmet.conf"); ssize_t rsize = tconfig_read(&tconfig, "helmet.conf");
if (rsize < 0) { if (rsize < 0) {
return SERVER_CONFIG_ERROR; return SERVER_CONFIG_ERROR;
} }
int res = tconfig_parse(&tconfig); int res = tconfig_parse(&tconfig);
if (res < 0) { if (res < 0) {
return SERVER_CONFIG_ERROR; return SERVER_CONFIG_ERROR;
} }
@@ -40,11 +35,16 @@ int server_config(void) {
tconfig_destroy(&tconfig); tconfig_destroy(&tconfig);
logger_dprintf("logpath = %s", logpath); logger_dprintf("logpath = %s", logpath);
clconfig_t tconfig;
tconfig_init(&tconfig);
return 0; return 0;
} }
int server_run(void) { int server_run(void) {
logger_dprintf("server start"); logger_dprintf("server started");
return 0; return 0;
} }