diff --git a/parser/parser.h b/parser/parser.h index ebe0e2982..6c1cc4fd5 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -49,6 +49,12 @@ struct cod_pattern { char *regex; // posix regex }; +struct value_list { + char *value; + + struct value_list *next; +}; + struct cod_entry { char *namespace; char *name; @@ -275,6 +281,9 @@ extern struct var_string *split_out_var(char *string); extern void free_var_string(struct var_string *var); /* parser_misc.c */ +extern struct value_list *new_value_list(char *value); +extern void free_value_list(struct value_list *list); +extern void print_value_list(struct value_list *list); extern char *processid(char *string, int len); extern char *processquoted(char *string, int len); extern char *processunquoted(char *string, int len); diff --git a/parser/parser_misc.c b/parser/parser_misc.c index 8aca06101..f1779c785 100644 --- a/parser/parser_misc.c +++ b/parser/parser_misc.c @@ -939,6 +939,41 @@ void debug_cod_list(struct codomain *cod) dump_policy_hats(cod); } +struct value_list *new_value_list(char *value) +{ + struct value_list *val = calloc(1, sizeof(struct value_list)); + if (val) + val->value = value; + return val; +} + +void free_value_list(struct value_list *list) +{ + struct value_list *next; + + while (list) { + next = list->next; + if (list->value) + free(list->value); + free(list); + list = next; + } +} + +void print_value_list(struct value_list *list) +{ + struct value_list *entry; + + if (!list) + return; + + fprintf(stderr, "%s", list->value); + list = list->next; + list_for_each(list, entry) { + fprintf(stderr, ", %s", entry->value); + } +} + #ifdef UNIT_TEST int test_str_to_boolean(void) { diff --git a/parser/parser_yacc.y b/parser/parser_yacc.y index 45083d922..8043d3005 100644 --- a/parser/parser_yacc.y +++ b/parser/parser_yacc.y @@ -64,14 +64,8 @@ #define CAP_TO_MASK(x) (1ull << (x)) -struct value_list { - char *value; - struct value_list *next; -}; - int parser_token = 0; -void free_value_list(struct value_list *list); struct cod_entry *do_file_rule(char *namespace, char *id, int mode, char *link_id, char *nt); @@ -377,26 +371,23 @@ varassign: TOK_BOOL_VAR TOK_EQUALS TOK_VALUE valuelist: TOK_VALUE { - struct value_list *new = calloc(1, sizeof(struct value_list)); - if (!new) + struct value_list *val = new_value_list($1); + if (!val) yyerror(_("Memory allocation error.")); PDEBUG("Matched: value (%s)\n", $1); - new->value = $1; - new->next = NULL; - $$ = new; + $$ = val; } valuelist: valuelist TOK_VALUE { - struct value_list *new = calloc(1, sizeof(struct value_list)); - if (!new) + struct value_list *val = new_value_list($2); + if (!val) yyerror(_("Memory allocation error.")); PDEBUG("Matched: value list\n"); - new->value = $2; - new->next = $1; - $$ = new; + val->next = $1; + $$ = val; } flags: { /* nothing */ @@ -1114,19 +1105,6 @@ void yyerror(char *msg, ...) exit(1); } -void free_value_list(struct value_list *list) -{ - struct value_list *next; - - while (list) { - next = list->next; - if (list->value) - free(list->value); - free(list); - list = next; - } -} - struct cod_entry *do_file_rule(char *namespace, char *id, int mode, char *link_id, char *nt) {