]>
git.wh0rd.org - fontconfig.git/blob - fc-cache/fc-cache.c
78418d786c4cc0844f86ba1c3f41da1e9fc8a7be
2 * $XFree86: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.8tsi 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>
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
;
70 fprintf (stderr
, "usage: %s [-fvV?] [--force] [--verbose] [--version] [--help] [dirs]\n",
72 fprintf (stderr
, "Build font information caches in [dirs]\n"
73 "(all directories in font configuration by default).\n");
74 fprintf (stderr
, "\n");
75 fprintf (stderr
, " -f, --force scan directories with apparently valid caches\n");
76 fprintf (stderr
, " -s, --system-only scan system-wide directories only\n");
77 fprintf (stderr
, " -v, --verbose display status information while busy\n");
78 fprintf (stderr
, " -V, --version display font config version and exit\n");
79 fprintf (stderr
, " -?, --help display this help and exit\n");
84 nsubdirs (FcStrSet
*set
)
89 list
= FcStrListCreate (set
);
92 while (FcStrListNext (list
))
99 scanDirs (FcStrList
*list
, FcConfig
*config
, char *program
, FcBool force
, FcBool verbose
)
109 * Now scan all of the directories into separate databases
110 * and write out the results
112 while ((dir
= FcStrListNext (list
)))
116 printf ("%s: \"%s\": ", program
, dir
);
119 set
= FcFontSetCreate ();
122 fprintf (stderr
, "Can't create font set\n");
126 subdirs
= FcStrSetCreate ();
129 fprintf (stderr
, "Can't create directory set\n");
134 if (access ((char *) dir
, W_OK
) < 0)
140 printf ("skipping, no such directory\n");
145 printf ("skipping, no write access\n");
148 fprintf (stderr
, "\"%s\": ", dir
);
154 if (stat ((char *) dir
, &statb
) == -1)
156 fprintf (stderr
, "\"%s\": ", dir
);
161 if (!S_ISDIR (statb
.st_mode
))
163 fprintf (stderr
, "\"%s\": not a directory, skipping\n", dir
);
166 if (!FcDirScan (set
, subdirs
, 0, FcConfigGetBlanks (config
), dir
, force
))
168 fprintf (stderr
, "\"%s\": error scanning\n", dir
);
172 if (!force
&& FcDirCacheValid (dir
))
175 printf ("skipping, %d fonts, %d dirs\n",
176 set
->nfont
, nsubdirs(subdirs
));
181 printf ("caching, %d fonts, %d dirs\n",
182 set
->nfont
, nsubdirs (subdirs
));
183 if (!FcDirSave (set
, subdirs
, dir
))
185 fprintf (stderr
, "Can't save cache in \"%s\"\n", dir
);
189 FcFontSetDestroy (set
);
190 sublist
= FcStrListCreate (subdirs
);
193 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
197 ret
+= scanDirs (sublist
, config
, program
, force
, verbose
);
198 FcStrSetDestroy (subdirs
);
200 FcStrListDone (list
);
205 main (int argc
, char **argv
)
209 FcBool verbose
= FcFalse
;
210 FcBool force
= FcFalse
;
211 FcBool systemOnly
= FcFalse
;
215 #if HAVE_GETOPT_LONG || HAVE_GETOPT
219 while ((c
= getopt_long (argc
, argv
, "fVv?", longopts
, NULL
)) != -1)
221 while ((c
= getopt (argc
, argv
, "fVv?")) != -1)
232 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
233 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
248 FcConfigEnableHome (FcFalse
);
249 config
= FcInitLoadConfig ();
252 fprintf (stderr
, "%s: Can't init font config library\n", argv
[0]);
257 dirs
= FcStrSetCreate ();
260 fprintf (stderr
, "%s: Can't create list of directories\n",
266 if (!FcStrSetAdd (dirs
, (FcChar8
*) argv
[i
]))
268 fprintf (stderr
, "%s: Can't add directory\n", argv
[0]);
273 list
= FcStrListCreate (dirs
);
274 FcStrSetDestroy (dirs
);
277 list
= FcConfigGetConfigDirs (config
);
278 ret
= scanDirs (list
, config
, argv
[0], force
, verbose
);
280 printf ("%s: %s\n", argv
[0], ret
? "failed" : "succeeded");