From a8113fb3a89984cc65d51436480cee45b60543e8 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 20 Oct 2022 01:25:45 +0300 Subject: apps: Share common source between applications Multiple source files in the src/apps/cam/ directory are used by cam, qcam and lc-compliance. They are compiled separately for each application. Move them to a new src/apps/common/ directory and compile them in a static library to decrease the number of compilation operations. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham --- src/apps/common/options.cpp | 1141 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1141 insertions(+) create mode 100644 src/apps/common/options.cpp (limited to 'src/apps/common/options.cpp') diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp new file mode 100644 index 00000000..4f7e8691 --- /dev/null +++ b/src/apps/common/options.cpp @@ -0,0 +1,1141 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * options.cpp - cam - Options parsing + */ + +#include +#include +#include +#include +#include + +#include "options.h" + +/** + * \enum OptionArgument + * \brief Indicate if an option takes an argument + * + * \var OptionArgument::ArgumentNone + * \brief The option doesn't accept any argument + * + * \var OptionArgument::ArgumentRequired + * \brief The option requires an argument + * + * \var OptionArgument::ArgumentOptional + * \brief The option accepts an optional argument + */ + +/** + * \enum OptionType + * \brief The type of argument for an option + * + * \var OptionType::OptionNone + * \brief No argument type, used for options that take no argument + * + * \var OptionType::OptionInteger + * \brief Integer argument type, with an optional base prefix (`0` for base 8, + * `0x` for base 16, none for base 10) + * + * \var OptionType::OptionString + * \brief String argument + * + * \var OptionType::OptionKeyValue + * \brief key=value list argument + */ + +/* ----------------------------------------------------------------------------- + * Option + */ + +/** + * \struct Option + * \brief Store metadata about an option + * + * \var Option::opt + * \brief The option identifier + * + * \var Option::type + * \brief The type of the option argument + * + * \var Option::name + * \brief The option name + * + * \var Option::argument + * \brief Whether the option accepts an optional argument, a mandatory + * argument, or no argument at all + * + * \var Option::argumentName + * \brief The argument name used in the help text + * + * \var Option::help + * \brief The help text (may be a multi-line string) + * + * \var Option::keyValueParser + * \brief For options of type OptionType::OptionKeyValue, the key-value parser + * to parse the argument + * + * \var Option::isArray + * \brief Whether the option can appear once or multiple times + * + * \var Option::parent + * \brief The parent option + * + * \var Option::children + * \brief List of child options, storing all options whose parent is this option + * + * \fn Option::hasShortOption() + * \brief Tell if the option has a short option specifier (e.g. `-f`) + * \return True if the option has a short option specifier, false otherwise + * + * \fn Option::hasLongOption() + * \brief Tell if the option has a long option specifier (e.g. `--foo`) + * \return True if the option has a long option specifier, false otherwise + */ +struct Option { + int opt; + OptionType type; + const char *name; + OptionArgument argument; + const char *argumentName; + const char *help; + KeyValueParser *keyValueParser; + bool isArray; + Option *parent; + std::list