X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fargpar-utils%2Fargpar-utils.cpp;h=7c8934778a5b478ac1252d937a61f44151e577ea;hb=cd9adb8b829564212158943a0d279bb35322ab30;hp=0beff92adfc7598bb02cc2389a406e517a84ae52;hpb=c9e313bc594f40a86eed237dce222c0fc99c957f;p=lttng-tools.git diff --git a/src/common/argpar-utils/argpar-utils.cpp b/src/common/argpar-utils/argpar-utils.cpp index 0beff92ad..7c8934778 100644 --- a/src/common/argpar-utils/argpar-utils.cpp +++ b/src/common/argpar-utils/argpar-utils.cpp @@ -7,11 +7,11 @@ #include "argpar-utils.hpp" -#include - #include #include +#include + /* * Given argpar error status `status` and error `error`, return a formatted * error message describing the error. @@ -25,12 +25,14 @@ * * The returned string must be freed by the caller. */ -static ATTR_FORMAT_PRINTF(4, 0) -char *format_arg_error_v(const struct argpar_error *error, int argc_offset, - const char **argv, const char *context_fmt, va_list args) +static ATTR_FORMAT_PRINTF(4, 0) char *format_arg_error_v(const struct argpar_error *error, + int argc_offset, + const char **argv, + const char *context_fmt, + va_list args) { - char *str = NULL; - char *str_ret = NULL; + char *str = nullptr; + char *str_ret = nullptr; int ret; if (context_fmt) { @@ -40,7 +42,7 @@ char *format_arg_error_v(const struct argpar_error *error, int argc_offset, * If vasprintf fails, the content of str is undefined, * and we shouldn't try to free it. */ - str = NULL; + str = nullptr; goto end; } @@ -50,16 +52,18 @@ char *format_arg_error_v(const struct argpar_error *error, int argc_offset, } } - switch (argpar_error_type(error)) - { + switch (argpar_error_type(error)) { case ARGPAR_ERROR_TYPE_MISSING_OPT_ARG: { const int orig_index = argpar_error_orig_index(error); const char *arg = argv[orig_index]; ret = strutils_appendf(&str, - WHILE_PARSING_ARG_N_ARG_FMT "Missing required argument for option `%s`", - orig_index + 1 + argc_offset, argv[orig_index], arg); + WHILE_PARSING_ARG_N_ARG_FMT + "Missing required argument for option `%s`", + orig_index + 1 + argc_offset, + argv[orig_index], + arg); if (ret < 0) { goto end; } @@ -69,19 +73,24 @@ char *format_arg_error_v(const struct argpar_error *error, int argc_offset, case ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG: { bool is_short; - const struct argpar_opt_descr *descr = - argpar_error_opt_descr(error, &is_short); + const struct argpar_opt_descr *descr = argpar_error_opt_descr(error, &is_short); int orig_index = argpar_error_orig_index(error); const char *arg = argv[orig_index]; if (is_short) { ret = strutils_appendf(&str, - WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `-%c`", - orig_index + 1 + argc_offset, arg, descr->short_name); + WHILE_PARSING_ARG_N_ARG_FMT + "Unexpected argument for option `-%c`", + orig_index + 1 + argc_offset, + arg, + descr->short_name); } else { ret = strutils_appendf(&str, - WHILE_PARSING_ARG_N_ARG_FMT "Unexpected argument for option `--%s`", - orig_index + 1 + argc_offset, arg, descr->long_name); + WHILE_PARSING_ARG_N_ARG_FMT + "Unexpected argument for option `--%s`", + orig_index + 1 + argc_offset, + arg, + descr->long_name); } if (ret < 0) { @@ -96,8 +105,10 @@ char *format_arg_error_v(const struct argpar_error *error, int argc_offset, const char *unknown_opt = argpar_error_unknown_opt_name(error); ret = strutils_appendf(&str, - WHILE_PARSING_ARG_N_ARG_FMT "Unknown option `%s`", - orig_index + 1 + argc_offset, argv[orig_index], unknown_opt); + WHILE_PARSING_ARG_N_ARG_FMT "Unknown option `%s`", + orig_index + 1 + argc_offset, + argv[orig_index], + unknown_opt); if (ret < 0) { goto end; @@ -106,11 +117,11 @@ char *format_arg_error_v(const struct argpar_error *error, int argc_offset, break; } default: - abort (); + abort(); } str_ret = str; - str = NULL; + str = nullptr; end: free(str); @@ -118,13 +129,16 @@ end: } enum parse_next_item_status parse_next_item(struct argpar_iter *iter, - const struct argpar_item **item, int argc_offset, - const char **argv, bool unknown_opt_is_error, - const struct argpar_error **error_out, - const char *context_fmt, ...) + const struct argpar_item **item, + int argc_offset, + const char **argv, + bool unknown_opt_is_error, + const struct argpar_error **error_out, + const char *context_fmt, + ...) { enum argpar_iter_next_status status; - const struct argpar_error *error = NULL; + const struct argpar_error *error = nullptr; enum parse_next_item_status ret; ARGPAR_ITEM_DESTROY_AND_RESET(*item); @@ -141,14 +155,13 @@ enum parse_next_item_status parse_next_item(struct argpar_iter *iter, char *err_str; if (argpar_error_type(error) == ARGPAR_ERROR_TYPE_UNKNOWN_OPT && - !unknown_opt_is_error) { + !unknown_opt_is_error) { ret = PARSE_NEXT_ITEM_STATUS_END; break; } va_start(args, context_fmt); - err_str = format_arg_error_v(error, argc_offset, argv, - context_fmt, args); + err_str = format_arg_error_v(error, argc_offset, argv, context_fmt, args); va_end(args); if (err_str) { @@ -174,7 +187,7 @@ enum parse_next_item_status parse_next_item(struct argpar_iter *iter, if (error_out) { argpar_error_destroy(*error_out); *error_out = error; - error = NULL; + error = nullptr; } argpar_error_destroy(error);