// Search exhausted & argument not found. RIP. if (!parsed_arg->def)
{
err = ZYAN_STATUS_ARG_NOT_UNDERSTOOD;
ZYAN_ERR_TOK(cur_arg); goto failure;
}
// Does the argument expect a value? If yes, consume next token. if (!parsed_arg->def->boolean)
{ if (i == cfg->argc - 1)
{
err = ZYAN_STATUS_ARG_MISSES_VALUE;
ZYAN_ERR_TOK(cur_arg); goto failure;
}
parsed_arg->has_value = ZYAN_TRUE;
ZYAN_CHECK(ZyanStringViewInsideBuffer(&parsed_arg->value, cfg->argv[++i]));
}
}
// Continue parsing at next token. continue;
}
// Single-dash argument? // TODO: How to deal with just dashes? Current code treats it as unnamed arg. if (accept_dash_args && arg_len > 1 && cur_arg[0] == '-')
{ // Iterate argument token chars until there are either no more chars left // or we encounter a non-boolean argument, in which case we consume the // remaining chars as its value. for (constchar* read_ptr = cur_arg + 1; *read_ptr; ++read_ptr)
{ // Allocate parsed argument struct.
ZyanArgParseArg* parsed_arg;
ZYAN_CHECK(ZyanVectorEmplace(parsed, (void**)&parsed_arg, ZYAN_NULL));
ZYAN_MEMSET(parsed_arg, 0, sizeof(*parsed_arg));
// All tokens processed. Do we have enough unnamed arguments? if (num_unnamed_args < cfg->min_unnamed_args)
{
err = ZYAN_STATUS_TOO_FEW_ARGS; // No sensible error token for this error type. goto failure;
}
// Check whether all required arguments are present.
ZyanUSize num_parsed_args;
ZYAN_CHECK(ZyanVectorGetSize(parsed, &num_parsed_args)); for (const ZyanArgParseDefinition* def = cfg->args; def && def->name; ++def)
{ if (!def->required) continue;
ZyanBool arg_found = ZYAN_FALSE; for (ZyanUSize i = 0; i < num_parsed_args; ++i)
{ const ZyanArgParseArg* arg = ZYAN_NULL;
ZYAN_CHECK(ZyanVectorGetPointer(parsed, i, (constvoid**)&arg));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.