2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_M_OPTION_H
|
|
|
|
#define MPLAYER_M_OPTION_H
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2008-03-04 23:35:24 +00:00
|
|
|
#include <string.h>
|
2008-04-28 03:19:53 +00:00
|
|
|
#include <stddef.h>
|
2011-07-27 17:59:44 +00:00
|
|
|
#include <stdbool.h>
|
2008-03-04 23:35:24 +00:00
|
|
|
|
2011-04-19 01:11:52 +00:00
|
|
|
#include "config.h"
|
2011-07-28 08:07:47 +00:00
|
|
|
#include "bstr.h"
|
2011-04-19 01:11:52 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// m_option allows to parse, print and copy data of various types.
|
2006-04-24 19:20:04 +00:00
|
|
|
|
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
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
///////////////////////////// Options types declarations ////////////////////
|
2002-11-12 01:56:42 +00:00
|
|
|
|
|
|
|
// Simple types
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_flag;
|
|
|
|
extern const m_option_type_t m_option_type_int;
|
2009-03-02 11:17:50 +00:00
|
|
|
extern const m_option_type_t m_option_type_int64;
|
2010-04-24 17:09:31 +00:00
|
|
|
extern const m_option_type_t m_option_type_intpair;
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_float;
|
|
|
|
extern const m_option_type_t m_option_type_double;
|
|
|
|
extern const m_option_type_t m_option_type_string;
|
|
|
|
extern const m_option_type_t m_option_type_string_list;
|
|
|
|
extern const m_option_type_t m_option_type_position;
|
|
|
|
extern const m_option_type_t m_option_type_time;
|
|
|
|
extern const m_option_type_t m_option_type_time_size;
|
2010-12-17 23:00:28 +00:00
|
|
|
extern const m_option_type_t m_option_type_choice;
|
2007-11-09 06:50:53 +00:00
|
|
|
|
|
|
|
extern const m_option_type_t m_option_type_print;
|
|
|
|
extern const m_option_type_t m_option_type_print_func;
|
2012-08-05 21:34:28 +00:00
|
|
|
extern const m_option_type_t m_option_type_print_func_param;
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_subconfig;
|
2012-08-06 15:45:17 +00:00
|
|
|
extern const m_option_type_t m_option_type_subconfig_struct;
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_imgfmt;
|
|
|
|
extern const m_option_type_t m_option_type_afmt;
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2012-05-07 23:10:39 +00:00
|
|
|
// Callback used by m_option_type_print_func options.
|
2010-02-25 22:32:28 +00:00
|
|
|
typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
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 {
|
2011-07-03 12:42:04 +00:00
|
|
|
double pos;
|
|
|
|
int type;
|
2006-09-25 16:47:56 +00:00
|
|
|
} m_time_size_t;
|
|
|
|
|
2011-07-03 12:42: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 {
|
2011-07-03 12:42:04 +00:00
|
|
|
// Pointer to an array of pointer to some object type description struct.
|
|
|
|
void **list;
|
|
|
|
// Offset of the object type name (char*) in the description struct.
|
|
|
|
void *name_off;
|
|
|
|
// Offset of the object type info string (char*) in the description struct.
|
|
|
|
void *info_off;
|
|
|
|
// Offset of the object type parameter description (\ref m_struct_st)
|
|
|
|
// in the description struct.
|
|
|
|
void *desc_off;
|
2003-03-15 18:01:02 +00:00
|
|
|
} m_obj_list_t;
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The data type used by \ref m_option_type_obj_settings_list.
|
2006-04-24 19:20:04 +00:00
|
|
|
typedef struct m_obj_settings {
|
2011-07-03 12:42:04 +00:00
|
|
|
// Type of the object.
|
|
|
|
char *name;
|
|
|
|
// NULL terminated array of parameter/value pairs.
|
|
|
|
char **attribs;
|
2003-03-15 18:01:02 +00:00
|
|
|
} m_obj_settings_t;
|
|
|
|
|
2011-07-03 12:42:04 +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.
|
|
|
|
*/
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_obj_settings_list;
|
2003-03-15 18:01:02 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Extra definition needed for \ref m_option_type_obj_presets options.
|
2003-03-15 18:01:02 +00:00
|
|
|
typedef struct {
|
2011-07-03 12:42:04 +00:00
|
|
|
// Description of the struct holding the presets.
|
|
|
|
const struct m_struct_st *in_desc;
|
|
|
|
// Description of the struct that should be set by the presets.
|
|
|
|
const struct m_struct_st *out_desc;
|
|
|
|
// Pointer to an array of structs defining the various presets.
|
|
|
|
const 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
|
|
|
|
2011-07-03 12:42: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.
|
|
|
|
*/
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_obj_presets;
|
2003-03-15 18:01:02 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Parse an URL into a struct.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** 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.
|
|
|
|
*/
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_custom_url;
|
2003-04-02 16:11:15 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Extra definition needed for \ref m_option_type_obj_params options.
|
2003-04-02 16:11:15 +00:00
|
|
|
typedef struct {
|
2011-07-03 12:42:04 +00:00
|
|
|
// Field descriptions.
|
|
|
|
const 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
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Parse a set of parameters.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** 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.
|
|
|
|
*/
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_option_type_t m_option_type_obj_params;
|
2003-04-02 16:11:15 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-07-03 12:42:04 +00:00
|
|
|
int start;
|
|
|
|
int end;
|
2003-04-02 16:11:15 +00:00
|
|
|
} m_span_t;
|
2011-07-03 12:42:04 +00:00
|
|
|
// Ready made settings to parse a \ref m_span_t with a start-end syntax.
|
2007-11-09 06:50:53 +00:00
|
|
|
extern const m_obj_params_t m_span_params_def;
|
2003-04-02 16:11:15 +00:00
|
|
|
|
2010-12-17 23:00:28 +00:00
|
|
|
struct m_opt_choice_alternatives {
|
|
|
|
char *name;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
2012-08-06 15:45:17 +00:00
|
|
|
// m_option.priv points to this if M_OPT_TYPE_USE_SUBSTRUCT is used
|
|
|
|
struct m_sub_options {
|
|
|
|
const struct m_option *opts;
|
|
|
|
size_t size;
|
|
|
|
const void *defaults;
|
|
|
|
};
|
2003-04-02 16:11:15 +00:00
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
// FIXME: backward compatibility
|
2011-07-03 12:42:04 +00:00
|
|
|
#define CONF_TYPE_FLAG (&m_option_type_flag)
|
|
|
|
#define CONF_TYPE_INT (&m_option_type_int)
|
|
|
|
#define CONF_TYPE_INT64 (&m_option_type_int64)
|
|
|
|
#define CONF_TYPE_FLOAT (&m_option_type_float)
|
|
|
|
#define CONF_TYPE_DOUBLE (&m_option_type_double)
|
|
|
|
#define CONF_TYPE_STRING (&m_option_type_string)
|
|
|
|
#define CONF_TYPE_PRINT (&m_option_type_print)
|
|
|
|
#define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func)
|
|
|
|
#define CONF_TYPE_SUBCONFIG (&m_option_type_subconfig)
|
|
|
|
#define CONF_TYPE_STRING_LIST (&m_option_type_string_list)
|
|
|
|
#define CONF_TYPE_POSITION (&m_option_type_position)
|
|
|
|
#define CONF_TYPE_IMGFMT (&m_option_type_imgfmt)
|
|
|
|
#define CONF_TYPE_AFMT (&m_option_type_afmt)
|
|
|
|
#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)
|
2011-07-03 12:42:04 +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)
|
|
|
|
#define CONF_TYPE_TIME (&m_option_type_time)
|
|
|
|
#define CONF_TYPE_TIME_SIZE (&m_option_type_time_size)
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Option type description
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option_type {
|
2011-07-03 12:42:04 +00:00
|
|
|
const char *name;
|
|
|
|
// Size needed for the data.
|
|
|
|
unsigned int size;
|
2012-08-05 21:34:28 +00:00
|
|
|
// One of M_OPT_TYPE*.
|
2011-07-03 12:42:04 +00:00
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
// 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.
|
2011-07-27 17:59:44 +00:00
|
|
|
* may not be an argument meant for this option
|
2011-07-03 12:42:04 +00:00
|
|
|
* \param dst Pointer to the memory where the data should be written.
|
|
|
|
* If NULL the parameter validity should still be checked.
|
2011-07-27 17:59:44 +00:00
|
|
|
* \return On error a negative value is returned, on success the number
|
|
|
|
* of arguments consumed. For details see \ref OptionParserReturn.
|
2011-07-03 12:42:04 +00:00
|
|
|
*/
|
2011-07-28 08:07:47 +00:00
|
|
|
int (*parse)(const m_option_t *opt, struct bstr name, struct bstr param,
|
2012-08-05 21:34:28 +00:00
|
|
|
void *dst);
|
2011-07-03 12:42: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.
|
|
|
|
*/
|
|
|
|
char *(*print)(const m_option_t *opt, const void *val);
|
|
|
|
|
2012-05-07 23:10:39 +00:00
|
|
|
// Copy data between two locations. Deep copy if the data has pointers.
|
2011-07-03 12:42:04 +00:00
|
|
|
/** \param opt The option to copy.
|
|
|
|
* \param dst Pointer to the destination memory.
|
|
|
|
* \param src Pointer to the source memory.
|
|
|
|
*/
|
2012-08-04 09:14:38 +00:00
|
|
|
void (*copy)(const m_option_t *opt, void *dst, const void *src);
|
2011-07-03 12:42: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.
|
|
|
|
*/
|
|
|
|
void (*free)(void *dst);
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Option description
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option {
|
2011-07-03 12:42:04 +00:00
|
|
|
// Option name.
|
|
|
|
const char *name;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42: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
|
|
|
|
* use the priv field but this was inherited from older versions of the
|
|
|
|
* config code.
|
|
|
|
*/
|
|
|
|
void *p;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Option type.
|
|
|
|
const m_option_type_t *type;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// See \ref OptionFlags.
|
|
|
|
unsigned int flags;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// \brief Mostly useful for numeric types, the \ref M_OPT_MIN flags must
|
|
|
|
// also be set.
|
|
|
|
double min;
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// \brief Mostly useful for numeric types, the \ref M_OPT_MAX flags must
|
|
|
|
// also be set.
|
|
|
|
double max;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-07-03 12:42:04 +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.
|
|
|
|
* Now it can be used to pass any type of extra args needed by the parser.
|
|
|
|
*/
|
|
|
|
void *priv;
|
2008-03-31 03:19:29 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
int new;
|
2008-03-31 03:19:29 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
int offset;
|
2012-05-17 00:31:11 +00:00
|
|
|
|
|
|
|
// Initialize variable to given default before parsing options
|
|
|
|
void *defval;
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option has a minimum set in \ref m_option::min.
|
|
|
|
#define M_OPT_MIN (1 << 0)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option has a maximum set in \ref m_option::max.
|
|
|
|
#define M_OPT_MAX (1 << 1)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option has a minimum and maximum in m_option::min and m_option::max.
|
|
|
|
#define M_OPT_RANGE (M_OPT_MIN | M_OPT_MAX)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option is forbidden in config files.
|
|
|
|
#define M_OPT_NOCFG (1 << 2)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option is forbidden on the command line.
|
|
|
|
#define M_OPT_NOCMD (1 << 3)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option is global in the \ref Config.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** 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
|
|
|
|
*/
|
2011-07-03 12:42:04 +00:00
|
|
|
#define M_OPT_GLOBAL (1 << 4)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// The option should be set during command line pre-parsing
|
|
|
|
#define M_OPT_PRE_PARSE (1 << 6)
|
|
|
|
|
2012-08-06 15:42:53 +00:00
|
|
|
// For options with children, add all children as top-level arguments
|
|
|
|
// (e.g. "--parent=child=value" becomes "--parent-child=value")
|
|
|
|
#define M_OPT_PREFIXED (1 << 8)
|
|
|
|
|
|
|
|
// Similar to M_OPT_PREFIXED, but drop the prefix.
|
|
|
|
// (e.g. "--parent=child=value" becomes "--child=value")
|
|
|
|
#define M_OPT_MERGE (1 << 9)
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// These are kept for compatibility with older code.
|
|
|
|
#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_PRE_PARSE M_OPT_PRE_PARSE
|
|
|
|
|
|
|
|
// These flags are used to describe special parser capabilities or behavior.
|
|
|
|
|
|
|
|
// Suboption parser flag.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** 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.
|
|
|
|
*/
|
2011-07-03 12:42:04 +00:00
|
|
|
#define M_OPT_TYPE_HAS_CHILD (1 << 0)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42: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
|
|
|
*/
|
2011-07-03 12:42:04 +00:00
|
|
|
#define M_OPT_TYPE_ALLOW_WILDCARD (1 << 1)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42: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
|
|
|
*/
|
2011-07-03 12:42:04 +00:00
|
|
|
#define M_OPT_TYPE_DYNAMIC (1 << 2)
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2012-08-05 21:34:28 +00:00
|
|
|
// The parameter is optional and by default no parameter is preferred. If the
|
|
|
|
// "old syntax" is used, the command line parser will assume that the argument
|
|
|
|
// takes no parameter.
|
|
|
|
#define M_OPT_TYPE_OLD_SYNTAX_NO_PARAM (1 << 3)
|
|
|
|
|
2012-08-06 15:45:17 +00:00
|
|
|
// modify M_OPT_TYPE_HAS_CHILD so that m_option::p points to
|
|
|
|
// struct m_sub_options, instead of a direct m_option array.
|
|
|
|
#define M_OPT_TYPE_USE_SUBSTRUCT (1 << 4)
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
///////////////////////////// Parser flags /////////////////////////////////
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// On success parsers return the number of arguments consumed: 0 or 1.
|
|
|
|
//
|
|
|
|
// To indicate that MPlayer should exit without playing anything,
|
|
|
|
// parsers return M_OPT_EXIT minus the number of parameters they
|
|
|
|
// consumed: \ref M_OPT_EXIT or \ref M_OPT_EXIT-1.
|
|
|
|
//
|
|
|
|
// On error one of the following (negative) error codes is returned:
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// For use by higher level APIs when the option name is invalid.
|
|
|
|
#define M_OPT_UNKNOWN -1
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Returned when a parameter is needed but wasn't provided.
|
|
|
|
#define M_OPT_MISSING_PARAM -2
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Returned when the given parameter couldn't be parsed.
|
|
|
|
#define M_OPT_INVALID -3
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Returned if the value is "out of range". The exact meaning may
|
|
|
|
// vary from type to type.
|
|
|
|
#define M_OPT_OUT_OF_RANGE -4
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Returned if the parser failed for any other reason than a bad parameter.
|
|
|
|
#define M_OPT_PARSER_ERR -5
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Returned when MPlayer should exit. Used by various help stuff.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** 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
|
|
|
|
2011-07-29 04:52:29 +00:00
|
|
|
char *m_option_strerror(int code);
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Find the option matching the given name in the list.
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \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).
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param list Pointer to an array of \ref m_option.
|
|
|
|
* \param name Name of the option.
|
|
|
|
* \return The matching option or NULL.
|
|
|
|
*/
|
2011-07-03 12:42:04 +00:00
|
|
|
const m_option_t *m_option_list_find(const m_option_t *list, const char *name);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2010-12-18 06:02:48 +00:00
|
|
|
static inline void *m_option_get_ptr(const struct m_option *opt,
|
|
|
|
void *optstruct)
|
|
|
|
{
|
|
|
|
return opt->new ? (char *) optstruct + opt->offset : opt->p;
|
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Helper to parse options, see \ref m_option_type::parse.
|
2011-07-28 08:07:47 +00:00
|
|
|
static inline int m_option_parse(const m_option_t *opt, struct bstr name,
|
2012-08-05 21:34:28 +00:00
|
|
|
struct bstr param, void *dst)
|
2011-07-03 12:42:04 +00:00
|
|
|
{
|
2012-08-05 21:34:28 +00:00
|
|
|
return opt->type->parse(opt, name, param, dst);
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Helper to print options, see \ref m_option_type::print.
|
|
|
|
static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
|
|
|
|
{
|
|
|
|
if (opt->type->print)
|
|
|
|
return opt->type->print(opt, val_ptr);
|
|
|
|
else
|
2011-07-03 17:04:21 +00:00
|
|
|
return NULL;
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Helper around \ref m_option_type::copy.
|
|
|
|
static inline void m_option_copy(const m_option_t *opt, void *dst,
|
|
|
|
const void *src)
|
|
|
|
{
|
|
|
|
if (opt->type->copy)
|
2012-08-04 09:14:38 +00:00
|
|
|
opt->type->copy(opt, dst, src);
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 12:42:04 +00:00
|
|
|
// Helper around \ref m_option_type::free.
|
|
|
|
static inline void m_option_free(const m_option_t *opt, void *dst)
|
|
|
|
{
|
|
|
|
if (opt->type->free)
|
|
|
|
opt->type->free(dst);
|
2002-11-12 01:56:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
/*@}*/
|
|
|
|
|
2011-04-19 01:11:52 +00:00
|
|
|
#define OPTION_LIST_SEPARATOR ','
|
|
|
|
|
|
|
|
#if HAVE_DOS_PATHS
|
|
|
|
#define OPTION_PATH_SEPARATOR ';'
|
|
|
|
#else
|
|
|
|
#define OPTION_PATH_SEPARATOR ':'
|
|
|
|
#endif
|
|
|
|
|
2012-05-17 00:31:11 +00:00
|
|
|
#define OPTDEF_STR(s) .defval = (void *)&(char * const){s}
|
|
|
|
#define OPTDEF_INT(i) .defval = (void *)&(const int){i}
|
|
|
|
|
|
|
|
#define OPT_GENERAL(optname, varname, flagv, ...) {.name = optname, .flags = flagv, .new = 1, .offset = offsetof(OPT_BASE_STRUCT, varname), __VA_ARGS__}
|
|
|
|
|
|
|
|
/* The OPT_FLAG_CONSTANTS->OPT_FLAG_CONSTANTS_ kind of redirection exists to
|
|
|
|
* make the code fully standard-conforming: the C standard requires that
|
|
|
|
* __VA_ARGS__ has at least one argument (though GCC for example would accept
|
|
|
|
* 0). Thus the first OPT_FLAG_CONSTANTS is a wrapper which just adds one
|
|
|
|
* argument to ensure __VA_ARGS__ is not empty when calling the next macro.
|
|
|
|
*/
|
|
|
|
#define OPT_FLAG_ON(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_flag, .max = 1)
|
|
|
|
#define OPT_FLAG_OFF(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_flag, .min = 1)
|
2012-07-29 23:58:41 +00:00
|
|
|
#define OPT_MAKE_FLAGS OPT_FLAG_ON
|
2012-05-17 00:31:11 +00:00
|
|
|
#define OPT_FLAG_CONSTANTS(...) OPT_FLAG_CONSTANTS_(__VA_ARGS__, .type = &m_option_type_flag)
|
|
|
|
#define OPT_FLAG_CONSTANTS_(optname, varname, flags, offvalue, value, ...) OPT_GENERAL(optname, varname, flags, .min = offvalue, .max = value, __VA_ARGS__)
|
|
|
|
#define OPT_STRINGLIST(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_string_list)
|
|
|
|
#define OPT_PATHLIST(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_string_list, .priv = (void *)&(const char){OPTION_PATH_SEPARATOR})
|
|
|
|
#define OPT_INT(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_int)
|
|
|
|
#define OPT_INTRANGE(...) OPT_RANGE_(__VA_ARGS__, .type = &m_option_type_int)
|
|
|
|
#define OPT_RANGE_(optname, varname, flags, minval, maxval, ...) OPT_GENERAL(optname, varname, (flags) | CONF_RANGE, .min = minval, .max = maxval, __VA_ARGS__)
|
|
|
|
#define OPT_INTPAIR(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_intpair)
|
|
|
|
#define OPT_FLOAT(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_float)
|
|
|
|
#define OPT_FLOATRANGE(...) OPT_RANGE_(__VA_ARGS__, .type = &m_option_type_float)
|
|
|
|
#define OPT_STRING(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_string)
|
|
|
|
#define OPT_SETTINGSLIST(optname, varname, flags, objlist) OPT_GENERAL(optname, varname, flags, .type = &m_option_type_obj_settings_list, .priv = objlist)
|
|
|
|
#define OPT_AUDIOFORMAT(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_afmt)
|
2010-12-17 23:00:28 +00:00
|
|
|
#define OPT_HELPER_REMOVEPAREN(...) __VA_ARGS__
|
2012-05-17 00:31:11 +00:00
|
|
|
#define OPT_CHOICE(...) OPT_CHOICE_(__VA_ARGS__, .type = &m_option_type_choice)
|
|
|
|
#define OPT_CHOICE_(optname, varname, flags, choices, ...) OPT_GENERAL(optname, varname, flags, .priv = (void *)&(const struct m_opt_choice_alternatives[]){OPT_HELPER_REMOVEPAREN choices, {NULL}}, __VA_ARGS__)
|
2012-09-05 00:17:13 +00:00
|
|
|
// Union of choices and an int range. The choice values can be included in the
|
|
|
|
// int range, or be completely separate - both works.
|
|
|
|
#define OPT_CHOICE_OR_INT(...) OPT_CHOICE_OR_INT_(__VA_ARGS__, .type = &m_option_type_choice)
|
|
|
|
#define OPT_CHOICE_OR_INT_(optname, varname, flags, minval, maxval, choices, ...) OPT_GENERAL(optname, varname, (flags) | CONF_RANGE, .min = minval, .max = maxval, .priv = (void *)&(const struct m_opt_choice_alternatives[]){OPT_HELPER_REMOVEPAREN choices, {NULL}}, __VA_ARGS__)
|
2012-05-17 00:31:11 +00:00
|
|
|
#define OPT_TIME(...) OPT_GENERAL(__VA_ARGS__, .type = &m_option_type_time)
|
|
|
|
|
2012-09-05 00:39:12 +00:00
|
|
|
#define OPT_TRACKCHOICE(name, var) OPT_CHOICE_OR_INT(name, var, 0, 0, 8190, ({"off", -2}, {"no", -2}, {"auto", -1}))
|
|
|
|
|
2012-08-06 15:45:17 +00:00
|
|
|
// subconf must have the type struct m_sub_options.
|
|
|
|
// flagv should be M_OPT_MERGE or M_OPT_FLATTEN.
|
|
|
|
// varname refers to the field, that must be a pointer to a field described by
|
|
|
|
// the subconf struct.
|
|
|
|
#define OPT_SUBSTRUCT(varname, subconf, flagv) OPT_GENERAL("-", varname, flagv, .type = &m_option_type_subconfig_struct, .priv = (void*)&subconf)
|
|
|
|
|
2012-05-17 00:31:11 +00:00
|
|
|
#define OPT_BASE_STRUCT struct MPOpts
|
2008-04-23 23:10:37 +00:00
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_M_OPTION_H */
|