1N/A/*
1N/A FUSE: Filesystem in Userspace
1N/A Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
1N/A
1N/A This program can be distributed under the terms of the GNU LGPLv2.
1N/A See the file COPYING.LIB.
1N/A*/
1N/A
1N/A#ifndef _FUSE_OPT_H_
1N/A#define _FUSE_OPT_H_
1N/A
1N/A/** @file
1N/A *
1N/A * This file defines the option parsing interface of FUSE
1N/A */
1N/A
1N/A#ifdef __cplusplus
1N/Aextern "C" {
1N/A#endif
1N/A
1N/A/**
1N/A * Option description
1N/A *
1N/A * This structure describes a single option, and and action associated
1N/A * with it, in case it matches.
1N/A *
1N/A * More than one such match may occur, in which case the action for
1N/A * each match is executed.
1N/A *
1N/A * There are three possible actions in case of a match:
1N/A *
1N/A * i) An integer (int or unsigned) variable determined by 'offset' is
1N/A * set to 'value'
1N/A *
1N/A * ii) The processing function is called, with 'value' as the key
1N/A *
1N/A * iii) An integer (any) or string (char *) variable determined by
1N/A * 'offset' is set to the value of an option parameter
1N/A *
1N/A * 'offset' should normally be either set to
1N/A *
1N/A * - 'offsetof(struct foo, member)' actions i) and iii)
1N/A *
1N/A * - -1 action ii)
1N/A *
1N/A * The 'offsetof()' macro is defined in the <stddef.h> header.
1N/A *
1N/A * The template determines which options match, and also have an
1N/A * effect on the action. Normally the action is either i) or ii), but
1N/A * if a format is present in the template, then action iii) is
1N/A * performed.
1N/A *
1N/A * The types of templates are:
1N/A *
1N/A * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only
1N/A * themselves. Invalid values are "--" and anything beginning
1N/A * with "-o"
1N/A *
1N/A * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or
1N/A * the relevant option in a comma separated option list
1N/A *
1N/A * 3) "bar=", "--foo=", etc. These are variations of 1) and 2)
1N/A * which have a parameter
1N/A *
1N/A * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform
1N/A * action iii).
1N/A *
1N/A * 5) "-x ", etc. Matches either "-xparam" or "-x param" as
1N/A * two separate arguments
1N/A *
1N/A * 6) "-x %s", etc. Combination of 4) and 5)
1N/A *
1N/A * If the format is "%s", memory is allocated for the string unlike
1N/A * with scanf().
1N/A */
1N/Astruct fuse_opt {
1N/A /** Matching template and optional parameter formatting */
1N/A const char *templ;
1N/A
1N/A /**
1N/A * Offset of variable within 'data' parameter of fuse_opt_parse()
1N/A * or -1
1N/A */
1N/A unsigned long offset;
1N/A
1N/A /**
1N/A * Value to set the variable to, or to be passed as 'key' to the
1N/A * processing function. Ignored if template has a format
1N/A */
1N/A int value;
1N/A};
1N/A
1N/A/**
1N/A * Key option. In case of a match, the processing function will be
1N/A * called with the specified key.
1N/A */
1N/A#define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
1N/A
1N/A/**
1N/A * Last option. An array of 'struct fuse_opt' must end with a NULL
1N/A * template value
1N/A */
1N/A#define FUSE_OPT_END { .templ = NULL }
1N/A
1N/A/**
1N/A * Argument list
1N/A */
1N/Astruct fuse_args {
1N/A /** Argument count */
1N/A int argc;
1N/A
1N/A /** Argument vector. NULL terminated */
1N/A char **argv;
1N/A
1N/A /** Is 'argv' allocated? */
1N/A int allocated;
1N/A};
1N/A
1N/A/**
1N/A * Initializer for 'struct fuse_args'
1N/A */
1N/A#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
1N/A
1N/A/**
1N/A * Key value passed to the processing function if an option did not
1N/A * match any template
1N/A */
1N/A#define FUSE_OPT_KEY_OPT -1
1N/A
1N/A/**
1N/A * Key value passed to the processing function for all non-options
1N/A *
1N/A * Non-options are the arguments beginning with a charater other than
1N/A * '-' or all arguments after the special '--' option
1N/A */
1N/A#define FUSE_OPT_KEY_NONOPT -2
1N/A
1N/A/**
1N/A * Special key value for options to keep
1N/A *
1N/A * Argument is not passed to processing function, but behave as if the
1N/A * processing function returned 1
1N/A */
1N/A#define FUSE_OPT_KEY_KEEP -3
1N/A
1N/A/**
1N/A * Special key value for options to discard
1N/A *
1N/A * Argument is not passed to processing function, but behave as if the
1N/A * processing function returned zero
1N/A */
1N/A#define FUSE_OPT_KEY_DISCARD -4
1N/A
1N/A/**
1N/A * Processing function
1N/A *
1N/A * This function is called if
1N/A * - option did not match any 'struct fuse_opt'
1N/A * - argument is a non-option
1N/A * - option did match and offset was set to -1
1N/A *
1N/A * The 'arg' parameter will always contain the whole argument or
1N/A * option including the parameter if exists. A two-argument option
1N/A * ("-x foo") is always converted to single arguemnt option of the
1N/A * form "-xfoo" before this function is called.
1N/A *
1N/A * Options of the form '-ofoo' are passed to this function without the
1N/A * '-o' prefix.
1N/A *
1N/A * The return value of this function determines whether this argument
1N/A * is to be inserted into the output argument vector, or discarded.
1N/A *
1N/A * @param data is the user data passed to the fuse_opt_parse() function
1N/A * @param arg is the whole argument or option
1N/A * @param key determines why the processing function was called
1N/A * @param outargs the current output argument list
1N/A * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept
1N/A */
1N/Atypedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key,
1N/A struct fuse_args *outargs);
1N/A
1N/A/**
1N/A * Option parsing function
1N/A *
1N/A * If 'args' was returned from a previous call to fuse_opt_parse() or
1N/A * it was constructed from
1N/A *
1N/A * A NULL 'args' is equivalent to an empty argument vector
1N/A *
1N/A * A NULL 'opts' is equivalent to an 'opts' array containing a single
1N/A * end marker
1N/A *
1N/A * A NULL 'proc' is equivalent to a processing function always
1N/A * returning '1'
1N/A *
1N/A * @param args is the input and output argument list
1N/A * @param data is the user data
1N/A * @param opts is the option description array
1N/A * @param proc is the processing function
1N/A * @return -1 on error, 0 on success
1N/A */
1N/Aint fuse_opt_parse(struct fuse_args *args, void *data,
1N/A const struct fuse_opt opts[], fuse_opt_proc_t proc);
1N/A
1N/A/**
1N/A * Add an option to a comma separated option list
1N/A *
1N/A * @param opts is a pointer to an option list, may point to a NULL value
1N/A * @param opt is the option to add
1N/A * @return -1 on allocation error, 0 on success
1N/A */
1N/Aint fuse_opt_add_opt(char **opts, const char *opt);
1N/A
1N/A/**
1N/A * Add an argument to a NULL terminated argument vector
1N/A *
1N/A * @param args is the structure containing the current argument list
1N/A * @param arg is the new argument to add
1N/A * @return -1 on allocation error, 0 on success
1N/A */
1N/Aint fuse_opt_add_arg(struct fuse_args *args, const char *arg);
1N/A
1N/A/**
1N/A * Add an argument at the specified position in a NULL terminated
1N/A * argument vector
1N/A *
1N/A * Adds the argument to the N-th position. This is useful for adding
1N/A * options at the beggining of the array which must not come after the
1N/A * special '--' option.
1N/A *
1N/A * @param args is the structure containing the current argument list
1N/A * @param pos is the position at which to add the argument
1N/A * @param arg is the new argument to add
1N/A * @return -1 on allocation error, 0 on success
1N/A */
1N/Aint fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg);
1N/A
1N/A/**
1N/A * Free the contents of argument list
1N/A *
1N/A * The structure itself is not freed
1N/A *
1N/A * @param args is the structure containing the argument list
1N/A */
1N/Avoid fuse_opt_free_args(struct fuse_args *args);
1N/A
1N/A
1N/A/**
1N/A * Check if an option matches
1N/A *
1N/A * @param opts is the option description array
1N/A * @param opt is the option to match
1N/A * @return 1 if a match is found, 0 if not
1N/A */
1N/Aint fuse_opt_match(const struct fuse_opt opts[], const char *opt);
1N/A
1N/A#ifdef __cplusplus
1N/A}
1N/A#endif
1N/A
1N/A#endif /* _FUSE_OPT_H_ */