summaryrefslogtreecommitdiffstats
path: root/core/m_config.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/m_config.h')
-rw-r--r--core/m_config.h92
1 files changed, 40 insertions, 52 deletions
diff --git a/core/m_config.h b/core/m_config.h
index 35955cfa4b..c2f88dfe65 100644
--- a/core/m_config.h
+++ b/core/m_config.h
@@ -19,6 +19,7 @@
#ifndef MPLAYER_M_CONFIG_H
#define MPLAYER_M_CONFIG_H
+#include <stddef.h>
#include <stdbool.h>
#include "core/bstr.h"
@@ -36,66 +37,54 @@ struct m_obj_desc;
// Config option
struct m_config_option {
struct m_config_option *next;
- // For positional parameters
- int pos;
+ bool is_generated : 1;
// Full name (ie option-subopt).
char *name;
// Option description.
const struct m_option *opt;
// Raw value of the option.
void *data;
- // Raw value of the backup of the global value (or NULL).
- void *global_backup;
// If this is a suboption, the option that contains this option.
struct m_config_option *parent;
- // If this option aliases another, more important option. The alias_owner
- // option is the one that has the most correct option type for the data
- // variable, and which is considered the original.
- struct m_config_option *alias_owner;
-};
-
-// Profiles allow to predefine some sets of options that can then
-// be applied later on with the internal -profile option.
-
-// Config profile
-struct m_profile {
- struct m_profile *next;
- char *name;
- char *desc;
- int num_opts;
- // Option/value pair array.
- char **opts;
};
// Config object
/** \ingroup Config */
typedef struct m_config {
// Registered options.
- /** This contains all options and suboptions.
- */
- struct m_config_option *opts;
- int num_pos_opts;
- // When options are set (via m_config_set_option or m_config_set_profile),
- // back up the old value (unless it's already backed up). Used for restoring
- // global options when per-file options are set.
- bool file_local_mode;
+ struct m_config_option *opts; // all options, even suboptions
// List of defined profiles.
struct m_profile *profiles;
// Depth when recursively including profiles.
int profile_depth;
- void *optstruct; // struct mpopts or other
- int (*includefunc)(struct m_config *conf, char *filename);
+ struct m_opt_backup *backup_opts;
+
bool use_profiles;
+ int (*includefunc)(struct m_config *conf, char *filename, int flags);
+
+ const void *optstruct_defaults;
+ size_t optstruct_size;
+ const struct m_option *options; // top-level options
+ const char *suboptinit;
+
+ void *optstruct; // struct mpopts or other
} m_config_t;
// Create a new config object.
-struct m_config *
-m_config_new(void *optstruct,
- int includefunc(struct m_config *conf, char *filename));
-
-struct m_config *m_config_simple(void *optstruct);
+// talloc_parent: talloc parent context for the m_config allocation
+// size: size of the optstruct (where option values are stored)
+// defaults: if not NULL, points to a struct of same type as optstruct, which
+// contains default values for all options
+// options: list of options. Each option defines a member of the optstruct
+// and a corresponding option switch or sub-option field.
+// suboptinit: if not NULL, initialize the suboption string (used for presets)
+// Note that the m_config object will keep pointers to defaults and options.
+struct m_config *m_config_new(void *talloc_parent, size_t size,
+ const void *defaults,
+ const struct m_option *options,
+ const char *suboptinit);
struct m_config *m_config_from_obj_desc(void *talloc_parent,
struct m_obj_desc *desc);
@@ -107,26 +96,22 @@ int m_config_set_obj_params(struct m_config *conf, char **args);
int m_config_initialize_obj(struct m_config *config, struct m_obj_desc *desc,
void **ppriv, char ***pargs);
-// Free a config object.
-void m_config_free(struct m_config *config);
+// Make sure the option is backed up. If it's already backed up, do nothing.
+// All backed up options can be restored with m_config_restore_backups().
+void m_config_backup_opt(struct m_config *config, const char *opt);
-void m_config_enter_file_local(struct m_config *config);
-void m_config_leave_file_local(struct m_config *config);
-void m_config_mark_file_local(struct m_config *config, const char *opt);
-void m_config_mark_all_file_local(struct m_config *config);
+// Call m_config_backup_opt() on all options.
+void m_config_backup_all_opts(struct m_config *config);
-/* Register some options to be used.
- * \param config The config object.
- * \param args An array of \ref m_option struct.
- * \return 1 on success, 0 on failure.
- */
-int m_config_register_options(struct m_config *config,
- const struct m_option *args);
+// Restore all options backed up with m_config_backup_opt(), and delete the
+// backups afterwards.
+void m_config_restore_backups(struct m_config *config);
enum {
M_SETOPT_PRE_PARSE_ONLY = 1, // Silently ignore non-M_OPT_PRE_PARSE opt.
M_SETOPT_CHECK_ONLY = 2, // Don't set, just check name/value
M_SETOPT_FROM_CONFIG_FILE = 4, // Reject M_OPT_NOCFG opt. (print error)
+ M_SETOPT_BACKUP = 8, // Call m_config_backup_opt() before
};
// Set the named option to the given string.
@@ -186,8 +171,9 @@ void m_config_print_option_list(const struct m_config *config);
* \param arg The profile's name.
* \return The profile object or NULL.
*/
-struct m_profile *m_config_get_profile(const struct m_config *config,
- char *name);
+struct m_profile *m_config_get_profile0(const struct m_config *config,
+ char *name);
+struct m_profile *m_config_get_profile(const struct m_config *config, bstr name);
/* Get the profile with the given name, creating it if necessary.
* \param config The config object.
@@ -220,8 +206,10 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
*
* \param config The config object.
* \param p The profile object.
+ * \param flags M_SETOPT_* bits
*/
-void m_config_set_profile(struct m_config *config, struct m_profile *p);
+void m_config_set_profile(struct m_config *config, struct m_profile *p,
+ int flags);
void *m_config_alloc_struct(void *talloc_parent,
const struct m_sub_options *subopts);