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.
25 #include <sys/types.h>
31 #define FC_INVALID_FONT_FILE "."
34 FcFileScan (FcFontSet *set,
50 name = FcFileCacheFind (cache, file, id, &count);
55 /* "." means the file doesn't contain a font */
56 if (strcmp ((const char *) name, FC_INVALID_FONT_FILE) != 0)
58 font = FcNameParse (name);
60 FcPatternAddString (font, FC_FILE, file);
67 if (FcDebug () & FC_DBG_SCAN)
69 printf ("\tScanning file %s...", file);
72 font = FcFreeTypeQuery (file, id, blanks, &count);
73 if (FcDebug () & FC_DBG_SCAN)
81 unparse = FcNameUnparse (font);
84 (void) FcFileCacheUpdate (cache, file, id, unparse);
90 /* negative cache files not containing fonts */
91 FcFileCacheUpdate (cache, file, id, (FcChar8 *) FC_INVALID_FONT_FILE);
97 if (!FcFontSetAdd (set, font))
99 FcPatternDestroy (font);
105 } while (font && ret && id < count);
110 FcDirScan (FcFontSet *set,
122 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + 256 + 1);
126 strcpy ((char *) file, (char *) dir);
127 strcat ((char *) file, "/");
128 base = file + strlen ((char *) file);
131 strcpy ((char *) base, FC_DIR_CACHE_FILE);
133 if (FcFileCacheReadDir (set, file))
140 d = opendir ((char *) dir);
146 while (ret && (e = readdir (d)))
148 if (e->d_name[0] != '.')
150 strcpy ((char *) base, (char *) e->d_name);
151 FcFileScan (set, cache, blanks, file, force);
160 FcDirSave (FcFontSet *set, const FcChar8 *dir)
166 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + 256 + 1);
170 strcpy ((char *) file, (char *) dir);
171 strcat ((char *) file, "/");
172 base = file + strlen ((char *) file);
173 strcpy ((char *) base, FC_DIR_CACHE_FILE);
174 ret = FcFileCacheWriteDir (set, file);