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) enum qse_cli_optflag_t
#define QSE_CLI_OPTVAL (1 << 1) {
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 enum qse_cli_error_code_t
{ {
@ -86,7 +91,7 @@ struct qse_cli_opt_t
{ {
/* input */ /* input */
const qse_char_t* name; 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 */ /* output - you don't have to initialize this field */
qse_char_t* value; qse_char_t* value;

View File

@ -124,7 +124,7 @@ int qse_parsecli (qse_cli_t* cli, qse_mmgr_t* mmgr, int argc, qse_char_t* const
} }
else 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) 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; 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) 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++) 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) 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}; 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); 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)
{ {
if (fd != 0) QSE_DUP2 (fd, 0); if (fd != 0) QSE_DUP2 (fd, 0);