]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Eliminate global cache. Eliminate multi-arch cache code.
[fontconfig.git] / src / fccfg.c
index aaca6efc75652446ace1edda21bef51acde3a1c4..586c6567e4fca29fd6a9950ac617ebd5d7aa6bfe 100644 (file)
@@ -23,6 +23,8 @@
  */
 
 #include "fcint.h"
+#include <dirent.h>
+#include <sys/types.h>
 
 #if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
 #define STRICT
@@ -98,13 +100,17 @@ FcConfigCreate (void)
            if (!FcConfigSetCache (config, cache_dir))
            {
                FcStrFree (cache_dir);
-               goto bail6;
+               goto bail8;
            }
            FcStrFree (cache_dir);
        }
     }
 #endif
 
+    config->cacheDirs = FcStrSetCreate ();
+    if (!config->cacheDirs)
+       goto bail9;
+    
     config->blanks = 0;
 
     config->substPattern = 0;
@@ -118,6 +124,8 @@ FcConfigCreate (void)
     
     return config;
 
+bail9:
+    FcStrFree (config->cache);
 bail8:
     FcFontSetDestroy (config->rejectPatterns);
 bail7:
@@ -139,11 +147,6 @@ bail0:
     return 0;
 }
 
-typedef struct _FcFileTime {
-    time_t  time;
-    FcBool  set;
-} FcFileTime;
-
 static FcFileTime
 FcConfigNewestFile (FcStrSet *files)
 {
@@ -166,6 +169,19 @@ FcConfigNewestFile (FcStrSet *files)
     return newest;
 }
 
