]> git.wh0rd.org - fontconfig.git/blob - fc-cache/fc-cache.c
Update to Xft version 2
[fontconfig.git] / fc-cache / fc-cache.c
1 /*
2 * $XFree86: $
3 *
4 * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
5 *
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.
15 *
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.
23 */
24
25 #include <fontconfig/fontconfig.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #else
31 #define HAVE_GETOPT 1
32 #endif
33
34 #if HAVE_GETOPT_LONG
35 #define _GNU_SOURCE
36 #include <getopt.h>
37 const struct option longopts[] = {
38 {"version", 0, 0, 'V'},
39 {"verbose", 0, 0, 'v'},
40 {"help", 0, 0, '?'},
41 {NULL,0,0,0},
42 };
43 #else
44 #if HAVE_GETOPT
45 extern char *optarg;
46 extern int optind, opterr, optopt;
47 #endif
48 #endif
49
50 static void
51 usage (char *program)
52 {
53 fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
54 program);
55 fprintf (stderr, "Build font information caches in [dirs]\n"
56 "(all directories in font configuration by default).\n");
57 fprintf (stderr, "\n");
58 fprintf (stderr, " -v, --verbose display status information while busy\n");
59 fprintf (stderr, " -V, --version display font config version and exit\n");
60 fprintf (stderr, " -?, --help display this help and exit\n");
61 exit (1);
62 }
63
64 int
65 main (int argc, char **argv)
66 {
67 int ret = 0;
68 FcFontSet *set;
69 FcChar8 **dirs;
70 int verbose = 0;
71 int i;
72 #if HAVE_GETOPT_LONG || HAVE_GETOPT
73 int c;
74
75 #if HAVE_GETOPT_LONG
76 while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
77 #else
78 while ((c = getopt (argc, argv, "Vv?")) != -1)
79 #endif
80 {
81 switch (c) {
82 case 'V':
83 fprintf (stderr, "fontconfig version %d.%d.%d\n",
84 FC_MAJOR, FC_MINOR, FC_REVISION);
85 exit (0);
86 case 'v':
87 verbose = 1;
88 break;
89 default:
90 usage (argv[0]);
91 }
92 }
93 i = optind;
94 #else
95 i = 1;
96 #endif
97
98 if (!FcInitConfig ())
99 {
100 fprintf (stderr, "Can't init font config library\n");
101 return 1;
102 }
103 if (argv[i])
104 dirs = (FcChar8 **) (argv+i);
105 else
106 dirs = FcConfigGetDirs (0);
107 /*
108 * Now scan all of the directories into separate databases
109 * and write out the results
110 */
111 while (dirs && *dirs)
112 {
113 if (verbose)
114 printf ("%s: Scanning directory \"%s\"\n", argv[0], *dirs);
115 set = FcFontSetCreate ();
116 if (!set)
117 {
118 fprintf (stderr, "Out of memory in \"%s\"\n", *dirs);
119 ret++;
120 }
121 else
122 {
123 if (!FcDirScan (set, 0, FcConfigGetBlanks (0), *dirs, FcTrue))
124 {
125 fprintf (stderr, "Can't scan directory \"%s\"\n", *dirs);
126 ret++;
127 }
128 else
129 {
130 if (verbose)
131 printf ("%s: Saving %d font names for \"%s\"\n",
132 argv[0], set->nfont, *dirs);
133 if (!FcDirSave (set, *dirs))
134 {
135 fprintf (stderr, "Can't save cache in \"%s\"\n", *dirs);
136 ret++;
137 }
138 }
139 FcFontSetDestroy (set);
140 }
141 ++dirs;
142 }
143 if (verbose)
144 printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");
145 return ret;
146 }