diff --git a/include/lib/util_fmt.h b/include/lib/util_fmt.h index 1d3b9af9..ac57cd4f 100644 --- a/include/lib/util_fmt.h +++ b/include/lib/util_fmt.h @@ -157,6 +157,16 @@ void util_fmt_exit(void); */ bool util_fmt_name_to_type(const char *name, enum util_fmt_t *type); +/** + * util_fmt_type_to_name() - Get name of given format type identifier. + * @type: Format type identifier + * + * Get the name corresponding to the given format type identifier. + * + * Return: name of the format type + */ +const char *util_fmt_type_to_name(enum util_fmt_t type); + /** * util_fmt_set_indent() - Set indentation parameters. * @base : Base indentation level to apply to all output lines (default 0) diff --git a/libutil/util_fmt.c b/libutil/util_fmt.c index 31bbe704..f4e05fae 100644 --- a/libutil/util_fmt.c +++ b/libutil/util_fmt.c @@ -89,11 +89,26 @@ static const struct { const char *name; enum util_fmt_t fmt; } formats[] = { - { "json", FMT_JSON }, - { "json-seq", FMT_JSONSEQ }, - { "jsonl", FMT_JSONL }, - { "pairs", FMT_PAIRS }, - { "csv", FMT_CSV }, + [FMT_JSON] = { + .name = "json", + .fmt = FMT_JSON + }, + [FMT_JSONSEQ] = { + .name = "json-seq", + .fmt = FMT_JSONSEQ + }, + [FMT_JSONL] = { + .name = "jsonl", + .fmt = FMT_JSONL + }, + [FMT_PAIRS] = { + .name = "pairs", + .fmt = FMT_PAIRS + }, + [FMT_CSV] = { + .name = "csv", + .fmt = FMT_CSV + }, }; /* Signal mask for blocking INT and TERM signals. */ @@ -112,6 +127,11 @@ bool util_fmt_name_to_type(const char *name, enum util_fmt_t *type) return false; } +const char *util_fmt_type_to_name(enum util_fmt_t type) +{ + return formats[type].name; +} + bool util_fmt_is_json(enum util_fmt_t type) { switch (type) {