diff options
Diffstat (limited to 'tools/console.c')
-rw-r--r-- | tools/console.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/console.c b/tools/console.c index 0f66a2f1..0aef9c01 100644 --- a/tools/console.c +++ b/tools/console.c @@ -31,6 +31,23 @@ #define MAX_DEPTH 128U +typedef struct LogLevelLabels { + const char* number; + const char* symbol; + const char* name; +} LogLevelLabels; + +static const LogLevelLabels log_level_strings[] = { + {"0", "emerg", "emergency"}, + {"1", "alert", NULL}, + {"2", "crit", "critical"}, + {"3", "err", "error"}, + {"4", "warn", "warning"}, + {"5", "note", "notice"}, + {"6", "info", NULL}, + {"7", "debug", NULL}, +}; + ZIX_PURE_FUNC bool serd_option_iter_is_end(const OptionIter iter) { @@ -49,6 +66,21 @@ serd_option_iter_advance(OptionIter* const iter) return SERD_SUCCESS; } +SerdCommonOptions +serd_default_options(void) +{ + const SerdCommonOptions opts = { + "", + NULL, + 4096U, + 1048576U, + {SERD_SYNTAX_EMPTY, 0U, false}, + {SERD_SYNTAX_EMPTY, 0U, false}, + SERD_LOG_LEVEL_NOTICE, + }; + return opts; +} + SerdStatus serd_tool_setup(SerdTool* const tool, const char* const program, @@ -336,6 +368,28 @@ serd_parse_output_argument(OptionIter* const iter, return st; } +static SerdStatus +serd_parse_log_level_argument(OptionIter* const iter, + SerdLogLevel* const log_level) +{ + SerdStatus st = SERD_SUCCESS; + const char* argument = NULL; + + if (!(st = serd_get_argument(iter, &argument))) { + fprintf(stderr, "LOG LEVEL: %s\n", argument); + for (unsigned i = 0U; i < (unsigned)SERD_LOG_LEVEL_DEBUG; ++i) { + const LogLevelLabels* const labels = &log_level_strings[i]; + if (!strcmp(argument, labels->number) || + !strcmp(argument, labels->symbol) || + (labels->name && !strcmp(argument, labels->name))) { + *log_level = (SerdLogLevel)i; + } + } + } + + return st; +} + SerdStatus serd_parse_common_option(OptionIter* const iter, SerdCommonOptions* const opts) { @@ -359,6 +413,9 @@ serd_parse_common_option(OptionIter* const iter, SerdCommonOptions* const opts) case 'o': return serd_get_argument(iter, &opts->out_filename); + case 'l': + return serd_parse_log_level_argument(iter, &opts->log_level); + default: break; } |