diff options
-rw-r--r-- | command.c | 39 | ||||
-rw-r--r-- | m_property.c | 49 |
2 files changed, 48 insertions, 40 deletions
@@ -1493,42 +1493,6 @@ static const m_option_t mp_properties[] = { {0}, }; -struct legacy_prop { - const char *old, *new; -}; -static const struct legacy_prop legacy_props[] = { - {"switch_video", "video"}, - {"switch_audio", "audio"}, - {"switch_program", "program"}, - {"framedropping", "framedrop"}, - {"osdlevel", "osd-level"}, - {0} -}; - -static char *translate_legacy_property(void *talloc_ctx, const char *name) -{ - char *new_name = NULL; - for (int n = 0; legacy_props[n].new; n++) { - if (strcmp(name, legacy_props[n].old) == 0) { - new_name = (char *)legacy_props[n].new; - break; - } - } - if (!new_name && strchr(name, '_')) { - // Old names used "_" instead of "-" - new_name = talloc_strdup(talloc_ctx, name); - for (int n = 0; new_name[n]; n++) { - if (new_name[n] == '_') - new_name[n] = '-'; - } - } - if (new_name) { - mp_msg(MSGT_CPLAYER, MSGL_V, "Warning: property '%s' is deprecated, " - "replaced with '%s'. Fix your input.conf!\n", name, new_name); - } - return new_name ? new_name : (char *)name; -} - int mp_property_do(const char *name, int action, void *val, struct MPContext *ctx) { @@ -1820,7 +1784,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } case MP_CMD_SET: { - cmd->args[0].v.s = translate_legacy_property(cmd, cmd->args[0].v.s); int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_SET_STRING, cmd->args[1].v.s, mpctx); if (r == M_PROPERTY_UNKNOWN) @@ -1838,7 +1801,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_ADD: case MP_CMD_CYCLE: { - cmd->args[0].v.s = translate_legacy_property(cmd, cmd->args[0].v.s); struct m_property_switch_arg s = { .inc = 1, .wrap = cmd->id == MP_CMD_CYCLE, @@ -1859,7 +1821,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } case MP_CMD_GET_PROPERTY: { - cmd->args[0].v.s = translate_legacy_property(cmd, cmd->args[0].v.s); char *tmp; int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_GET_STRING, &tmp, mpctx); diff --git a/m_property.c b/m_property.c index 1644dbd997..c8cf4e3dcf 100644 --- a/m_property.c +++ b/m_property.c @@ -39,6 +39,49 @@ const struct m_option_type m_option_type_dummy = { .name = "Unknown", }; +struct legacy_prop { + const char *old, *new; +}; +static const struct legacy_prop legacy_props[] = { + {"switch_video", "video"}, + {"switch_audio", "audio"}, + {"switch_program", "program"}, + {"framedropping", "framedrop"}, + {"osdlevel", "osd-level"}, + {0} +}; + +static bool translate_legacy_property(const char *name, char *buffer, + size_t buffer_size) +{ + if (strlen(name) + 1 > buffer_size) + return false; + + const char *old_name = name; + + for (int n = 0; legacy_props[n].new; n++) { + if (strcmp(name, legacy_props[n].old) == 0) { + name = legacy_props[n].new; + break; + } + } + + snprintf(buffer, buffer_size, "%s", name); + + // Old names used "_" instead of "-" + for (int n = 0; buffer[n]; n++) { + if (buffer[n] == '_') + buffer[n] = '-'; + } + + if (strcmp(old_name, buffer) != 0) { + mp_msg(MSGT_CPLAYER, MSGL_V, "Warning: property '%s' is deprecated, " + "replaced with '%s'. Fix your input.conf!\n", old_name, buffer); + } + + return true; +} + static int do_action(const m_option_t *prop_list, const char *name, int action, void *arg, void *ctx) { @@ -72,12 +115,16 @@ static int do_action(const m_option_t *prop_list, const char *name, return r; } -int m_property_do(const m_option_t *prop_list, const char *name, +int m_property_do(const m_option_t *prop_list, const char *in_name, int action, void *arg, void *ctx) { union m_option_value val = {0}; int r; + char name[64]; + if (!translate_legacy_property(in_name, name, sizeof(name))) + return M_PROPERTY_UNKNOWN; + struct m_option opt = {0}; r = do_action(prop_list, name, M_PROPERTY_GET_TYPE, &opt, ctx); if (r <= 0) |