]> git.sesse.net Git - vlc/blobdiff - src/misc/configuration.c
* src/misc/charset.c: New function vlc_fix_readdir_charset. It is used
[vlc] / src / misc / configuration.c
index 7e8f2f399a8d6de92979c0b73947592289a80980..820cb4da6dd3fb639e6967c9a290e7103a43e439 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * configuration.c management of the modules configuration
  *****************************************************************************
- * Copyright (C) 2001-2004 VideoLAN
+ * Copyright (C) 2001-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
@@ -527,6 +527,8 @@ void config_Duplicate( module_t *p_module, module_config_t *p_orig )
                                    strdup( p_orig[i].psz_type ) : NULL;
         p_module->p_config[i].psz_name = p_orig[i].psz_name ?
                                    strdup( p_orig[i].psz_name ) : NULL;
+        p_module->p_config[i].psz_current = p_orig[i].psz_current?
+                                   strdup( p_orig[i].psz_current ) : NULL;
         p_module->p_config[i].psz_text = p_orig[i].psz_text ?
                                    strdup( _(p_orig[i].psz_text) ) : NULL;
         p_module->p_config[i].psz_longtext = p_orig[i].psz_longtext ?
@@ -625,6 +627,9 @@ void config_Free( module_t *p_module )
         if( p_item->psz_name )
             free( p_item->psz_name );
 
+        if( p_item->psz_current )
+            free( p_item->psz_current );
+
         if( p_item->psz_text )
             free( p_item->psz_text );
 
@@ -911,8 +916,9 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
                         if( p_item->psz_value_saved )
                             free( p_item->psz_value_saved );
                         p_item->psz_value_saved = 0;
-                        if( p_item->psz_value && p_item->psz_value_orig &&
-                            strcmp(p_item->psz_value, p_item->psz_value_orig) )
+                        if( !p_item->psz_value || !p_item->psz_value_orig ||
+                            (p_item->psz_value && p_item->psz_value_orig &&
+                             strcmp(p_item->psz_value,p_item->psz_value_orig)))
                             p_item->psz_value_saved = p_item->psz_value ?
                                 strdup( p_item->psz_value ) : 0;
 
@@ -1195,6 +1201,12 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
             float f_value = p_item->f_value;
             char  *psz_value = p_item->psz_value;
 
+            if( p_item->i_type & CONFIG_HINT )
+                /* ignore hints */
+                continue;
+            /* Ignore deprecated options */
+            if( p_item->psz_current )
+                continue;
             if( b_autosave && !p_item->b_autosave )
             {
                 i_value = p_item->i_value_saved;
@@ -1202,10 +1214,10 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
                 psz_value = p_item->psz_value_saved;
                 if( !psz_value ) psz_value = p_item->psz_value_orig;
             }
-
-            if( p_item->i_type & CONFIG_HINT )
-                /* ignore hints */
-                continue;
+            else
+            {
+                p_item->b_dirty = VLC_FALSE;
+            }
 
             switch( p_item->i_type )
             {
@@ -1258,14 +1270,15 @@ int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
                 fprintf( file, "%s=%s\n", p_item->psz_name,
                          psz_value ? psz_value : "" );
 
-                if( p_item->psz_value_saved )
-                    free( p_item->psz_value_saved );
+                if( b_autosave && !p_item->b_autosave ) break;
+
+                if( p_item->psz_value_saved ) free( p_item->psz_value_saved );
                 p_item->psz_value_saved = 0;
-                if( psz_value && p_item->psz_value_orig &&
-                    strcmp( psz_value, p_item->psz_value_orig ) )
+                if( (psz_value && p_item->psz_value_orig &&
+                     strcmp( psz_value, p_item->psz_value_orig )) ||
+                    !psz_value || !p_item->psz_value_orig)
                     p_item->psz_value_saved = psz_value ? strdup(psz_value):0;
             }
-            p_item->b_dirty = VLC_FALSE;
         }
 
         fprintf( file, "\n" );
@@ -1533,40 +1546,79 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
 
             /* Store the configuration option */
             p_conf = config_FindConfig( p_this, psz_name );
+            if( p_conf )
+            {
+                /* Check if the option is deprecated */
+                if( p_conf->psz_current )
+                {
+                    if( !strcmp(p_conf->psz_current,"SUPPRESSED") )
+                    {
+                       if( !b_ignore_errors ) 
+                        {
+                            fprintf(stderr,
+                                    "Warning: option --%s is no longer used.\n",
+                                    p_conf->psz_name);
+                        }
+                       continue;
+                    }
+                    if( !b_ignore_errors )
+                    {
+                        if( p_conf->b_strict )
+                        {
+                            fprintf( stderr,
+                                     "Error: option --%s is deprecated. "
+                                     "Use --%s instead.\n",
+                                     p_conf->psz_name, p_conf->psz_current);
+                            /*free */
+                            for( i_index = 0; p_longopts[i_index].name; i_index++ )
+                                free( (char *)p_longopts[i_index].name );
+
+                            free( p_longopts );
+                            free( psz_shortopts );
+                            return -1;
+                        }
+                        fprintf(stderr,
+                                "Warning: option --%s is deprecated. "
+                                "You should use --%s instead.\n",
+                                p_conf->psz_name, p_conf->psz_current);
+                    }
+                    psz_name=p_conf->psz_current;
+                    p_conf = config_FindConfig( p_this, psz_name );
+                }
 
-            if( p_conf ) switch( p_conf->i_type )
+            switch( p_conf->i_type )
             {
-            case CONFIG_ITEM_STRING:
-            case CONFIG_ITEM_FILE:
-            case CONFIG_ITEM_DIRECTORY:
-            case CONFIG_ITEM_MODULE:
-            case CONFIG_ITEM_MODULE_LIST:
-            case CONFIG_ITEM_MODULE_LIST_CAT:
-            case CONFIG_ITEM_MODULE_CAT:
-                config_PutPsz( p_this, psz_name, optarg );
-                break;
-            case CONFIG_ITEM_INTEGER:
-                config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));
-                break;
-            case CONFIG_ITEM_FLOAT:
-                config_PutFloat( p_this, psz_name, (float)atof(optarg) );
-                break;
-            case CONFIG_ITEM_KEY:
-                config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );
-                break;
-            case CONFIG_ITEM_BOOL:
-                config_PutInt( p_this, psz_name, !flag );
-                break;
+                case CONFIG_ITEM_STRING:
+                case CONFIG_ITEM_FILE:
+                case CONFIG_ITEM_DIRECTORY:
+                case CONFIG_ITEM_MODULE:
+                case CONFIG_ITEM_MODULE_LIST:
+                case CONFIG_ITEM_MODULE_LIST_CAT:
+                case CONFIG_ITEM_MODULE_CAT:
+                    config_PutPsz( p_this, psz_name, optarg );
+                    break;
+                case CONFIG_ITEM_INTEGER:
+                    config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));
+                    break;
+                case CONFIG_ITEM_FLOAT:
+                    config_PutFloat( p_this, psz_name, (float)atof(optarg) );
+                    break;
+                case CONFIG_ITEM_KEY:
+                    config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );
+                    break;
+                case CONFIG_ITEM_BOOL:
+                    config_PutInt( p_this, psz_name, !flag );
+                    break;
             }
 
             continue;
         }
-
-        /* A short option has been recognized */
-        if( pp_shortopts[i_cmd] != NULL )
+    }
+    /* A short option has been recognized */
+    if( pp_shortopts[i_cmd] != NULL )
+    {
+        switch( pp_shortopts[i_cmd]->i_type )
         {
-            switch( pp_shortopts[i_cmd]->i_type )
-            {
             case CONFIG_ITEM_STRING:
             case CONFIG_ITEM_FILE:
             case CONFIG_ITEM_DIRECTORY:
@@ -1619,8 +1671,9 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
         /* Internal error: unknown option */
         if( !b_ignore_errors )
         {
-            fprintf( stderr, "%s: unknown option ",
-                             p_this->p_vlc->psz_object_name );
+            fprintf( stderr, "%s: unknown option"
+                     " or missing mandatory argument ",
+                     p_this->p_vlc->psz_object_name );
             if( optopt )
             {
                 fprintf( stderr, "`-%c'\n", optopt );
@@ -1632,6 +1685,8 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
             fprintf( stderr, "Try `%s --help' for more information.\n",
                              p_this->p_vlc->psz_object_name );
 
+            for( i_index = 0; p_longopts[i_index].name; i_index++ )
+                free( (char *)p_longopts[i_index].name );
             free( p_longopts );
             free( psz_shortopts );
             return -1;