/*
* $RCSId: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
*
- * Copyright © 2000 Keith Packard
+ * 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
#include "fcint.h"
#include <dirent.h>
-static FcBool
+FcBool
FcFileIsDir (const FcChar8 *file)
{
struct stat statb;
}
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;
{
need_scan = FcTrue;
font = 0;
+#if 0
/*
* Check the cache
*/
}
}
}
+#endif
/*
* Nothing in the cache, scan the file
*/
isDir = FcTrue;
ret = FcStrSetAdd (dirs, file);
}
+#if 0
/*
* Update the cache
*/
FcStrFree (unparse);
}
}
+#endif
}
/*
* Add the font
*/
- if (font)
+ if (font && (!config || FcConfigAcceptFont (config, font)))
{
if (!FcFontSetAdd (set, font))
{
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
*/
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;
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);
/*
* 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 */
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);
* 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);
}