2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_M_CONFIG_H
20 #define MPLAYER_M_CONFIG_H
26 // m_config provides an API to manipulate the config variables in MPlayer.
27 // It makes use of the Options API to provide a context stack that
28 // allows saving and later restoring the state of all variables.
30 typedef struct m_profile m_profile_t
;
34 // Config option save slot
35 struct m_config_save_slot
{
36 // Previous level slot.
37 struct m_config_save_slot
*prev
;
38 // Level at which the save was made.
40 // We have to store other datatypes in this as well,
41 // so make sure we get properly aligned addresses.
42 unsigned char data
[0] __attribute__ ((aligned(8)));
46 struct m_config_option
{
47 struct m_config_option
*next
;
48 // Full name (ie option:subopt).
50 // Compiled without support for this option? If so set to name of feature
51 char *disabled_feature
;
52 // Option description.
53 const struct m_option
*opt
;
55 struct m_config_save_slot
*slots
;
56 // See \ref ConfigOptionFlags.
60 // Profiles allow to predefine some sets of options that can then
61 // be applied later on with the internal -profile option.
65 struct m_profile
*next
;
69 // Option/value pair array.
74 // Set when parsing from a config file.
76 // Set when parsing command line arguments.
78 // Set when pre-parsing the command line
79 M_COMMAND_LINE_PRE_PARSE
,
83 /** \ingroup Config */
84 typedef struct m_config
{
85 // Registered options.
86 /** This contains all options and suboptions.
88 struct m_config_option
*opts
;
89 // Current stack level.
91 enum option_source mode
;
92 // List of defined profiles.
93 struct m_profile
*profiles
;
94 // Depth when recursively including profiles.
97 void *optstruct
; // struct mpopts or other
101 // Set if an option has been set at the current level.
102 #define M_CFG_OPT_SET (1 << 0)
104 // Set if another option already uses the same variable.
105 #define M_CFG_OPT_ALIAS (1 << 1)
107 // Create a new config object.
109 m_config_new(void *optstruct
,
110 int includefunc(struct m_option
*conf
, char *filename
));
112 // Free a config object.
113 void m_config_free(struct m_config
*config
);
115 /* Push a new context.
116 * \param config The config object.
118 void m_config_push(struct m_config
*config
);
120 /* Pop the current context restoring the previous context state.
121 * \param config The config object.
123 void m_config_pop(struct m_config
*config
);
125 /* Register some options to be used.
126 * \param config The config object.
127 * \param args An array of \ref m_option struct.
128 * \return 1 on success, 0 on failure.
130 int m_config_register_options(struct m_config
*config
,
131 const struct m_option
*args
);
134 * \param config The config object.
135 * \param name The option's name.
136 * \param param The value of the option, can be NULL.
137 * \param ambiguous_param: old style cmdline option, "param" may be a
138 parameter to this option or something entirely unrelated
139 * \return See \ref OptionParserReturn.
141 int m_config_set_option(struct m_config
*config
, struct bstr name
,
142 struct bstr param
, bool ambiguous_param
);
144 static inline int m_config_set_option0(struct m_config
*config
,
145 const char *name
, const char *param
,
148 return m_config_set_option(config
, bstr(name
), bstr(param
), ambiguous
);
151 /* Check if an option setting is valid.
152 * Same as above m_config_set_option() but doesn't actually set anything.
154 int m_config_check_option(const struct m_config
*config
, struct bstr name
,
155 struct bstr param
, bool ambiguous_param
);
157 static inline int m_config_check_option0(struct m_config
*config
,
158 const char *name
, const char *param
,
161 return m_config_check_option(config
, bstr(name
), bstr(param
), ambiguous
);
165 /* Get the option matching the given name.
166 * \param config The config object.
167 * \param name The option's name.
169 const struct m_option
*m_config_get_option(const struct m_config
*config
,
172 /* Print a list of all registered options.
173 * \param config The config object.
175 void m_config_print_option_list(const struct m_config
*config
);
178 /* Find the profile with the given name.
179 * \param config The config object.
180 * \param arg The profile's name.
181 * \return The profile object or NULL.
183 struct m_profile
*m_config_get_profile(const struct m_config
*config
,
186 /* Get the profile with the given name, creating it if necessary.
187 * \param config The config object.
188 * \param arg The profile's name.
189 * \return The profile object.
191 struct m_profile
*m_config_add_profile(struct m_config
*config
, char *name
);
193 /* Set the description of a profile.
194 * Used by the config file parser when defining a profile.
196 * \param p The profile object.
197 * \param arg The profile's name.
199 void m_profile_set_desc(struct m_profile
*p
, char *desc
);
201 /* Add an option to a profile.
202 * Used by the config file parser when defining a profile.
204 * \param config The config object.
205 * \param p The profile object.
206 * \param name The option's name.
207 * \param val The option's value.
209 int m_config_set_profile_option(struct m_config
*config
, struct m_profile
*p
,
210 char *name
, char *val
);
212 /* Enables profile usage
213 * Used by the config file parser when loading a profile.
215 * \param config The config object.
216 * \param p The profile object.
218 void m_config_set_profile(struct m_config
*config
, struct m_profile
*p
);
220 #endif /* MPLAYER_M_CONFIG_H */