]>
git.wh0rd.org - fontconfig.git/blob - fc-cache/fc-cache.c
2 * $RCSId: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.8tsi Exp $
4 * Copyright © 2002 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.
25 #include <fontconfig/fontconfig.h>
29 #include <sys/types.h>
36 #define HAVE_GETOPT_LONG 1
44 #ifndef HAVE_GETOPT_LONG
45 #define HAVE_GETOPT_LONG 0
52 const struct option longopts
[] = {
54 {"system-only", 0, 0, 's'},
55 {"version", 0, 0, 'V'},
56 {"verbose", 0, 0, 'v'},
63 extern int optind
, opterr
, optopt
;
71 fprintf (stderr
, "usage: %s [-fsvV?] [--force] [--system-only] [--verbose] [--version] [--help] [dirs]\n",
74 fprintf (stderr
, "usage: %s [-fsvV?] [dirs]\n",
77 fprintf (stderr
, "Build font information caches in [dirs]\n"
78 "(all directories in font configuration by default).\n");
79 fprintf (stderr
, "\n");
81 fprintf (stderr
, " -f, --force scan directories with apparently valid caches\n");
82 fprintf (stderr
, " -s, --system-only scan system-wide directories only\n");
83 fprintf (stderr
, " -v, --verbose display status information while busy\n");
84 fprintf (stderr
, " -V, --version display font config version and exit\n");
85 fprintf (stderr
, " -?, --help display this help and exit\n");
87 fprintf (stderr
, " -f (force) scan directories with apparently valid caches\n");
88 fprintf (stderr
, " -s (system) scan system-wide directories only\n");
89 fprintf (stderr
, " -v (verbose) display status information while busy\n");
90 fprintf (stderr
, " -V (version) display font config version and exit\n");
91 fprintf (stderr
, " -? (help) display this help and exit\n");
96 static FcStrSet
*processed_dirs
;
99 nsubdirs (FcStrSet
*set
)
104 list
= FcStrListCreate (set
);
107 while (FcStrListNext (list
))
109 FcStrListDone (list
);
114 scanDirs (FcStrList
*list
, FcConfig
*config
, char *program
, FcBool force
, FcBool verbose
)
118 const FcChar8
*dir_orig
;
125 * Now scan all of the directories into separate databases
126 * and write out the results
128 while ((dir_orig
= FcStrListNext (list
)))
130 dir
= FcConfigNormalizeFontDir (config
, dir_orig
);
134 printf ("%s: \"%s\": ", program
, dir
? dir
: dir_orig
);
141 printf ("skipping, no such directory\n");
145 if (FcStrSetMember (processed_dirs
, dir
))
148 printf ("skipping, looped directory detected\n");
152 set
= FcFontSetCreate ();
155 fprintf (stderr
, "Can't create font set\n");
159 subdirs
= FcStrSetCreate ();
162 fprintf (stderr
, "Can't create directory set\n");
164 FcFontSetDestroy (set
);
168 if (access ((char *) dir
, W_OK
) < 0)
174 printf ("skipping, no such directory\n");
179 printf ("skipping, no write access\n");
182 fprintf (stderr
, "\"%s\": ", dir
);
186 FcFontSetDestroy (set
);
187 FcStrSetDestroy (subdirs
);
190 if (stat ((char *) dir
, &statb
) == -1)
192 fprintf (stderr
, "\"%s\": ", dir
);
194 FcFontSetDestroy (set
);
195 FcStrSetDestroy (subdirs
);
199 if (!S_ISDIR (statb
.st_mode
))
201 fprintf (stderr
, "\"%s\": not a directory, skipping\n", dir
);
202 FcFontSetDestroy (set
);
203 FcStrSetDestroy (subdirs
);
206 if (!FcDirScanConfig (set
, subdirs
, 0, FcConfigGetBlanks (config
), dir
, force
, config
))
208 fprintf (stderr
, "\"%s\": error scanning\n", dir
);
209 FcFontSetDestroy (set
);
210 FcStrSetDestroy (subdirs
);
214 if (!force
&& FcDirCacheValid (dir
) && FcDirCacheHasCurrentArch (dir
))
217 printf ("skipping, %d fonts, %d dirs\n",
218 set
->nfont
, nsubdirs(subdirs
));
223 printf ("caching, %d fonts, %d dirs\n",
224 set
->nfont
, nsubdirs (subdirs
));
226 if (!FcDirCacheValid (dir
))
227 if (!FcDirCacheUnlink (dir
, config
))
230 if (!FcDirSave (set
, subdirs
, dir
))
233 fprintf (stderr
, "Caches are currently saved to \"%s\"\n", PKGCACHEDIR
);
234 fprintf (stderr
, "Can't save cache for \"%s\"\n", dir
);
238 FcFontSetDestroy (set
);
239 sublist
= FcStrListCreate (subdirs
);
240 FcStrSetDestroy (subdirs
);
243 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
247 FcStrSetAdd (processed_dirs
, dir
);
248 ret
+= scanDirs (sublist
, config
, program
, force
, verbose
);
250 FcStrListDone (list
);
255 main (int argc
, char **argv
)
259 FcBool verbose
= FcFalse
;
260 FcBool force
= FcFalse
;
261 FcBool systemOnly
= FcFalse
;
265 #if HAVE_GETOPT_LONG || HAVE_GETOPT
269 while ((c
= getopt_long (argc
, argv
, "fsVv?", longopts
, NULL
)) != -1)
271 while ((c
= getopt (argc
, argv
, "fsVv?")) != -1)
282 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
283 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
298 FcConfigEnableHome (FcFalse
);
299 config
= FcInitLoadConfig ();
302 fprintf (stderr
, "%s: Can't init font config library\n", argv
[0]);
305 FcConfigSetCurrent (config
);
309 dirs
= FcStrSetCreate ();
312 fprintf (stderr
, "%s: Can't create list of directories\n",
318 if (!FcStrSetAdd (dirs
, (FcChar8
*) argv
[i
]))
320 fprintf (stderr
, "%s: Can't add directory\n", argv
[0]);
325 list
= FcStrListCreate (dirs
);
326 FcStrSetDestroy (dirs
);
329 list
= FcConfigGetConfigDirs (config
);
331 if ((processed_dirs
= FcStrSetCreate()) == NULL
) {
332 fprintf(stderr
, "Cannot malloc\n");
336 ret
= scanDirs (list
, config
, argv
[0], force
, verbose
);
338 FcStrSetDestroy (processed_dirs
);
341 * Now we need to sleep a second (or two, to be extra sure), to make
342 * sure that timestamps for changes after this run of fc-cache are later
343 * then any timestamps we wrote. We don't use gettimeofday() because
344 * sleep(3) can't be interrupted by a signal here -- this isn't in the
345 * library, and there aren't any signals flying around here.
347 FcConfigDestroy (config
);
350 printf ("%s: %s\n", argv
[0], ret
? "failed" : "succeeded");