renaming
This commit is contained in:
55
libxtools/clcomp.c
Normal file
55
libxtools/clcomp.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cllexer.h>
|
||||
#include <clcomp.h>
|
||||
|
||||
void clcomp_init(clcomp_t* lexer, char** argv, int argc) {
|
||||
lexer->argv = argv;
|
||||
lexer->argc = argc;
|
||||
lexer->argn = 1;
|
||||
if (lexer->argc > lexer->argn) {
|
||||
cllexer_init(&(lexer->alex), lexer->argv[lexer->argn]);
|
||||
}
|
||||
}
|
||||
|
||||
int clcomp_gettok(clcomp_t* lexer, char* token) {
|
||||
|
||||
if (lexer->argn > lexer->argc) {
|
||||
strcpy(token, "EOF");
|
||||
return TOKEN_ENDF;
|
||||
}
|
||||
|
||||
int toktype = cllexer_gettok(&(lexer->alex), token);
|
||||
if (toktype == TOKEN_ENDF && lexer->argn != lexer->argc) {
|
||||
lexer->argn++;
|
||||
cllexer_init(&(lexer->alex), lexer->argv[lexer->argn]);
|
||||
strcpy(token, "space");
|
||||
return TOKEN_SPACE;
|
||||
}
|
||||
|
||||
return toktype;
|
||||
}
|
||||
|
||||
/*
|
||||
int clcomp_parse(clcomp_t* lexer, char* token) {
|
||||
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = cllexer_gettok(&lex, token);
|
||||
printf("cllexer_gettok res: %d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void clcomp_destroy(clcomp_t* clcomp) {
|
||||
(void)clcomp;
|
||||
}
|
||||
@@ -11,16 +11,17 @@
|
||||
//#include <stdbool.h>
|
||||
//#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <cllexer.h>
|
||||
|
||||
typedef struct {
|
||||
char** argv;
|
||||
int argc;
|
||||
int argn;
|
||||
galexer_t alex;
|
||||
} gclexer_t;
|
||||
cllexer_t alex;
|
||||
} clcomp_t;
|
||||
|
||||
void gclexer_init(gclexer_t* lexer, char** argv, int argc);
|
||||
int gclexer_gettok(gclexer_t* lexer, char* token);
|
||||
void clcomp_init(clcomp_t* lexer, char** argv, int argc);
|
||||
int clcomp_gettok(clcomp_t* lexer, char* token);
|
||||
void clcomp_destroy(clcomp_t* clcomp);
|
||||
|
||||
#endif
|
||||
@@ -8,25 +8,25 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <gclexer.h>
|
||||
#include <cllexer.h>
|
||||
#include <clcomp.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char*_argv[] = { argv[0], "--qwerty=-num12345", "--foo=-bar" };
|
||||
char*_argv[] = { argv[0], "--qwerty=12345", "--foo=bar" };
|
||||
int _argc = 2;
|
||||
|
||||
gclexer_t lex;
|
||||
gclexer_init(&lex, _argv, _argc);
|
||||
clcomp_t lex;
|
||||
clcomp_init(&lex, _argv, _argc);
|
||||
|
||||
char token[1024];
|
||||
int toktype = TOKEN_NULL;
|
||||
int i = 0;
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = gclexer_gettok(&lex, token);
|
||||
printf("%d: %d [%s]\n", i, toktype, token);
|
||||
toktype = clcomp_gettok(&lex, token);
|
||||
printf("clcomp_gettok res: %d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
}
|
||||
|
||||
63
libxtools/clconfig.c
Normal file
63
libxtools/clconfig.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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) {
|
||||
clcomp_init(&(clconfig->lexer), argv, argc);
|
||||
vmapper_init(&(clconfig->mapper));
|
||||
}
|
||||
|
||||
int clconfig_bind(clconfig_t* clconfig, int type, char* name, void* ptr) {
|
||||
vmapper_t* vmapper = &(clconfig->mapper);
|
||||
return vmapper_bind(vmapper, type, name, ptr);
|
||||
}
|
||||
|
||||
int clconfig_parse(clconfig_t* clconfig) {
|
||||
|
||||
char token[1024];
|
||||
int toktype = TOKEN_NULL;
|
||||
int i = 0;
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = clcomp_gettok(&(clconfig->lexer), token);
|
||||
printf("clconfig_parse %d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clconfig_destroy(clconfig_t* clconfig) {
|
||||
clcomp_destroy(&(clconfig->lexer));
|
||||
vmapper_destroy(&(clconfig->mapper));
|
||||
}
|
||||
|
||||
int __main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char*_argv[] = { argv[0], "--qwerty=-num12345", "--foo=-bar" };
|
||||
int _argc = 2;
|
||||
|
||||
clcomp_t lex;
|
||||
clcomp_init(&lex, _argv, _argc);
|
||||
|
||||
char token[1024];
|
||||
int toktype = TOKEN_NULL;
|
||||
int i = 0;
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = clcomp_gettok(&lex, token);
|
||||
printf("%d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
libxtools/clconfig.h
Normal file
29
libxtools/clconfig.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*/
|
||||
|
||||
#ifndef GCONFIG_H_QWERTY
|
||||
#define GCONFIG_H_QWERTY
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <clcomp.h>
|
||||
#include <vmapper.h>
|
||||
|
||||
typedef struct {
|
||||
clcomp_t lexer;
|
||||
vmapper_t mapper;
|
||||
int argc;
|
||||
char ** argv;
|
||||
} clconfig_t;
|
||||
|
||||
#define GCONF_STR MAPPER_STR
|
||||
#define GCONF_INT MAPPER_INT
|
||||
#define GCONF_BOOL MAPPER_BOOL
|
||||
|
||||
void clconfig_init(clconfig_t* clconfig, int argc, char **argv);
|
||||
int clconfig_bind(clconfig_t* clconfig, int type, char* name, void* ptr);
|
||||
int clconfig_parse(clconfig_t* clconfig);
|
||||
void clconfig_destroy(clconfig_t* clconfig);
|
||||
|
||||
#endif
|
||||
37
libxtools/clconfig_test.c
Normal file
37
libxtools/clconfig_test.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <clconfig.h>
|
||||
#include <massert.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char*_argv[] = { argv[0], "--strkey=num5678", "--intkey=12345" };
|
||||
int _argc = 2;
|
||||
|
||||
clconfig_t clconfig;
|
||||
clconfig_init(&clconfig, _argc, _argv);
|
||||
|
||||
int intkey = 0;
|
||||
char* strkey = NULL;
|
||||
|
||||
clconfig_bind(&clconfig, GCONF_INT, "intkey", &intkey);
|
||||
clconfig_bind(&clconfig, GCONF_STR, "strkey", &strkey);
|
||||
|
||||
int res = clconfig_parse(&clconfig);
|
||||
MASSERT(res == 0);
|
||||
|
||||
clconfig_destroy(&clconfig);
|
||||
|
||||
printf("int key = %d\n", intkey);
|
||||
printf("str key = %s\n", strkey);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <cllexer.h>
|
||||
|
||||
#define LTYPE_LETTER 1
|
||||
#define LTYPE_PREFIX 2
|
||||
@@ -34,7 +34,7 @@ static int get_ltype(char newletter) {
|
||||
return LTYPE_LETTER;
|
||||
}
|
||||
|
||||
void galexer_init(galexer_t* lexer, char* arg) {
|
||||
void cllexer_init(cllexer_t* lexer, char* arg) {
|
||||
lexer->arg = arg;
|
||||
lexer->rpos = 0;
|
||||
lexer->tpos = 0;
|
||||
@@ -42,14 +42,14 @@ void galexer_init(galexer_t* lexer, char* arg) {
|
||||
lexer->newletter = '\0';
|
||||
}
|
||||
|
||||
static void galexer_getletter(galexer_t* lexer, char* arg, int size) {
|
||||
static void cllexer_getletter(cllexer_t* lexer, char* arg, int size) {
|
||||
lexer->newletter = EOF;
|
||||
if (lexer->rpos < size) {
|
||||
lexer->newletter = arg[lexer->rpos++];
|
||||
}
|
||||
}
|
||||
|
||||
int galexer_gettok(galexer_t* lexer, char* token) {
|
||||
int cllexer_gettok(cllexer_t* lexer, char* token) {
|
||||
|
||||
char* arg = lexer->arg;
|
||||
size_t size = strlen(arg);
|
||||
@@ -155,7 +155,7 @@ int galexer_gettok(galexer_t* lexer, char* token) {
|
||||
}
|
||||
}
|
||||
token[lexer->tpos++] = lexer->newletter;
|
||||
galexer_getletter(lexer, arg, size);
|
||||
cllexer_getletter(lexer, arg, size);
|
||||
}
|
||||
|
||||
lexer->currcontext = LCONTEXT_ENDFL;
|
||||
@@ -22,9 +22,9 @@ typedef struct {
|
||||
int rpos;
|
||||
int tpos;
|
||||
char newletter;
|
||||
} galexer_t;
|
||||
} cllexer_t;
|
||||
|
||||
void galexer_init(galexer_t* lexer, char* arg);
|
||||
int galexer_gettok(galexer_t* lexer, char* token);
|
||||
void cllexer_init(cllexer_t* lexer, char* arg);
|
||||
int cllexer_gettok(cllexer_t* lexer, char* token);
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <cllexer.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
@@ -16,15 +16,15 @@ int main(int argc, char **argv) {
|
||||
|
||||
char* arg = "--qwerty=-num-12345";
|
||||
|
||||
galexer_t lex;
|
||||
galexer_init(&lex, arg);
|
||||
cllexer_t lex;
|
||||
cllexer_init(&lex, arg);
|
||||
|
||||
char token[1024];
|
||||
int toktype = TOKEN_NULL;
|
||||
int i = 0;
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = galexer_gettok(&lex, token);
|
||||
printf("%d: %d [%s]\n", i, toktype, token);
|
||||
toktype = cllexer_gettok(&lex, token);
|
||||
printf("cllexer_gettok res: %d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <gclexer.h>
|
||||
|
||||
void gclexer_init(gclexer_t* lexer, char** argv, int argc) {
|
||||
lexer->argv = argv;
|
||||
lexer->argc = argc;
|
||||
lexer->argn = 1;
|
||||
if (lexer->argc > lexer->argn) {
|
||||
galexer_init(&(lexer->alex), lexer->argv[lexer->argn]);
|
||||
}
|
||||
}
|
||||
|
||||
int gclexer_gettok(gclexer_t* lexer, char* token) {
|
||||
|
||||
if (lexer->argn >= lexer->argc) {
|
||||
strcpy(token, "EOF");
|
||||
return TOKEN_ENDF;
|
||||
}
|
||||
|
||||
int toktype = galexer_gettok(&(lexer->alex), token);
|
||||
if (toktype == TOKEN_ENDF && lexer->argn != lexer->argc) {
|
||||
lexer->argn++;
|
||||
galexer_init(&(lexer->alex), lexer->argv[lexer->argn]);
|
||||
strcpy(token, "space");
|
||||
return TOKEN_SPACE;
|
||||
}
|
||||
return toktype;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <galexer.h>
|
||||
#include <gclexer.h>
|
||||
#include <vmapper.h>
|
||||
#include <gconfig.h>
|
||||
|
||||
void gconfig_init(gconfig_t* gconfig, int argc, char **argv) {
|
||||
gclexer_init(&(gconfig->lex), argv, argc);
|
||||
vmapper_init(&(gconfig->mapper));
|
||||
}
|
||||
|
||||
int gconfig_bind(gconfig_t* gconfig, int type, char* name, void* ptr) {
|
||||
vmapper_t* vmapper = &(gconfig->mapper);
|
||||
return vmapper_bind(vmapper, type, name, ptr);
|
||||
}
|
||||
|
||||
int gconfig_parse(gconfig_t* gconfig) {
|
||||
// return tccomp_parse(&(gconfig->comp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gconfig_destroy(gconfig_t* gconfig) {
|
||||
//gclexer_destroy(&(gconfig->lexer));
|
||||
vmapper_destroy(&(gconfig->mapper));
|
||||
}
|
||||
|
||||
int __main(int argc, char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char*_argv[] = { argv[0], "--qwerty=-num12345", "--foo=-bar" };
|
||||
int _argc = 2;
|
||||
|
||||
gclexer_t lex;
|
||||
gclexer_init(&lex, _argv, _argc);
|
||||
|
||||
char token[1024];
|
||||
int toktype = TOKEN_NULL;
|
||||
int i = 0;
|
||||
while (toktype != TOKEN_ENDF) {
|
||||
toktype = gclexer_gettok(&lex, token);
|
||||
printf("%d: %d [%s]\n", i, toktype, token);
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*/
|
||||
|
||||
#ifndef GCONFIG_H_QWERTY
|
||||
#define GCONFIG_H_QWERTY
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gclexer.h>
|
||||
|
||||
typedef struct {
|
||||
gclexer_t lex;
|
||||
vmapper_t mapper;
|
||||
} gconfig_t;
|
||||
|
||||
#define GCONF_STR MAPPER_STR
|
||||
#define GCONF_INT MAPPER_INT
|
||||
#define GCONF_BOOL MAPPER_BOOL
|
||||
|
||||
void gconfig_init(gconfig_t* gconfig, int argc, char **argv);
|
||||
int gconfig_bind(gconfig_t* gconfig, int type, char* name, void* ptr);
|
||||
int gconfig_parse(gconfig_t* gconfig);
|
||||
void gconfig_destroy(gconfig_t* gconfig);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user