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 if (config && !FcConfigAcceptFilename (config, file))
63 * Nothing in the cache, scan the file
65 if (FcDebug () & FC_DBG_SCAN)
67 printf ("\tScanning file %s...", file);
70 font = FcFreeTypeQuery (file, id, blanks, &count);
71 if (FcDebug () & FC_DBG_SCAN)
74 if (!font && FcFileIsDir (file))
77 ret = FcStrSetAdd (dirs, file);
82 if (font && (!config || FcConfigAcceptFont (config, font)))
84 if (!FcFontSetAdd (set, font))
86 FcPatternDestroy (font);
92 FcPatternDestroy (font);
94 } while (font && ret && id < count);
99 FcFileScan (FcFontSet *set,
101 FcGlobalCache *cache,
106 return FcFileScanConfig (set, dirs, cache, blanks, file, force, 0);
110 * Scan 'dir', adding font files to 'set' and
111 * subdirectories to 'dirs'
115 FcDirScanConfig (FcFontSet *set,
117 FcGlobalCache *cache,
131 if (config && !FcConfigAcceptFilename (config, dir))
137 * Check ~/.fonts.cache-<version> file
139 if (cache && FcGlobalCacheReadDir (set, dirs, cache, (char *)dir, config))
142 if (FcDirCacheValid (dir) && FcDirCacheRead (set, dirs, dir))
147 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
151 strcpy ((char *) file, (char *) dir);
152 strcat ((char *) file, "/");
153 base = file + strlen ((char *) file);
155 if (FcDebug () & FC_DBG_SCAN)
156 printf ("\tScanning dir %s\n", dir);
158 d = opendir ((char *) dir);
162 /* Don't complain about missing directories */
168 tmpSet = FcFontSetCreate();
175 while (ret && (e = readdir (d)))
177 if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
179 strcpy ((char *) base, (char *) e->d_name);
180 ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
186 * Now that the directory has been scanned,
187 * add the cache entry
190 FcGlobalCacheUpdate (cache, (char *)dir, tmpSet);
192 for (i = 0; i < tmpSet->nfont; i++)
193 FcFontSetAdd (set, tmpSet->fonts[i]);
197 FcMemFree (FC_MEM_FONTPTR, tmpSet->sfont * sizeof (FcPattern *));
198 free (tmpSet->fonts);
200 FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
207 FcDirScan (FcFontSet *set,
209 FcGlobalCache *cache,
214 return FcDirScanConfig (set, dirs, cache, blanks, dir, force, 0);
218 FcDirSave (FcFontSet *set, FcStrSet * dirs, const FcChar8 *dir)
220 return FcDirCacheWrite (set, dirs, dir);