* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.
// 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.