From patchwork Mon Jul 12 21:56:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12918 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id F2816C3226 for ; Mon, 12 Jul 2021 21:57:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 100BF68539; Mon, 12 Jul 2021 23:57:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DlIOVnLn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 977AF6852C for ; Mon, 12 Jul 2021 23:57:37 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D6AA3F1 for ; Mon, 12 Jul 2021 23:57:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626127057; bh=MrcoK9ETCZ9MY++9sd/Nevj0m43NJwjorkwqpdEd6b0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DlIOVnLn5WcplnRwwvqoiOWxRNiKjhO3wEviC7C6Bfj5zi9Jf4o7ND1O1YRVX3ZI7 5ZLFsXoAeVtsX+WcAUH6hhz/+w+5c5mD600Rf60w2I7oX4C3z70D1VKELzaMI4+uKC GhzNUFkyFZ9wv7zA2O4SyqK10/xpHxK4SNnGFQD8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Jul 2021 00:56:20 +0300 Message-Id: <20210712215645.30478-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> References: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/30] cam: options: Add optionName() function to Option structure X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an Option::optionName() function that returns a string describing the option name, with leading dashes. As a result, OptionsParser::parseValueError() function becomes a single-line function and can be inlined in its caller. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/options.cpp | 32 ++++++++++++++++++-------------- src/cam/options.h | 2 -- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 135dd7622e48..721a808ac859 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -100,6 +100,7 @@ struct Option { bool hasShortOption() const { return isalnum(opt); } bool hasLongOption() const { return name != nullptr; } const char *typeName() const; + std::string optionName() const; }; /** @@ -125,6 +126,20 @@ const char *Option::typeName() const return "unknown"; } +/** + * \brief Retrieve a string describing the option name, with leading dashes + * \return A string describing the option name, as a long option identifier + * (double dash) if the option has a name, or a short option identifier (single + * dash) otherwise + */ +std::string Option::optionName() const +{ + if (name) + return "--" + std::string(name); + else + return "-" + std::string(1, opt); +} + /* ----------------------------------------------------------------------------- * OptionBase */ @@ -865,7 +880,9 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) const Option &option = *optionsMap_[c]; if (!options.parseValue(c, option, optarg)) { - parseValueError(option); + std::cerr << "Can't parse " << option.typeName() + << " argument for option " << option.optionName() + << std::endl; usage(); return options; } @@ -952,16 +969,3 @@ void OptionsParser::usage() option.keyValueParser->usage(indent); } } - -void OptionsParser::parseValueError(const Option &option) -{ - std::string optionName; - - if (option.name) - optionName = "--" + std::string(option.name); - else - optionName = "-" + std::string(1, option.opt); - - std::cerr << "Can't parse " << option.typeName() - << " argument for option " << optionName << std::endl; -} diff --git a/src/cam/options.h b/src/cam/options.h index a3b18bb6c4ea..0b8bb172d184 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -95,8 +95,6 @@ public: void usage(); private: - void parseValueError(const Option &option); - std::list