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:
hyung-hwan 2018-10-17 08:07:45 +00:00
parent e936bf3502
commit 4a10c5d7cd
4 changed files with 14 additions and 9 deletions

View File

@ -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;

View File

@ -57,7 +57,7 @@
/* options */
#define QSE_LOG_KEEP_FILE_OPEN (1 << 13)
#define QSE_LOG_MASKED_PRIORITY (1 << 14)
#define QSE_LOG_MASKED_PRIORITY (1 << 14)
#define QSE_LOG_INCLUDE_PID (1 << 15)
#define QSE_LOG_HOST_IN_REMOTE_SYSLOG (1 << 16)

View File

@ -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)
{

View File

@ -136,12 +136,12 @@ int App::daemonize (bool chdir_to_root, int fork_count, bool root_only) QSE_CPP_
{
int keep[] = { 0, 1, 2};
if (qse_close_open_fds_using_proc (keep, QSE_COUNTOF(keep)) <= -1)
if (qse_close_open_fds_using_proc(keep, QSE_COUNTOF(keep)) <= -1)
{
for (int i = qse_get_highest_fd(); i >= 3; i--) QSE_CLOSE (i);
}
int fd = QSE_OPEN ("/dev/null", O_RDWR, 0);
int fd = QSE_OPEN("/dev/null", O_RDWR, 0);
if (fd >= 0)
{
if (fd != 0) QSE_DUP2 (fd, 0);