From 34e2a55f695edfd0cdf15a399a2c47372a6e0ead Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Tue, 16 Jan 2024 15:27:52 +0100 Subject: [PATCH] yanglint REFACTOR reduce NDEBUG macro usage --- tools/lint/cmd.c | 6 ++++-- tools/lint/cmd.h | 2 -- tools/lint/cmd_debug.c | 4 ---- tools/lint/completion.c | 5 ----- tools/lint/main_ni.c | 25 ++++++++----------------- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/tools/lint/cmd.c b/tools/lint/cmd.c index 344900d41..8b2ec5d8f 100644 --- a/tools/lint/cmd.c +++ b/tools/lint/cmd.c @@ -96,12 +96,14 @@ COMMAND commands[] = { "verb", cmd_verb_opt, cmd_verb_dep, cmd_verb_exec, NULL, cmd_verb_help, NULL, "Change verbosity", "h" }, -#ifndef NDEBUG { "debug", cmd_debug_opt, cmd_debug_dep, cmd_debug_store, cmd_debug_setlog, cmd_debug_help, NULL, +#ifndef NDEBUG "Display specific debug message groups", "h" - }, +#else + "Unsupported for the Release build", "h" #endif + }, {"quit", NULL, NULL, cmd_quit_exec, NULL, NULL, NULL, "Quit the program", "h"}, /* synonyms for previous commands */ {"?", NULL, NULL, cmd_help_exec, NULL, NULL, NULL, "Display commands description", "h"}, diff --git a/tools/lint/cmd.h b/tools/lint/cmd.h index bd2f2f23a..37894cbd0 100644 --- a/tools/lint/cmd.h +++ b/tools/lint/cmd.h @@ -79,9 +79,7 @@ enum COMMAND_INDEX { CMD_EXTDATA, CMD_CLEAR, CMD_VERB, -#ifndef NDEBUG CMD_DEBUG, -#endif }; /** diff --git a/tools/lint/cmd_debug.c b/tools/lint/cmd_debug.c index 3661bfae6..a1a89897e 100644 --- a/tools/lint/cmd_debug.c +++ b/tools/lint/cmd_debug.c @@ -12,8 +12,6 @@ * https://opensource.org/licenses/BSD-3-Clause */ -#ifndef NDEBUG - #include "cmd.h" #include @@ -130,5 +128,3 @@ cmd_debug_setlog(struct ly_ctx *ctx, struct yl_opt *yo) (void) ctx; return ly_log_dbg_groups(yo->dbg_groups); } - -#endif diff --git a/tools/lint/completion.c b/tools/lint/completion.c index 67c6b6876..59207ca0e 100644 --- a/tools/lint/completion.c +++ b/tools/lint/completion.c @@ -378,7 +378,6 @@ get_verb_arg(const char *hint, char ***matches, unsigned int *match_count) get_arg_completion(hint, args, matches, match_count); } -#ifndef NDEBUG /** * @copydoc get_print_format_arg */ @@ -390,8 +389,6 @@ get_debug_arg(const char *hint, char ***matches, unsigned int *match_count) get_arg_completion(hint, args, matches, match_count); } -#endif - /** * @brief Get the string before the hint, which autocompletion is for. * @@ -455,9 +452,7 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc) {CMD_LIST, NULL, NULL, get_list_format_arg}, {CMD_FEATURE, NULL, NULL, get_model_completion}, {CMD_VERB, NULL, NULL, get_verb_arg}, -#ifndef NDEBUG {CMD_DEBUG, NULL, NULL, get_debug_arg}, -#endif }; size_t name_len; const char *last, *name, *getoptstr; diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c index c08acc3d4..df0d6ff47 100644 --- a/tools/lint/main_ni.c +++ b/tools/lint/main_ni.c @@ -211,12 +211,15 @@ help(int shortout) printf(" -X, --extended-leafref\n" " Allow usage of deref() XPath function within leafref\n\n"); -#ifndef NDEBUG printf(" -G GROUPS, --debug=GROUPS\n" +#ifndef NDEBUG " Enable printing of specific debugging message group\n" " (nothing will be printed unless verbosity is set to debug):\n" - " [,]* (dict, xpath, dep-sets)\n\n"); + " [,]* (dict, xpath, dep-sets)\n\n" +#else + " Unsupported for the Release build\n\n" #endif + ); } static void @@ -381,7 +384,6 @@ fill_context_inputs(int argc, char *argv[], int optind, LYD_FORMAT data_in_forma return 0; } -#ifndef NDEBUG /** * @brief Enable specific debugging messages. * @@ -417,8 +419,6 @@ set_debug_groups(char *groups, struct yl_opt *yo) return 0; } -#endif - /** * @brief Process command line options and store the settings into the context. * @@ -459,9 +459,7 @@ fill_context(int argc, char *argv[], struct yl_opt *yo, struct ly_ctx **ctx) {"yang-library", no_argument, NULL, 'y'}, {"yang-library-file", required_argument, NULL, 'Y'}, {"extended-leafref", no_argument, NULL, 'X'}, -#ifndef NDEBUG - {"debug", required_argument, NULL, 'G'}, -#endif + {"debug", required_argument, NULL, 'G'}, {NULL, 0, NULL, 0} }; uint8_t data_type_set = 0; @@ -472,12 +470,7 @@ fill_context(int argc, char *argv[], struct yl_opt *yo, struct ly_ctx **ctx) yo->line_length = 0; opterr = 0; -#ifndef NDEBUG - while ((opt = getopt_long(argc, argv, "hvVQf:I:p:DF:iP:qs:neE:t:d:lL:o:O:R:myY:Xx:G:", options, &opt_index)) != -1) -#else - while ((opt = getopt_long(argc, argv, "hvVQf:I:p:DF:iP:qs:neE:t:d:lL:o:O:R:myY:Xx:", options, &opt_index)) != -1) -#endif - { + while ((opt = getopt_long(argc, argv, "hvVQf:I:p:DF:iP:qs:neE:t:d:lL:o:O:R:myY:Xx:G:", options, &opt_index)) != -1) { switch (opt) { case 'h': /* --help */ help(0); @@ -657,14 +650,12 @@ fill_context(int argc, char *argv[], struct yl_opt *yo, struct ly_ctx **ctx) yo->ctx_options |= LY_CTX_LEAFREF_EXTENDED; break; -#ifndef NDEBUG case 'G': /* --debug */ if (set_debug_groups(optarg, yo)) { return -1; } break; - /* case 'G' */ -#endif + default: YLMSG_E("Invalid option or missing argument: -%c.", optopt); return -1;