2 * $RCSId: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 keithp Exp $
4 * Copyright © 2000 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 FcFileIsDir (const FcChar8 *file)
33 if (stat ((const char *) file, &statb) != 0)
35 return S_ISDIR(statb.st_mode);
39 FcFileScanConfig (FcFontSet *set,
53 FcGlobalCacheFile *cache_file;
54 FcGlobalCacheDir *cache_dir;
57 if (config && !FcConfigAcceptFilename (config, file))
72 if ((cache_file = FcGlobalCacheFileGet (cache, file, id, &count)))
75 * Found a cache entry for the file
77 if (FcGlobalCacheCheckTime (file, &cache_file->info))
79 name = cache_file->name;
81 FcGlobalCacheReferenced (cache, &cache_file->info);
82 /* "." means the file doesn't contain a font */
83 if (FcStrCmp (name, FC_FONT_FILE_INVALID) != 0)
85 font = FcNameParse (name);
87 if (!FcPatternAddString (font, FC_FILE, file))
92 else if ((cache_dir = FcGlobalCacheDirGet (cache, file,
93 strlen ((const char *) file),
96 if (FcGlobalCacheCheckTime (cache_dir->info.file,
101 FcGlobalCacheReferenced (cache, &cache_dir->info);
102 if (!FcStrSetAdd (dirs, file))
108 * Nothing in the cache, scan the file
112 if (FcDebug () & FC_DBG_SCAN)
114 printf ("\tScanning file %s...", file);
117 font = FcFreeTypeQuery (file, id, blanks, &count);
118 if (FcDebug () & FC_DBG_SCAN)
121 if (!font && FcFileIsDir (file))
124 ret = FcStrSetAdd (dirs, file);
133 unparse = FcNameUnparse (font);
136 (void) FcGlobalCacheUpdate (cache, file, id, unparse);
146 if (!FcFontSetAdd (set, font))
148 FcPatternDestroy (font);
154 } while (font && ret && id < count);
159 FcFileScan (FcFontSet *set,
161 FcGlobalCache *cache,
166 return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0);
169 #define FC_MAX_FILE_LEN 4096
172 * Scan 'dir', adding font files to 'set' and
173 * subdirectories to 'dirs'
177 FcDirScanConfig (FcFontSet *set,
179 FcGlobalCache *cache,
191 if (config && !FcConfigAcceptFilename (config, dir))
197 * Check fonts.cache-<version> file
199 if (FcDirCacheReadDir (set, dirs, dir, config))
202 FcGlobalCacheReferenceSubdir (cache, dir);
207 * Check ~/.fonts.cache-<version> file
209 if (cache && FcGlobalCacheScanDir (set, dirs, cache, dir, config))
214 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
218 strcpy ((char *) file, (char *) dir);
219 strcat ((char *) file, "/");
220 base = file + strlen ((char *) file);
222 if (FcDebug () & FC_DBG_SCAN)
223 printf ("\tScanning dir %s\n", dir);
225 d = opendir ((char *) dir);
230 /* Don't complain about missing directories */
235 while (ret && (e = readdir (d)))
237 if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
239 strcpy ((char *) base, (char *) e->d_name);
240 ret = FcFileScanConfig (set, dirs, cache, blanks, file, force, config);
246 * Now that the directory has been scanned,
247 * add the cache entry
250 FcGlobalCacheUpdate (cache, dir, 0, 0);
256 FcDirScan (FcFontSet *set,
258 FcGlobalCache *cache,
263 return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0);
267 FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
269 return FcDirCacheWriteDir (set, dirs, dir);