]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcdir.c
Update links to new freedesktop.org locations
[fontconfig.git] / src / fcdir.c
index 3feb5ee88ffe173231941fa42a37670935b6eb2d..5c9646f30a80b5029d8818cacdde766437ac9639 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcdir.c,v 1.7 2002/07/28 10:50:59 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,12 +36,13 @@ 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;
     FcChar8            *name;
@@ -53,6 +54,9 @@ FcFileScan (FcFontSet     *set,
     FcGlobalCacheDir   *cache_dir;
     FcBool             need_scan;
     
+    if (config && !FcConfigAcceptFilename (config, file))
+       return FcTrue;
+
     if (force)
        cache = 0;
     id = 0;
@@ -70,7 +74,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 +93,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;
@@ -136,7 +141,7 @@ FcFileScan (FcFontSet           *set,
        /*
         * Add the font
         */
-       if (font)
+       if (font && (!config || FcConfigAcceptFont (config, font)))
        {
            if (!FcFontSetAdd (set, font))
            {
@@ -150,15 +155,30 @@ FcFileScan (FcFontSet         *set,
     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
+ * subdirectories to 'dirs'
+ */
 
 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;
@@ -166,18 +186,25 @@ FcDirScan (FcFontSet          *set,
     FcChar8            *base;
     FcBool             ret = FcTrue;
 
+    if (config && !FcConfigAcceptFilename (config, dir))
+       return FcTrue;
+
     if (!force)
     {
        /*
         * 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;
     }
     
@@ -190,6 +217,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)
@@ -205,17 +235,32 @@ 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);
     closedir (d);
+    /*
+     * Now that the directory has been scanned,
+     * add the cache entry 
+     */
     if (ret && cache)
        FcGlobalCacheUpdate (cache, dir, 0, 0);
        
     return ret;
 }
 
+FcBool
+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, FcStrSet *dirs, const FcChar8 *dir)
 {