]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
2 * $XFree86: xc/lib/fontconfig/src/fcdir.c,v 1.9 2002/08/31 22:17:32 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
,
52 FcGlobalCacheFile
*cache_file
;
53 FcGlobalCacheDir
*cache_dir
;
68 if ((cache_file
= FcGlobalCacheFileGet (cache
, file
, id
, &count
)))
71 * Found a cache entry for the file
73 if (FcGlobalCacheCheckTime (&cache_file
->info
))
75 name
= cache_file
->name
;
77 FcGlobalCacheReferenced (cache
, &cache_file
->info
);
78 /* "." means the file doesn't contain a font */
79 if (FcStrCmp (name
, FC_FONT_FILE_INVALID
) != 0)
81 font
= FcNameParse (name
);
83 if (!FcPatternAddString (font
, FC_FILE
, file
))
88 else if ((cache_dir
= FcGlobalCacheDirGet (cache
, file
,
89 strlen ((const char *) file
),
92 if (FcGlobalCacheCheckTime (&cache_dir
->info
))
96 FcGlobalCacheReferenced (cache
, &cache_dir
->info
);
97 if (!FcStrSetAdd (dirs
, file
))
103 * Nothing in the cache, scan the file
107 if (FcDebug () & FC_DBG_SCAN
)
109 printf ("\tScanning file %s...", file
);
112 font
= FcFreeTypeQuery (file
, id
, blanks
, &count
);
113 if (FcDebug () & FC_DBG_SCAN
)
116 if (!font
&& FcFileIsDir (file
))
119 ret
= FcStrSetAdd (dirs
, file
);
128 unparse
= FcNameUnparse (font
);
131 (void) FcGlobalCacheUpdate (cache
, file
, id
, unparse
);
141 if (!FcFontSetAdd (set
, font
))
143 FcPatternDestroy (font
);
149 } while (font
&& ret
&& id
< count
);
153 #define FC_MAX_FILE_LEN 4096
156 * Scan 'dir', adding font files to 'set' and
157 * subdirectories to 'dirs'
161 FcDirScan (FcFontSet
*set
,
163 FcGlobalCache
*cache
,
177 * Check fonts.cache-<version> file
179 if (FcDirCacheReadDir (set
, dirs
, dir
))
182 FcGlobalCacheReferenceSubdir (cache
, dir
);
187 * Check ~/.fonts.cache-<version> file
189 if (cache
&& FcGlobalCacheScanDir (set
, dirs
, cache
, dir
))
194 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
198 strcpy ((char *) file
, (char *) dir
);
199 strcat ((char *) file
, "/");
200 base
= file
+ strlen ((char *) file
);
202 d
= opendir ((char *) dir
);
207 /* Don't complain about missing directories */
212 while (ret
&& (e
= readdir (d
)))
214 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
216 strcpy ((char *) base
, (char *) e
->d_name
);
217 ret
= FcFileScan (set
, dirs
, cache
, blanks
, file
, force
);
223 * Now that the directory has been scanned,
224 * add the cache entry
227 FcGlobalCacheUpdate (cache
, dir
, 0, 0);
233 FcDirSave (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
)
235 return FcDirCacheWriteDir (set
, dirs
, dir
);