Lines Matching refs:ctx
302 void parse_options_start(struct parse_opt_ctx_t *ctx,
305 memset(ctx, 0, sizeof(*ctx));
306 ctx->argc = argc - 1;
307 ctx->argv = argv + 1;
308 ctx->out = argv;
309 ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
310 ctx->flags = flags;
319 int parse_options_step(struct parse_opt_ctx_t *ctx,
323 int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
326 ctx->opt = NULL;
328 for (; ctx->argc; ctx->argc--, ctx->argv++) {
329 const char *arg = ctx->argv[0];
332 if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
334 ctx->out[ctx->cpidx++] = ctx->argv[0];
339 ctx->opt = arg + 1;
340 if (internal_help && *ctx->opt == 'h')
342 switch (parse_short_opt(ctx, options)) {
350 if (ctx->opt)
352 while (ctx->opt) {
353 if (internal_help && *ctx->opt == 'h')
355 switch (parse_short_opt(ctx, options)) {
364 ctx->argv[0] = strdup(ctx->opt - 1);
365 *(char *)ctx->argv[0] = '-';
375 if (!(ctx->flags & PARSE_OPT_KEEP_DASHDASH)) {
376 ctx->argc--;
377 ctx->argv++;
386 switch (parse_long_opt(ctx, arg + 2, options)) {
396 if (!(ctx->flags & PARSE_OPT_KEEP_UNKNOWN))
398 ctx->out[ctx->cpidx++] = ctx->argv[0];
399 ctx->opt = NULL;
404 int parse_options_end(struct parse_opt_ctx_t *ctx)
406 memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
407 ctx->out[ctx->cpidx + ctx->argc] = NULL;
408 return ctx->cpidx + ctx->argc;
414 struct parse_opt_ctx_t ctx;
416 parse_options_start(&ctx, argc, argv, flags);
417 switch (parse_options_step(&ctx, options, usagestr)) {
423 if (ctx.argv[0][1] == '-') {
424 error("unknown option `%s'", ctx.argv[0] + 2);
426 error("unknown switch `%c'", *ctx.opt);
431 return parse_options_end(&ctx);