talloc.[ch]: remove "type safety" hack that violates C types
[mplayer.git] / m_config.h
blob75dd85ac1402f8835274f2e7b60ac329828bb7a6
1 /*
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
22 #include <stdbool.h>
24 #include "bstr.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;
31 struct m_option;
32 struct m_option_type;
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.
39 int lvl;
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)));
45 // Config option
46 struct m_config_option {
47 struct m_config_option *next;
48 // Full name (ie option:subopt).
49 char *name;
50 // Option description.
51 const struct m_option *opt;
52 // Save slot stack.
53 struct m_config_save_slot *slots;
54 // See \ref ConfigOptionFlags.
55 unsigned int flags;
58 // Profiles allow to predefine some sets of options that can then
59 // be applied later on with the internal -profile option.
61 // Config profile
62 struct m_profile {
63 struct m_profile *next;
64 char *name;
65 char *desc;
66 int num_opts;
67 // Option/value pair array.
68 char **opts;
71 enum option_source {
72 // Set when parsing from a config file.
73 M_CONFIG_FILE,
74 // Set when parsing command line arguments.
75 M_COMMAND_LINE,
76 // Set when pre-parsing the command line
77 M_COMMAND_LINE_PRE_PARSE,
80 // Config object
81 /** \ingroup Config */
82 typedef struct m_config {
83 // Registered options.
84 /** This contains all options and suboptions.
86 struct m_config_option *opts;
87 // Current stack level.
88 int lvl;
89 enum option_source mode;
90 // List of defined profiles.
91 struct m_profile *profiles;
92 // Depth when recursively including profiles.
93 int profile_depth;
95 void *optstruct; // struct mpopts or other
96 } m_config_t;
99 // Set if an option has been set at the current level.
100 #define M_CFG_OPT_SET (1 << 0)
102 // Set if another option already uses the same variable.
103 #define M_CFG_OPT_ALIAS (1 << 1)
105 // Create a new config object.
106 struct m_config *
107 m_config_new(void *optstruct,
108 int includefunc(struct m_option *conf, char *filename));
110 // Free a config object.
111 void m_config_free(struct m_config *config);
113 /* Push a new context.
114 * \param config The config object.
116 void m_config_push(struct m_config *config);
118 /* Pop the current context restoring the previous context state.
119 * \param config The config object.
121 void m_config_pop(struct m_config *config);
123 /* Register some options to be used.
124 * \param config The config object.
125 * \param args An array of \ref m_option struct.
126 * \return 1 on success, 0 on failure.
128 int m_config_register_options(struct m_config *config,
129 const struct m_option *args);
131 /* Set an option.
132 * \param config The config object.
133 * \param name The option's name.
134 * \param param The value of the option, can be NULL.
135 * \param ambiguous_param: old style cmdline option, "param" may be a
136 parameter to this option or something entirely unrelated
137 * \return See \ref OptionParserReturn.
139 int m_config_set_option(struct m_config *config, struct bstr name,
140 struct bstr param, bool ambiguous_param);
142 static inline int m_config_set_option0(struct m_config *config,
143 const char *name, const char *param,
144 bool ambiguous)
146 return m_config_set_option(config, bstr(name), bstr(param), ambiguous);
149 /* Check if an option setting is valid.
150 * Same as above m_config_set_option() but doesn't actually set anything.
152 int m_config_check_option(const struct m_config *config, struct bstr name,
153 struct bstr param, bool ambiguous_param);
155 static inline int m_config_check_option0(struct m_config *config,
156 const char *name, const char *param,
157 bool ambiguous)
159 return m_config_check_option(config, bstr(name), bstr(param), ambiguous);
163 /* Get the option matching the given name.
164 * \param config The config object.
165 * \param name The option's name.
167 const struct m_option *m_config_get_option(const struct m_config *config,
168 struct bstr name);
170 /* Print a list of all registered options.
171 * \param config The config object.
173 void m_config_print_option_list(const struct m_config *config);
176 /* Find the profile with the given name.
177 * \param config The config object.
178 * \param arg The profile's name.
179 * \return The profile object or NULL.
181 struct m_profile *m_config_get_profile(const struct m_config *config,
182 char *name);
184 /* Get the profile with the given name, creating it if necessary.
185 * \param config The config object.
186 * \param arg The profile's name.
187 * \return The profile object.
189 struct m_profile *m_config_add_profile(struct m_config *config, char *name);
191 /* Set the description of a profile.
192 * Used by the config file parser when defining a profile.
194 * \param p The profile object.
195 * \param arg The profile's name.
197 void m_profile_set_desc(struct m_profile *p, char *desc);
199 /* Add an option to a profile.
200 * Used by the config file parser when defining a profile.
202 * \param config The config object.
203 * \param p The profile object.
204 * \param name The option's name.
205 * \param val The option's value.
207 int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
208 char *name, char *val);
210 /* Enables profile usage
211 * Used by the config file parser when loading a profile.
213 * \param config The config object.
214 * \param p The profile object.
216 void m_config_set_profile(struct m_config *config, struct m_profile *p);
218 #endif /* MPLAYER_M_CONFIG_H */