Commit 3655c1c6 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Add support for aliases through vlc_config_set

parent 2bca4f1c
......@@ -184,8 +184,8 @@ struct module_config_t
/* to take effect */
/* Deprecated */
const char *psz_current; /* Good option name */
vlc_bool_t b_strict; /* Transitionnal or strict */
char *psz_oldname; /* Old option name */
vlc_bool_t b_removed;
/* Option values loaded from config file */
vlc_bool_t b_autosave; /* Config will be auto-saved at exit time */
......@@ -278,6 +278,9 @@ enum vlc_config_properties
VLC_CONFIG_ADD_ACTION,
/* add value change callback (args=vlc_callback_t, const char *) */
VLC_CONFIG_OLDNAME,
/* former option name (args=const char *) */
};
......@@ -408,17 +411,6 @@ VLC_EXPORT( int, vlc_config_set, (module_config_t *, int, ...) );
add_typename_inner( CONFIG_ITEM_BOOL, name, text, longtext, advc, p_callback ); \
if (v) vlc_config_set (p_config + i_config, VLC_CONFIG_VALUE, (int)VLC_TRUE)
/* For renamed option */
#define add_deprecated_alias( name ) \
add_config_inner( ); \
p_config[ i_config ].i_type = p_config[ i_config -1 ].i_type; \
vlc_config_set (p_config + i_config, VLC_CONFIG_NAME, \
(const char *)(name), (vlc_callback_t)NULL); \
p_config[i_config].b_strict = VLC_FALSE; \
p_config[ i_config ].psz_current = p_config[ i_config-1 ].psz_current \
? p_config[ i_config-1 ].psz_current \
: p_config[ i_config-1 ].psz_name;
/* For removed option */
#define add_obsolete_inner( name, type ) \
add_type_inner( type ); \
......@@ -439,6 +431,11 @@ VLC_EXPORT( int, vlc_config_set, (module_config_t *, int, ...) );
add_obsolete_inner( name, CONFIG_ITEM_STRING )
/* Modifier macros for the config options (used for fine tuning) */
#define add_deprecated_alias( name ) \
vlc_config_set (p_config + i_config, VLC_CONFIG_OLDNAME, \
(const char *)(name))
#define change_short( ch ) \
vlc_config_set (p_config + i_config, VLC_CONFIG_SHORTCUT, (int)(ch))
......
......@@ -296,20 +296,24 @@ void __config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
/* This is basically cut and paste from src/misc/configuration.c
* with slight changes */
if( p_conf && p_conf->psz_current )
if( p_conf )
{
if( p_conf->b_strict )
if( p_conf->b_removed )
{
msg_Err( p_this, "Option %s is not supported anymore.",
p_conf->psz_name );
name );
/* TODO: this should return an error and end option parsing
* ... but doing this would change the VLC API and all the
* modules so i'll do it later */
continue;
}
msg_Warn( p_this, "Option %s is obsolete. Use %s instead.",
p_conf->psz_name, p_conf->psz_current );
psz_name = p_conf->psz_current;
if( p_conf->psz_oldname
&& !strcmp( p_conf->psz_oldname, name ) )
{
psz_name = p_conf->psz_name;
msg_Warn( p_this, "Option %s is obsolete. Use %s instead.",
name, psz_name );
}
}
/* </Check if the option is deprecated> */
......
......@@ -278,20 +278,21 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc,
if( p_conf )
{
/* Check if the option is deprecated */
if( p_conf->psz_current )
if( p_conf->b_removed )
{
if( p_conf->b_strict )
{
fprintf(stderr,
"Warning: option --%s no longer exists.\n",
p_conf->psz_name);
continue;
}
fprintf(stderr,
"Warning: option --%s no longer exists.\n",
psz_name);
continue;
}
if( p_conf->psz_oldname
&& !strcmp( p_conf->psz_oldname, psz_name) )
{
fprintf( stderr,
"%s: option --%s is deprecated. Use --%s instead.\n",
b_ignore_errors ? "Warning" : "Error",
p_conf->psz_name, p_conf->psz_current);
psz_name, p_conf->psz_name );
if( !b_ignore_errors )
{
/*free */
......@@ -303,8 +304,7 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc,
return -1;
}
psz_name = (char *)p_conf->psz_current;
p_conf = config_FindConfig( p_this, psz_name );
psz_name = p_conf->psz_name;
}
switch( p_conf->i_type )
......
......@@ -464,7 +464,9 @@ module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
if( p_item->i_type & CONFIG_HINT )
/* ignore hints */
continue;
if( !strcmp( psz_name, p_item->psz_name ) )
if( !strcmp( psz_name, p_item->psz_name )
|| ( p_item->psz_oldname
&& !strcmp( psz_name, p_item->psz_oldname ) ) )
{
vlc_list_release( p_list );
return p_item;
......
......@@ -543,7 +543,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
vlc_bool_t b_retain = b_autosave && !p_item->b_autosave;
if ((p_item->i_type & CONFIG_HINT) /* ignore hint */
|| p_item->psz_current /* ignore deprecated option */
|| p_item->b_removed /* ignore deprecated option */
|| p_item->b_unsaveable) /* ignore volatile option */
continue;
......
......@@ -1455,8 +1455,8 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
signed int i;
size_t i_cur_width;
/* Skip deprecated options */
if( p_item->psz_current )
/* Skip removed options */
if( p_item->b_removed )
{
continue;
}
......
......@@ -352,7 +352,8 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
LOAD_STRING( p_module->p_config[i].psz_name );
LOAD_STRING( p_module->p_config[i].psz_text );
LOAD_STRING( p_module->p_config[i].psz_longtext );
LOAD_STRING( p_module->p_config[i].psz_current );
LOAD_STRING( p_module->p_config[i].psz_oldname );
LOAD_IMMEDIATE( p_module->p_config[i].b_removed );
if (IsConfigStringType (p_module->p_config[i].i_type))
{
......@@ -617,7 +618,9 @@ static int CacheSaveConfig( module_t *p_module, FILE *file )
SAVE_STRING( p_module->p_config[i].psz_name );
SAVE_STRING( p_module->p_config[i].psz_text );
SAVE_STRING( p_module->p_config[i].psz_longtext );
SAVE_STRING( p_module->p_config[i].psz_current );
SAVE_STRING( p_module->p_config[i].psz_oldname );
SAVE_IMMEDIATE( p_module->p_config[i].b_removed );
if (IsConfigStringType (p_module->p_config[i].i_type))
SAVE_STRING( p_module->p_config[i].orig.psz );
......
......@@ -268,7 +268,7 @@ int vlc_config_set (module_config_t *restrict item, int id, ...)
break;
case VLC_CONFIG_REMOVED:
item->psz_current = "SUPPRESSED";
item->b_removed = VLC_TRUE;
ret = 0;
break;
......@@ -384,6 +384,15 @@ int vlc_config_set (module_config_t *restrict item, int id, ...)
item->i_action++;
ret = 0;
break;
}
case VLC_CONFIG_OLDNAME:
{
const char *oldname = va_arg (ap, const char *);
item->psz_oldname = oldname ? strdup (oldname) : NULL;
ret = 0;
break;
}
}
......
......@@ -804,7 +804,7 @@ module_config_t *module_GetConfig (const module_t *module, unsigned *restrict ps
const module_config_t *item = module->p_config + i;
if (item->b_internal /* internal option */
|| item->b_unsaveable /* non-modifiable option */
|| item->psz_current /* deprecated option name */)
|| item->b_removed /* removed option */)
continue;
if (config != NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment