summaryrefslogtreecommitdiff
path: root/fc-cache
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2002-05-21 17:06:22 +0000
committerKeith Packard <keithp@keithp.com>2002-05-21 17:06:22 +0000
commit179c39959cc9c19004f8ca948623590e404c8c46 (patch)
tree96fdd61e9a589abdd00ae763fa10ca69074b76f2 /fc-cache
parent1ce2a1bbadc15147e35dbc4c43fae072b8c4805e (diff)
Fix autoconf build process for fontconfig
Diffstat (limited to 'fc-cache')
-rw-r--r--fc-cache/Imakefile7
-rw-r--r--fc-cache/Makefile.in46
-rw-r--r--fc-cache/fc-cache.c161
3 files changed, 172 insertions, 42 deletions
diff --git a/fc-cache/Imakefile b/fc-cache/Imakefile
index afd1601..0e3cbfc 100644
--- a/fc-cache/Imakefile
+++ b/fc-cache/Imakefile
@@ -1,3 +1,8 @@
+#ifdef UseInstalled
+/* building outside the tree, use private defines */
+#include "../local.def"
+#endif
+
INCLUDES=$(FREETYPE2INCLUDES) $(LIBXML2INCLUDES) -I..
LOCAL_LIBRARIES=FontconfigClientLibs
@@ -11,5 +16,5 @@ LinkBuildBinary(ProgramTargetName(fc-cache))
install::
if [ x$${DESTDIR} = x ]; then \
- FC_DEBUG=128 $(FCCACHE) -v ;\
+ $(FCCACHE) -v -f;\
fi
diff --git a/fc-cache/Makefile.in b/fc-cache/Makefile.in
new file mode 100644
index 0000000..7cde602
--- /dev/null
+++ b/fc-cache/Makefile.in
@@ -0,0 +1,46 @@
+#
+# $XFree86$
+#
+# Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of Keith Packard not be used in
+# advertising or publicity pertaining to distribution of the software without
+# specific, written prior permission. Keith Packard makes no
+# representations about the suitability of this software for any purpose. It
+# is provided "as is" without express or implied warranty.
+#
+# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+#
+
+TOPDIR=..
+
+include $(TOPDIR)/config/Makedefs
+
+SRCS=fc-cache.c
+
+OBJS=fc-cache.o
+
+PROG=fc-cache
+
+all:: $(PROG)
+
+install:: $(BINDIR)/$(PROG)
+
+$(BINDIR)/$(PROG): $(PROG)
+ $(INSTALL_PROGRAM) $(PROG) $(BINDIR)
+
+clean::
+ rm -f $(PROG) $(OBJS)
+
+$(PROG): $(OBJS)
+ $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBFONTCONFIG)
diff --git a/fc-cache/fc-cache.c b/fc-cache/fc-cache.c
index 881278e..b3d0f3f 100644
--- a/fc-cache/fc-cache.c
+++ b/fc-cache/fc-cache.c
@@ -46,6 +46,7 @@
#define _GNU_SOURCE
#include <getopt.h>
const struct option longopts[] = {
+ {"force", 0, 0, 'f'},
{"version", 0, 0, 'V'},
{"verbose", 0, 0, 'v'},
{"help", 0, 0, '?'},
@@ -61,41 +62,134 @@ extern int optind, opterr, optopt;
static void
usage (char *program)
{
- fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
+ fprintf (stderr, "usage: %s [-fvV?] [--force] [--verbose] [--version] [--help] [dirs]\n",
program);
fprintf (stderr, "Build font information caches in [dirs]\n"
"(all directories in font configuration by default).\n");
fprintf (stderr, "\n");
+ fprintf (stderr, " -v, --force scan directories with apparently valid caches\n");
fprintf (stderr, " -v, --verbose display status information while busy\n");
fprintf (stderr, " -V, --version display font config version and exit\n");
fprintf (stderr, " -?, --help display this help and exit\n");
exit (1);
}
-int
-main (int argc, char **argv)
+static int
+nsubdirs (FcStrSet *set)
+{
+ FcStrList *list;
+ int n = 0;
+
+ list = FcStrListCreate (set);
+ if (!list)
+ return 0;
+ while (FcStrListNext (list))
+ n++;
+ FcStrListDone (list);
+ return n;
+}
+
+static int
+scanDirs (FcStrList *list, char *program, FcBool force, FcBool verbose)
{
int ret = 0;
+ FcChar8 *dir;
FcFontSet *set;
- FcChar8 **dirs;
- int verbose = 0;
+ FcStrSet *subdirs;
+ FcStrList *sublist;
+
+ /*
+ * Now scan all of the directories into separate databases
+ * and write out the results
+ */
+ while ((dir = FcStrListNext (list)))
+ {
+ if (verbose)
+ {
+ printf ("%s: \"%s\": ", program, dir);
+ fflush (stdout);
+ }
+ set = FcFontSetCreate ();
+ if (!set)
+ {
+ fprintf (stderr, "Can't create font set\n");
+ ret++;
+ continue;
+ }
+ subdirs = FcStrSetCreate ();
+ if (!subdirs)
+ {
+ fprintf (stderr, "Can't create directory set\n");
+ ret++;
+ continue;
+ }
+ if (!FcDirScan (set, subdirs, 0, FcConfigGetBlanks (0), dir, force))
+ {
+ fprintf (stderr, "Can't scan \"%s\"\n", dir);
+ ret++;
+ continue;
+ }
+ if (!force && FcDirCacheValid (dir))
+ {
+ if (verbose)
+ printf ("skipping, %d fonts, %d dirs\n",
+ set->nfont, nsubdirs(subdirs));
+ }
+ else
+ {
+ if (verbose)
+ printf ("caching, %d fonts, %d dirs\n",
+ set->nfont, nsubdirs (subdirs));
+ if (!FcDirSave (set, subdirs, dir))
+ {
+ fprintf (stderr, "Can't save cache in \"%s\"\n", dir);
+ ret++;
+ }
+ }
+ FcFontSetDestroy (set);
+ sublist = FcStrListCreate (subdirs);
+ if (!sublist)
+ {
+ fprintf (stderr, "Can't create subdir list in \"%s\"\n", dir);
+ ret++;
+ continue;
+ }
+ ret += scanDirs (sublist, program, force, verbose);
+ FcStrSetDestroy (subdirs);
+ }
+ FcStrListDone (list);
+ return ret;
+}
+
+int
+main (int argc, char **argv)
+{
+ FcStrSet *dirs;
+ FcStrList *list;
+ FcBool verbose = FcFalse;
+ FcBool force = FcFalse;
+ FcConfig *config;
int i;
+ int ret;
#if HAVE_GETOPT_LONG || HAVE_GETOPT
int c;
#if HAVE_GETOPT_LONG
- while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
+ while ((c = getopt_long (argc, argv, "fVv?", longopts, NULL)) != -1)
#else
- while ((c = getopt (argc, argv, "Vv?")) != -1)
+ while ((c = getopt (argc, argv, "fVv?")) != -1)
#endif
{
switch (c) {
+ case 'f':
+ force = FcTrue;
+ break;
case 'V':
fprintf (stderr, "fontconfig version %d.%d.%d\n",
FC_MAJOR, FC_MINOR, FC_REVISION);
exit (0);
case 'v':
- verbose = 1;
+ verbose = FcTrue;
break;
default:
usage (argv[0]);
@@ -106,51 +200,36 @@ main (int argc, char **argv)
i = 1;
#endif
- if (!FcInitConfig ())
+ config = FcInitLoadConfig ();
+ if (!config)
{
- fprintf (stderr, "Can't init font config library\n");
+ fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
return 1;
}
if (argv[i])
- dirs = (FcChar8 **) (argv+i);
- else
- dirs = FcConfigGetDirs (0);
- /*
- * Now scan all of the directories into separate databases
- * and write out the results
- */
- while (dirs && *dirs)
{
- if (verbose)
- printf ("%s: Scanning directory \"%s\"\n", argv[0], *dirs);
- set = FcFontSetCreate ();
- if (!set)
+ dirs = FcStrSetCreate ();
+ if (!dirs)
{
- fprintf (stderr, "Out of memory in \"%s\"\n", *dirs);
- ret++;
+ fprintf (stderr, "%s: Can't create list of directories\n",
+ argv[0]);
+ return 1;
}
- else
+ while (argv[i])
{
- if (!FcDirScan (set, 0, FcConfigGetBlanks (0), *dirs, FcTrue))
+ if (!FcStrSetAdd (dirs, (FcChar8 *) argv[i]))
{
- fprintf (stderr, "Can't scan directory \"%s\"\n", *dirs);
- ret++;
+ fprintf (stderr, "%s: Can't add directory\n", argv[0]);
+ return 1;
}
- else
- {
- if (verbose)
- printf ("%s: Saving %d font names for \"%s\"\n",
- argv[0], set->nfont, *dirs);
- if (!FcDirSave (set, *dirs))
- {
- fprintf (stderr, "Can't save cache in \"%s\"\n", *dirs);
- ret++;
- }
- }
- FcFontSetDestroy (set);
+ i++;
}
- ++dirs;
+ list = FcStrListCreate (dirs);
+ FcStrSetDestroy (dirs);
}
+ else
+ list = FcConfigGetConfigDirs (config);
+ ret = scanDirs (list, argv[0], force, verbose);
if (verbose)
printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");
return ret;