]>
git.wh0rd.org - fontconfig.git/blob - src/fcdir.c
2 * fontconfig/src/fcdir.c
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 the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) 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
)
31 return FcFileIsDir2 (FcConfigGetCurrent (), file
);
35 FcFileIsDir2 (FcConfig
*config
, const FcChar8
*file
)
39 if (FcStat (config
, file
, &statb
) != 0)
41 return S_ISDIR(statb
.st_mode
);
45 FcFileScanFontConfig (FcFontSet
*set
,
60 * Nothing in the cache, scan the file
62 if (FcDebug () & FC_DBG_SCAN
)
64 printf ("\tScanning file %s...", file
);
67 font
= FcFreeTypeQuery2 (config
, file
, id
, blanks
, &count
);
68 if (FcDebug () & FC_DBG_SCAN
)
72 * Edit pattern with user-defined rules
74 if (font
&& config
&& !FcConfigSubstitute (config
, font
, FcMatchScan
))
76 FcPatternDestroy (font
);
86 if (FcDebug() & FC_DBG_SCANV
)
88 printf ("Final font pattern:\n");
89 FcPatternPrint (font
);
91 if (!FcFontSetAdd (set
, font
))
93 FcPatternDestroy (font
);
99 FcPatternDestroy (font
);
101 } while (font
&& ret
&& id
< count
);
106 FcFileScanConfig (FcFontSet
*set
,
112 if (FcFileIsDir2 (config
, file
))
113 return FcStrSetAdd (dirs
, file
);
115 return FcFileScanFontConfig (set
, blanks
, file
, config
);
119 FcFileScan (FcFontSet
*set
,
121 FcFileCache
*cache
, /* XXX unused */
126 return FcFileScanConfig (set
, dirs
, blanks
, file
, FcConfigGetCurrent ());
130 * Strcmp helper that takes pointers to pointers, copied from qsort(3) manpage
133 cmpstringp(const void *p1
, const void *p2
)
135 return strcmp(* (char **) p1
, * (char **) p2
);
139 FcDirScanConfig (FcFontSet
*set
,
143 FcBool force
, /* XXX unused */
151 const FcChar8
*scanDir
;
163 blanks
= FcConfigGetBlanks (config
);
166 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
172 strcpy ((char *) file
, (char *) dir
);
173 strcat ((char *) file
, "/");
174 base
= file
+ strlen ((char *) file
);
176 if (FcDebug () & FC_DBG_SCAN
)
177 printf ("\tScanning dir %s\n", dir
);
179 fullDir
= FcConfigGetRootPlus (config
, dir
);
184 d
= opendir ((char *) scanDir
);
189 /* Don't complain about missing directories */
195 files
= FcStrSetCreate ();
201 while ((e
= readdir (d
)))
203 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
205 strcpy ((char *) base
, (char *) e
->d_name
);
206 if (!FcStrSetAdd (files
, file
)) {
214 * Sort files to make things prettier
216 qsort(files
->strs
, files
->num
, sizeof(FcChar8
*), cmpstringp
);
219 * Scan file files to build font patterns
221 for (i
= 0; i
< files
->num
; i
++)
222 FcFileScanConfig (set
, dirs
, blanks
, files
->strs
[i
], config
);
225 FcStrSetDestroy (files
);
233 FcDirScan (FcFontSet
*set
,
235 FcFileCache
*cache
, /* XXX unused */
238 FcBool force
/* XXX unused */)
243 return FcDirScanConfig (set
, dirs
, blanks
, dir
, force
, FcConfigGetCurrent ());
247 * Scan the specified directory and construct a cache of its contents
250 FcDirCacheScan (const FcChar8
*dir
, FcConfig
*config
)
254 FcCache
*cache
= NULL
;
255 struct stat dir_stat
;
257 if (FcDebug () & FC_DBG_FONTSET
)
258 printf ("cache scan dir %s\n", dir
);
260 if (FcStat (config
, dir
, &dir_stat
) < 0)
263 set
= FcFontSetCreate();
267 dirs
= FcStrSetCreate ();
274 if (!FcDirScanConfig (set
, dirs
, NULL
, dir
, FcTrue
, config
))
278 * Build the cache object
280 cache
= FcDirCacheBuild (set
, dir
, &dir_stat
, dirs
);
285 * Write out the cache file, ignoring any troubles
287 FcDirCacheWrite (cache
, config
);
290 FcStrSetDestroy (dirs
);
292 FcFontSetDestroy (set
);
298 * Read (or construct) the cache for a directory
301 FcDirCacheRead (const FcChar8
*dir
, FcBool force
, FcConfig
*config
)
303 FcCache
*cache
= NULL
;
305 /* Try to use existing cache file */
307 cache
= FcDirCacheLoad (dir
, config
, NULL
);
309 /* Not using existing cache file, construct new cache */
311 cache
= FcDirCacheScan (dir
, config
);
317 FcDirSave (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
)
319 return FcFalse
; /* XXX deprecated */
322 #include "fcaliastail.h"