]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
2 * $XFree86: xc/lib/fontconfig/src/fcdir.c,v 1.5 2002/05/21 17:06:22 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 if (!FcPatternAddString (font
, FC_FILE
, file
))
80 if (FcDebug () & FC_DBG_SCAN
)
82 printf ("\tScanning file %s...", file
);
85 font
= FcFreeTypeQuery (file
, id
, blanks
, &count
);
86 if (FcDebug () & FC_DBG_SCAN
)
89 if (!font
&& FcFileIsDir (file
))
92 ret
= FcStrSetAdd (dirs
, file
);
100 unparse
= FcNameUnparse (font
);
103 (void) FcFileCacheUpdate (cache
, file
, id
, unparse
);
111 FcFileCacheUpdate (cache
, file
, id
, (FcChar8
*)
116 /* negative cache files not containing fonts */
117 FcFileCacheUpdate (cache
, file
, id
, (FcChar8
*)
118 FC_FONT_FILE_INVALID
);
125 if (!FcFontSetAdd (set
, font
))
127 FcPatternDestroy (font
);
133 } while (font
&& ret
&& id
< count
);
138 FcDirCacheValid (const FcChar8
*dir
)
143 path
= (FcChar8
*) malloc (strlen ((const char *) dir
) + 1 +
144 strlen ((const char *) FC_DIR_CACHE_FILE
) + 1);
147 strcpy ((char *) path
, (const char *) dir
);
148 strcat ((char *) path
, (const char *) "/");
149 strcat ((char *) path
, (const char *) FC_DIR_CACHE_FILE
);
150 ret
= FcFileCacheValid (path
);
155 #define FC_MAX_FILE_LEN 4096
158 FcDirScan (FcFontSet
*set
,
171 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
175 strcpy ((char *) file
, (char *) dir
);
176 strcat ((char *) file
, "/");
177 base
= file
+ strlen ((char *) file
);
180 strcpy ((char *) base
, FC_DIR_CACHE_FILE
);
182 if (FcFileCacheReadDir (set
, dirs
, file
))
189 d
= opendir ((char *) dir
);
193 /* Don't complain about missing directories */
198 while (ret
&& (e
= readdir (d
)))
200 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
202 strcpy ((char *) base
, (char *) e
->d_name
);
203 ret
= FcFileScan (set
, dirs
, cache
, blanks
, file
, force
);
212 FcDirSave (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
)
218 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + 256 + 1);
222 strcpy ((char *) file
, (char *) dir
);
223 strcat ((char *) file
, "/");
224 base
= file
+ strlen ((char *) file
);
225 strcpy ((char *) base
, FC_DIR_CACHE_FILE
);
226 ret
= FcFileCacheWriteDir (set
, dirs
, file
);