]> git.sesse.net Git - vlc/commitdiff
modules: simplify storage of choices in cache
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 14 Aug 2012 21:58:21 +0000 (00:58 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 14 Aug 2012 21:59:37 +0000 (00:59 +0300)
src/modules/cache.c

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