2 * $XFree86: xc/lib/fontconfig/src/fcdir.c,v 1.2 2002/02/15 06:01:28 keithp Exp $
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
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 FcFileScan (FcFontSet *set,
57 name = FcFileCacheFind (cache, file, id, &count);
62 /* "." means the file doesn't contain a font */
63 if (FcStrCmp (name, FC_FONT_FILE_INVALID) == 0)
65 else if (FcStrCmp (name, FC_FONT_FILE_DIR) == 0)
67 ret = FcStrSetAdd (dirs, file);
72 font = FcNameParse (name);
74 FcPatternAddString (font, FC_FILE, file);
79 if (FcDebug () & FC_DBG_SCAN)
81 printf ("\tScanning file %s...", file);
84 font = FcFreeTypeQuery (file, id, blanks, &count);
85 if (FcDebug () & FC_DBG_SCAN)
88 if (!font && FcFileIsDir (file))
91 ret = FcStrSetAdd (dirs, file);
99 unparse = FcNameUnparse (font);
102 (void) FcFileCacheUpdate (cache, file, id, unparse);
110 FcFileCacheUpdate (cache, file, id, (FcChar8 *)
115 /* negative cache files not containing fonts */
116 FcFileCacheUpdate (cache, file, id, (FcChar8 *)
117 FC_FONT_FILE_INVALID);
124 if (!FcFontSetAdd (set, font))
126 FcPatternDestroy (font);
132 } while (font && ret && id < count);
137 FcDirCacheValid (const FcChar8 *dir)
142 path = (FcChar8 *) malloc (strlen ((const char *) dir) + 1 +
143 strlen ((const char *) FC_DIR_CACHE_FILE) + 1);
146 strcpy ((char *) path, (const char *) dir);
147 strcat ((char *) path, (const char *) "/");
148 strcat ((char *) path, (const char *) FC_DIR_CACHE_FILE);
149 ret = FcFileCacheValid (path);
154 #define FC_MAX_FILE_LEN 4096
157 FcDirScan (FcFontSet *set,
170 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
174 strcpy ((char *) file, (char *) dir);
175 strcat ((char *) file, "/");
176 base = file + strlen ((char *) file);
179 strcpy ((char *) base, FC_DIR_CACHE_FILE);
181 if (FcFileCacheReadDir (set, dirs, file))
188 d = opendir ((char *) dir);
192 /* Don't complain about missing directories */
197 while (ret && (e = readdir (d)))
199 if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
201 strcpy ((char *) base, (char *) e->d_name);
202 ret = FcFileScan (set, dirs, cache, blanks, file, force);
211 FcDirSave (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
217 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + 256 + 1);
221 strcpy ((char *) file, (char *) dir);
222 strcat ((char *) file, "/");
223 base = file + strlen ((char *) file);
224 strcpy ((char *) base, FC_DIR_CACHE_FILE);
225 ret = FcFileCacheWriteDir (set, dirs, file);