enum parse_orig_arg_opt_ret {
PARSE_ORIG_ARG_OPT_RET_OK,
- PARSE_ORIG_ARG_OPT_RET_ERROR_UNKNOWN_OPT = -2,
- PARSE_ORIG_ARG_OPT_RET_ERROR = -1,
+ PARSE_ORIG_ARG_OPT_RET_ERROR_UNKNOWN_OPT = -1,
+ PARSE_ORIG_ARG_OPT_RET_ERROR_MISSING_OPT_ARG = -2,
+ PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT = -3,
+ PARSE_ORIG_ARG_OPT_RET_ERROR_UNEXPECTED_OPT_ARG = -4,
+ PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY = -5,
};
static
if (strlen(short_opts) == 0) {
try_append_string_printf(error, "Invalid argument");
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT;
goto error;
}
/* Find corresponding option descriptor */
descr = find_descr(descrs, *iter->short_opt_ch, NULL);
if (!descr) {
- ret = PARSE_ORIG_ARG_OPT_RET_ERROR_UNKNOWN_OPT;
try_append_string_printf(error, "Unknown option `-%c`",
*iter->short_opt_ch);
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_UNKNOWN_OPT;
goto error;
}
"Missing required argument for option `-%c`",
*iter->short_opt_ch);
used_next_orig_arg = false;
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MISSING_OPT_ARG;
goto error;
}
}
/* Create and append option argument */
opt_item = create_opt_item(descr, opt_arg);
if (!opt_item) {
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
goto error;
}
goto end;
error:
- if (ret == PARSE_ORIG_ARG_OPT_RET_OK) {
- ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
- }
+ ARGPAR_ASSERT(ret != PARSE_ORIG_ARG_OPT_RET_OK);
end:
return ret;
if (strlen(long_opt_arg) == 0) {
try_append_string_printf(error, "Invalid argument");
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT;
goto error;
}
if (long_opt_name_size > max_len) {
try_append_string_printf(error,
"Invalid argument `--%s`", long_opt_arg);
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT;
goto error;
}
try_append_string_printf(error,
"Missing required argument for option `--%s`",
long_opt_name);
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MISSING_OPT_ARG;
goto error;
}
*/
try_append_string_printf(error,
"Unexpected argument for option `--%s`", long_opt_name);
+ ret = PARSE_ORIG_ARG_OPT_RET_ERROR_UNEXPECTED_OPT_ARG;
goto error;
}
goto end;
error:
- if (ret == PARSE_ORIG_ARG_OPT_RET_OK) {
- ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
- }
+ ARGPAR_ASSERT(ret != PARSE_ORIG_ARG_OPT_RET_OK);
end:
return ret;
orig_arg);
status = ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT;
break;
- case PARSE_ORIG_ARG_OPT_RET_ERROR:
+ case PARSE_ORIG_ARG_OPT_RET_ERROR_MISSING_OPT_ARG:
+ case PARSE_ORIG_ARG_OPT_RET_ERROR_INVALID_OPT:
+ case PARSE_ORIG_ARG_OPT_RET_ERROR_UNEXPECTED_OPT_ARG:
+ case PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY:
try_prepend_while_parsing_arg_to_error(error, iter->i,
orig_arg);
status = ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR;