]> git.sesse.net Git - vlc/commitdiff
Add support for aliases through vlc_config_set
authorRémi Denis-Courmont <rem@videolan.org>
Mon, 17 Dec 2007 19:36:58 +0000 (19:36 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Mon, 17 Dec 2007 19:36:58 +0000 (19:36 +0000)
include/vlc_configuration.h
src/config/chain.c
src/config/cmdline.c
src/config/core.c
src/config/file.c
src/libvlc-common.c
src/modules/cache.c
src/modules/entry.c
src/modules/modules.c

index 79982517e514ab765cd0a9b7359e91e6c8b1ac6e..0611e5549e2101278f03f9e42588424c1b8aa861 100644 (file)
@@ -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))
 
index 47061250181b319c6d81e98872be20ee966da31c..4d71bd5c6e4dbfa0d369a3cf1849240fd41d1880 100644 (file)
@@ -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> */
 
index a16c3225fc6181d6e2ef07292189986c0688731e..591c1a0ff615ea3d4a74ca72eb1cb72213e5b350 100644 (file)
@@ -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 )
index d5e21b6f7a47fdd08875501151d11a63cad29aa4..082023accd9df365701018af5855c9fb86652e2f 100644 (file)
@@ -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;
index 521e8cec14fb14063e77dfbed7e0d3e2e07254e4..04f072b50a17e29c2fb827c2978baffc1d68cb0f 100644 (file)
@@ -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;
 
index 1a0bdf71a1322dcd6107daab6ccfb37b93495f34..468fd953bc3da85968abf0302db83057f2245b46 100644 (file)
@@ -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;
             }
index afda6074da84f0016d0ad2de83733d9c9d7b057e..4d6393c6c6afbfeca8448c3c53fb19790e4f3a7a 100644 (file)
@@ -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 );
 
index bb0da23f90d3fee543cfc762230718d88e50d89e..b59d8f7f7b2303456a24db88e9f789662a484695 100644 (file)
@@ -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;
         }
     }
 
index d73f010c99853f8d1ff2e5050f6acf8d5fcaf53a..077b95abc5f640652a629a5fdcd09ccdeff10eef 100644 (file)
@@ -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)