From b07ce59da7d3c0391dd389a68420bf2c53ef09cf Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 17 Oct 2022 10:00:50 +0200 Subject: [PATCH] don't return failure on '--audio-capture-format help' --- src/host.cpp | 19 ++++++++++++------- src/host.h | 2 +- src/main.cpp | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/host.cpp b/src/host.cpp index 6a8fb4e13..110563a75 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -227,13 +227,18 @@ static void load_libgcc() #endif } -bool parse_audio_capture_format(const char *optarg) +/** + * @retval -1 invalid usage + * @retval 0 success + * @retval 1 help was printed + */ +int parse_audio_capture_format(const char *optarg) { if (strcmp(optarg, "help") == 0) { printf("Usage:\n"); printf("\t--audio-capture-format {channels=|bps=|sample_rate=}*\n"); printf("\t\tmultiple options can be separated by a colon\n"); - return false; + return 1; } unique_ptr arg_copy(new char[strlen(optarg) + 1]); @@ -251,7 +256,7 @@ bool parse_audio_capture_format(const char *optarg) audio_capture_channels = strtol(item, &endptr, 10); if (audio_capture_channels < 1 || endptr != item + strlen(item)) { log_msg(LOG_LEVEL_ERROR, "Invalid number of channels %s!\n", item); - return false; + return -1; } } else if (strncmp(item, "bps=", strlen("bps=")) == 0) { item += strlen("bps="); @@ -262,7 +267,7 @@ bool parse_audio_capture_format(const char *optarg) LOG(LOG_LEVEL_WARNING) << "bps is in bits per sample but a value not divisible by 8 was given.\n"; } log_msg(LOG_LEVEL_ERROR, "Supported values are 8, 16, 24, or 32 bits.\n"); - return false; + return -1; } audio_capture_bps = bps / 8; @@ -271,18 +276,18 @@ bool parse_audio_capture_format(const char *optarg) long long val = unit_evaluate(sample_rate_str); if (val <= 0 || val > numeric_limits::max()) { LOG(LOG_LEVEL_ERROR) << "Invalid sample_rate " << sample_rate_str << "!\n"; - return false; + return -1; } audio_capture_sample_rate = val; } else { LOG(LOG_LEVEL_ERROR) << "Unkonwn option \"" << item << "\" for --audio-capture-format!\n"; - return false; + return -1; } tmp = nullptr; } - return true; + return 0; } /** diff --git a/src/host.h b/src/host.h index 1c07ccaf1..d80e7b4ee 100644 --- a/src/host.h +++ b/src/host.h @@ -143,7 +143,7 @@ void print_configuration(void); const char *get_commandline_param(const char *key); -bool parse_audio_capture_format(const char *optarg); +int parse_audio_capture_format(const char *optarg); bool parse_params(const char *optarg, bool preinit); void print_pixel_formats(void); void print_video_codecs(void); diff --git a/src/main.cpp b/src/main.cpp index fea3cce27..31f018d2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1009,8 +1009,8 @@ static int parse_options(int argc, char *argv[], struct ug_options *opt) { } break; case OPT_AUDIO_CAPTURE_FORMAT: - if (!parse_audio_capture_format(optarg)) { - return -EXIT_FAIL_USAGE; + if (int ret = parse_audio_capture_format(optarg)) { + return ret < 0 ? -EXIT_FAIL_USAGE : 1; } break; case OPT_AUDIO_FILTER: