summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
Diffstat (limited to 'options')
-rw-r--r--options/m_option.c31
-rw-r--r--options/m_option.h26
-rw-r--r--options/options.c22
-rw-r--r--options/options.h1
4 files changed, 26 insertions, 54 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 5de59500f9..9f98008c64 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -1153,36 +1153,11 @@ const m_option_type_t m_option_type_string_list = {
static int parse_print(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{
- if (opt->type == CONF_TYPE_PRINT) {
- const char *msg = opt->p;
- mp_info(log, "%s", msg);
- } else {
- char *name0 = bstrdup0(NULL, name);
- char *param0 = bstrdup0(NULL, param);
- int r = ((m_opt_func_full_t) opt->p)(log, opt, name0, param0);
- talloc_free(name0);
- talloc_free(param0);
- return r;
- }
-
- if (opt->priv == NULL)
- return M_OPT_EXIT;
- return 0;
+ ((m_opt_print_fn) opt->priv)(log);
+ return M_OPT_EXIT;
}
-const m_option_type_t m_option_type_print = {
- .name = "Print",
- .flags = M_OPT_TYPE_OPTIONAL_PARAM,
- .parse = parse_print,
-};
-
-const m_option_type_t m_option_type_print_func_param = {
- .name = "Print",
- .flags = M_OPT_TYPE_ALLOW_WILDCARD,
- .parse = parse_print,
-};
-
-const m_option_type_t m_option_type_print_func = {
+const m_option_type_t m_option_type_print_fn = {
.name = "Print",
.flags = M_OPT_TYPE_ALLOW_WILDCARD | M_OPT_TYPE_OPTIONAL_PARAM,
.parse = parse_print,
diff --git a/options/m_option.h b/options/m_option.h
index abc45b07aa..7f9b89bea1 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -50,9 +50,7 @@ extern const m_option_type_t m_option_type_time;
extern const m_option_type_t m_option_type_rel_time;
extern const m_option_type_t m_option_type_choice;
extern const m_option_type_t m_option_type_msglevels;
-extern const m_option_type_t m_option_type_print;
-extern const m_option_type_t m_option_type_print_func;
-extern const m_option_type_t m_option_type_print_func_param;
+extern const m_option_type_t m_option_type_print_fn;
extern const m_option_type_t m_option_type_subconfig;
extern const m_option_type_t m_option_type_subconfig_struct;
extern const m_option_type_t m_option_type_imgfmt;
@@ -63,9 +61,8 @@ extern const m_option_type_t m_option_type_geometry;
extern const m_option_type_t m_option_type_size_box;
extern const m_option_type_t m_option_type_chmap;
-// Callback used by m_option_type_print_func options.
-typedef int (*m_opt_func_full_t)(struct mp_log *log, const m_option_t *,
- const char *, const char *);
+// Callback used by m_option_type_print_fn options.
+typedef void (*m_opt_print_fn)(struct mp_log *log);
enum m_rel_time_type {
REL_TIME_NONE,
@@ -178,8 +175,6 @@ struct m_sub_options {
#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_IMGFMT (&m_option_type_imgfmt)
@@ -291,11 +286,7 @@ struct m_option {
// Option name.
const char *name;
- // 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.
- */
+ // Deprecated field for "old" options which mutate global state.
void *p;
// Option type.
@@ -313,9 +304,6 @@ struct m_option {
double max;
// 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;
int is_new_option;
@@ -635,6 +623,12 @@ extern const char m_option_path_separator;
#define OPT_STRING_VALIDATE(...) \
OPT_STRING_VALIDATE_(__VA_ARGS__, .type = &m_option_type_string)
+#define OPT_PRINT(optname, fn) \
+ {.name = optname, \
+ .flags = M_OPT_GLOBAL | M_OPT_NOCFG | M_OPT_PRE_PARSE, \
+ .type = &m_option_type_print_fn, \
+ .priv = MP_EXPECT_TYPE(m_opt_print_fn, fn) }
+
// subconf must have the type struct m_sub_options.
// All sub-options are prefixed with "name-" and are added to the current
// (containing) option list.
diff --git a/options/options.c b/options/options.c
index 7f98149369..f53f33245e 100644
--- a/options/options.c
+++ b/options/options.c
@@ -40,6 +40,7 @@
#include "audio/filter/af.h"
#include "audio/decode/dec_audio.h"
#include "player/core.h"
+#include "player/command.h"
#include "osdep/priority.h"
/* defined in demux: */
@@ -51,11 +52,14 @@ extern int sws_flags;
extern const char mp_help_text[];
-static int print_version_opt(struct mp_log *log, const m_option_t *opt,
- const char *name, const char *param)
+static void print_version(struct mp_log *log)
{
mp_print_version(log, true);
- return M_OPT_EXIT;
+}
+
+static void print_help(struct mp_log *log)
+{
+ mp_info(log, "%s", mp_help_text);
}
#if HAVE_RADIO
@@ -214,7 +218,7 @@ const m_option_t mp_opts[] = {
{ "show-profile", NULL, CONF_TYPE_STRING, CONF_NOCFG },
{ "list-options", NULL, CONF_TYPE_STORE, CONF_NOCFG },
- // handled in mplayer.c (looks at the raw argv[])
+ // handled in main.c (looks at the raw argv[])
{"leak-report", NULL, CONF_TYPE_STORE, CONF_GLOBAL | CONF_NOCFG },
OPT_FLAG("shuffle", shuffle, CONF_GLOBAL | CONF_NOCFG),
@@ -614,11 +618,11 @@ const m_option_t mp_opts[] = {
{"", (void *) mp_input_opts, CONF_TYPE_SUBCONFIG},
- OPT_FLAG("list-properties", list_properties, CONF_GLOBAL),
- {"help", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
- {"h", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
- {"version", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE},
- {"V", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE},
+ OPT_PRINT("list-properties", property_print_help),
+ OPT_PRINT("help", print_help),
+ OPT_PRINT("h", print_help),
+ OPT_PRINT("version", print_version),
+ OPT_PRINT("V", print_version),
#if HAVE_ENCODING
OPT_STRING("o", encode_output.file, CONF_GLOBAL),
diff --git a/options/options.h b/options/options.h
index 4889201b93..6e44dc838c 100644
--- a/options/options.h
+++ b/options/options.h
@@ -133,7 +133,6 @@ typedef struct MPOpts {
int player_idle_mode;
int slave_mode;
int consolecontrols;
- int list_properties;
struct m_rel_time play_start;
struct m_rel_time play_end;
struct m_rel_time play_length;