]>
git.wh0rd.org - fontconfig.git/blob - fc-cache/fc-cache.c
2 * $XFree86: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.2 2002/02/15 07:36:14 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>
32 #define HAVE_GETOPT_LONG 1
40 #ifndef HAVE_GETOPT_LONG
41 #define HAVE_GETOPT_LONG 0
48 const struct option longopts
[] = {
50 {"version", 0, 0, 'V'},
51 {"verbose", 0, 0, 'v'},
58 extern int optind
, opterr
, optopt
;
65 fprintf (stderr
, "usage: %s [-fvV?] [--force] [--verbose] [--version] [--help] [dirs]\n",
67 fprintf (stderr
, "Build font information caches in [dirs]\n"
68 "(all directories in font configuration by default).\n");
69 fprintf (stderr
, "\n");
70 fprintf (stderr
, " -v, --force scan directories with apparently valid caches\n");
71 fprintf (stderr
, " -v, --verbose display status information while busy\n");
72 fprintf (stderr
, " -V, --version display font config version and exit\n");
73 fprintf (stderr
, " -?, --help display this help and exit\n");
78 nsubdirs (FcStrSet
*set
)
83 list
= FcStrListCreate (set
);
86 while (FcStrListNext (list
))
93 scanDirs (FcStrList
*list
, char *program
, FcBool force
, FcBool verbose
)
102 * Now scan all of the directories into separate databases
103 * and write out the results
105 while ((dir
= FcStrListNext (list
)))
109 printf ("%s: \"%s\": ", program
, dir
);
112 set
= FcFontSetCreate ();
115 fprintf (stderr
, "Can't create font set\n");
119 subdirs
= FcStrSetCreate ();
122 fprintf (stderr
, "Can't create directory set\n");
126 if (!FcDirScan (set
, subdirs
, 0, FcConfigGetBlanks (0), dir
, force
))
128 fprintf (stderr
, "Can't scan \"%s\"\n", dir
);
132 if (!force
&& FcDirCacheValid (dir
))
135 printf ("skipping, %d fonts, %d dirs\n",
136 set
->nfont
, nsubdirs(subdirs
));
141 printf ("caching, %d fonts, %d dirs\n",
142 set
->nfont
, nsubdirs (subdirs
));
143 if (!FcDirSave (set
, subdirs
, dir
))
145 fprintf (stderr
, "Can't save cache in \"%s\"\n", dir
);
149 FcFontSetDestroy (set
);
150 sublist
= FcStrListCreate (subdirs
);
153 fprintf (stderr
, "Can't create subdir list in \"%s\"\n", dir
);
157 ret
+= scanDirs (sublist
, program
, force
, verbose
);
158 FcStrSetDestroy (subdirs
);
160 FcStrListDone (list
);
165 main (int argc
, char **argv
)
169 FcBool verbose
= FcFalse
;
170 FcBool force
= FcFalse
;
174 #if HAVE_GETOPT_LONG || HAVE_GETOPT
178 while ((c
= getopt_long (argc
, argv
, "fVv?", longopts
, NULL
)) != -1)
180 while ((c
= getopt (argc
, argv
, "fVv?")) != -1)
188 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
189 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
203 config
= FcInitLoadConfig ();
206 fprintf (stderr
, "%s: Can't init font config library\n", argv
[0]);
211 dirs
= FcStrSetCreate ();
214 fprintf (stderr
, "%s: Can't create list of directories\n",
220 if (!FcStrSetAdd (dirs
, (FcChar8
*) argv
[i
]))
222 fprintf (stderr
, "%s: Can't add directory\n", argv
[0]);
227 list
= FcStrListCreate (dirs
);
228 FcStrSetDestroy (dirs
);
231 list
= FcConfigGetConfigDirs (config
);
232 ret
= scanDirs (list
, argv
[0], force
, verbose
);
234 printf ("%s: %s\n", argv
[0], ret
? "failed" : "succeeded");