added QSE_CLI_DISCRETIONARY_OPTVAL.
renamed QSE_CLI_OPTVAL to QSE_CLI_REQUIRE_OPTVAL renamed QSE_CLI_OPTNAME to QSE_CLI_REQUIRE_OPTNAME
This commit is contained in:
parent
e936bf3502
commit
4a10c5d7cd
@ -66,8 +66,13 @@ struct qse_opt_t
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
#define QSE_CLI_OPTNAME (1 << 0)
|
||||
#define QSE_CLI_OPTVAL (1 << 1)
|
||||
enum qse_cli_optflag_t
|
||||
{
|
||||
QSE_CLI_REQUIRE_OPTNAME = (1 << 0), /* if set, the option itself is require */
|
||||
QSE_CLI_REQUIRE_OPTVAL = (1 << 1), /* if set, the option's value is mandatory */
|
||||
QSE_CLI_DISCRETIONARY_OPTVAL = (1 << 2) /* if set, the option's value is optional. */
|
||||
};
|
||||
typedef enum qse_cli_optflag_t qse_cli_optflag_t;
|
||||
|
||||
enum qse_cli_error_code_t
|
||||
{
|
||||
@ -86,7 +91,7 @@ struct qse_cli_opt_t
|
||||
{
|
||||
/* input */
|
||||
const qse_char_t* name;
|
||||
int requires;
|
||||
int optflags; /* 0 or bitwise-ORed of qse_cli_optflags_t enumerartors */
|
||||
|
||||
/* output - you don't have to initialize this field */
|
||||
qse_char_t* value;
|
||||
|
@ -124,7 +124,7 @@ int qse_parsecli (qse_cli_t* cli, qse_mmgr_t* mmgr, int argc, qse_char_t* const
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value && !(opt->requires & QSE_CLI_OPTVAL))
|
||||
if (value && !(opt->optflags & (QSE_CLI_REQUIRE_OPTVAL | QSE_CLI_DISCRETIONARY_OPTVAL)))
|
||||
{
|
||||
if (cli->data.errcb(cli, QSE_CLI_ERROR_REDUNDANT_OPTVAL, name.ptr, value) <= -1)
|
||||
{
|
||||
@ -132,7 +132,7 @@ int qse_parsecli (qse_cli_t* cli, qse_mmgr_t* mmgr, int argc, qse_char_t* const
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!value && (opt->requires & QSE_CLI_OPTVAL))
|
||||
else if (!value && (opt->optflags & QSE_CLI_REQUIRE_OPTVAL))
|
||||
{
|
||||
if (cli->data.errcb(cli, QSE_CLI_ERROR_MISSING_OPTVAL, name.ptr, value) <= -1)
|
||||
{
|
||||
@ -175,7 +175,7 @@ int qse_parsecli (qse_cli_t* cli, qse_mmgr_t* mmgr, int argc, qse_char_t* const
|
||||
|
||||
for (opt = cli->data.opts; opt->name != QSE_NULL; opt++)
|
||||
{
|
||||
if ((opt->requires & QSE_CLI_OPTNAME) && opt->value == QSE_NULL)
|
||||
if ((opt->optflags & QSE_CLI_REQUIRE_OPTNAME) && opt->value == QSE_NULL)
|
||||
{
|
||||
if (cli->data.errcb(cli, QSE_CLI_ERROR_MISSING_OPTNAME, opt->name, QSE_NULL) <= -1)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user