From 3655c1c6edfa65212b263fa330e0bf4809eeb5d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Mon, 17 Dec 2007 19:36:58 +0000 Subject: [PATCH] Add support for aliases through vlc_config_set --- include/vlc_configuration.h | 23 ++++++++++------------- src/config/chain.c | 16 ++++++++++------ src/config/cmdline.c | 22 +++++++++++----------- src/config/core.c | 4 +++- src/config/file.c | 2 +- src/libvlc-common.c | 4 ++-- src/modules/cache.c | 7 +++++-- src/modules/entry.c | 11 ++++++++++- src/modules/modules.c | 2 +- 9 files changed, 53 insertions(+), 38 deletions(-) diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h index 79982517e5..0611e5549e 100644 --- a/include/vlc_configuration.h +++ b/include/vlc_configuration.h @@ -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)) diff --git a/src/config/chain.c b/src/config/chain.c index 4706125018..4d71bd5c6e 100644 --- a/src/config/chain.c +++ b/src/config/chain.c @@ -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 ); + } } /* */ diff --git a/src/config/cmdline.c b/src/config/cmdline.c index a16c3225fc..591c1a0ff6 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -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 ) diff --git a/src/config/core.c b/src/config/core.c index d5e21b6f7a..082023accd 100644 --- a/src/config/core.c +++ b/src/config/core.c @@ -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; diff --git a/src/config/file.c b/src/config/file.c index 521e8cec14..04f072b50a 100644 --- a/src/config/file.c +++ b/src/config/file.c @@ -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; diff --git a/src/libvlc-common.c b/src/libvlc-common.c index 1a0bdf71a1..468fd953bc 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -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; } diff --git a/src/modules/cache.c b/src/modules/cache.c index afda6074da..4d6393c6c6 100644 --- a/src/modules/cache.c +++ b/src/modules/cache.c @@ -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 ); diff --git a/src/modules/entry.c b/src/modules/entry.c index bb0da23f90..b59d8f7f7b 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -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; } } diff --git a/src/modules/modules.c b/src/modules/modules.c index d73f010c99..077b95abc5 100644 --- a/src/modules/modules.c +++ b/src/modules/modules.c @@ -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) -- 2.39.2