]> git.wh0rd.org - fontconfig.git/commitdiff
Add new command-line utility, fc-cat, to convert fonts.cache-2 files into
authorPatrick Lam <plam@MIT.EDU>
Fri, 23 Sep 2005 05:59:19 +0000 (05:59 +0000)
committerPatrick Lam <plam@MIT.EDU>
Fri, 23 Sep 2005 05:59:19 +0000 (05:59 +0000)
    fonts.cache-1 files (e.g. for grepping and validation of the mmap
    codepath), as per James Cloos' request.
Remove done 'TODO' comment.
Updates for development release 2.3.90.

Makefile.am
README
configure.in
fc-cache/fc-cache.c
fc-cache/fc-cache.sgml
fc-cat/.cvsignore [new file with mode: 0644]
fc-cat/Makefile.am [new file with mode: 0644]
fc-cat/fc-cat.c [new file with mode: 0644]
fc-cat/fc-cat.sgml [new file with mode: 0644]
fontconfig/fontconfig.h

index ed624c6f09f2d55cccd4117b613471f62701b648..d1ef440c86e919161be33260b4d5b0f7eff89964 100644 (file)
@@ -23,7 +23,7 @@
 
 DOCSRC=@DOCSRC@
 SUBDIRS=fontconfig fc-case fc-lang fc-glyphname src \
-       fc-cache fc-list fc-match conf.d $(DOCSRC) test
+       fc-cache fc-cat fc-list fc-match conf.d $(DOCSRC) test
 
 DEBIAN = \
        debian/changelog \
diff --git a/README b/README
index 26fe4b92e3ff007d531bb3d3de03dde77a846974..9e8124ba3dc46b6ed2c49786fdab52dd97d07849 100644 (file)
--- a/README
+++ b/README
@@ -1,11 +1,16 @@
                        Fontconfig
        Font configuration and customization library
                      Version 2.3.2
-                        2005-4-27
+                        2005-9-23
 
 Check INSTALL for compilation and installation instructions.
 Report bugs to https://bugs.freedesktop.org in the fontconfig module.
 
+2.3.90
+
+Development release of mmap patch: load pattern information
+directly from cache files.  (Patrick Lam)
+
 2.3.2
 
 Patch memory leaks in using iconv.  (Reported by Chris Capoccia)
index f737353290e375d879fbdfeccf2316d36d46a7e0..4505b93ed23e9f4f8222013d41479469d438079c 100644 (file)
@@ -33,7 +33,7 @@ dnl This is the package version number, not the shared library
 dnl version.  This same version number must appear in fontconfig/fontconfig.h
 dnl Yes, it is a pain to synchronize version numbers.  Unfortunately, it's
 dnl not possible to extract the version number here from fontconfig.h
-AM_INIT_AUTOMAKE(fontconfig, 2.3.2)
+AM_INIT_AUTOMAKE(fontconfig, 2.3.90)
 AM_MAINTAINER_MODE
 
 dnl libtool versioning
@@ -469,6 +469,7 @@ src/Makefile
 src/fontconfig.def
 conf.d/Makefile
 fc-cache/Makefile
+fc-cat/Makefile
 fc-list/Makefile
 fc-match/Makefile
 doc/Makefile
index fed64295b00f2d1106ac3300455ba4e00706311a..20c7c95bb5e92c952c5b64a7de760739a723c7af 100644 (file)
@@ -269,7 +269,6 @@ main (int argc, char **argv)
 
     if (systemOnly)
        FcConfigEnableHome (FcFalse);
