]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
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
,
50 FcGlobalCacheFile
*cache_file
;
51 FcGlobalCacheDir
*cache_dir
;
59 if (config
&& !FcConfigAcceptFilename (config
, file
))
75 if ((cache_file
= FcGlobalCacheFileGet (cache
, file
, id
, &count
)))
78 * Found a cache entry for the file
80 if (FcGlobalCacheCheckTime (file
, &cache_file
->info
))
82 name
= cache_file
->name
;
84 FcGlobalCacheReferenced (cache
, &cache_file
->info
);
85 /* "." means the file doesn't contain a font */
86 if (FcStrCmp (name
, FC_FONT_FILE_INVALID
) != 0)
88 font
= FcNameParse (name
);
90 if (!FcPatternAddString (font
, FC_FILE
, file
))
95 else if ((cache_dir
= FcGlobalCacheDirGet (cache
, file
,
96 strlen ((const char *) file
),
99 if (FcGlobalCacheCheckTime (cache_dir
->info
.file
,
104 FcGlobalCacheReferenced (cache
, &cache_dir
->info
);
105 if (!FcStrSetAdd (dirs
, file
))
112 * Nothing in the cache, scan the file
116 if (FcDebug () & FC_DBG_SCAN
)
118 printf ("\tScanning file %s...", file
);
121 font
= FcFreeTypeQuery (file
, id
, blanks
, &count
);
122 if (FcDebug () & FC_DBG_SCAN
)
125 if (!font
&& FcFileIsDir (file
))
128 ret
= FcStrSetAdd (dirs
, file
);
138 unparse
= FcNameUnparse (font
);
141 (void) FcGlobalCacheUpdate (cache
, file
, id
, unparse
);
150 if (font
&& (!config
|| FcConfigAcceptFont (config
, font
)))
152 if (!FcFontSetAdd (set
, font
))
154 FcPatternDestroy (font
);
160 FcPatternDestroy (font
);
162 } while (font
&& ret
&& id
< count
);
167 FcFileScan (FcFontSet
*set
,
169 FcGlobalCache
*cache
,
174 return FcFileScanConfig (set
, dirs
, cache
, blanks
, file
, force
, 0);
178 * Scan 'dir', adding font files to 'set' and
179 * subdirectories to 'dirs'
183 FcDirScanConfig (FcFontSet
*set
,
185 FcGlobalCache
*cache
,
197 if (config
&& !FcConfigAcceptFilename (config
, dir
))
204 * Check fonts.cache-<version> file
206 if (FcDirCacheReadDir (set
, dirs
, dir
, config
))
209 FcGlobalCacheReferenceSubdir (cache
, dir
);
214 * Check ~/.fonts.cache-<version> file
216 if (cache
&& FcGlobalCacheScanDir (set
, dirs
, cache
, dir
, config
))
222 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
226 strcpy ((char *) file
, (char *) dir
);
227 strcat ((char *) file
, "/");
228 base
= file
+ strlen ((char *) file
);
230 if (FcDebug () & FC_DBG_SCAN
)
231 printf ("\tScanning dir %s\n", dir
);
233 d
= opendir ((char *) dir
);
238 /* Don't complain about missing directories */
243 while (ret
&& (e
= readdir (d
)))
245 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
247 strcpy ((char *) base
, (char *) e
->d_name
);
248 ret
= FcFileScanConfig (set
, dirs
, cache
, blanks
, file
, force
, config
);
254 * Now that the directory has been scanned,
255 * add the cache entry
259 FcGlobalCacheUpdate (cache
, dir
, 0, 0);
266 FcDirScan (FcFontSet
*set
,
268 FcGlobalCache
*cache
,
273 return FcDirScanConfig (set
, dirs
, cache
, blanks
, dir
, force
, 0);
277 FcDirSave (FcFontSet
*set
, FcStrSet
*dirs
, const FcChar8
*dir
)
280 return FcDirCacheWriteDir (set
, dirs
, dir
);