Lines Matching refs:ctx

360 void parse_options_start(struct parse_opt_ctx_t *ctx,  in parse_options_start()  argument
363 memset(ctx, 0, sizeof(*ctx)); in parse_options_start()
364 ctx->argc = argc - 1; in parse_options_start()
365 ctx->argv = argv + 1; in parse_options_start()
366 ctx->out = argv; in parse_options_start()
367 ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); in parse_options_start()
368 ctx->flags = flags; in parse_options_start()
377 int parse_options_step(struct parse_opt_ctx_t *ctx, in parse_options_step() argument
381 int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); in parse_options_step()
386 ctx->opt = NULL; in parse_options_step()
388 for (; ctx->argc; ctx->argc--, ctx->argv++) { in parse_options_step()
389 arg = ctx->argv[0]; in parse_options_step()
391 if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) in parse_options_step()
393 ctx->out[ctx->cpidx++] = ctx->argv[0]; in parse_options_step()
398 ctx->opt = ++arg; in parse_options_step()
399 if (internal_help && *ctx->opt == 'h') in parse_options_step()
401 switch (parse_short_opt(ctx, options)) { in parse_options_step()
411 if (ctx->opt) in parse_options_step()
413 while (ctx->opt) { in parse_options_step()
414 if (internal_help && *ctx->opt == 'h') in parse_options_step()
416 arg = ctx->opt; in parse_options_step()
417 switch (parse_short_opt(ctx, options)) { in parse_options_step()
426 ctx->argv[0] = strdup(ctx->opt - 1); in parse_options_step()
427 *(char *)ctx->argv[0] = '-'; in parse_options_step()
439 if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) { in parse_options_step()
440 ctx->argc--; in parse_options_step()
441 ctx->argv++; in parse_options_step()
455 switch (parse_long_opt(ctx, arg, options)) { in parse_options_step()
468 if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN)) in parse_options_step()
470 ctx->out[ctx->cpidx++] = ctx->argv[0]; in parse_options_step()
471 ctx->opt = NULL; in parse_options_step()
477 if ((excl_short_opt && ctx->excl_opt->short_name) || in parse_options_step()
478 ctx->excl_opt->long_name == NULL) { in parse_options_step()
479 char opt = ctx->excl_opt->short_name; in parse_options_step()
482 parse_options_usage(NULL, options, ctx->excl_opt->long_name, 0); in parse_options_step()
487 int parse_options_end(struct parse_opt_ctx_t *ctx) in parse_options_end() argument
489 memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out)); in parse_options_end()
490 ctx->out[ctx->cpidx + ctx->argc] = NULL; in parse_options_end()
491 return ctx->cpidx + ctx->argc; in parse_options_end()
497 struct parse_opt_ctx_t ctx; in parse_options_subcommand() local
517 parse_options_start(&ctx, argc, argv, flags); in parse_options_subcommand()
518 switch (parse_options_step(&ctx, options, usagestr)) { in parse_options_subcommand()
539 if (ctx.argv[0][1] == '-') { in parse_options_subcommand()
540 error("unknown option `%s'", ctx.argv[0] + 2); in parse_options_subcommand()
542 error("unknown switch `%c'", *ctx.opt); in parse_options_subcommand()
547 return parse_options_end(&ctx); in parse_options_subcommand()