From patchwork Mon Jan 28 00:41:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 424 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EC67560DB9 for ; Mon, 28 Jan 2019 01:41:32 +0100 (CET) X-Halon-ID: 67a9eeb8-2295-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 67a9eeb8-2295-11e9-911a-0050569116f7; Mon, 28 Jan 2019 01:41:09 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Jan 2019 01:41:06 +0100 Message-Id: <20190128004109.25860-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128004109.25860-1-niklas.soderlund@ragnatech.se> References: <20190128004109.25860-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/6] cam: options: return if addOption() succeeds or not X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2019 00:41:33 -0000 To later extend the options handling to cover subparsing of arguments it will be needed to know if the addition of the option itself was successful or not. The information is already present in addOption() this change just makes it available. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 11 ++++++----- src/cam/options.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index b24964a8ce413a85..c9ca017b4cf3fa3d 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -12,7 +12,7 @@ #include "options.h" -void OptionsParser::addOption(int opt, const char *help, const char *name, +bool OptionsParser::addOption(int opt, const char *help, const char *name, OptionArgument argument, const char *argumentName) { /* @@ -20,18 +20,19 @@ void OptionsParser::addOption(int opt, const char *help, const char *name, * If an argument is accepted, it must be described by argumentName. */ if (!isalnum(opt) && !name) - return; + return false; if (!help || help[0] == '\0') - return; + return false; if (argument != ArgumentNone && !argumentName) - return; + return false; /* Reject duplicate options. */ if (optionsMap_.find(opt) != optionsMap_.end()) - return; + return false; options_.push_back(Option({ opt, name, argument, argumentName, help })); optionsMap_[opt] = &options_.back(); + return true; } OptionsParser::Options OptionsParser::parse(int argc, char **argv) diff --git a/src/cam/options.h b/src/cam/options.h index a08bfea1ba74c96b..dfb7fcc9f6fa3324 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -38,7 +38,7 @@ public: { }; - void addOption(int opt, const char *help, const char *name = nullptr, + bool addOption(int opt, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, const char *argumentName = nullptr);