Lines Matching refs:ctx

97 static int next_arg(struct fuse_opt_context *ctx, const char *opt)
99 if (ctx->argctr + 1 >= ctx->argc) {
103 ctx->argctr++;
107 static int add_arg(struct fuse_opt_context *ctx, const char *arg)
109 return fuse_opt_add_arg(&ctx->outargs, arg);
132 static int add_opt(struct fuse_opt_context *ctx, const char *opt)
134 return fuse_opt_add_opt(&ctx->opts, opt);
137 static int call_proc(struct fuse_opt_context *ctx, const char *arg, int key,
143 if (key != FUSE_OPT_KEY_KEEP && ctx->proc) {
144 int res = ctx->proc(ctx->data, arg, key, &ctx->outargs);
149 return add_opt(ctx, arg);
151 return add_arg(ctx, arg);
209 static int process_opt(struct fuse_opt_context *ctx,
214 if (call_proc(ctx, arg, opt->value, iso) == -1)
217 void *var = (char*)ctx->data + opt->offset;
231 static int process_opt_sep_arg(struct fuse_opt_context *ctx,
239 if (next_arg(ctx, arg) == -1)
242 param = ctx->argv[ctx->argctr];
249 res = process_opt(ctx, opt, sep, newarg, iso);
255 static int process_gopt(struct fuse_opt_context *ctx, const char *arg, int iso)
258 const struct fuse_opt *opt = find_opt(ctx->opt, arg, &sep);
263 res = process_opt_sep_arg(ctx, opt, sep, arg,
266 res = process_opt(ctx, opt, sep, arg, iso);
272 return call_proc(ctx, arg, FUSE_OPT_KEY_OPT, iso);
275 static int process_real_option_group(struct fuse_opt_context *ctx, char *opts)
284 res = process_gopt(ctx, opts, 1);
293 static int process_option_group(struct fuse_opt_context *ctx, const char *opts)
299 return process_gopt(ctx, opts, 1);
306 res = process_real_option_group(ctx, copy);
311 static int process_one(struct fuse_opt_context *ctx, const char *arg)
313 if (ctx->nonopt || arg[0] != '-')
314 return call_proc(ctx, arg, FUSE_OPT_KEY_NONOPT, 0);
317 return process_option_group(ctx, arg + 2);
319 if (next_arg(ctx, arg) == -1)
322 return process_option_group(ctx,
323 ctx->argv[ctx->argctr]);
326 if (add_arg(ctx, arg) == -1)
328 ctx->nonopt = ctx->outargs.argc;
331 return process_gopt(ctx, arg, 0);
334 static int opt_parse(struct fuse_opt_context *ctx)
336 if (ctx->argc) {
337 if (add_arg(ctx, ctx->argv[0]) == -1)
341 for (ctx->argctr = 1; ctx->argctr < ctx->argc; ctx->argctr++)
342 if (process_one(ctx, ctx->argv[ctx->argctr]) == -1)
345 if (ctx->opts) {
346 if (fuse_opt_insert_arg(&ctx->outargs, 1, "-o") == -1 ||
347 fuse_opt_insert_arg(&ctx->outargs, 2, ctx->opts) == -1)
350 if (ctx->nonopt && ctx->nonopt == ctx->outargs.argc) {
351 free(ctx->outargs.argv[ctx->outargs.argc - 1]);
352 ctx->outargs.argv[--ctx->outargs.argc] = NULL;
362 struct fuse_opt_context ctx = {
371 ctx.argc = args->argc;
372 ctx.argv = args->argv;
374 res = opt_parse(&ctx);
377 *args = ctx.outargs;
378 ctx.outargs = tmp;
380 free(ctx.opts);
381 fuse_opt_free_args(&ctx.outargs);