From 1bd57b667c4764f3a86024028250eca8fcc3599b Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Sun, 4 Jun 2023 12:08:14 +1100 Subject: [PATCH] adapt to new stack familly function --- src/lib66/module/regex_get_file_name.c | 12 +++++---- src/lib66/parse/parse_clean_line.c | 22 ++++++++-------- src/lib66/parse/parse_line_g.c | 28 +++++++++------------ src/lib66/parse/parse_section.c | 29 +++++++++++----------- src/lib66/parse/parse_split_from_section.c | 17 ++++++++----- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/lib66/module/regex_get_file_name.c b/src/lib66/module/regex_get_file_name.c index b97fab05..3d28ba82 100644 --- a/src/lib66/module/regex_get_file_name.c +++ b/src/lib66/module/regex_get_file_name.c @@ -17,6 +17,7 @@ #include <oblibs/log.h> #include <oblibs/string.h> #include <oblibs/mill.h> +#include <oblibs/stack.h> #include <skalibs/stralloc.h> @@ -29,20 +30,21 @@ int regex_get_file_name(char *filename, char const *str) int r ; size_t pos = 0 ; - stralloc kp = STRALLOC_ZERO ; - + _init_stack_(stk, strlen(str) + 1) ; parse_mill_t MILL_GET_COLON = { .open = ':', .close = ':', .skip = " \t\r", .skiplen = 3, .forceclose = 1, .inner.debug = "get_colon" } ; - r = mill_element(&kp, str, &MILL_GET_COLON, &pos) ; + r = mill_element(&stk, str, &MILL_GET_COLON, &pos) ; if (r == -1) log_dieu(LOG_EXIT_SYS, "get filename of line: ", str) ; - auto_strings(filename, kp.s) ; + if (!stack_close(&stk)) + log_die(LOG_EXIT_SYS, "stack overflow") ; + + auto_strings(filename, stk.s) ; - stralloc_free(&kp) ; return pos ; } diff --git a/src/lib66/parse/parse_clean_line.c b/src/lib66/parse/parse_clean_line.c index 375c13d2..12461f2a 100644 --- a/src/lib66/parse/parse_clean_line.c +++ b/src/lib66/parse/parse_clean_line.c @@ -16,27 +16,25 @@ #include <oblibs/mill.h> #include <oblibs/string.h> +#include <oblibs/stack.h> +#include <oblibs/log.h> #include <skalibs/stralloc.h> int parse_clean_line(char *str) { - - int r = 0, e = 0 ; + int r = 0 ; size_t tpos = 0 ; - stralloc sa = STRALLOC_ZERO ; - + _init_stack_(stk, strlen(str) + 1) ; wild_zero_all(&MILL_CLEAN_LINE) ; - r = mill_element(&sa, str, &MILL_CLEAN_LINE, &tpos) ; + r = mill_element(&stk, str, &MILL_CLEAN_LINE, &tpos) ; if (r <= 0) - goto err ; - - auto_strings(str, sa.s) ; + return 0 ; - e = 1 ; + if (!stack_close(&stk)) + log_die(LOG_EXIT_SYS, "stack overflow") ; - err: - stralloc_free(&sa) ; - return e ; + auto_strings(str, stk.s) ; + return 1 ; } diff --git a/src/lib66/parse/parse_line_g.c b/src/lib66/parse/parse_line_g.c index 6ca436db..a98c4ccc 100644 --- a/src/lib66/parse/parse_line_g.c +++ b/src/lib66/parse/parse_line_g.c @@ -16,26 +16,26 @@ #include <oblibs/string.h> #include <oblibs/mill.h> +#include <oblibs/stack.h> #include <skalibs/stralloc.h> #include <66/parse.h> -/* @Return 2 if bad format */ int parse_line_g(char *store, parse_mill_t *config, char const *str, size_t *pos) { - int r = 0, e = 0 ; - stralloc sa = STRALLOC_ZERO ; + int r = 0 ; + _init_stack_(stk, strlen(str) + 1) ; - r = mill_element(&sa, str, config, pos) ; - if (r <= 0 || !sa.len) - goto err ; + r = mill_element(&stk, str, config, pos) ; + if (r <= 0 || !stk.len) + return 0 ; - if (!stralloc_0(&sa)) - goto err ; + if (!stack_close(&stk)) + return 0 ; - if (sa.s[0] == ' ') - goto err ; + if (stk.s[0] == ' ') + return 0 ; r = get_len_until(str, '\n') ; if (r < 1) @@ -43,11 +43,7 @@ int parse_line_g(char *store, parse_mill_t *config, char const *str, size_t *pos (*pos) = r + 1 ; // +1 remove '\n' - e = 1 ; + auto_strings(store, stk.s) ; - auto_strings(store, sa.s) ; - - err: - stralloc_free(&sa) ; - return e ; + return 1 ; } diff --git a/src/lib66/parse/parse_section.c b/src/lib66/parse/parse_section.c index 80c5a404..88b07b26 100644 --- a/src/lib66/parse/parse_section.c +++ b/src/lib66/parse/parse_section.c @@ -17,6 +17,7 @@ #include <oblibs/mill.h> #include <oblibs/log.h> #include <oblibs/string.h> +#include <oblibs/stack.h> #include <skalibs/stralloc.h> @@ -26,33 +27,32 @@ int parse_section(stralloc *secname, char const *str, size_t *pos) { int id = -1 ; - size_t len = strlen(str) ; - size_t newpos = 0, found = 0 ; - - stralloc tmp = STRALLOC_ZERO ; + size_t len = strlen(str), newpos = 0, found = 0 ; + _init_stack_(stk, len + 1) ; while ((*pos) < len) { - tmp.len = 0 ; + + stk.len = 0 ; newpos = 0 ; - if (mill_element(&tmp, str + (*pos), &MILL_GET_SECTION_NAME, &newpos) == -1) + if (mill_element(&stk, str + (*pos), &MILL_GET_SECTION_NAME, &newpos) == -1) goto end ; - if (tmp.len) { - if (!stralloc_0(&tmp)) - return -1 ; + if (stk.len) { + if (!stack_close(&stk)) + return -1 ; found = 1 ; // check the validity of the section name - id = get_enum_by_key(tmp.s) ; + id = get_enum_by_key(stk.s) ; if (id < 0) { - log_warn("invalid section name: ", tmp.s, " -- ignoring it") ; + log_warn("invalid section name: ", stk.s, " -- ignoring it") ; newpos-- ; // " retrieve the last ']'" // find the start of the section and pass the next line - id = get_len_until(str + (newpos - tmp.len), '\n') ; - newpos = newpos - tmp.len + id + 1 ; + id = get_len_until(str + (newpos - strlen(stk.s)), '\n') ; + newpos = newpos - strlen(stk.s) + id + 1 ; found = 0 ; } } @@ -63,10 +63,9 @@ int parse_section(stralloc *secname, char const *str, size_t *pos) } if (found) - if (!stralloc_catb(secname, tmp.s, strlen(tmp.s) + 1)) + if (!stralloc_catb(secname, stk.s, strlen(stk.s) + 1)) return -1 ; end: - stralloc_free(&tmp) ; return found ? 1 : 0 ; } diff --git a/src/lib66/parse/parse_split_from_section.c b/src/lib66/parse/parse_split_from_section.c index 1e77451f..e1abd53a 100644 --- a/src/lib66/parse/parse_split_from_section.c +++ b/src/lib66/parse/parse_split_from_section.c @@ -15,6 +15,7 @@ #include <string.h> #include <sys/types.h> +#include <oblibs/stack.h> #include <oblibs/log.h> #include <oblibs/sastr.h> #include <oblibs/string.h> @@ -48,7 +49,6 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st int e = 0, r = 0, found = 0 ; key_all_t const *list = total_list ; - stralloc sakey = STRALLOC_ZERO ; // cpos -> current, ipos -> idx pos, tpos -> temporary pos, end -> end the parse process size_t len = strlen(str), cpos = 0, ipos = 0, tpos = 0, end = 0 ; @@ -89,7 +89,7 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st ipos = 0 ; tpos = 0 ; end = 0 ; - sakey.len = 0 ; + line = (char *)str + cpos ; // (char *) shut up compiler /** comment must be the first character found @@ -126,7 +126,8 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st // get a cleaned key string wild_zero_all(&MILL_GET_KEY) ; - r = mill_element(&sakey, line, &MILL_GET_KEY, &tpos) ; + _init_stack_(stk, strlen(line) + 1) ; + r = mill_element(&stk, line, &MILL_GET_KEY, &tpos) ; if (r < 1) { log_warnu("get key at frontend service file of service: ", svname, " from line: ", line, " -- please make a bug report") ; goto err ; @@ -135,6 +136,11 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st break ; } + if (!stack_close(&stk)) { + log_warnu("stack overflow") ; + goto err ; + } + // copy the string to parse auto_strings(tline, line) ; @@ -146,7 +152,7 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st found = 0 ; // look for a valid key name - if (*list[id].list[ipos].name && !strcmp(sakey.s, *list[id].list[ipos].name)) { + if (*list[id].list[ipos].name && !strcmp(stk.s, *list[id].list[ipos].name)) { found = 1 ; @@ -208,7 +214,7 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st } if (!found && r >= 0) { - log_warn("unknown key: ", sakey.s," : in section: ", secname->s + previous_sec, " -- ignoring it") ; + log_warn("unknown key: ", store," : in section: ", secname->s + previous_sec, " -- ignoring it") ; tpos = get_len_until(line, '\n') ; cpos += tpos + 1 ; } @@ -218,6 +224,5 @@ int parse_split_from_section(resolve_service_t *res, stralloc *secname, char *st e = 1 ; err: - stralloc_free(&sakey) ; return e ; } -- GitLab