2 * $XFree86: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.7 2002/08/11 15:09:33 keithp Exp $
4 * Copyright © 2002 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.
25 #include <fontconfig/fontconfig.h>
28 #include <sys/types.h>
35 #define HAVE_GETOPT_LONG 1
43 #ifndef HAVE_GETOPT_LONG
44 #define HAVE_GETOPT_LONG 0
51 const struct option longopts[] = {
53 {"version", 0, 0, 'V'},
54 {"verbose", 0, 0, 'v'},
61 extern int optind, opterr, optopt;
68 fprintf (stderr, "usage: %s [-fvV?] [--force] [--verbose] [--version] [--help] [dirs]\n",
70 fprintf (stderr, "Build font information caches in [dirs]\n"
71 "(all directories in font configuration by default).\n");
72 fprintf (stderr, "\n");
73 fprintf (stderr, " -f, --force scan directories with apparently valid caches\n");
74 fprintf (stderr, " -v, --verbose display status information while busy\n");
75 fprintf (stderr, " -V, --version display font config version and exit\n");
76 fprintf (stderr, " -?, --help display this help and exit\n");
81 nsubdirs (FcStrSet *set)
86 list = FcStrListCreate (set);
89 while (FcStrListNext (list))
96 scanDirs (FcStrList *list, FcConfig *config, char *program, FcBool force, FcBool verbose)
106 * Now scan all of the directories into separate databases
107 * and write out the results
109 while ((dir = FcStrListNext (list)))
113 printf ("%s: \"%s\": ", program, dir);
116 set = FcFontSetCreate ();
119 fprintf (stderr, "Can't create font set\n");
123 subdirs = FcStrSetCreate ();
126 fprintf (stderr, "Can't create directory set\n");
131 if (stat ((char *) dir, &statb) == -1)
133 if (errno == ENOENT || errno == ENOTDIR)
136 printf ("no such directory, skipping\n");
140 fprintf (stderr, "\"%s\": ", dir);
146 if (!S_ISDIR (statb.st_mode))
148 fprintf (stderr, "\"%s\": not a directory, skipping\n", dir);
151 if (!FcDirScan (set, subdirs, 0, FcConfigGetBlanks (config), dir, force))
153 fprintf (stderr, "\"%s\": error scanning\n", dir);
157 if (!force && FcDirCacheValid (dir))
160 printf ("skipping, %d fonts, %d dirs\n",
161 set->nfont, nsubdirs(subdirs));
166 printf ("caching, %d fonts, %d dirs\n",
167 set->nfont, nsubdirs (subdirs));
168 if (!FcDirSave (set, subdirs, dir))
170 fprintf (stderr, "Can't save cache in \"%s\"\n", dir);
174 FcFontSetDestroy (set);
175 sublist = FcStrListCreate (subdirs);
178 fprintf (stderr, "Can't create subdir list in \"%s\"\n", dir);
182 ret += scanDirs (sublist, config, program, force, verbose);
183 FcStrSetDestroy (subdirs);
185 FcStrListDone (list);
190 main (int argc, char **argv)
194 FcBool verbose = FcFalse;
195 FcBool force = FcFalse;
199 #if HAVE_GETOPT_LONG || HAVE_GETOPT
203 while ((c = getopt_long (argc, argv, "fVv?", longopts, NULL)) != -1)
205 while ((c = getopt (argc, argv, "fVv?")) != -1)
213 fprintf (stderr, "fontconfig version %d.%d.%d\n",
214 FC_MAJOR, FC_MINOR, FC_REVISION);
228 config = FcInitLoadConfig ();
231 fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
236 dirs = FcStrSetCreate ();
239 fprintf (stderr, "%s: Can't create list of directories\n",
245 if (!FcStrSetAdd (dirs, (FcChar8 *) argv[i]))
247 fprintf (stderr, "%s: Can't add directory\n", argv[0]);
252 list = FcStrListCreate (dirs);
253 FcStrSetDestroy (dirs);
256 list = FcConfigGetConfigDirs (config);
257 ret = scanDirs (list, config, argv[0], force, verbose);
259 printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");