]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Compare device numbers as well as inodes. Always normalize directory names
[fontconfig.git] / src / fccfg.c
index 0032a9bbf62d52aeca6aa86287dbad50eafd60f6..c830444b127d8902c6fc49263a3919f1c03d6cf0 100644 (file)
@@ -139,11 +139,6 @@ bail0:
     return 0;
 }
 
-typedef struct _FcFileTime {
-    time_t  time;
-    FcBool  set;
-} FcFileTime;
-
 static FcFileTime
 FcConfigNewestFile (FcStrSet *files)
 {
@@ -166,6 +161,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)
 {
@@ -250,6 +258,7 @@ FcConfigBuildFonts (FcConfig *config)
     FcFontSet      *fonts, *cached_fonts;
     FcGlobalCache   *cache;
     FcStrList      *list;
+    FcStrSet       *oldDirs;
     FcChar8        *dir;
 
     fonts = FcFontSetCreate ();
@@ -260,20 +269,24 @@ FcConfigBuildFonts (FcConfig *config)
     if (!cache)
        goto bail1;
 
+    oldDirs = FcStrSetCreate ();
+    if (!oldDirs)
+        goto bail2;
+
     if (config->cache)
-       FcGlobalCacheLoad (cache, config->cache);
+       FcGlobalCacheLoad (cache, oldDirs, config->cache, config);
 
     cached_fonts = FcCacheRead(config, cache);
     if (!cached_fonts)
     {
        list = FcConfigGetFontDirs (config);
        if (!list)
-           goto bail1;
+           goto bail2;
        
        while ((dir = FcStrListNext (list)))
        {
            if (FcDebug () & FC_DBG_FONTSET)
-               printf ("scan dir %s\n", dir);
+               printf ("build scan dir %s\n", dir);
            FcDirScanConfig (fonts, config->fontDirs, cache, 
                             config->blanks, dir, FcFalse, config);
        }
@@ -284,9 +297,22 @@ FcConfigBuildFonts (FcConfig *config)
     {
        int i;
 
+        for (i = 0; i < oldDirs->num; i++)
+        {
+           if (FcDebug () & FC_DBG_FONTSET)
+               printf ("scan dir %s\n", oldDirs->strs[i]);
+           FcDirScanConfig (fonts, config->fontDirs, cache, 
+                            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 */
@@ -299,12 +325,15 @@ FcConfigBuildFonts (FcConfig *config)
        FcFontSetPrint (fonts);
 
     if (config->cache)
-       FcGlobalCacheSave (cache, config->cache);
+       FcGlobalCacheSave (cache, config->cache, config);
     FcGlobalCacheDestroy (cache);
+    FcStrSetDestroy (oldDirs);
 
     FcConfigSetFonts (config, fonts, FcSetSystem);
     
     return FcTrue;
+bail2:
+    FcStrSetDestroy (oldDirs);
 bail1:
     FcFontSetDestroy (fonts);
 bail0:
@@ -359,6 +388,30 @@ FcConfigAddFontDir (FcConfig           *config,
     return FcStrSetAddFilename (config->fontDirs, d);
 }
 
+const FcChar8 *
+FcConfigNormalizeFontDir (FcConfig     *config, 
+                         const FcChar8 *d)
+{
+    /* If this is a bottleneck, we can cache the fontDir inodes. */
+    ino_t      di;
+    dev_t      dd;
+    int                n;
+    struct stat s;
+
+    if (stat ((char *)d, &s) == -1)
+       return 0;
+    di = s.st_ino; dd = s.st_dev;
+
+    for (n = 0; n < config->fontDirs->num; n++)
+    {
+       if (stat ((char *)config->fontDirs->strs[n], &s) == -1)
+           continue;
+       if (di == s.st_ino && dd == s.st_dev)
+           return config->fontDirs->strs[n];
+    }
+    return 0;
+}
+
 FcBool
 FcConfigAddDir (FcConfig           *config,
                const FcChar8       *d)
@@ -794,6 +847,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))
@@ -1066,7 +1120,6 @@ static FcValueList *
 FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
 {
     FcValueList        *l;
-    FcValueListPtr lp;
     
     if (!e)
        return 0;
@@ -1085,18 +1138,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;
 }
 
@@ -1635,7 +1685,7 @@ FcConfigHome (void)
            home = getenv ("USERPROFILE");
 #endif
 
-       return home;
+       return (FcChar8 *) home;
     }
     return 0;
 }