+FcFileTime
+FcConfigModifiedTime (FcConfig *config)
+{
+    if (!config)
+    {
+       FcFileTime v = { 0, FcFalse };
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return v;
+    }
+    return FcConfigNewestFile (config->configFiles);
+}
+
 FcBool
 FcConfigUptoDate (FcConfig *config)
 {
@@ -216,6 +232,7 @@ FcConfigDestroy (FcConfig *config)
 
     FcStrSetDestroy (config->configDirs);
     FcStrSetDestroy (config->fontDirs);
+    FcStrSetDestroy (config->cacheDirs);
     FcStrSetDestroy (config->configFiles);
     FcStrSetDestroy (config->acceptGlobs);
     FcStrSetDestroy (config->rejectGlobs);
@@ -248,7 +265,6 @@ FcBool
 FcConfigBuildFonts (FcConfig *config)
 {
     FcFontSet      *fonts, *cached_fonts;
-    FcGlobalCache   *cache;
     FcStrList      *list;
     FcStrSet       *oldDirs;
     FcChar8        *dir;
@@ -257,29 +273,22 @@ FcConfigBuildFonts (FcConfig *config)
     if (!fonts)
        goto bail0;
     
-    cache = FcGlobalCacheCreate ();
-    if (!cache)
-       goto bail1;
-
     oldDirs = FcStrSetCreate ();
     if (!oldDirs)
         goto bail2;
 
-    if (config->cache)
-       FcGlobalCacheLoad (cache, oldDirs, config->cache);
-
-    cached_fonts = FcCacheRead(config, cache);
+    cached_fonts = FcCacheRead(config);
     if (!cached_fonts)
     {
        list = FcConfigGetFontDirs (config);
        if (!list)
-           goto bail2;
+           goto bail3;
        
        while ((dir = FcStrListNext (list)))
        {
            if (FcDebug () & FC_DBG_FONTSET)
                printf ("build scan dir %s\n", dir);
-           FcDirScanConfig (fonts, config->fontDirs, cache, 
+           FcDirScanConfig (fonts, config->fontDirs,
                             config->blanks, dir, FcFalse, config);
        }
        
@@ -292,15 +301,19 @@ FcConfigBuildFonts (FcConfig *config)
         for (i = 0; i < oldDirs->num; i++)
         {
            if (FcDebug () & FC_DBG_FONTSET)
-               printf ("scan dir %s\n", dir);
-           FcDirScanConfig (fonts, config->fontDirs, cache, 
+               printf ("scan dir %s\n", oldDirs->strs[i]);
+           FcDirScanConfig (fonts, config->fontDirs,
                             config->blanks, oldDirs->strs[i], 
                              FcFalse, config);
        }
 
        for (i = 0; i < cached_fonts->nfont; i++)
        {
-           if (FcConfigAcceptFont (config, cached_fonts->fonts[i]))
+           FcChar8     *cfn; 
+           FcPatternGetString (cached_fonts->fonts[i], FC_FILE, 0, &cfn);
+
+           if (FcConfigAcceptFont (config, cached_fonts->fonts[i]) &&
+                (cfn && FcConfigAcceptFilename (config, cfn)))
                FcFontSetAdd (fonts, cached_fonts->fonts[i]);
 
            cached_fonts->fonts[i] = 0; /* prevent free in FcFontSetDestroy */
@@ -312,17 +325,14 @@ FcConfigBuildFonts (FcConfig *config)
     if (FcDebug () & FC_DBG_FONTSET)
        FcFontSetPrint (fonts);
 
-    if (config->cache)
-       FcGlobalCacheSave (cache, config->cache);
-    FcGlobalCacheDestroy (cache);
     FcStrSetDestroy (oldDirs);
 
     FcConfigSetFonts (config, fonts, FcSetSystem);
     
     return FcTrue;
-bail2:
+bail3:
     FcStrSetDestroy (oldDirs);
-bail1:
+bail2:
     FcFontSetDestroy (fonts);
 bail0:
     return FcFalse;
@@ -396,6 +406,25 @@ FcConfigGetFontDirs (FcConfig      *config)
     return FcStrListCreate (config->fontDirs);
 }
 
+FcBool
+FcConfigAddCacheDir (FcConfig      *config,
+                    const FcChar8  *d)
+{
+    return FcStrSetAddFilename (config->cacheDirs, d);
+}
+
+FcStrList *
+FcConfigGetCacheDirs (FcConfig *config)
+{
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return 0;
+    }
+    return FcStrListCreate (config->cacheDirs);
+}
+    
 FcBool
 FcConfigAddConfigFile (FcConfig            *config,
                       const FcChar8   *f)
@@ -490,17 +519,21 @@ FcBool
 FcConfigAddBlank (FcConfig     *config,
                  FcChar32      blank)
 {
-    FcBlanks   *b;
+    FcBlanks   *b, *freeme = 0;
     
     b = config->blanks;
     if (!b)
     {
-       b = FcBlanksCreate ();
+       freeme = b = FcBlanksCreate ();
        if (!b)
            return FcFalse;
     }
     if (!FcBlanksAdd (b, blank))
+    {
+        if (freeme)
+            FcBlanksDestroy (freeme);
        return FcFalse;
+    }
     config->blanks = b;
     return FcTrue;
 }
@@ -778,6 +811,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
     FcValue    v, vl, vr;
     FcResult   r;
     FcMatrix   *m;
+    FcChar8     *str;
     
     switch (e->op) {
     case FcOpInteger:
@@ -791,7 +825,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
     case FcOpString:
        v.type = FcTypeString;
        v.u.s = FcStrStaticName(e->u.sval);
-       v = FcValueSave (v);
        break;
     case FcOpMatrix:
        v.type = FcTypeMatrix;
@@ -811,6 +844,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        r = FcPatternGet (p, e->u.field, 0, &v);
        if (r != FcResultMatch)
            v.type = FcTypeVoid;
+       v = FcValueSave (v);
        break;
     case FcOpConst:
        if (FcNameConstant (e->u.constant, &v.u.i))
@@ -908,7 +942,9 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
                switch (e->op) {
                case FcOpPlus:
                    v.type = FcTypeString;
-                   v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s));
+                   str = FcStrPlus (vl.u.s, vr.u.s);
+                   v.u.s = FcStrStaticName (str);
+                   FcStrFree (str);
                         
                    if (!v.u.s)
                        v.type = FcTypeVoid;
@@ -1083,7 +1119,6 @@ static FcValueList *
 FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
 {
     FcValueList        *l;
-    FcValueListPtr lp;
     
     if (!e)
        return 0;
@@ -1102,18 +1137,15 @@ FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
        l->next  = FcValueListPtrCreateDynamic(0);
     }
     l->binding = binding;
-    lp = FcValueListPtrCreateDynamic(l);
-    while (FcValueListPtrU(lp) && FcValueListPtrU(lp)->value.type == FcTypeVoid)
+    if (l->value.type == FcTypeVoid)
     {
-       FcValueListPtr  next = FcValueListPtrU(lp)->next;
+       FcValueList  *next = FcValueListPtrU(l->next);
 
-       if (lp.bank == FC_BANK_DYNAMIC)
-       {
-           FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
-           free (l);
-       }
-       lp = next;
+       FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
+       free (l);
+       l = next;
     }
+
     return l;
 }
 
@@ -1393,7 +1425,8 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                    /*
                     * Delete the marked value
                     */
-                   FcConfigDel (&st[i].elt->values, thisValue);
+                    if (thisValue)
+                       FcConfigDel (&st[i].elt->values, thisValue);
                    /*
                     * Adjust any pointers into the value list to ensure
                     * future edits occur at the same place
@@ -1448,6 +1481,7 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                FcConfigPatternAdd (p, e->field, l, FcTrue);
                break;
            default:
+                FcValueListDestroy (FcValueListPtrCreateDynamic(l));
                break;
            }
        }
@@ -1752,7 +1786,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
        FcConfigSetFonts (config, set, FcSetApplication);
     }
        
-    if (!FcFileScanConfig (set, subdirs, 0, config->blanks, file, FcFalse, config))
+    if (!FcFileScanConfig (set, subdirs, config->blanks, file, FcFalse, config))
     {
        FcStrSetDestroy (subdirs);
        return FcFalse;
@@ -1765,6 +1799,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
        }
        FcStrListDone (sublist);
     }
+    FcStrSetDestroy (subdirs);
     return FcTrue;
 }
 
@@ -1799,7 +1834,7 @@ FcConfigAppFontAddDir (FcConfig       *config,
        FcConfigSetFonts (config, set, FcSetApplication);
     }
     
-    if (!FcDirScanConfig (set, subdirs, 0, config->blanks, dir, FcFalse, config))
+    if (!FcDirScanConfig (set, subdirs, config->blanks, dir, FcFalse, config))
     {
        FcStrSetDestroy (subdirs);
        return FcFalse;
@@ -1812,6 +1847,7 @@ FcConfigAppFontAddDir (FcConfig       *config,
        }
        FcStrListDone (sublist);
     }
+    FcStrSetDestroy (subdirs);
     return FcTrue;
 }