Skip to content

Commit

Permalink
yaml/v2: wrap state_names behind state_str function.
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan committed Jul 6, 2023
1 parent 8e2ded6 commit d37fa58
Showing 1 changed file with 13 additions and 79 deletions.
92 changes: 13 additions & 79 deletions src/config_format/flb_cf_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ static char *state_names[] = {
"stop" /* end state */
};

static char *state_str(enum state val)
{
char* ret;

if (val < 0 || val > STATE_STOP) {
return "unknown";
}

return state_names[val];
}

struct file_state {
/* file */
flb_sds_t name; /* file name */
Expand Down Expand Up @@ -281,83 +292,6 @@ static char *event_type_str(yaml_event_t *event)
}
}

static char *state_str(enum state val)
{
char* ret;
switch(val) {
case STATE_START:
ret = "start";
break;
case STATE_STREAM:
ret = "stream";
break;
case STATE_DOCUMENT:
ret = "document";
break;
case STATE_SECTION:
ret = "section";
break;
case STATE_SECTION_KEY:
ret = "section-key";
break;
case STATE_SECTION_VAL:
ret = "section-val";
break;
case STATE_SERVICE:
ret = "service";
break;
case STATE_INCLUDE:
ret = "include";
break;
case STATE_OTHER:
ret = "other";
break;
case STATE_PIPELINE:
ret = "pipeline";
break;
case STATE_PLUGIN_INPUT:
ret = "plugin-input";
break;
case STATE_PLUGIN_FILTER:
ret = "plugin-filter";
break;
case STATE_PLUGIN_OUTPUT:
ret = "plugin-output";
break;
case STATE_CUSTOM:
ret = "custom";
break;
case STATE_PLUGIN_KEY:
ret = "plugin-key";
break;
case STATE_PLUGIN_VAL:
ret = "plugin-val";
break;
case STATE_PLUGIN_VAL_LIST:
ret = "plugin-val-list";
break;
case STATE_GROUP_KEY:
ret = "group-key";
break;
case STATE_GROUP_VAL:
ret = "group-val";
break;
case STATE_INPUT_PROCESSOR:
ret = "input-processor";
break;
case STATE_ENV:
ret = "env";
break;
case STATE_STOP:
ret = "stop";
break;

default:
ret = "UNKNOWN";
}
return ret;
}

static char *get_last_included_file(struct local_ctx *ctx)
{
struct flb_slist_entry *e;
Expand Down Expand Up @@ -552,7 +486,7 @@ static void print_current_state(struct local_ctx *ctx, struct parser_state *s,
{
int i;

flb_debug("%*s%s->%s", s->level*2, "", state_names[s->state],
flb_debug("%*s%s->%s", s->level*2, "", state_str(s->state),
event_type_str(event));
}

Expand Down Expand Up @@ -831,7 +765,7 @@ static int consume_event(struct flb_cf *cf, struct local_ctx *ctx,
case STATE_OTHER:
break;
default:
printf("BAD STATE FOR SECTION KEY POP=%s\n", state_names[s->state]);
printf("BAD STATE FOR SECTION KEY POP=%s\n", state_str(s->state));
yaml_error_event(ctx, s, event);
return YAML_FAILURE;
}
Expand Down

0 comments on commit d37fa58

Please sign in to comment.