Skip to content

Commit

Permalink
m_config, command: remove some minor code duplication
Browse files Browse the repository at this point in the history
I would have been fine with this, but now I want to add another flag,
and the duplication would become more messy than having a strange
function for deduplication.
  • Loading branch information
wm4 committed Sep 23, 2016
1 parent b9153ee commit f0fd663
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions options/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ static int handle_set_opt_flags(struct m_config *config,
return set ? 2 : 1;
}

void m_config_mark_co_flags(struct m_config_option *co, int flags)
{
if (flags & M_SETOPT_FROM_CMDLINE)
co->is_set_from_cmdline = true;
}

// Unlike m_config_set_option_raw() this does not go through the property layer
// via config.option_set_callback.
int m_config_set_option_raw_direct(struct m_config *config,
Expand All @@ -696,9 +702,7 @@ int m_config_set_option_raw_direct(struct m_config *config,

m_option_copy(co->opt, co->data, data);

if (flags & M_SETOPT_FROM_CMDLINE)
co->is_set_from_cmdline = true;

m_config_mark_co_flags(co, flags);
m_config_notify_change_co(config, co);

return 0;
Expand Down
2 changes: 2 additions & 0 deletions options/m_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ static inline int m_config_set_option0(struct m_config *config,
int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
void *data, int flags);

void m_config_mark_co_flags(struct m_config_option *co, int flags);

int m_config_set_option_raw_direct(struct m_config *config,
struct m_config_option *co,
void *data, int flags);
Expand Down
5 changes: 2 additions & 3 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flag
if (r != M_PROPERTY_OK)
return M_OPT_INVALID;

// The flag can't be passed through the property layer correctly.
if (flags & M_SETOPT_FROM_CMDLINE)
co->is_set_from_cmdline = true;
// The flags can't be passed through the property layer correctly.
m_config_mark_co_flags(co, flags);

return 0;

Expand Down

0 comments on commit f0fd663

Please sign in to comment.