Skip to content

Commit

Permalink
yanglint REFACTOR reduce NDEBUG macro usage
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Jan 16, 2024
1 parent ea4943c commit 34e2a55
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
6 changes: 4 additions & 2 deletions tools/lint/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 0 additions & 2 deletions tools/lint/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ enum COMMAND_INDEX {
CMD_EXTDATA,
CMD_CLEAR,
CMD_VERB,
#ifndef NDEBUG
CMD_DEBUG,
#endif
};

/**
Expand Down
4 changes: 0 additions & 4 deletions tools/lint/cmd_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/

#ifndef NDEBUG

#include "cmd.h"

#include <assert.h>
Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions tools/lint/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 8 additions & 17 deletions tools/lint/main_ni.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
" <group>[,<group>]* (dict, xpath, dep-sets)\n\n");
" <group>[,<group>]* (dict, xpath, dep-sets)\n\n"
#else
" Unsupported for the Release build\n\n"
#endif
);
}

static void
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 34e2a55

Please sign in to comment.