Lines Matching refs:ctx

363 void parse_options_start(struct parse_opt_ctx_t *ctx,  in parse_options_start()  argument
366 memset(ctx, 0, sizeof(*ctx)); in parse_options_start()
367 ctx->argc = argc - 1; in parse_options_start()
368 ctx->argv = argv + 1; in parse_options_start()
369 ctx->out = argv; in parse_options_start()
370 ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); in parse_options_start()
371 ctx->flags = flags; in parse_options_start()
381 int parse_options_step(struct parse_opt_ctx_t *ctx, in parse_options_step() argument
385 int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); in parse_options_step()
390 ctx->opt = NULL; in parse_options_step()
392 for (; ctx->argc; ctx->argc--, ctx->argv++) { in parse_options_step()
393 arg = ctx->argv[0]; in parse_options_step()
395 if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) in parse_options_step()
397 ctx->out[ctx->cpidx++] = ctx->argv[0]; in parse_options_step()
402 ctx->opt = ++arg; in parse_options_step()
403 if (internal_help && *ctx->opt == 'h') { in parse_options_step()
404 return usage_with_options_internal(usagestr, options, 0, ctx); in parse_options_step()
406 switch (parse_short_opt(ctx, options)) { in parse_options_step()
416 if (ctx->opt) in parse_options_step()
418 while (ctx->opt) { in parse_options_step()
419 if (internal_help && *ctx->opt == 'h') in parse_options_step()
420 return usage_with_options_internal(usagestr, options, 0, ctx); in parse_options_step()
421 arg = ctx->opt; in parse_options_step()
422 switch (parse_short_opt(ctx, options)) { in parse_options_step()
431 ctx->argv[0] = strdup(ctx->opt - 1); in parse_options_step()
432 *(char *)ctx->argv[0] = '-'; in parse_options_step()
444 if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) { in parse_options_step()
445 ctx->argc--; in parse_options_step()
446 ctx->argv++; in parse_options_step()
453 return usage_with_options_internal(usagestr, options, 1, ctx); in parse_options_step()
455 return usage_with_options_internal(usagestr, options, 0, ctx); in parse_options_step()
460 switch (parse_long_opt(ctx, arg, options)) { in parse_options_step()
473 if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN)) in parse_options_step()
475 ctx->out[ctx->cpidx++] = ctx->argv[0]; in parse_options_step()
476 ctx->opt = NULL; in parse_options_step()
482 if ((excl_short_opt && ctx->excl_opt->short_name) || in parse_options_step()
483 ctx->excl_opt->long_name == NULL) { in parse_options_step()
484 char opt = ctx->excl_opt->short_name; in parse_options_step()
487 parse_options_usage(NULL, options, ctx->excl_opt->long_name, 0); in parse_options_step()
492 int parse_options_end(struct parse_opt_ctx_t *ctx) in parse_options_end() argument
494 memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out)); in parse_options_end()
495 ctx->out[ctx->cpidx + ctx->argc] = NULL; in parse_options_end()
496 return ctx->cpidx + ctx->argc; in parse_options_end()
502 struct parse_opt_ctx_t ctx; in parse_options_subcommand() local
522 parse_options_start(&ctx, argc, argv, flags); in parse_options_subcommand()
523 switch (parse_options_step(&ctx, options, usagestr)) { in parse_options_subcommand()
544 if (ctx.argv[0][1] == '-') { in parse_options_subcommand()
546 ctx.argv[0] + 2); in parse_options_subcommand()
549 *ctx.opt); in parse_options_subcommand()
554 return parse_options_end(&ctx); in parse_options_subcommand()
691 static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) in option__in_argv() argument
695 for (i = 1; i < ctx->argc; ++i) { in option__in_argv()
696 const char *arg = ctx->argv[i]; in option__in_argv()
724 struct parse_opt_ctx_t *ctx) in usage_with_options_internal() argument
756 if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx)) in usage_with_options_internal()