]>
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
,
52 if (config
&& !FcConfigAcceptFilename (config
, file
))
55 if (FcFileIsDir (file
))
56 return FcStrSetAdd (dirs
, file
);
63 * Nothing in the cache, scan the file
65 if (FcDebug () & FC_DBG_SCAN
)
67 printf ("\tScanning file %s...", file
);
70 font
= FcFreeTypeQuery (file
, id
, blanks
, &count
);
71 if (FcDebug () & FC_DBG_SCAN
)
76 if (font
&& (!config
|| FcConfigAcceptFont (config
, font
)))
78 if (!FcFontSetAdd (set
, font
))
80 FcPatternDestroy (font
);
86 FcPatternDestroy (font
);
88 } while (font
&& ret
&& id
< count
);
93 FcFileScan (FcFontSet
*set
,
100 return FcFileScanConfig (set
, dirs
, cache
, blanks
, file
, force
, 0);
104 * Strcmp helper that takes pointers to pointers, copied from qsort(3) manpage
108 cmpstringp(const void *p1
, const void *p2
)
110 return strcmp(* (char **) p1
, * (char **) p2
);
114 * Scan 'dir', adding font files to 'set' and
115 * subdirectories to 'dirs'
119 FcDirScanConfig (FcFontSet
*set
,
121 FcGlobalCache
*cache
,
130 int dirlistlen
, dirlistalloc
;
137 if (config
&& !FcConfigAcceptFilename (config
, dir
))
143 * Check ~/.fonts.cache-<version> file
145 if (cache
&& FcGlobalCacheReadDir (set
, dirs
, cache
, (char *)dir
, config
))
148 if (FcDirCacheValid (dir
, config
) &&
149 FcDirCacheHasCurrentArch (dir
, config
) &&
150 FcDirCacheRead (set
, dirs
, dir
, config
))
155 file
= (FcChar8
*) malloc (strlen ((char *) dir
) + 1 + FC_MAX_FILE_LEN
+ 1);
159 strcpy ((char *) file
, (char *) dir
);
160 strcat ((char *) file
, "/");
161 base
= file
+ strlen ((char *) file
);
163 if (FcDebug () & FC_DBG_SCAN
)
164 printf ("\tScanning dir %s\n", dir
);
166 d
= opendir ((char *) dir
);
170 /* Don't complain about missing directories */
176 tmpSet
= FcFontSetCreate();
185 dirlist
= malloc(dirlistalloc
* sizeof(FcChar8
*));
191 while ((e
= readdir (d
)))
193 if (e
->d_name
[0] != '.' && strlen (e
->d_name
) < FC_MAX_FILE_LEN
)
195 if (dirlistlen
== dirlistalloc
)
197 FcChar8
**tmp_dirlist
;
200 tmp_dirlist
= realloc(dirlist
,
201 dirlistalloc
* sizeof(FcChar8
*));
207 dirlist
= tmp_dirlist
;
209 dirlist
[dirlistlen
] = malloc(strlen (e
->d_name
) + 1);
210 if (!dirlist
[dirlistlen
])
215 strcpy((char *)dirlist
[dirlistlen
], e
->d_name
);
219 qsort(dirlist
, dirlistlen
, sizeof(FcChar8
*), cmpstringp
);
221 while (ret
&& i
< dirlistlen
)
223 strcpy ((char *) base
, (char *) dirlist
[i
]);
224 ret
= FcFileScanConfig (tmpSet
, dirs
, cache
, blanks
, file
, force
, config
);
228 * Now that the directory has been scanned,
229 * add the cache entry
232 FcGlobalCacheUpdate (cache
, dirs
, (char *)dir
, tmpSet
, config
);
234 for (i
= 0; i
< tmpSet
->nfont
; i
++)
235 FcFontSetAdd (set
, tmpSet
->fonts
[i
]);
239 FcMemFree (FC_MEM_FONTPTR
, tmpSet
->sfont
* sizeof (FcPattern
*));
240 free (tmpSet
->fonts
);
242 FcMemFree (FC_MEM_FONTSET
, sizeof (FcFontSet
));
245 for (i
= 0; i
< dirlistlen
; i
++)
261 FcDirScan (FcFontSet
*set
,
263 FcGlobalCache
*cache
,
268 return FcDirScanConfig (set
, dirs
, cache
, blanks
, dir
, force
, 0);
272 FcDirSave (FcFontSet
*set
, FcStrSet
* dirs
, const FcChar8
*dir
)
274 return FcDirCacheWrite (set
, dirs
, dir
, FcConfigGetCurrent ());