Skip to content
Snippets Groups Projects
Commit 31e19b31 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

Remove the '@' prefix at key name.

Key name now begin with a capital letters instead of using the '@' character.
Also, '-' character are removed from  a composite name.
This is introduce the very first change of the key field.
Some simplications and changes to the key name will be made.
Add the  get_enum_list() function.
parent f0a7aeaa
No related branches found
No related tags found
No related merge requests found
......@@ -351,5 +351,6 @@ enum actions_e
extern ssize_t get_enum_by_key(key_description_t const *list, char const *key) ;
extern char const *get_key_by_enum(key_description_t const *list, int const key) ;
extern const char **get_enum_list(const int sid) ;
#endif
......@@ -82,9 +82,8 @@ extern int parse_get_section(lexer_config *acfg, unsigned int *ncfg, char const
extern int parse_key(stack *key, lexer_config *cfg, key_description_t const *list) ;
extern int parse_value(stack *store, lexer_config *kcfg, const int sid, key_description_t const *list, int const kid) ;
extern int parse_list(stack *stk) ;
extern int parse_bracket(stack *store, lexer_config *kcfg) ;
extern int parse_bracket(stack *store, lexer_config *kcfg, const int sid) ;
extern int parse_clean_runas(char const *str, int idsec, int idkey) ;
extern int parse_bracket(stack *store, lexer_config *kcfg) ;
extern int parse_get_value_of_key(stack *store, char const *str, const int sid, key_description_t const *list, const int kid) ;
extern int parse_mandatory(resolve_service_t *res) ;
extern void parse_error(int ierr, int idsec, key_description_t const *list, int idkey) ;
......
......@@ -19,72 +19,72 @@
#include <oblibs/log.h>
char const *enum_str_section[] = {
"main" ,
"start" ,
"stop" ,
"logger" ,
"environment" ,
"regex" ,
"Main" ,
"Start" ,
"Stop" ,
"Logger" ,
"Environment" ,
"Regex" ,
0
} ;
char const *enum_str_key_section_main[] = {
"@type" ,
"@version" ,
"@description" ,
"@depends" ,
"@requiredby",
"@optsdepends" ,
"@contents" ,
"@options" ,
"@notify" ,
"@user" ,
"@timeout-finish" ,
"@timeout-kill" ,
"@timeout-up" ,
"@timeout-down" ,
"@maxdeath" ,
"@hiercopy" ,
"@down-signal" ,
"@flags" ,
"@intree" ,
"Type" ,
"Version" ,
"Description" ,
"Depends" ,
"RequiredBy",
"OptsDepends" ,
"Contents" ,
"Options" ,
"Notify" ,
"User" ,
"TimeoutFinish" ,
"TimeoutKill" ,
"TimeoutUp" ,
"TimeoutDown" ,
"MaxDeath" ,
"Hiercopy" ,
"DownSignal" ,
"Flags" ,
"Intree" ,
0
} ;
char const *enum_str_key_section_startstop[] = {
"@build" ,
"@runas" ,
"@shebang" ,
"@execute" ,
"Build" ,
"Runas" ,
"Shebang" ,
"Execute" ,
0
} ;
char const *enum_str_key_section_logger[] = {
"@build" ,
"@runas" ,
"@shebang" ,
"@execute" ,
"@destination" ,
"@backup" ,
"@maxsize" ,
"@timestamp" ,
"@timeout-finish" ,
"@timeout-kill" ,
"@depends" ,
"Build" ,
"Runas" ,
"Shebang" ,
"Execute" ,
"Destination" ,
"Backup" ,
"Maxsize" ,
"Timestamp" ,
"TimeoutFinish" ,
"TimeoutKill" ,
"Depends" ,
0
} ;
char const *enum_str_key_section_environ[] = {
"@environ" ,
"Environ" ,
0
} ;
char const *enum_str_key_section_regex[] = {
"@configure" ,
"@directories" ,
"@files" ,
"@infiles" ,
"Configure" ,
"Directories" ,
"Files" ,
"Infiles" ,
0
} ;
......@@ -163,3 +163,31 @@ char const *get_key_by_enum(key_description_t const *list, int const key)
{
return *list[key].name ;
}
const char **get_enum_list(int const sid)
{
switch (sid) {
case SECTION_MAIN:
return enum_str_key_section_main ;
case SECTION_START:
return enum_str_key_section_startstop ;
case SECTION_STOP:
return enum_str_key_section_startstop ;
case SECTION_LOG:
return enum_str_key_section_logger ;
case SECTION_ENV:
return enum_str_key_section_environ ;
case SECTION_REGEX:
return enum_str_key_section_regex ;
default:
errno = EINVAL ;
return 0 ;
}
}
\ No newline at end of file
......@@ -32,7 +32,39 @@ static char parse_char_next(char const *s, size_t slen, size_t *pos)
return c ;
}
int parse_bracket(stack *store, lexer_config *kcfg)
static void key_isvalid(const char *line, size_t *o, uint8_t *bracket, int *vp, int lvp, const int sid)
{
unsigned int pos = 0 ;
const char **key_list = get_enum_list(sid) ;
size_t e = 0 ;
char key[50] ;
int r = get_sep_before(line + (*o), '=', '\n') ;
if (r < 0) {
e = get_len_until(line + (*o), '\n') + 1 ;
(*o) += e ;
return ;
}
/** parse_char_next increase o by one
* reverse it to get the full name of the key
* */
memcpy(key, line + ((*o) - 1), r) ;
key[r] = 0 ;
while (key_list[pos]) {
if (!strcmp(key, key_list[pos])) {
(*o) = (size_t)lvp ;
(*bracket)-- ;
(*vp) = 0 ;
return ;
}
pos++ ;
}
return ;
}
int parse_bracket(stack *store, lexer_config *kcfg, const int sid)
{
log_flow() ;
......@@ -46,8 +78,10 @@ int parse_bracket(stack *store, lexer_config *kcfg)
cfg.slen = kcfg->slen - kcfg->cpos ;
cfg.open = "(";
cfg.olen = 1 ;
cfg.close = ")" ;
cfg.clen = 1 ;
cfg.close = ")\n" ;
cfg.clen = 2 ;
cfg.skip = " \t\r" ;
cfg.skiplen = 3 ;
cfg.kopen = 0 ;
cfg.kclose = 0 ;
......@@ -129,16 +163,14 @@ int parse_bracket(stack *store, lexer_config *kcfg)
while(line[o] == ' ' || line[o] == '\t' || line[o] == '\r')
o++ ;
if (line[o] != '#' && line[o] != '@')
if (line[o] != '#' && (line[o] < 65 || line[o] > 90))
break ;
if (line[o] == '#') {
if (line[o + 1] == '@') {
if (line[o + 1] >= 65 && line[o + 1] <= 90) {
/** a commented key validates the parenthese */
o = lp ;
bracket-- ;
vp = 0 ;
key_isvalid(line, &o, &bracket, &vp, lvp, sid) ;
} else {
// this is a comment
e = get_len_until(line + o, '\n') + 1 ;
......@@ -165,10 +197,8 @@ int parse_bracket(stack *store, lexer_config *kcfg)
/** we previously coming from a comment.
* this validates the parenthese.*/
if (line[o + 1] == '@') {
o = lvp ;
bracket-- ;
vp = 0 ;
if (line[o + 1] >= 65 && line[o + 1] <= 90) {
key_isvalid(line, &o, &bracket, &vp, lvp, sid) ;
} else {
/** another comment, continue the check at the
* next line */
......@@ -206,14 +236,37 @@ int parse_bracket(stack *store, lexer_config *kcfg)
}
}
break ;
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
/** we previously coming from a comment.
* this validates the parenthese.*/
if (vp) {
o = lvp ;
bracket-- ;
vp = 0 ;
}
if (vp)
key_isvalid(line, &o, &bracket, &vp, lvp, sid) ;
break ;
case '\n':
break ;
......
......@@ -131,8 +131,8 @@ lexer_config LEXER_CONFIG_LIST = { \
lexer_config LEXER_CONFIG_KEY = { \
.str = 0,\
.slen = 0,\
.open = "@",\
.olen = 1,\
.open = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",\
.olen = 26,\
.close = "=\n",\
.clen = 2,\
.skip = " \t\r",\
......
......@@ -45,7 +45,7 @@ int parse_value(stack *store, lexer_config *kcfg, const int sid, key_description
case EXPECT_BRACKET:
pos = 0 ;
if (!parse_bracket(store, kcfg))
if (!parse_bracket(store, kcfg, sid))
parse_error_return(LOG_EXIT_ZERO, 6, sid, list, kid) ;
kcfg->pos += pos ;
break ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment