Commit 3b7f8b1f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Load the whole config file all the time

This avoids iterating through all config items of each modules. On my
system, this cuts the vlcrc load time in half, and is also far simpler.
The loader is essentially ignoring the config section, which reflects
the architectural "limitation" of the VLC configuration.

This also avoids loosing settings during VLC upgrades if an option moves
from one module to another one (which did happen in the past).
parent d7cf24fe
...@@ -33,9 +33,9 @@ int config_AutoSaveConfigFile( vlc_object_t * ); ...@@ -33,9 +33,9 @@ int config_AutoSaveConfigFile( vlc_object_t * );
void config_Free( module_t * ); void config_Free( module_t * );
int config_LoadCmdLine ( vlc_object_t *, int, const char *[], int * ); int config_LoadCmdLine ( vlc_object_t *, int, const char *[], int * );
int config_LoadConfigFile( vlc_object_t *, const char * ); int config_LoadConfigFile( vlc_object_t * );
#define config_LoadCmdLine(a,b,c,d) config_LoadCmdLine(VLC_OBJECT(a),b,c,d) #define config_LoadCmdLine(a,b,c,d) config_LoadCmdLine(VLC_OBJECT(a),b,c,d)
#define config_LoadConfigFile(a,b) config_LoadConfigFile(VLC_OBJECT(a),b) #define config_LoadConfigFile(a) config_LoadConfigFile(VLC_OBJECT(a))
int config_SortConfig (void); int config_SortConfig (void);
void config_UnsortConfig (void); void config_UnsortConfig (void);
......
...@@ -164,7 +164,7 @@ static int64_t strtoi (const char *str) ...@@ -164,7 +164,7 @@ static int64_t strtoi (const char *str)
* This function is called to load the config options stored in the config * This function is called to load the config options stored in the config
* file. * file.
*****************************************************************************/ *****************************************************************************/
int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) int config_LoadConfigFile( vlc_object_t *p_this )
{ {
FILE *file; FILE *file;
...@@ -172,9 +172,6 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -172,9 +172,6 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
if (file == NULL) if (file == NULL)
return VLC_EGENERIC; return VLC_EGENERIC;
/* Look for the selected module, if NULL then save everything */
module_t **list = module_list_get (NULL);
/* Look for UTF-8 Byte Order Mark */ /* Look for UTF-8 Byte Order Mark */
char * (*convert) (const char *) = strdupnull; char * (*convert) (const char *) = strdupnull;
char bom[3]; char bom[3];
...@@ -186,9 +183,7 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -186,9 +183,7 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
rewind (file); /* no BOM, rewind */ rewind (file); /* no BOM, rewind */
} }
module_t *module = NULL; char line[1024];
char line[1024], section[1022];
section[0] = '\0';
/* Ensure consistent number formatting... */ /* Ensure consistent number formatting... */
locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
...@@ -201,48 +196,12 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -201,48 +196,12 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
switch (line[0]) switch (line[0])
{ {
case '#': case '#':
case '[':
case '\n': case '\n':
case '\0': case '\0':
continue; continue;
} }
if (line[0] == '[')
{
char *ptr = strchr (line, ']');
if (ptr == NULL)
continue; /* syntax error; */
*ptr = '\0';
/* New section ( = a given module) */
strcpy (section, line + 1);
module = NULL;
if ((psz_module_name == NULL)
|| (strcmp (psz_module_name, section) == 0))
{
for (int i = 0; list[i]; i++)
{
module_t *m = list[i];
if ((strcmp (section, m->psz_object_name) == 0)
&& (m->i_config_items > 0)) /* ignore config-less modules */
{
module = m;
if (psz_module_name != NULL)
msg_Dbg (p_this,
"loading config for module \"%s\"",
section);
break;
}
}
}
continue;
}
if (module == NULL)
continue; /* no need to parse if there is no matching module */
char *ptr = strchr (line, '\n'); char *ptr = strchr (line, '\n');
if (ptr != NULL) if (ptr != NULL)
*ptr = '\0'; *ptr = '\0';
...@@ -253,61 +212,51 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -253,61 +212,51 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
ptr = strchr (line, '='); ptr = strchr (line, '=');
if (ptr == NULL) if (ptr == NULL)
continue; /* syntax error */ continue; /* syntax error */
*ptr = '\0'; *ptr = '\0';
const char *psz_option_value = ptr + 1;
/* try to match this option with one of the module's options */
for (size_t i = 0; i < module->confsize; i++)
{
module_config_t *p_item = module->p_config + i;
if ((p_item->i_type & CONFIG_HINT) module_config_t *item = config_FindConfig (p_this, psz_option_name);
|| strcmp (p_item->psz_name, psz_option_name)) if (item == NULL)
continue; continue;
/* We found it */ const char *psz_option_value = ptr + 1;
errno = 0; switch (item->i_type)
switch( p_item->i_type )
{ {
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
{ {
int64_t l = strtoi (psz_option_value); int64_t l;
if ((l > p_item->max.i) || (l < p_item->min.i))
errno = 0;
l = strtoi (psz_option_value);
if ((l > item->max.i) || (l < item->min.i))
errno = ERANGE; errno = ERANGE;
if (errno) if (errno)
msg_Warn (p_this, "Integer value (%s) for %s: %m", msg_Warn (p_this, "Integer value (%s) for %s: %m",
psz_option_value, psz_option_name); psz_option_value, psz_option_name);
else else
p_item->saved.i = p_item->value.i = l; item->saved.i = item->value.i = l;
break; break;
} }
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
if( !*psz_option_value ) if (!*psz_option_value)
break; /* ignore empty option */ break; /* ignore empty option */
p_item->value.f = (float)atof (psz_option_value); item->value.f = (float)atof (psz_option_value);
p_item->saved.f = p_item->value.f; item->saved.f = item->value.f;
break; break;
case CONFIG_ITEM_KEY: case CONFIG_ITEM_KEY:
if( !*psz_option_value ) if (!*psz_option_value)
break; /* ignore empty option */ break; /* ignore empty option */
p_item->value.i = ConfigStringToKey(psz_option_value); item->value.i = ConfigStringToKey(psz_option_value);
p_item->saved.i = p_item->value.i; item->saved.i = item->value.i;
break; break;
default: default:
/* free old string */ free ((char *)item->value.psz);
free( (char*) p_item->value.psz ); free ((char *)item->saved.psz);
free( (char*) p_item->saved.psz ); item->value.psz = convert (psz_option_value);
item->saved.psz = strdupnull (item->value.psz);
p_item->value.psz = convert (psz_option_value);
p_item->saved.psz = strdupnull (p_item->value.psz);
break;
}
break; break;
} }
} }
...@@ -320,7 +269,6 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) ...@@ -320,7 +269,6 @@ int config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
} }
fclose (file); fclose (file);
module_list_free (list);
if (loc != (locale_t)0) if (loc != (locale_t)0)
{ {
uselocale (baseloc); uselocale (baseloc);
......
...@@ -387,7 +387,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -387,7 +387,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
&& ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
# if defined (WIN32) || defined (__APPLE__) # if defined (WIN32) || defined (__APPLE__)
if( !var_InheritBool( p_libvlc, "ignore-config" ) ) if( !var_InheritBool( p_libvlc, "ignore-config" ) )
config_LoadConfigFile( p_libvlc, "main" ); config_LoadConfigFile( p_libvlc );
priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );
/* Check if the user specified a custom language */ /* Check if the user specified a custom language */
...@@ -489,7 +489,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -489,7 +489,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
* Override default configuration with config file settings * Override default configuration with config file settings
*/ */
if( !var_InheritBool( p_libvlc, "ignore-config" ) ) if( !var_InheritBool( p_libvlc, "ignore-config" ) )
config_LoadConfigFile( p_libvlc, NULL ); config_LoadConfigFile( p_libvlc );
/* /*
* Override configuration with command line settings * Override configuration with command line settings
......
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