]> 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 aaa05f56b47341ca34a3fb07eb0faaa7c1778f5f..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,36 +258,35 @@ FcConfigBuildFonts (FcConfig *config)
     FcFontSet      *fonts, *cached_fonts;
     FcGlobalCache   *cache;
     FcStrList      *list;
+    FcStrSet       *oldDirs;
     FcChar8        *dir;
 
-#if 0
-    if (config->cache)
-       FcGlobalCacheLoad (cache, config->cache);
-#endif
-    if (config->fonts[FcSetSystem])
-       return FcTrue;
-
     fonts = FcFontSetCreate ();
     if (!fonts)
        goto bail0;
-
-#if 0
+    
     cache = FcGlobalCacheCreate ();
     if (!cache)
        goto bail1;
-#endif
 
-    cached_fonts = FcCacheRead(config);
+    oldDirs = FcStrSetCreate ();
+    if (!oldDirs)
+        goto bail2;
+
+    if (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);
        }
@@ -290,26 +297,43 @@ 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 */
        }
+       cached_fonts->nfont = 0;
        FcFontSetDestroy (cached_fonts);
     }
     
     if (FcDebug () & FC_DBG_FONTSET)
        FcFontSetPrint (fonts);
 
-#if 0
     if (config->cache)
-       FcGlobalCacheSave (cache, config->cache);
+       FcGlobalCacheSave (cache, config->cache, config);
     FcGlobalCacheDestroy (cache);
-#endif
+    FcStrSetDestroy (oldDirs);
 
     FcConfigSetFonts (config, fonts, FcSetSystem);
     
     return FcTrue;
+bail2:
+    FcStrSetDestroy (oldDirs);
 bail1:
     FcFontSetDestroy (fonts);
 bail0:
@@ -364,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)
@@ -778,7 +826,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        break;
     case FcOpString:
        v.type = FcTypeString;
-       v.u.s = FcObjectStaticName(e->u.sval);
+       v.u.s = FcStrStaticName(e->u.sval);
        v = FcValueSave (v);
        break;
     case FcOpMatrix:
@@ -799,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))
@@ -896,7 +945,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
                switch (e->op) {
                case FcOpPlus:
                    v.type = FcTypeString;
-                   v.u.s = FcObjectStaticName (FcStrPlus (vl.u.s, vr.u.s));
+                   v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s));
                         
                    if (!v.u.s)
                        v.type = FcTypeVoid;
@@ -1071,7 +1120,6 @@ static FcValueList *
 FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
 {
     FcValueList        *l;
-    FcValueListPtr lp;
     
     if (!e)
        return 0;
@@ -1090,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;
 }
 
@@ -1640,7 +1685,7 @@ FcConfigHome (void)
            home = getenv ("USERPROFILE");
 #endif
 
-       return home;
+       return (FcChar8 *) home;
     }
     return 0;
 }