Browse Source

- add some function static

development
Andreas Romeyke 8 months ago
parent
commit
21a547e34a
  1. 18
      src/headers/config_parser.h
  2. 108
      src/parser/config_parser.c

18
src/headers/config_parser.h

@ -112,12 +112,12 @@ typedef struct parser_state_s {
int logical_elements;
} parser_state_t;
void _helper_push_result(full_res_t res);
full_res_t _helper_pop_result();
void _helper_mark_top_n_results(int n, returncode_t type);
full_res_t _helper_get_nth(int n);
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
void set_parse_error(char * msg, char * yytext);
static void _helper_push_result(full_res_t res);
static full_res_t _helper_pop_result();
static void _helper_mark_top_n_results(int n, returncode_t type);
static full_res_t _helper_get_nth(int n);
static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
static void set_parse_error(char * msg, char * yytext);
void execute_plan (ctiff_t * ctif);
void print_plan ();
ret_t print_plan_results (retmsg_t *);
@ -125,9 +125,9 @@ void clean_plan ();
void parse_plan ();
void parse_plan_via_stream (FILE * file);
void parse_plan_via_file (const char * cfg_file);
void add_default_rules_to_plan();
void set_include( const char * );
static void add_default_rules_to_plan();
static void set_include( const char * );
void exe_printstack_human_readable ();
void result_push(full_res_t);
static void result_push(full_res_t);
#endif
/* _FIXIT_TIFF_CONFIG_PARSER */

108
src/parser/config_parser.c