-    /* need to use FcInitLoadConfig when we use dirs */
     config = FcInitLoadConfig ();
     if (!config)
     {
index 72df17e483878f0fde1b3496205e7bf6347c0e22..8fc743554f1135eb09656aa0231d1325abe716bb 100644 (file)
@@ -20,7 +20,7 @@ manpage.1: manpage.sgml
   <!ENTITY dhfirstname "<firstname>Josselin</firstname>">
   <!ENTITY dhsurname   "<surname>Mouette</surname>">
   <!-- Please adjust the date whenever revising the manpage. -->
-  <!ENTITY dhdate      "<date>Sep 16, 2003</date>">
+  <!ENTITY dhdate      "<date>Sep 22, 2005</date>">
   <!-- SECTION should be 1-8, maybe w/ subsection other parameters are
        allowed: see man(7), man(1). -->
   <!ENTITY dhsection   "<manvolnum>1</manvolnum>">
@@ -160,7 +160,7 @@ manpage.1: manpage.sgml
     <title>FILES</title>
     <variablelist>
       <varlistentry>
-        <term><filename>fonts.cache-1</filename></term>
+        <term><filename>fonts.cache-2</filename></term>
        <listitem>
          <para>These files are generated by <command>&dhpackage;</command>
             and contain maps from file names to font properties. They are
diff --git a/fc-cat/.cvsignore b/fc-cat/.cvsignore
new file mode 100644 (file)
index 0000000..09b6835
--- /dev/null
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile
+Makefile.in
+fc-cache
+fc-cache.1
diff --git a/fc-cat/Makefile.am b/fc-cat/Makefile.am
new file mode 100644 (file)
index 0000000..cf34009
--- /dev/null
@@ -0,0 +1,55 @@
+# 
+#  $Id$
+# 
+#  Copyright © 2003 Keith Packard
+# 
+#  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.
+
+DOC2MAN = docbook2man
+
+FC_CAT_SRC=${top_srcdir}/fc-cat
+
+SGML = ${FC_CAT_SRC}/fc-cat.sgml
+
+INCLUDES=-I${top_srcdir} $(FREETYPE_CFLAGS)
+
+bin_PROGRAMS=fc-cat
+
+EXTRA_DIST=$(SGML)
+
+fc_cat_LDADD = ${top_builddir}/src/libfontconfig.la
+
+if USEDOCBOOK
+
+man_MANS=fc-cat.1
+
+${man_MANS}: ${SGML}   
+       $(RM) $@
+       $(DOC2MAN) ${SGML}
+       $(RM) manpage.refs manpage.links
+
+all-local: $(man_MANS)
+
+clean-local:
+       $(RM) $(man_MANS)
+
+else
+all-local:
+clean-local:
+endif
diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c
new file mode 100644 (file)
index 0000000..109a058
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+ * $RCSId: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.8tsi Exp $
+ *
+ * Copyright © 2002 Keith Packard
+ *
+ * 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.
+ */
+
+#include <fontconfig/fontconfig.h>
+#include <../src/fccache.c>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#ifdef linux
+#define HAVE_GETOPT_LONG 1
+#endif
+#define HAVE_GETOPT 1
+#endif
+
+#ifndef HAVE_GETOPT
+#define HAVE_GETOPT 0
+#endif
+#ifndef HAVE_GETOPT_LONG
+#define HAVE_GETOPT_LONG 0
+#endif
+
+#if HAVE_GETOPT_LONG
+#undef  _GNU_SOURCE
+#define _GNU_SOURCE
+#include <getopt.h>
+const struct option longopts[] = {
+    {"version", 0, 0, 'V'},
+    {"help", 0, 0, '?'},
+    {NULL,0,0,0},
+};
+#else
+#if HAVE_GETOPT
+extern char *optarg;
+extern int optind, opterr, optopt;
+#endif
+#endif
+
+/*
+ * POSIX has broken stdio so that getc must do thread-safe locking,
+ * this is a serious performance problem for applications doing large
+ * amounts of IO with getc (as is done here).  If available, use
+ * the getc_unlocked varient instead.
+ */
+#if defined(getc_unlocked) || defined(_IO_getc_unlocked)
+#define GETC(f) getc_unlocked(f)
+#define PUTC(c,f) putc_unlocked(c,f)
+#else
+#define GETC(f) getc(f)
+#define PUTC(c,f) putc(c,f)
+#endif
+
+static FcBool
+FcCacheWriteChars (FILE *f, const FcChar8 *chars)
+{
+    FcChar8    c;
+    while ((c = *chars++))
+    {
+       switch (c) {
+       case '"':
+       case '\\':
+           if (PUTC ('\\', f) == EOF)
+               return FcFalse;
+           /* fall through */
+       default:
+           if (PUTC (c, f) == EOF)
+               return FcFalse;
+       }
+    }
+    return FcTrue;
+}
+
+static FcBool
+FcCacheWriteUlong (FILE *f, unsigned long t)
+{
+    int            pow;
+    unsigned long   temp, digit;
+
+    temp = t;
+    pow = 1;
+    while (temp >= 10)
+    {
+       temp /= 10;
+       pow *= 10;
+    }
+    temp = t;
+    while (pow)
+    {
+       digit = temp / pow;
+       if (PUTC ((char) digit + '0', f) == EOF)
+           return FcFalse;
+       temp = temp - pow * digit;
+       pow = pow / 10;
+    }
+    return FcTrue;
+}
+
+static FcBool
+FcCacheWriteInt (FILE *f, int i)
+{
+    return FcCacheWriteUlong (f, (unsigned long) i);
+}
+
+static FcBool
+FcCacheWriteStringOld (FILE *f, const FcChar8 *string)
+{
+
+    if (PUTC ('"', f) == EOF)
+       return FcFalse;
+    if (!FcCacheWriteChars (f, string))
+       return FcFalse;
+    if (PUTC ('"', f) == EOF)
+       return FcFalse;
+    return FcTrue;
+}
+
+static void
+usage (char *program)
+{
+#if HAVE_GETOPT_LONG
+    fprintf (stderr, "usage: %s [-V?] [--version] [--help] <fonts.cache-2>\n",
+            program);
+#else
+    fprintf (stderr, "usage: %s [-fsvV?] <fonts.cache-2>\n",
+            program);
+#endif
+    fprintf (stderr, "Reads font information caches in <fonts.cache-2>\n");
+    fprintf (stderr, "\n");
+#if HAVE_GETOPT_LONG
+    fprintf (stderr, "  -V, --version        display font config version and exit\n");
+    fprintf (stderr, "  -?, --help           display this help and exit\n");
+#else
+    fprintf (stderr, "  -V         (version) display font config version and exit\n");
+    fprintf (stderr, "  -?         (help)    display this help and exit\n");
+#endif
+    exit (1);
+}
+
+/* read serialized state from the cache file */
+static FcBool
+FcCacheFileRead (FcFontSet * set, FcStrSet *dirs, char *cache_file)
+{
+    int fd;
+    char * current_arch_machine_name;
+    char candidate_arch_machine_name[9+MACHINE_SIGNATURE_SIZE];
+    off_t current_arch_start = 0;
+    char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
+
+    if (!cache_file)
+        goto bail;
+
+    current_arch_machine_name = FcCacheMachineSignature();
+    fd = open(cache_file, O_RDONLY);
+    if (fd == -1)
+        goto bail;
+
+    current_arch_start = FcCacheSkipToArch(fd, current_arch_machine_name);
+    if (current_arch_start < 0)
+        goto bail1;
+
+    lseek (fd, current_arch_start, SEEK_SET);
+    if (FcCacheReadString (fd, candidate_arch_machine_name, 
+                          sizeof (candidate_arch_machine_name)) == 0)
+       goto bail1;
+
+    while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
+        FcStrSetAdd (dirs, (FcChar8 *)subdirName);
+
+    if (!FcDirCacheConsume (fd, set))
+       goto bail1;
+       
+    close(fd);
+    free (cache_file);
+    return FcTrue;
+
+ bail1:
+    close (fd);
+ bail:
+    free (cache_file);
+    return FcFalse;
+}
+
+/*
+ * return the path from the directory containing 'cache' to 'file'
+ */
+
+static const FcChar8 *
+FcFileBaseName (const char *cache, const FcChar8 *file)
+{
+    const FcChar8   *cache_slash;
+
+    cache_slash = FcStrLastSlash ((const FcChar8 *)cache);
+    if (cache_slash && !strncmp ((const char *) cache, (const char *) file,
+                                (cache_slash + 1) - (const FcChar8 *)cache))
+       return file + ((cache_slash + 1) - (const FcChar8 *)cache);
+    return file;
+}
+
+FcBool
+FcCachePrintSet (FcFontSet *set, FcStrSet *dirs, char *cache_file)
+{
+    FcPattern      *font;
+    FcChar8        *name, *dir;
+    const FcChar8   *file, *base;
+    int                    n;
+    int                    id;
+    FcBool         ret;
+    FcStrList      *list;
+
+    list = FcStrListCreate (dirs);
+    if (!list)
+       goto bail2;
+    
+    while ((dir = FcStrListNext (list)))
+    {
+       base = FcFileBaseName (cache_file, dir);
+       if (!FcCacheWriteStringOld (stdout, base))
+           goto bail3;
+       if (PUTC (' ', stdout) == EOF)
+           goto bail3;
+       if (!FcCacheWriteInt (stdout, 0))
+           goto bail3;
+        if (PUTC (' ', stdout) == EOF)
+           goto bail3;
+       if (!FcCacheWriteStringOld (stdout, FC_FONT_FILE_DIR))
+           goto bail3;
+       if (PUTC ('\n', stdout) == EOF)
+           goto bail3;
+    }
+    
+    for (n = 0; n < set->nfont; n++)
+    {
+       font = set->fonts[n];
+       if (FcPatternGetString (font, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
+           goto bail3;
+       base = FcFileBaseName (cache_file, file);
+       if (FcPatternGetInteger (font, FC_INDEX, 0, &id) != FcResultMatch)
+           goto bail3;
+       if (FcDebug () & FC_DBG_CACHEV)
+           printf (" write file \"%s\"\n", base);
+       if (!FcCacheWriteStringOld (stdout, base))
+           goto bail3;
+       if (PUTC (' ', stdout) == EOF)
+           goto bail3;
+       if (!FcCacheWriteInt (stdout, id))
+           goto bail3;
+        if (PUTC (' ', stdout) == EOF)
+           goto bail3;
+       name = FcNameUnparse (font);
+       if (!name)
+           goto bail3;
+       ret = FcCacheWriteStringOld (stdout, name);
+       FcStrFree (name);
+       if (!ret)
+           goto bail3;
+       if (PUTC ('\n', stdout) == EOF)
+           goto bail3;
+    }
+    
+    FcStrListDone (list);
+
+    return FcTrue;
+    
+bail3:
+    FcStrListDone (list);
+bail2:
+bail1:
+bail0:
+    return FcFalse;
+}
+
+int
+main (int argc, char **argv)
+{
+    int                i;
+    int                ret;
+#if HAVE_GETOPT_LONG || HAVE_GETOPT
+    int                c;
+    FcFontSet  *fs = FcFontSetCreate();
+    FcStrSet    *dirs = FcStrSetCreate();
+
+#if HAVE_GETOPT_LONG
+    while ((c = getopt_long (argc, argv, "fsVv?", longopts, NULL)) != -1)
+#else
+    while ((c = getopt (argc, argv, "fsVv?")) != -1)
+#endif
+    {
+       switch (c) {
+       case 'V':
+           fprintf (stderr, "fontconfig version %d.%d.%d\n", 
+                    FC_MAJOR, FC_MINOR, FC_REVISION);
+           exit (0);
+       default:
+           usage (argv[0]);
+       }
+    }
+    i = optind;
+#else
+    i = 1;
+#endif
+
+    if (FcCacheFileRead (fs, dirs, argv[i]))
+       FcCachePrintSet (fs, dirs, argv[i]);
+
+    FcStrSetDestroy (dirs);
+    FcFontSetDestroy (fs);
+
+    return 0;
+}
diff --git a/fc-cat/fc-cat.sgml b/fc-cat/fc-cat.sgml
new file mode 100644 (file)
index 0000000..812b0fa
--- /dev/null
@@ -0,0 +1,139 @@
+<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [
+
+<!-- Process this file with docbook-to-man to generate an nroff manual
+     page: `docbook-to-man manpage.sgml > manpage.1'.  You may view
+     the manual page with: `docbook-to-man manpage.sgml | nroff -man |
+     less'.  A typical entry in a Makefile or Makefile.am is:
+
+manpage.1: manpage.sgml
+       docbook-to-man $< > $@
+
+    
+       The docbook-to-man binary is found in the docbook-to-man package.
+       Please remember that if you create the nroff version in one of the
+       debian/rules file targets (such as build), you will need to include
+       docbook-to-man in your Build-Depends control field.
+
+  -->
+
+  <!-- Fill in your name for FIRSTNAME and SURNAME. -->
+  <!ENTITY dhfirstname "<firstname>Patrick</firstname>">
+  <!ENTITY dhsurname   "<surname>Lam</surname>">
+  <!-- Please adjust the date whenever revising the manpage. -->
+  <!ENTITY dhdate      "<date>Sep 22, 2005</date>">
+  <!-- SECTION should be 1-8, maybe w/ subsection other parameters are
+       allowed: see man(7), man(1). -->
+  <!ENTITY dhsection   "<manvolnum>1</manvolnum>">
+  <!ENTITY dhemail     "<email>plam@mit.edu</email>">
+  <!ENTITY dhusername  "Patrick Lam">
+  <!ENTITY dhucpackage "<refentrytitle>fc-cat</refentrytitle>">
+  <!ENTITY dhpackage   "fc-cat">
+
+  <!ENTITY debian      "<productname>Debian</productname>">
+  <!ENTITY gnu         "<acronym>GNU</acronym>">
+  <!ENTITY gpl         "&gnu; <acronym>GPL</acronym>">
+]>
+
+<refentry>
+  <refentryinfo>
+    <address>
+      &dhemail;
+    </address>
+    <author>
+      &dhfirstname;
+      &dhsurname;
+    </author>
+    <copyright>
+      <year>2005</year>
+      <holder>&dhusername;</holder>
+    </copyright>
+    &dhdate;
+  </refentryinfo>
+  <refmeta>
+    &dhucpackage;
+
+    &dhsection;
+  </refmeta>
+  <refnamediv>
+    <refname>&dhpackage;</refname>
+
+    <refpurpose>read font information cache files</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <cmdsynopsis>
+      <command>&dhpackage; &lt; fonts-cache-2-file &gt;</command>
+
+      <arg><option>-V?</option></arg>
+      <arg><option>--version</option></arg>
+      <arg><option>--help</option></arg>
+      <arg><option><replaceable>dirs</replaceable></option></arg>
+      
+     </cmdsynopsis>
+  </refsynopsisdiv>
+  <refsect1>
+    <title>DESCRIPTION</title>
+
+      <para><command>&dhpackage;</command> reads a font information cache file
+        and emits it in ASCII form.</para>
+
+  </refsect1>
+  <refsect1>
+    <title>OPTIONS</title>
+
+    <para>This program follows the usual &gnu; command line syntax,
+      with long options starting with two dashes (`-').  A summary of
+      options is included below.</para>
+
+    <variablelist>
+      <varlistentry>
+        <term><option>-?</option>
+          <option>--help</option>
+        </term>
+        <listitem>
+          <para>Show summary of options.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-V</option>
+          <option>--version</option>
+        </term>
+        <listitem>
+          <para>Show version of the program and exit.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>SEE ALSO</title>
+
+    <para><command>fc-cache</command> (1).</para>
+
+    <para>The fontconfig user's guide, in HTML format:
+      <filename>/usr/share/doc/fontconfig/fontconfig-user.html</filename>.</para>
+
+ </refsect1>
+  <refsect1>
+    <title>AUTHOR</title>
+
+    <para>This manual page was written by &dhusername; &dhemail;.</para>
+
+  </refsect1>
+</refentry>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
index 312256f879e3321faae2c137f188bc6f4895a9f9..b1175682ce22803734bbf686488d109e8fe17f45 100644 (file)
@@ -40,7 +40,7 @@ typedef int           FcBool;
 
 #define FC_MAJOR       2
 #define FC_MINOR       3
-#define FC_REVISION    2
+#define FC_REVISION    90
 
 #define FC_VERSION     ((FC_MAJOR * 10000) + (FC_MINOR * 100) + (FC_REVISION))