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

modules: simplify storage of choices in cache

parent 2f3f0899
...@@ -59,7 +59,7 @@ static int CacheLoadConfig ( module_t *, FILE * ); ...@@ -59,7 +59,7 @@ static int CacheLoadConfig ( module_t *, FILE * );
/* Sub-version number /* Sub-version number
* (only used to avoid breakage in dev version when cache structure changes) */ * (only used to avoid breakage in dev version when cache structure changes) */
#define CACHE_SUBVERSION_NUM 18 #define CACHE_SUBVERSION_NUM 19
/* Cache filename */ /* Cache filename */
#define CACHE_NAME "plugins.dat" #define CACHE_NAME "plugins.dat"
...@@ -321,49 +321,27 @@ static int CacheLoadConfig( module_t *p_module, FILE *file ) ...@@ -321,49 +321,27 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
p_module->p_config[i].value.psz = p_module->p_config[i].value.psz =
(p_module->p_config[i].orig.psz != NULL) (p_module->p_config[i].orig.psz != NULL)
? strdup (p_module->p_config[i].orig.psz) : NULL; ? strdup (p_module->p_config[i].orig.psz) : NULL;
p_module->p_config[i].ppsz_list =
xmalloc( p_module->p_config[i].i_list * sizeof(char *) );
for( int j = 0; j < p_module->p_config[i].i_list; j++ )
LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
} }
else else
{
memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig, memcpy (&p_module->p_config[i].value, &p_module->p_config[i].orig,
sizeof (p_module->p_config[i].value)); sizeof (p_module->p_config[i].value));
p_module->p_config[i].pi_list =
if( p_module->p_config[i].i_list ) xmalloc( p_module->p_config[i].i_list * sizeof(int) );
{ for( int j = 0; j < p_module->p_config[i].i_list; j++ )
if( p_module->p_config[i].ppsz_list ) LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
{
p_module->p_config[i].ppsz_list =
xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
if( p_module->p_config[i].ppsz_list )
{
int j;
for( j = 0; j < p_module->p_config[i].i_list; j++ )
LOAD_STRING( p_module->p_config[i].ppsz_list[j] );
p_module->p_config[i].ppsz_list[j] = NULL;
}
}
if( p_module->p_config[i].ppsz_list_text )
{
p_module->p_config[i].ppsz_list_text =
xmalloc( (p_module->p_config[i].i_list+1) * sizeof(char *));
if( p_module->p_config[i].ppsz_list_text )
{
int j;
for( j = 0; j < p_module->p_config[i].i_list; j++ )
LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
p_module->p_config[i].ppsz_list_text[j] = NULL;
}
}
if( p_module->p_config[i].pi_list )
{
p_module->p_config[i].pi_list =
xmalloc( (p_module->p_config[i].i_list + 1) * sizeof(int) );
if( p_module->p_config[i].pi_list )
{
for (int j = 0; j < p_module->p_config[i].i_list; j++)
LOAD_IMMEDIATE( p_module->p_config[i].pi_list[j] );
}
}
} }
p_module->p_config[i].ppsz_list_text =
xmalloc( p_module->p_config[i].i_list * sizeof(char *) );
for( int j = 0; j < p_module->p_config[i].i_list; j++ )
LOAD_STRING( p_module->p_config[i].ppsz_list_text[j] );
if( p_module->p_config[i].i_action ) if( p_module->p_config[i].i_action )
{ {
p_module->p_config[i].ppf_action = p_module->p_config[i].ppf_action =
...@@ -468,7 +446,7 @@ static int CacheSaveBank (FILE *file, const module_cache_t *cache, ...@@ -468,7 +446,7 @@ static int CacheSaveBank (FILE *file, const module_cache_t *cache,
goto error; goto error;
#define SAVE_IMMEDIATE( a ) \ #define SAVE_IMMEDIATE( a ) \
if (fwrite (&a, sizeof(a), 1, file) != 1) \ if (fwrite (&(a), sizeof(a), 1, file) != 1) \
goto error goto error
#define SAVE_STRING( a ) \ #define SAVE_STRING( a ) \
{ \ { \
...@@ -560,28 +538,20 @@ static int CacheSaveConfig (FILE *file, const module_t *p_module) ...@@ -560,28 +538,20 @@ static int CacheSaveConfig (FILE *file, const module_t *p_module)
SAVE_STRING( p_module->p_config[i].psz_longtext ); SAVE_STRING( p_module->p_config[i].psz_longtext );
if (IsConfigStringType (p_module->p_config[i].i_type)) if (IsConfigStringType (p_module->p_config[i].i_type))
{
SAVE_STRING( p_module->p_config[i].orig.psz ); SAVE_STRING( p_module->p_config[i].orig.psz );
for (int j = 0; j < p_module->p_config[i].i_list; j++)
if( p_module->p_config[i].i_list ) SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
}
else
{ {
if( p_module->p_config[i].ppsz_list ) for (int j = 0; j < p_module->p_config[i].i_list; j++)
{ SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
for (int j = 0; j < p_module->p_config[i].i_list; j++)
SAVE_STRING( p_module->p_config[i].ppsz_list[j] );
}
if( p_module->p_config[i].ppsz_list_text )
{
for (int j = 0; j < p_module->p_config[i].i_list; j++)
SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
}
if( p_module->p_config[i].pi_list )
{
for (int j = 0; j < p_module->p_config[i].i_list; j++)
SAVE_IMMEDIATE( p_module->p_config[i].pi_list[j] );
}
} }
for (int j = 0; j < p_module->p_config[i].i_list; j++)
SAVE_STRING( p_module->p_config[i].ppsz_list_text[j] );
for (int j = 0; j < p_module->p_config[i].i_action; j++) for (int j = 0; j < p_module->p_config[i].i_action; j++)
SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] ); SAVE_STRING( p_module->p_config[i].ppsz_action_text[j] );
} }
......
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