]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcdir.c
Overhaul the serialization system to create one mmapable file per directory
[fontconfig.git] / src / fcdir.c
index 08334ab2785fddff2820a184406c6b731c6c99c6..4f69f228bc0688fb98fb65df81b13d3a597f3fb1 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
+ * $RCSId: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
  *
- * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2000 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -25,7 +25,7 @@
 #include "fcint.h"
 #include <dirent.h>
 
-static FcBool
+FcBool
 FcFileIsDir (const FcChar8 *file)
 {
     struct stat            statb;
@@ -36,23 +36,29 @@ FcFileIsDir (const FcChar8 *file)
 }
 
 FcBool
-FcFileScan (FcFontSet      *set,
-           FcStrSet        *dirs,
-           FcGlobalCache   *cache,
-           FcBlanks        *blanks,
-           const FcChar8   *file,
-           FcBool          force)
+FcFileScanConfig (FcFontSet    *set,
+                 FcStrSet      *dirs,
+                 FcGlobalCache *cache,
+                 FcBlanks      *blanks,
+                 const FcChar8 *file,
+                 FcBool        force,
+                 FcConfig      *config)
 {
     int                        id;
+#if 0
     FcChar8            *name;
+    FcGlobalCacheFile  *cache_file;
+    FcGlobalCacheDir   *cache_dir;
+#endif
     FcPattern          *font;
     FcBool             ret = FcTrue;
     FcBool             isDir;
     int                        count = 0;
-    FcGlobalCacheFile  *cache_file;
-    FcGlobalCacheDir   *cache_dir;
     FcBool             need_scan;
     
+    if (config && !FcConfigAcceptFilename (config, file))
+       return FcTrue;
+
     if (force)
        cache = 0;
     id = 0;
@@ -60,6 +66,7 @@ FcFileScan (FcFontSet     *set,
     {
        need_scan = FcTrue;
        font = 0;
+#if 0
        /*
         * Check the cache
         */
@@ -70,7 +77,7 @@ FcFileScan (FcFontSet     *set,
                /*
                 * Found a cache entry for the file
                 */
-               if (FcGlobalCacheCheckTime (&cache_file->info))
+               if (FcGlobalCacheCheckTime (file, &cache_file->info))
                {
                    name = cache_file->name;
                    need_scan = FcFalse;
@@ -89,7 +96,8 @@ FcFileScan (FcFontSet     *set,
                                                       strlen ((const char *) file),
                                                       FcFalse)))
            {
-               if (FcGlobalCacheCheckTime (&cache_dir->info))
+               if (FcGlobalCacheCheckTime (cache_dir->info.file, 
+                                           &cache_dir->info))
                {
                    font = 0;
                    need_scan = FcFalse;
@@ -99,6 +107,7 @@ FcFileScan (FcFontSet            *set,
                }
            }
        }
+#endif
        /*
         * Nothing in the cache, scan the file
         */
@@ -118,6 +127,7 @@ FcFileScan (FcFontSet           *set,
                isDir = FcTrue;
                ret = FcStrSetAdd (dirs, file);
            }
+#if 0
            /*
             * Update the cache
             */
@@ -132,11 +142,12 @@ FcFileScan (FcFontSet         *set,
                    FcStrFree (unparse);
                }
            }
+#endif
        }
        /*
         * Add the font
         */
-       if (font)
+       if (font && (!config || FcConfigAcceptFont (config, font)))
        {
            if (!FcFontSetAdd (set, font))
            {
@@ -145,12 +156,23 @@ FcFileScan (FcFontSet         *set,
                ret = FcFalse;
            }
        }
+       else if (font)
+           FcPatternDestroy (font);
        id++;
     } while (font && ret && id < count);
     return ret;
 }
 
-#define FC_MAX_FILE_LEN            4096
+FcBool
+FcFileScan (FcFontSet      *set,
+           FcStrSet        *dirs,
+           FcGlobalCache   *cache,
+           FcBlanks        *blanks,
+           const FcChar8   *file,
+           FcBool          force)
+{
+    return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0);
+}
 
 /*
  * Scan 'dir', adding font files to 'set' and
@@ -158,12 +180,13 @@ FcFileScan (FcFontSet         *set,
  */
 
 FcBool
-FcDirScan (FcFontSet       *set,
-          FcStrSet         *dirs,
-          FcGlobalCache    *cache,
-          FcBlanks         *blanks,
-          const FcChar8    *dir,
-          FcBool           force)
+FcDirScanConfig (FcFontSet     *set,
+                FcStrSet       *dirs,
+                FcGlobalCache  *cache,
+                FcBlanks       *blanks,
+                const FcChar8  *dir,
+                FcBool         force,
+                FcConfig       *config)
 {
     DIR                        *d;
     struct dirent      *e;
@@ -171,19 +194,28 @@ FcDirScan (FcFontSet          *set,
     FcChar8            *base;
     FcBool             ret = FcTrue;
 
+    if (config && !FcConfigAcceptFilename (config, dir))
+       return FcTrue;
+
     if (!force)
     {
+#if 0
        /*
         * Check fonts.cache-<version> file
         */
-       if (FcDirCacheReadDir (set, dirs, dir))
+       if (FcDirCacheReadDir (set, dirs, dir, config))
+       {
+           if (cache)
+               FcGlobalCacheReferenceSubdir (cache, dir);
            return FcTrue;
+       }
     
        /*
         * Check ~/.fonts.cache-<version> file
         */
-       if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir))
+       if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
            return FcTrue;
+#endif
     }
     
     /* freed below */
@@ -195,6 +227,9 @@ FcDirScan (FcFontSet            *set,
     strcat ((char *) file, "/");
     base = file + strlen ((char *) file);
     
+    if (FcDebug () & FC_DBG_SCAN)
+       printf ("\tScanning dir %s\n", dir);
+       
     d = opendir ((char *) dir);
     
     if (!d)
@@ -210,7 +245,7 @@ FcDirScan (FcFontSet            *set,
        if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
        {
            strcpy ((char *) base, (char *) e->d_name);
-           ret = FcFileScan (set, dirs, cache, blanks, file, force);
+           ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
        }
     }
     free (file);
@@ -219,14 +254,37 @@ FcDirScan (FcFontSet          *set,
      * Now that the directory has been scanned,
      * add the cache entry 
      */
+#if 0
     if (ret && cache)
        FcGlobalCacheUpdate (cache, dir, 0, 0);
+#endif
        
     return ret;
 }
 
 FcBool
-FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
+FcDirScan (FcFontSet       *set,
+          FcStrSet         *dirs,
+          FcGlobalCache    *cache,
+          FcBlanks         *blanks,
+          const FcChar8    *dir,
+          FcBool           force)
+{
+    return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0);
+}
+
+FcBool
+FcDirSave (FcFontSet *set, const FcChar8 *dir)
 {
-    return FcDirCacheWriteDir (set, dirs, dir);
+    static int rand_state = 0;
+    int bank;
+
+    if (!rand_state) 
+       rand_state = time(0L);
+    bank = rand_r(&rand_state);
+
+    while (FcCacheHaveBank(bank))
+       bank = rand_r(&rand_state);
+
+    return FcDirCacheWrite (bank, set, dir);
 }