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_CONFIG_H
|
|
|
|
#define MPLAYER_M_CONFIG_H
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-27 17:59:44 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2011-07-28 08:07:47 +00:00
|
|
|
#include "bstr.h"
|
2011-07-27 17:59:44 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// m_config provides an API to manipulate the config variables in MPlayer.
|
|
|
|
// It makes use of the Options API to provide a context stack that
|
|
|
|
// allows saving and later restoring the state of all variables.
|
|
|
|
|
2006-01-24 11:16:13 +00:00
|
|
|
typedef struct m_profile m_profile_t;
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_option;
|
|
|
|
struct m_option_type;
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config option save slot
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_config_save_slot {
|
2011-07-05 19:31:44 +00:00
|
|
|
// Previous level slot.
|
|
|
|
struct m_config_save_slot *prev;
|
|
|
|
// Level at which the save was made.
|
|
|
|
int lvl;
|
|
|
|
// We have to store other datatypes in this as well,
|
|
|
|
// so make sure we get properly aligned addresses.
|
|
|
|
unsigned char data[0] __attribute__ ((aligned(8)));
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config option
|
2002-11-12 01:56:42 +00:00
|
|
|
struct m_config_option {
|
2011-07-05 19:31:44 +00:00
|
|
|
struct m_config_option *next;
|
|
|
|
// Full name (ie option:subopt).
|
|
|
|
char *name;
|
2011-09-04 11:34:45 +00:00
|
|
|
// Compiled without support for this option? If so set to name of feature
|
|
|
|
char *disabled_feature;
|
2011-07-05 19:31:44 +00:00
|
|
|
// Option description.
|
|
|
|
const struct m_option *opt;
|
|
|
|
// Save slot stack.
|
|
|
|
struct m_config_save_slot *slots;
|
|
|
|
// See \ref ConfigOptionFlags.
|
|
|
|
unsigned int flags;
|
2002-11-12 01:56:42 +00:00
|
|
|
};
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Profiles allow to predefine some sets of options that can then
|
|
|
|
// be applied later on with the internal -profile option.
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config profile
|
2006-01-24 11:16:13 +00:00
|
|
|
struct m_profile {
|
2011-07-05 19:31:44 +00:00
|
|
|
struct m_profile *next;
|
|
|
|
char *name;
|
|
|
|
char *desc;
|
|
|
|
int num_opts;
|
|
|
|
// Option/value pair array.
|
|
|
|
char **opts;
|
2006-01-24 11:16:13 +00:00
|
|
|
};
|
|
|
|
|
2011-07-27 17:59:44 +00:00
|
|
|
enum option_source {
|
|
|
|
// Set when parsing from a config file.
|
|
|
|
M_CONFIG_FILE,
|
|
|
|
// Set when parsing command line arguments.
|
|
|
|
M_COMMAND_LINE,
|
|
|
|
// Set when pre-parsing the command line
|
|
|
|
M_COMMAND_LINE_PRE_PARSE,
|
|
|
|
};
|
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Config object
|
2006-04-24 19:20:04 +00:00
|
|
|
/** \ingroup Config */
|
2002-11-12 01:56:42 +00:00
|
|
|
typedef struct m_config {
|
2011-07-05 19:31:44 +00:00
|
|
|
// Registered options.
|
|
|
|
/** This contains all options and suboptions.
|
|
|
|
*/
|
|
|
|
struct m_config_option *opts;
|
|
|
|
// Current stack level.
|
|
|
|
int lvl;
|
2011-07-27 17:59:44 +00:00
|
|
|
enum option_source mode;
|
2011-07-05 19:31:44 +00:00
|
|
|
// List of defined profiles.
|
|
|
|
struct m_profile *profiles;
|
|
|
|
// Depth when recursively including profiles.
|
|
|
|
int profile_depth;
|
|
|
|
|
|
|
|
void *optstruct; // struct mpopts or other
|
2002-11-12 01:56:42 +00:00
|
|
|
} m_config_t;
|
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Set if an option has been set at the current level.
|
|
|
|
#define M_CFG_OPT_SET (1 << 0)
|
2003-04-12 13:40:30 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Set if another option already uses the same variable.
|
|
|
|
#define M_CFG_OPT_ALIAS (1 << 1)
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Create a new config object.
|
|
|
|
struct m_config *
|
2008-04-26 07:44:59 +00:00
|
|
|
m_config_new(void *optstruct,
|
|
|
|
int includefunc(struct m_option *conf, char *filename));
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
// Free a config object.
|
|
|
|
void m_config_free(struct m_config *config);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Push a new context.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
void m_config_push(struct m_config *config);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Pop the current context restoring the previous context state.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
void m_config_pop(struct m_config *config);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Register some options to be used.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param args An array of \ref m_option struct.
|
|
|
|
* \return 1 on success, 0 on failure.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
int m_config_register_options(struct m_config *config,
|
|
|
|
const struct m_option *args);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Set an option.
|
|
|
|
* \param config The config object.
|
2011-07-28 08:07:47 +00:00
|
|
|
* \param name The option's name.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param param The value of the option, can be NULL.
|
2011-07-27 17:59:44 +00:00
|
|
|
* \param ambiguous_param: old style cmdline option, "param" may be a
|
|
|
|
parameter to this option or something entirely unrelated
|
2006-04-24 19:20:04 +00:00
|
|
|
* \return See \ref OptionParserReturn.
|
|
|
|
*/
|
2011-07-28 08:07:47 +00:00
|
|
|
int m_config_set_option(struct m_config *config, struct bstr name,
|
|
|
|
struct bstr param, bool ambiguous_param);
|
|
|
|
|
|
|
|
static inline int m_config_set_option0(struct m_config *config,
|
|
|
|
const char *name, const char *param,
|
|
|
|
bool ambiguous)
|
|
|
|
{
|
|
|
|
return m_config_set_option(config, bstr(name), bstr(param), ambiguous);
|
|
|
|
}
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Check if an option setting is valid.
|
2011-07-27 17:59:44 +00:00
|
|
|
* Same as above m_config_set_option() but doesn't actually set anything.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2011-07-28 08:07:47 +00:00
|
|
|
int m_config_check_option(const struct m_config *config, struct bstr name,
|
|
|
|
struct bstr param, bool ambiguous_param);
|
|
|
|
|
|
|
|
static inline int m_config_check_option0(struct m_config *config,
|
|
|
|
const char *name, const char *param,
|
|
|
|
bool ambiguous)
|
|
|
|
{
|
|
|
|
return m_config_check_option(config, bstr(name), bstr(param), ambiguous);
|
|
|
|
}
|
2011-07-27 17:59:44 +00:00
|
|
|
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Get the option matching the given name.
|
|
|
|
* \param config The config object.
|
2011-07-28 08:07:47 +00:00
|
|
|
* \param name The option's name.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
const struct m_option *m_config_get_option(const struct m_config *config,
|
2011-07-28 08:07:47 +00:00
|
|
|
struct bstr name);
|
2002-11-12 01:56:42 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Print a list of all registered options.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
void m_config_print_option_list(const struct m_config *config);
|
2002-11-12 12:39:05 +00:00
|
|
|
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Find the profile with the given name.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param arg The profile's name.
|
|
|
|
* \return The profile object or NULL.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
struct m_profile *m_config_get_profile(const struct m_config *config,
|
|
|
|
char *name);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Get the profile with the given name, creating it if necessary.
|
|
|
|
* \param config The config object.
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param arg The profile's name.
|
|
|
|
* \return The profile object.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
struct m_profile *m_config_add_profile(struct m_config *config, char *name);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Set the description of a profile.
|
|
|
|
* Used by the config file parser when defining a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param p The profile object.
|
|
|
|
* \param arg The profile's name.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
void m_profile_set_desc(struct m_profile *p, char *desc);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Add an option to a profile.
|
|
|
|
* Used by the config file parser when defining a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2006-04-24 19:20:04 +00:00
|
|
|
* \param config The config object.
|
|
|
|
* \param p The profile object.
|
|
|
|
* \param name The option's name.
|
|
|
|
* \param val The option's value.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
|
|
|
|
char *name, char *val);
|
2006-01-24 11:16:13 +00:00
|
|
|
|
2011-07-05 19:31:44 +00:00
|
|
|
/* Enables profile usage
|
|
|
|
* Used by the config file parser when loading a profile.
|
2009-07-06 23:26:13 +00:00
|
|
|
*
|
2008-01-10 18:41:21 +00:00
|
|
|
* \param config The config object.
|
|
|
|
* \param p The profile object.
|
|
|
|
*/
|
2011-07-05 19:31:44 +00:00
|
|
|
void m_config_set_profile(struct m_config *config, struct m_profile *p);
|
2006-04-24 19:20:04 +00:00
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_M_CONFIG_H */
|