@ -87,8 +87,8 @@ void print_plan () {
//endmacro PRINTV
void result_push(full_res_t r) { PUSH(&parser_state, result, r); }
void result_printstack() {
static void result_push(full_res_t r) { PUSH(&parser_state, result, r); }
static void result_printstack() {
printf("=== BEGIN result_printstack\n");
for (int i = 0; i < parser_state.result_stackp; i++) {
@ -105,10 +105,10 @@ void result_printstack() {
printf("=== END result_printstack\n");
}
void i_printstack () { PRINT(&parser_state, "%u", i); }
void i_push (unsigned int i) { PUSH(&parser_state, i, i);}
unsigned int i_pop () { unsigned i; POP(&parser_state, i, i); return i; }
void v_printstack () {
static void i_printstack () { PRINT(&parser_state, "%u", i); }
static void i_push (unsigned int i) { PUSH(&parser_state, i, i);}
static unsigned int i_pop () { unsigned i; POP(&parser_state, i, i); return i; }
static void v_printstack () {
const char * vname[] = {
"range",
"logical_or",
@ -119,14 +119,14 @@ void v_printstack () {
};
PRINTV(&parser_state, vname, val);
}
void v_push ( values_t v) { PUSH(&parser_state, val, v);}
values_t v_pop () { values_t v; POP(&parser_state, val, v); return v; }
static void v_push ( values_t v) { PUSH(&parser_state, val, v);}
static values_t v_pop () { values_t v; POP(&parser_state, val, v); return v; }
void r_printstack () { PRINT(&parser_state, "%s", regex); }
void r_push (char * r) { PUSH(&parser_state, regex, r); }
char * r_pop () { char * v; POP(&parser_state, regex, v); return v; }
void exe_push (internal_entry_t i) { PUSH(&parser_state, exe, i);}
internal_entry_t exe_pop () { internal_entry_t e; POP(&parser_state, exe, e); return e; }
static void r_printstack () { PRINT(&parser_state, "%s", regex); }
static void r_push (char * r) { PUSH(&parser_state, regex, r); }
static char * r_pop () { char * v; POP(&parser_state, regex, v); return v; }
static void exe_push (internal_entry_t i) { PUSH(&parser_state, exe, i);}
static internal_entry_t exe_pop () { internal_entry_t e; POP(&parser_state, exe, e); return e; }
void exe_printstack_human_readable () {
CHECKOVERFLOW(&parser_state, exe);
@ -153,7 +153,7 @@ void exe_printstack_human_readable () {
}
/* help function to print exe stack */
void exe_printstack () {
static void exe_printstack () {
CHECKOVERFLOW(&parser_state, exe);
CHECKUNDERFLOW(&parser_state, exe);
printf("=== BEGIN exe_printstack\n");
@ -186,7 +186,7 @@ void exe_printstack () {
/* reduce results */
void reduce_results() {
static void reduce_results() {
#ifdef DEBUG
printf("---------------------------------------------------------------------\n");
printf("begin REDUCE\n");
@ -260,14 +260,14 @@ void reduce_results() {
}
/* stack function for parser */
void exe_i_push (internal_entry_t * ep, unsigned int i) {
static void exe_i_push (internal_entry_t * ep, unsigned int i) {
PUSH( ep, i, i)
}
unsigned int exe_i_pop(internal_entry_t * ep) {
static unsigned int exe_i_pop(internal_entry_t * ep) {
unsigned int i; POP( ep, i, i); return i;
}
/* stack function for parser */
internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
static internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
#ifdef EXE_DEBUG
printf("-------------------\n");
printf("\tpush REGEX='%s'\n", s);
@ -279,7 +279,7 @@ internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
#endif
return ep;
}
char * exe_regex_pop(internal_entry_t * ep) {
static char * exe_regex_pop(internal_entry_t * ep) {
char * s;
POP( ep, regex, s);
#ifdef EXE_DEBUG
@ -291,7 +291,7 @@ char * exe_regex_pop(internal_entry_t * ep) {
return s;
}
char * __ch_malloc(char * msg) {
static char * __ch_malloc(char * msg) {
assert( msg == NULL);
msg = calloc(VALUESTRLEN, sizeof(char));
if (NULL == msg) {
@ -301,7 +301,7 @@ char * __ch_malloc(char * msg) {
}
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep) {
static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep) {
ret_t ret = *retp;
internal_entry_t exe = *exep;
char * expected_value=NULL;
@ -410,7 +410,7 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
}
/* ececute fc directly */
ret_t execute_function_and_set_results_for_next_call (ctiff_t * ctif, internal_entry_t * exep, ret_t * retp, int * precondition_result_p, function_t * precondition_function_p ) {
static ret_t execute_function_and_set_results_for_next_call (ctiff_t * ctif, internal_entry_t * exep, ret_t * retp, int * precondition_result_p, function_t * precondition_function_p ) {
assert(NULL != ctif);
assert(NULL != exep);
assert(NULL != retp);
@ -485,7 +485,7 @@ ret_t execute_function_and_set_results_for_next_call (ctiff_t * ctif, internal_e
return ret;
}
ret_t clean_logical_or_if_precondition_failed (internal_entry_t * exep, ret_t * retp) {
static ret_t clean_logical_or_if_precondition_failed (internal_entry_t * exep, ret_t * retp) {
assert(NULL != exep);
assert(NULL != retp);
internal_entry_t exe = *exep;
@ -622,11 +622,11 @@ void clean_plan () {
/* helper function for parser */
tag_t settag( tag_t tag) { parser_state.tag=tag; return tag; }
tag_t settagref( tag_t tag) { parser_state.tagref=tag; return tag; }
static tag_t settag( tag_t tag) { parser_state.tag=tag; return tag; }
static tag_t settagref( tag_t tag) { parser_state.tagref=tag; return tag; }
/* helper function for parser */
tag_t gettag( ) { return parser_state.tag;}
int incrlineno() {
static tag_t gettag( ) { return parser_state.tag;}
static int incrlineno() {
parser_state.lineno++;
#ifdef DEBUG
printf("##lineno=%i\n", parser_state.lineno);
@ -634,7 +634,7 @@ int incrlineno() {
return parser_state.lineno;
}
/* helper function for parser */
int getlineno() { return parser_state.lineno;}
static int getlineno() { return parser_state.lineno;}
/*
@ -651,7 +651,7 @@ int rule_tagorder_in_dsl( int tag ) {
*/
/* helper function for parser */
void commentline() {
static void commentline() {
#ifdef DEBUG
printf("commentline, %i\n", parser_state.lineno);
#endif
@ -666,7 +666,7 @@ void rule_should_not_occure(char* s) {
*/
/* helper function for parser */
void set_mandatory() {
static void set_mandatory() {
#ifdef DEBUG
printf("tag '%u' is mandatory\n", gettag());
#endif
@ -674,7 +674,7 @@ void set_mandatory() {
}
/* helper function for parser */
void set_optional() {
static void set_optional() {
#ifdef DEBUG
printf("tag '%u' is optional\n", gettag());
#endif
@ -684,7 +684,7 @@ void set_optional() {
}
/* helper function for parser */
void set_ifdepends() {
static void set_ifdepends() {
#ifdef DEBUG
printf("tag '%u' is set if depends\n", gettag());
#endif
@ -692,7 +692,7 @@ void set_ifdepends() {
}
/* helper function for parser */
void set_optdepends() {
static void set_optdepends() {
#ifdef DEBUG
printf("tag '%u' is set optional depends\n", gettag());
#endif
@ -701,7 +701,7 @@ void set_optdepends() {
/* helper function for parser */
void regex_push( char * regex_string) {
static void regex_push( char * regex_string) {
pcre *re;
int erroffset;
const char * errorcode;
@ -724,17 +724,17 @@ void regex_push( char * regex_string) {
}
/* helper function for parser */
void reset_valuelist() {
static void reset_valuelist() {
parser_state.valuelist = 0;
}
/* helper function for parser */
void incr_values () {
static void incr_values () {
parser_state.valuelist++;
}
/* prepare functions for preconditions */
internal_entry_t prepare_internal_entry() {
static internal_entry_t prepare_internal_entry() {
internal_entry_t p;
p.i_stackp=0;
p.regex_stackp=0;
@ -777,7 +777,7 @@ internal_entry_t prepare_internal_entry() {
void build_functional_structure__range(internal_entry_t * e_p) {
static void build_functional_structure__range(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("range found\n");
#endif
@ -786,7 +786,7 @@ void build_functional_structure__range(internal_entry_t * e_p) {
e_p->function=fc_tag_has_value_in_range;
}
void build_functional_structure__ntupel(internal_entry_t * e_p) {
static void build_functional_structure__ntupel(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("ntupel found\n");
#endif
@ -797,7 +797,7 @@ void build_functional_structure__ntupel(internal_entry_t * e_p) {
exe_i_push(e_p, c);
e_p->function=fc_tag_has_valuelist;
}
void build_functional_structure__only(internal_entry_t * e_p) {
static void build_functional_structure__only(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("only found\n");
#endif
@ -805,14 +805,14 @@ void build_functional_structure__only(internal_entry_t * e_p) {
e_p->function=fc_tag_has_value;
}
void build_functional_structure__any(internal_entry_t * e_p) {
static void build_functional_structure__any(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("any found\n");
#endif
e_p->function=fc_tag;
}
void build_functional_structure__regex(internal_entry_t * e_p) {
static void build_functional_structure__regex(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("regex found\n");
#endif
@ -820,21 +820,21 @@ void build_functional_structure__regex(internal_entry_t * e_p) {
e_p->function=fc_tag_has_value_matching_regex;
}
void build_functional_structure__iccprofile(internal_entry_t * e_p) {
static void build_functional_structure__iccprofile(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("iccprofile found\n");
#endif
e_p->function=fc_icc;
}
void build_functional_structure__datetime(internal_entry_t * e_p) {
static void build_functional_structure__datetime(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("datetime found\n");
#endif
e_p->function=fc_datetime;
}
void build_functional_structure__printable_ascii(internal_entry_t * e_p) {
static void build_functional_structure__printable_ascii(internal_entry_t * e_p) {
#ifdef RULE_DEBUG
printf("printable_ascii found\n");
#endif
@ -842,7 +842,7 @@ void build_functional_structure__printable_ascii(internal_entry_t * e_p) {
e_p->function=fc_tag_has_value_matching_regex;
}
/* builds an entry structure holding function and their values */
void build_functional_structure(internal_entry_t * e_p, values_t val) {
static void build_functional_structure(internal_entry_t * e_p, values_t val) {
switch (val) {
case range:
build_functional_structure__range(e_p);
@ -886,7 +886,7 @@ void build_functional_structure(internal_entry_t * e_p, values_t val) {
}
/* adds preconditions to stack, first comes the real function, than the preconditions! */
void evaluate_req_and_push_exe(requirements_t req, internal_entry_t e) {
static void evaluate_req_and_push_exe(requirements_t req, internal_entry_t e) {
assert( e.function != fc_dummy);
#ifdef RULE_DEBUG
printf("eval e=%s\n", get_parser_function_description(e.function));
@ -969,7 +969,7 @@ void evaluate_req_and_push_exe(requirements_t req, internal_entry_t e) {
}
}
void set_rule_logical_open() {
static void set_rule_logical_open() {
#ifdef RULE_DEBUG
printf("rule_add_logical_config\n");
#endif
@ -989,7 +989,7 @@ void set_rule_logical_open() {
}
void incr_logical_elements() {
static void incr_logical_elements() {
#ifdef RULE_DEBUG
printf("incr logical elements to %i\n", parser_state.logical_elements+1);
#endif
@ -998,7 +998,7 @@ void incr_logical_elements() {
}
/* helper function for parser */
void set_rule_logical_close() {
static void set_rule_logical_close() {
#ifdef RULE_DEBUG
printf("reset_logical_list\n");
#endif
@ -1018,7 +1018,7 @@ void set_rule_logical_close() {
/* this adds the config of a tagline to execution plan
* HINT: order of calling arguments from stacks is IMPORTANT! */
void rule_addtag_config() {
static void rule_addtag_config() {
if( parser_state.val_stackp > 0) {
#ifdef RULE_DEBUG
printf("rule_addtag_config\n");
@ -1087,7 +1087,7 @@ void rule_addtag_config() {
}
/* set_mode */
void set_mode(modes_t mode) {
static void set_mode(modes_t mode) {
#ifdef RULE_DEBUG
printf("Mode=%i at line=%i (needs to be implemented)\n", mode, parser_state.lineno );
#endif
@ -1161,7 +1161,7 @@ void reset_parser_state() {
#include "config_dsl.grammar.c" /* yyparse() */
/* set_include */
void set_include( const char * include_file ) {
static void set_include( const char * include_file ) {
if (parser_state.includedepth >= 1) {
fprintf( stderr, "only include depth of %i is supported\n", MAXINCLUDEDEPTH);
exit (EXIT_FAILURE);
@ -1244,7 +1244,7 @@ void parse_plan_via_file( const char * cfg_file ) {
* @param msg describes the details about what was going wrong
* @param yytext gives context of the error
*/
void set_parse_error(char * msg, char * yytext) {
static void set_parse_error(char * msg, char * yytext) {
fprintf(stderr, "%s at line %i (error at '%s')\n", msg, parser_state.lineno, yytext);
exit(EXIT_FAILURE);
}

Loading…
Cancel
Save