aboutsummaryrefslogtreecommitdiff
path: root/fontconfig/fc-cat
diff options
context:
space:
mode:
Diffstat (limited to 'fontconfig/fc-cat')
-rw-r--r--fontconfig/fc-cat/Makefile.am59
-rw-r--r--fontconfig/fc-cat/fc-cat.c408
-rw-r--r--fontconfig/fc-cat/fc-cat.sgml168
3 files changed, 635 insertions, 0 deletions
diff --git a/fontconfig/fc-cat/Makefile.am b/fontconfig/fc-cat/Makefile.am
new file mode 100644
index 000000000..27b637534
--- /dev/null
+++ b/fontconfig/fc-cat/Makefile.am
@@ -0,0 +1,59 @@
+#
+# fontconfig/fc-cat/Makefile.am
+#
+# 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.
+#
+# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+# EVENT SHALL THE AUTHOR(S) 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} $(WARN_CFLAGS)
+
+bin_PROGRAMS=fc-cat
+
+BUILT_MANS=fc-cat.1
+
+if ENABLE_DOCS
+man_MANS=${BUILT_MANS}
+endif
+
+EXTRA_DIST=fc-cat.sgml ${BUILT_MANS}
+
+fc_cat_LDADD = ${top_builddir}/src/libfontconfig.la
+
+if USEDOCBOOK
+
+${man_MANS}: ${SGML}
+ $(RM) $@
+ $(DOC2MAN) ${SGML}
+ $(RM) manpage.*
+
+all-local: $(man_MANS)
+
+clean-local:
+ $(RM) $(man_MANS)
+
+else
+all-local:
+clean-local:
+endif
diff --git a/fontconfig/fc-cat/fc-cat.c b/fontconfig/fc-cat/fc-cat.c
new file mode 100644
index 000000000..a9326c8eb
--- /dev/null
+++ b/fontconfig/fc-cat/fc-cat.c
@@ -0,0 +1,408 @@
+/*
+ * fontconfig/fc-cat/fc-cat.c
+ *
+ * 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.
+ *
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE AUTHOR(S) 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#else
+#ifdef linux
+#define HAVE_GETOPT_LONG 1
+#endif
+#define HAVE_GETOPT 1
+#endif
+
+#include <fontconfig/fontconfig.h>
+#include "../fc-arch/fcarch.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#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'},
+ {"verbose", 0, 0, 'v'},
+ {"recurse", 0, 0, 'r'},
+ {"help", 0, 0, 'h'},
+ {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
+write_chars (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
+write_ulong (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
+write_int (FILE *f, int i)
+{
+ return write_ulong (f, (unsigned long) i);
+}
+
+static FcBool
+write_string (FILE *f, const FcChar8 *string)
+{
+
+ if (PUTC ('"', f) == EOF)
+ return FcFalse;
+ if (!write_chars (f, string))
+ return FcFalse;
+ if (PUTC ('"', f) == EOF)
+ return FcFalse;
+ return FcTrue;
+}
+
+static void
+usage (char *program, int error)
+{
+ FILE *file = error ? stderr : stdout;
+#if HAVE_GETOPT_LONG
+ fprintf (file, "usage: %s [-rv] [--recurse] [--verbose] [*-%s.cache-2|directory]...\n",
+ program, FC_ARCHITECTURE);
+ fprintf (file, " %s [-Vh] [--version] [--help]\n", program);
+#else
+ fprintf (file, "usage: %s [-rvVh] [*-%s.cache-2|directory]...\n",
+ program, FC_ARCHITECTURE);
+#endif
+ fprintf (file, "Reads font information cache from:\n");
+ fprintf (file, " 1) specified fontconfig cache file\n");
+ fprintf (file, " 2) related to a particular font directory\n");
+ fprintf (file, "\n");
+#if HAVE_GETOPT_LONG
+ fprintf (file, " -r, --recurse recurse into subdirectories\n");
+ fprintf (file, " -v, --verbose be verbose\n");
+ fprintf (file, " -V, --version display font config version and exit\n");
+ fprintf (file, " -h, --help display this help and exit\n");
+#else
+ fprintf (file, " -r (recurse) recurse into subdirectories\n");
+ fprintf (file, " -v (verbose) be verbose\n");
+ fprintf (file, " -V (version) display font config version and exit\n");
+ fprintf (file, " -h (help) display this help and exit\n");
+#endif
+ exit (error);
+}
+
+/*
+ * return the path from the directory containing 'cache' to 'file'
+ */
+
+static const FcChar8 *
+file_base_name (const FcChar8 *cache, const FcChar8 *file)
+{
+ int cache_len = strlen ((char *) cache);
+
+ if (!strncmp ((char *) cache, (char *) file, cache_len) && file[cache_len] == '/')
+ return file + cache_len + 1;
+ return file;
+}
+
+#define FC_FONT_FILE_DIR ((FcChar8 *) ".dir")
+
+static FcBool
+cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
+{
+ FcChar8 *name, *dir;
+ const FcChar8 *file, *base;
+ int ret;
+ int n;
+ int id;
+ int ndir = 0;
+ FcStrList *list;
+
+ list = FcStrListCreate (dirs);
+ if (!list)
+ goto bail2;
+
+ while ((dir = FcStrListNext (list)))
+ {
+ base = file_base_name (base_name, dir);
+ if (!write_string (stdout, base))
+ goto bail3;
+ if (PUTC (' ', stdout) == EOF)
+ goto bail3;
+ if (!write_int (stdout, 0))
+ goto bail3;
+ if (PUTC (' ', stdout) == EOF)
+ goto bail3;
+ if (!write_string (stdout, FC_FONT_FILE_DIR))
+ goto bail3;
+ if (PUTC ('\n', stdout) == EOF)
+ goto bail3;
+ ndir++;
+ }
+
+ for (n = 0; n < set->nfont; n++)
+ {
+ FcPattern *font = set->fonts[n];
+
+ if (FcPatternGetString (font, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
+ goto bail3;
+ base = file_base_name (base_name, file);
+ if (FcPatternGetInteger (font, FC_INDEX, 0, &id) != FcResultMatch)
+ goto bail3;
+ if (!write_string (stdout, base))
+ goto bail3;
+ if (PUTC (' ', stdout) == EOF)
+ goto bail3;
+ if (!write_int (stdout, id))
+ goto bail3;
+ if (PUTC (' ', stdout) == EOF)
+ goto bail3;
+ name = FcNameUnparse (font);
+ if (!name)
+ goto bail3;
+ ret = write_string (stdout, name);
+ FcStrFree (name);
+ if (!ret)
+ goto bail3;
+ if (PUTC ('\n', stdout) == EOF)
+ goto bail3;
+ }
+ if (verbose && !set->nfont && !ndir)
+ printf ("<empty>\n");
+
+ FcStrListDone (list);
+
+ return FcTrue;
+
+bail3:
+ FcStrListDone (list);
+bail2:
+ return FcFalse;
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ int ret = 0;
+ FcFontSet *fs;
+ FcStrSet *dirs;
+ FcStrSet *args = NULL;
+ FcStrList *arglist;
+ FcCache *cache;
+ FcConfig *config;
+ FcChar8 *arg;
+ int verbose = 0;
+ int recurse = 0;
+ FcBool first = FcTrue;
+#if HAVE_GETOPT_LONG || HAVE_GETOPT
+ int c;
+
+#if HAVE_GETOPT_LONG
+ while ((c = getopt_long (argc, argv, "Vvrh", longopts, NULL)) != -1)
+#else
+ while ((c = getopt (argc, argv, "Vvrh")) != -1)
+#endif
+ {
+ switch (c) {
+ case 'V':
+ fprintf (stderr, "fontconfig version %d.%d.%d\n",
+ FC_MAJOR, FC_MINOR, FC_REVISION);
+ exit (0);
+ case 'v':
+ verbose++;
+ break;
+ case 'r':
+ recurse++;
+ break;
+ case 'h':
+ usage (argv[0], 0);
+ default:
+ usage (argv[0], 1);
+ }
+ }
+ i = optind;
+#else
+ i = 1;
+#endif
+
+ config = FcInitLoadConfig ();
+ if (!config)
+ {
+ fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
+ return 1;
+ }
+ FcConfigSetCurrent (config);
+
+ args = FcStrSetCreate ();
+ if (!args)
+ {
+ fprintf (stderr, "%s: malloc failure\n", argv[0]);
+ return 1;
+ }
+ if (i < argc)
+ {
+ for (; i < argc; i++)
+ {
+ if (!FcStrSetAddFilename (args, (const FcChar8 *) argv[i]))
+ {
+ fprintf (stderr, "%s: malloc failure\n", argv[0]);
+ return 1;
+ }
+ }
+ arglist = FcStrListCreate (args);
+ if (!arglist)
+ {
+ fprintf (stderr, "%s: malloc failure\n", argv[0]);
+ return 1;
+ }
+ }
+ else
+ {
+ recurse++;
+ arglist = FcConfigGetFontDirs (config);
+ while ((arg = FcStrListNext (arglist)))
+ if (!FcStrSetAdd (args, arg))
+ {
+ fprintf (stderr, "%s: malloc failure\n", argv[0]);
+ return 1;
+ }
+ FcStrListDone (arglist);
+ }
+ arglist = FcStrListCreate (args);
+ if (!arglist)
+ {
+ fprintf (stderr, "%s: malloc failure\n", argv[0]);
+ return 1;
+ }
+
+ while ((arg = FcStrListNext (arglist)))
+ {
+ int j;
+ FcChar8 *cache_file = NULL;
+ struct stat file_stat;
+
+ if (FcFileIsDir (arg))
+ cache = FcDirCacheLoad (arg, config, &cache_file);
+ else
+ cache = FcDirCacheLoadFile (arg, &file_stat);
+ if (!cache)
+ {
+ perror ((char *) arg);
+ ret++;
+ continue;
+ }
+
+ dirs = FcStrSetCreate ();
+ fs = FcCacheCopySet (cache);
+ for (j = 0; j < FcCacheNumSubdir (cache); j++)
+ {
+ FcStrSetAdd (dirs, FcCacheSubdir (cache, j));
+ if (recurse)
+ FcStrSetAdd (args, FcCacheSubdir (cache, j));
+ }
+
+ if (verbose)
+ {
+ if (!first)
+ printf ("\n");
+ printf ("Directory: %s\nCache: %s\n--------\n",
+ FcCacheDir(cache), cache_file ? cache_file : arg);
+ first = FcFalse;
+ }
+ cache_print_set (fs, dirs, FcCacheDir (cache), verbose);
+
+ FcStrSetDestroy (dirs);
+
+ FcFontSetDestroy (fs);
+ FcDirCacheUnload (cache);
+ if (cache_file)
+ FcStrFree (cache_file);
+ }
+
+ return 0;
+}
diff --git a/fontconfig/fc-cat/fc-cat.sgml b/fontconfig/fc-cat/fc-cat.sgml
new file mode 100644
index 000000000..b042dc65f
--- /dev/null
+++ b/fontconfig/fc-cat/fc-cat.sgml
@@ -0,0 +1,168 @@
+<!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>Aug 13, 2008</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;</command>
+
+ <arg><option>-rvVh</option></arg>
+ <arg><option>--recurse</option></arg>
+ <arg><option>--verbose</option></arg>
+ <arg><option>--version</option></arg>
+ <arg><option>--help</option></arg>
+ <sbr>
+ <group rep="repeat">
+ <arg><option><replaceable>fonts-cache-2-files</replaceable></option></arg>
+ <arg><option><replaceable>dirs</replaceable></option></arg>
+ </group>
+
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>DESCRIPTION</title>
+
+ <para><command>&dhpackage;</command> reads the font information from
+ cache files or related to font directories
+ 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>-r</option>
+ <option>--recurse</option>
+ </term>
+ <listitem>
+ <para>Recurse into subdirectories.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-v</option>
+ <option>--verbose</option>
+ </term>
+ <listitem>
+ <para>Be verbose.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-h</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)
+ <command>fc-list</command>(1)
+ <command>fc-match</command>(1)
+ <command>fc-query</command>(1)
+ <command>fc-scan</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:
+-->