2007-07-02 22:34:45 +00:00
|
|
|
#ifndef M_OPTION_H
|
|
|
|
#define M_OPTION_H
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup Options
|
2006-04-25 18:48:53 +00:00
|
|
|
/// m_option allows to parse, print and copy data of various types.
|
2006-04-24 19:20:04 +00:00
|
|
|
/// It is the base of the \ref OptionsStruct, \ref Config and
|
|
|
|
/// \ref Properties APIs.
|
|
|
|
///@{
|
|
|
|
|
|
|
|
/// \file m_option.h
|
|
|
|
|
|
|
|
/// \ingroup OptionTypes
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef struct m_option_type m_option_type_t;
|
|
|
|
typedef struct m_option m_option_t;
|
2003-04-02 16:15:06 +00:00
|
|
|
struct m_struct_st;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup OptionTypes Options types
|
|
|
|
/// \ingroup Options
|
|
|
|
///@{
|
|
|
|
|
2002-11-12 01:56:42 +00:00
|
|
|
///////////////////////////// Options types declarations ////////////////////////////
|
|
|
|
|
|
|
|
// Simple types
|
|
|
|
extern m_option_type_t m_option_type_flag;
|
|
|
|
extern m_option_type_t m_option_type_int;
|
|
|
|
extern m_option_type_t m_option_type_float;
|
2004-02-10 14:32:06 +00:00
|
|
|
extern m_option_type_t m_option_type_double;
|
2002-11-12 01:56:42 +00:00
|
|
|
extern m_option_type_t m_option_type_string;
|
|
|
|
extern m_option_type_t m_option_type_string_list;
|
|
|
|
extern m_option_type_t m_option_type_position;
|
2007-02-24 07:11:57 +00:00
|
|
|
extern m_option_type_t m_option_type_time;
|
2006-09-25 16:47:56 +00:00
|
|
|
extern m_option_type_t m_option_type_time_size;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
extern m_option_type_t m_option_type_print;
|
2003-01-03 12:40:10 +00:00
|
|
|
extern m_option_type_t m_option_type_print_indirect;
|
2006-01-24 11:14:13 +00:00
|
|
|
extern m_option_type_t m_option_type_print_func;
|
2002-11-12 01:56:42 +00:00
|
|
|
extern m_option_type_t m_option_type_subconfig;
|
|
|
|
extern m_option_type_t m_option_type_imgfmt;
|
2004-12-27 17:32:54 +00:00
|
|
|
extern m_option_type_t m_option_type_afmt;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
// Func-based types
|
2002-11-12 01:56:42 +00:00
|
|
|
extern m_option_type_t m_option_type_func_full;
|
|
|
|
extern m_option_type_t m_option_type_func_param;
|
|
|
|
extern m_option_type_t m_option_type_func;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Callback used to reset func options.
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef void (*m_opt_default_func_t)(m_option_t *, char*);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Callback used by m_option_type_func_full options.
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef int (*m_opt_func_full_t)(m_option_t *, char *, char *);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Callback used by m_option_type_func_param options.
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef int (*m_opt_func_param_t)(m_option_t *, char *);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Callback used by m_option_type_func options.
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef int (*m_opt_func_t)(m_option_t *);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
// Backwards compatibility
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef m_opt_default_func_t cfg_default_func_t;
|
|
|
|
typedef m_opt_func_full_t cfg_func_arg_param_t;
|
|
|
|
typedef m_opt_func_param_t cfg_func_param_t;
|
|
|
|
typedef m_opt_func_t cfg_func_t;
|
|
|
|
|
2006-09-25 16:47:56 +00:00
|
|
|
#define END_AT_NONE 0
|
|
|
|
#define END_AT_TIME 1
|
|
|
|
#define END_AT_SIZE 2
|
|
|
|
typedef struct {
|
|
|
|
double pos;
|
|
|
|
int type;
|
|
|
|
} m_time_size_t;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Extra definition needed for \ref m_option_type_obj_settings_list options.
|
2003-03-15 18:01:02 +00:00
|
|
|
typedef struct {
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Pointer to an array of pointer to some object type description struct.
|
2003-03-15 18:01:02 +00:00
|
|
|
void** list;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Offset of the object type name (char*) in the description struct.
|
2003-03-15 18:01:02 +00:00
|
|
|
void* name_off;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Offset of the object type info string (char*) in the description struct.
|
2003-03-15 18:01:02 +00:00
|
|
|
void* info_off;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \brief Offset of the object type parameter description (\ref m_struct_st)
|
|
|
|
/// in the description struct.
|
2003-03-15 18:01:02 +00:00
|
|
|
void* desc_off;
|
|
|
|
} m_obj_list_t;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// The data type used by \ref m_option_type_obj_settings_list.
|
|
|
|
typedef struct m_obj_settings {
|
|
|
|
/// Type of the object.
|
2003-03-15 18:01:02 +00:00
|
|
|
char* name;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// NULL terminated array of parameter/value pairs.
|
2003-03-15 18:01:02 +00:00
|
|
|
char** attribs;
|
|
|
|
} m_obj_settings_t;
|
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
/// A parser to set up a list of objects.
|
2006-04-25 18:48:53 +00:00
|
|
|
/** It creates a NULL terminated array \ref m_obj_settings. The option priv
|
2006-04-24 19:20:04 +00:00
|
|
|
* field (\ref m_option::priv) must point to a \ref m_obj_list_t describing
|
|
|
|
* the available object types.
|
|
|
|
*/
|
|
|
|
extern m_option_type_t m_option_type_obj_settings_list;
|
2003-03-15 18:01:02 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Extra definition needed for \ref m_option_type_obj_presets options.
|
2003-03-15 18:01:02 +00:00
|
|
|
typedef struct {
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Description of the struct holding the presets.
|
2003-04-02 16:11:15 +00:00
|
|
|
struct m_struct_st* in_desc;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Description of the struct that should be set by the presets.
|
2003-04-02 16:11:15 +00:00
|
|
|
struct m_struct_st* out_desc;
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Pointer to an array of structs defining the various presets.
|
2006-04-24 19:20:04 +00:00
|
|
|
void* presets;
|
|
|
|
/// Offset of the preset's name inside the in_struct.
|
|
|
|
void* name_off;
|
2003-03-15 18:01:02 +00:00
|
|
|
} m_obj_presets_t;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Set several fields in a struct at once.
|
2006-04-25 18:48:53 +00:00
|
|
|
/** For this two struct descriptions are used. One for the struct holding the
|
2006-04-24 19:20:04 +00:00
|
|
|
* preset and one for the struct beeing set. Every field present in both
|
2006-04-27 13:22:23 +00:00
|
|
|
* structs will be copied from the preset struct to the destination one.
|
2006-04-24 19:20:04 +00:00
|
|
|
* The option priv field (\ref m_option::priv) must point to a correctly
|
|
|
|
* filled \ref m_obj_presets_t.
|
|
|
|
*/
|
2003-03-15 18:01:02 +00:00
|
|
|
extern m_option_type_t m_option_type_obj_presets;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Parse an URL into a struct.
|
|
|
|
/** The option priv field (\ref m_option::priv) must point to a
|
|
|
|
* \ref m_struct_st describing which fields of the URL must be used.
|
|
|
|
*/
|
2003-04-02 16:11:15 +00:00
|
|
|
extern m_option_type_t m_option_type_custom_url;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Extra definition needed for \ref m_option_type_obj_params options.
|
2003-04-02 16:11:15 +00:00
|
|
|
typedef struct {
|
2006-04-25 18:48:53 +00:00
|
|
|
/// Field descriptions.
|
2006-04-24 19:20:04 +00:00
|
|
|
struct m_struct_st* desc;
|
|
|
|
/// Field separator to use.
|
|
|
|
char separator;
|
2003-04-02 16:11:15 +00:00
|
|
|
} m_obj_params_t;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Parse a set of parameters.
|
|
|
|
/** Parameters are separated by the given separator and each one
|
2006-04-25 18:48:53 +00:00
|
|
|
* successively sets a field from the struct. The option priv field
|
2006-04-24 19:20:04 +00:00
|
|
|
* (\ref m_option::priv) must point to a \ref m_obj_params_t.
|
|
|
|
*/
|
2003-04-02 16:11:15 +00:00
|
|
|
extern m_option_type_t m_option_type_obj_params;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int start;
|
|
|
|
int end;
|
|
|
|
} m_span_t;
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Ready made settings to parse a \ref m_span_t with a start-end syntax.
|
2003-04-02 16:11:15 +00:00
|
|
|
extern m_obj_params_t m_span_params_def;
|
|
|
|
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
// FIXME: backward compatibility
|
2002-11-12 01:56:42 +00:00
|
|
|
#define CONF_TYPE_FLAG (&m_option_type_flag)
|
|
|
|
#define CONF_TYPE_INT (&m_option_type_int)
|
|
|
|
#define CONF_TYPE_FLOAT (&m_option_type_float)
|
2004-02-10 14:32:06 +00:00
|
|
|
#define CONF_TYPE_DOUBLE (&m_option_type_double)
|
2003-08-13 16:29:32 +00:00
|
|
|
#define CONF_TYPE_STRING (&m_option_type_string)
|
2002-11-12 01:56:42 +00:00
|
|
|
#define CONF_TYPE_FUNC (&m_option_type_func)
|
|
|
|
#define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param)
|
|
|
|
#define CONF_TYPE_PRINT (&m_option_type_print)
|
2003-01-03 12:40:10 +00:00
|
|
|
#define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect)
|
2006-01-24 11:14:13 +00:00
|
|
|
#define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func)
|
2002-11-12 01:56:42 +00:00
|
|
|
#define CONF_TYPE_FUNC_FULL (&m_option_type_func_full)
|
|
|
|
#define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig)
|
2003-08-13 16:29:32 +00:00
|
|
|
#define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
|
2002-11-12 01:56:42 +00:00
|
|
|
#define CONF_TYPE_POSITION (&m_option_type_position)
|
2003-08-13 16:29:32 +00:00
|
|
|
#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
|
2004-12-27 17:32:54 +00:00
|
|
|
#define CONF_TYPE_AFMT (&m_option_type_afmt)
|
2002-11-12 01:56:42 +00:00
|
|
|
#define CONF_TYPE_SPAN (&m_option_type_span)
|
2003-03-15 18:01:02 +00:00
|
|
|
#define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list)
|
2003-08-13 16:29:32 +00:00
|
|
|
#define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets)
|
|
|
|
#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url)
|
|
|
|
#define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params)
|
2007-02-24 07:11:57 +00:00
|
|
|
#define CONF_TYPE_TIME (&m_option_type_time)
|
2006-09-25 16:47:56 +00:00
|
|
|
#define CONF_TYPE_TIME_SIZE (&m_option_type_time_size)
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Option type description
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option_type {
|
|
|
|
char* name;
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Syntax description, etc
|
2006-04-24 19:20:04 +00:00
|
|
|
char* comments;
|
|
|
|
/// Size needed for the data.
|
|
|
|
unsigned int size;
|
|
|
|
/// See \ref OptionTypeFlags.
|
2002-11-12 01:56:42 +00:00
|
|
|
unsigned int flags;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Parse the data from a string.
|
|
|
|
/** It is the only required function, all others can be NULL.
|
|
|
|
*
|
|
|
|
* \param opt The option that is parsed.
|
|
|
|
* \param name The full option name.
|
|
|
|
* \param param The parameter to parse.
|
2006-04-25 18:48:53 +00:00
|
|
|
* \param dst Pointer to the memory where the data should be written.
|
2006-04-24 19:20:04 +00:00
|
|
|
* If NULL the parameter validity should still be checked.
|
|
|
|
* \param src Source of the option, see \ref OptionParserModes.
|
2006-04-25 18:48:53 +00:00
|
|
|
* \return On error a negative value is returned, on success the number of arguments
|
2006-04-24 19:20:04 +00:00
|
|
|
* consumed. For details see \ref OptionParserReturn.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
int (*parse)(m_option_t* opt,char *name, char *param, void* dst, int src);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Print back a value in string form.
|
|
|
|
/** \param opt The option to print.
|
|
|
|
* \param val Pointer to the memory holding the data to be printed.
|
|
|
|
* \return An allocated string containing the text value or (void*)-1
|
|
|
|
* on error.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
char* (*print)(m_option_t* opt, void* val);
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \name
|
|
|
|
* These functions are called to save/set/restore the status of the
|
2006-04-25 18:48:53 +00:00
|
|
|
* variables. The difference between the 3 only matters for types like
|
2006-04-27 13:22:23 +00:00
|
|
|
* \ref m_option_type_func where 'setting' needs to do more than just
|
2006-04-24 19:20:04 +00:00
|
|
|
* copying some data.
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Update a save slot (dst) from the current value in the program (src).
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \param opt The option to copy.
|
|
|
|
* \param dst Pointer to the destination memory.
|
|
|
|
* \param src Pointer to the source memory.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
void (*save)(m_option_t* opt,void* dst, void* src);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Set the value in the program (dst) from a save slot.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \param opt The option to copy.
|
|
|
|
* \param dst Pointer to the destination memory.
|
|
|
|
* \param src Pointer to the source memory.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
void (*set)(m_option_t* opt,void* dst, void* src);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Copy the data between two save slots. If NULL and size is > 0 a memcpy will be used.
|
|
|
|
/** \param opt The option to copy.
|
|
|
|
* \param dst Pointer to the destination memory.
|
|
|
|
* \param src Pointer to the source memory.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
void (*copy)(m_option_t* opt,void* dst, void* src);
|
2006-04-24 19:20:04 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/// Free the data allocated for a save slot.
|
|
|
|
/** This is only needed for dynamic types like strings.
|
|
|
|
* \param dst Pointer to the data, usually a pointer that should be freed and
|
|
|
|
* set to NULL.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
void (*free)(void* dst);
|
|
|
|
};
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
///@}
|
|
|
|
|
|
|
|
/// Option description
|
|
|
|
/** \ingroup Options
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option {
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Option name.
|
2002-11-12 01:56:42 +00:00
|
|
|
char *name;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Reserved for higher level APIs, it shouldn't be used by parsers.
|
|
|
|
/** The suboption parser and func types do use it. They should instead
|
2006-04-25 18:48:53 +00:00
|
|
|
* use the priv field but this was inherited from older versions of the
|
2006-04-24 19:20:04 +00:00
|
|
|
* config code.
|
|
|
|
*/
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
/// Option type.
|
2002-11-12 01:56:42 +00:00
|
|
|
m_option_type_t* type;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// See \ref OptionFlags.
|
2002-11-12 01:56:42 +00:00
|
|
|
unsigned int flags;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// \brief Mostly useful for numeric types, the \ref M_OPT_MIN flags must
|
2006-04-24 19:20:04 +00:00
|
|
|
/// also be set.
|
|
|
|
double min;
|
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// \brief Mostly useful for numeric types, the \ref M_OPT_MAX flags must
|
2006-04-24 19:20:04 +00:00
|
|
|
/// also be set.
|
|
|
|
double max;
|
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Type dependent data (for all kinds of extended settings).
|
|
|
|
/** This used to be a function pointer to hold a 'reverse to defaults' func.
|
2006-04-24 19:20:04 +00:00
|
|
|
* Now it can be used to pass any type of extra args needed by the parser.
|
2006-04-27 13:22:23 +00:00
|
|
|
* Passing a 'default func' is still valid for all func based option types.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
|
|
|
void* priv;
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup OptionFlags Option flags
|
|
|
|
///@{
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// The option has a minimum set in \ref m_option::min.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_MIN (1<<0)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// The option has a maximum set in \ref m_option::max.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_MAX (1<<1)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// The option has a minimum and maximum in \ref m_option::min and \ref m_option::max.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_RANGE (M_OPT_MIN|M_OPT_MAX)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// The option is forbidden in config files.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_NOCFG (1<<2)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// The option is forbidden on the command line.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_NOCMD (1<<3)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// The option is global in the \ref Config.
|
|
|
|
/** It won't be saved on push and the command line parser will set it when
|
2006-04-27 13:22:23 +00:00
|
|
|
* it's parsed (i.e. it won't be set later)
|
2006-04-24 19:20:04 +00:00
|
|
|
* e.g options : -v, -quiet
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_GLOBAL (1<<4)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// The \ref Config won't save this option on push.
|
2006-04-25 18:48:53 +00:00
|
|
|
/** It won't be saved on push but the command line parser will add it with
|
2006-04-27 13:22:23 +00:00
|
|
|
* its entry (i.e. it may be set later)
|
2006-04-24 19:20:04 +00:00
|
|
|
* e.g options : -include
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_NOSAVE (1<<5)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2006-04-27 13:22:23 +00:00
|
|
|
/// \brief The \ref Config will emulate the old behavior by pushing the
|
2006-04-24 19:20:04 +00:00
|
|
|
/// option only if it was set by the user.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_OLD (1<<6)
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup OldOptionFlags Backward compatibility
|
|
|
|
///
|
2006-04-27 13:22:23 +00:00
|
|
|
/// These are kept for compatibility with older code.
|
2006-04-24 19:20:04 +00:00
|
|
|
/// @{
|
2003-08-13 16:29:32 +00:00
|
|
|
#define CONF_MIN M_OPT_MIN
|
|
|
|
#define CONF_MAX M_OPT_MAX
|
|
|
|
#define CONF_RANGE M_OPT_RANGE
|
|
|
|
#define CONF_NOCFG M_OPT_NOCFG
|
|
|
|
#define CONF_NOCMD M_OPT_NOCMD
|
|
|
|
#define CONF_GLOBAL M_OPT_GLOBAL
|
|
|
|
#define CONF_NOSAVE M_OPT_NOSAVE
|
|
|
|
#define CONF_OLD M_OPT_OLD
|
2006-04-24 19:20:04 +00:00
|
|
|
///@}
|
|
|
|
|
|
|
|
///@}
|
|
|
|
|
|
|
|
/// \defgroup OptionTypeFlags Option type flags
|
|
|
|
/// \ingroup OptionTypes
|
|
|
|
///
|
2006-04-27 13:22:23 +00:00
|
|
|
/// These flags are used to describe special parser capabilities or behavior.
|
2006-04-24 19:20:04 +00:00
|
|
|
///
|
|
|
|
///@{
|
|
|
|
|
|
|
|
/// Suboption parser flag.
|
|
|
|
/** When this flag is set, m_option::p should point to another m_option
|
|
|
|
* array. Only the parse function will be called. If dst is set, it should
|
|
|
|
* create/update an array of char* containg opt/val pairs. The options in
|
|
|
|
* the child array will then be set automatically by the \ref Config.
|
2006-04-25 18:48:53 +00:00
|
|
|
* Also note that suboptions may be directly accessed by using
|
2006-04-24 19:20:04 +00:00
|
|
|
* -option:subopt blah.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_TYPE_HAS_CHILD (1<<0)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Wildcard matching flag.
|
2006-04-27 13:22:23 +00:00
|
|
|
/** If set the option type has a use for option names ending with a *
|
2006-04-25 18:48:53 +00:00
|
|
|
* (used for -aa*), this only affects the option name matching.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_TYPE_ALLOW_WILDCARD (1<<1)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Dynamic data type.
|
2006-04-27 13:22:23 +00:00
|
|
|
/** This flag indicates that the data is dynamically allocated (m_option::p
|
|
|
|
* points to a pointer). It enables a little hack in the \ref Config wich
|
|
|
|
* replaces the initial value of such variables with a dynamic copy in case
|
|
|
|
* the initial value is statically allocated (pretty common with strings).
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_TYPE_DYNAMIC (1<<2)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Indirect option type.
|
|
|
|
/** If this is set the parse function doesn't directly return
|
|
|
|
* the wanted thing. Options use this if for some reasons they have to wait
|
|
|
|
* until the set call to be able to correctly set the target var.
|
|
|
|
* So for those types new values must first be parsed, then set to the target
|
|
|
|
* var. If this flag isn't set then new values can be parsed directly to the
|
2006-04-27 13:22:23 +00:00
|
|
|
* target var. It's used by the callback-based options as the callback call
|
2006-04-24 19:20:04 +00:00
|
|
|
* may append later on.
|
|
|
|
*/
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_TYPE_INDIRECT (1<<3)
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
///@}
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
///////////////////////////// Parser flags ////////////////////////////////////////
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup OptionParserModes Option parser modes
|
|
|
|
/// \ingroup Options
|
|
|
|
///
|
2006-04-27 13:22:23 +00:00
|
|
|
/// Some parsers behave differently depending on the mode passed in the src
|
2006-04-24 19:20:04 +00:00
|
|
|
/// parameter of m_option_type::parse. For example the flag type doesn't take
|
|
|
|
/// an argument when parsing from the command line.
|
|
|
|
///@{
|
|
|
|
|
|
|
|
/// Set when parsing from a config file.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_CONFIG_FILE 0
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Set when parsing command line arguments.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_COMMAND_LINE 1
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
///@}
|
|
|
|
|
|
|
|
/// \defgroup OptionParserReturn Option parser return code
|
|
|
|
/// \ingroup Options
|
|
|
|
///
|
2006-04-25 18:48:53 +00:00
|
|
|
/// On success parsers return the number of arguments consumed: 0 or 1.
|
2006-04-24 19:20:04 +00:00
|
|
|
///
|
2006-04-25 18:48:53 +00:00
|
|
|
/// To indicate that MPlayer should exit without playing anything,
|
2006-04-24 19:20:04 +00:00
|
|
|
/// parsers return M_OPT_EXIT minus the number of parameters they
|
|
|
|
/// consumed: \ref M_OPT_EXIT or \ref M_OPT_EXIT-1.
|
|
|
|
///
|
2006-04-25 18:48:53 +00:00
|
|
|
/// On error one of the following (negative) error codes is returned:
|
2006-04-24 19:20:04 +00:00
|
|
|
///@{
|
|
|
|
|
2006-04-25 18:48:53 +00:00
|
|
|
/// For use by higher level APIs when the option name is invalid.
|
2003-08-13 16:45:02 +00:00
|
|
|
#define M_OPT_UNKNOWN -1
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Returned when a parameter is needed but wasn't provided.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_MISSING_PARAM -2
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Returned when the given parameter couldn't be parsed.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_INVALID -3
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// \brief Returned if the value is "out of range". The exact meaning may
|
|
|
|
/// vary from type to type.
|
2002-11-12 01:56:42 +00:00
|
|
|
#define M_OPT_OUT_OF_RANGE -4
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Returned if the parser failed for any other reason than a bad parameter.
|
2003-08-13 16:29:32 +00:00
|
|
|
#define M_OPT_PARSER_ERR -5
|
2006-04-24 19:20:04 +00:00
|
|
|
|
|
|
|
/// Returned when MPlayer should exit. Used by various help stuff.
|
|
|
|
/** M_OPT_EXIT must be the lowest number on this list.
|
|
|
|
*/
|
2003-04-02 16:11:15 +00:00
|
|
|
#define M_OPT_EXIT -6
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// \defgroup OldOptionParserReturn Backward compatibility
|
|
|
|
///
|
2006-04-25 18:48:53 +00:00
|
|
|
/// These are kept for compatibility with older code.
|
2006-04-24 19:20:04 +00:00
|
|
|
///
|
|
|
|
///@{
|
2003-08-13 16:29:32 +00:00
|
|
|
#define ERR_NOT_AN_OPTION M_OPT_UNKNOWN
|
|
|
|
#define ERR_MISSING_PARAM M_OPT_MISSING_PARAM
|
|
|
|
#define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE
|
|
|
|
#define ERR_FUNC_ERR M_OPT_PARSER_ERR
|
2006-04-24 19:20:04 +00:00
|
|
|
///@}
|
|
|
|
|
|
|
|
///@}
|
|
|
|
|
|
|
|
/// Find the option matching the given name in the list.
|
|
|
|
/** \ingroup Options
|
2006-04-25 18:48:53 +00:00
|
|
|
* This function takes the possible wildcards into account (see
|
2006-04-24 19:20:04 +00:00
|
|
|
* \ref M_OPT_TYPE_ALLOW_WILDCARD).
|
|
|
|
*
|
|
|
|
* \param list Pointer to an array of \ref m_option.
|
|
|
|
* \param name Name of the option.
|
|
|
|
* \return The matching option or NULL.
|
|
|
|
*/
|
2006-07-13 05:03:43 +00:00
|
|
|
m_option_t* m_option_list_find(m_option_t* list,const char* name);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper to parse options, see \ref m_option_type::parse.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static int
|
|
|
|
m_option_parse(m_option_t* opt,char *name, char *param, void* dst, int src) {
|
|
|
|
return opt->type->parse(opt,name,param,dst,src);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper to print options, see \ref m_option_type::print.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static char*
|
|
|
|
m_option_print(m_option_t* opt, void* val_ptr) {
|
|
|
|
if(opt->type->print)
|
|
|
|
return opt->type->print(opt,val_ptr);
|
|
|
|
else
|
2002-11-12 12:39:05 +00:00
|
|
|
return (char*)-1;
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper around \ref m_option_type::save.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static void
|
|
|
|
m_option_save(m_option_t* opt,void* dst, void* src) {
|
|
|
|
if(opt->type->save)
|
|
|
|
opt->type->save(opt,dst,src);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper around \ref m_option_type::set.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static void
|
|
|
|
m_option_set(m_option_t* opt,void* dst, void* src) {
|
|
|
|
if(opt->type->set)
|
|
|
|
opt->type->set(opt,dst,src);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper around \ref m_option_type::copy.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static void
|
|
|
|
m_option_copy(m_option_t* opt,void* dst, void* src) {
|
|
|
|
if(opt->type->copy)
|
2006-01-22 12:43:14 +00:00
|
|
|
opt->type->copy(opt,dst,src);
|
2002-11-12 01:56:42 +00:00
|
|
|
else if(opt->type->size > 0)
|
|
|
|
memcpy(dst,src,opt->type->size);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/// Helper around \ref m_option_type::free.
|
2002-11-12 01:56:42 +00:00
|
|
|
inline static void
|
|
|
|
m_option_free(m_option_t* opt,void* dst) {
|
|
|
|
if(opt->type->free)
|
|
|
|
opt->type->free(dst);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/*@}*/
|
|
|
|
|
2007-07-02 22:34:45 +00:00
|
|
|
#endif /* M_OPTION_H */
|