summaryrefslogtreecommitdiff
path: root/fc-scan
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-01-15 18:39:48 -0500
committerBehdad Esfahbod <behdad@behdad.org>2009-02-13 16:54:06 -0800
commit6bffe1a95bfd6609358d38590ad638c688232575 (patch)
tree515b3053dcda6bab42b7a343572a85e3804f4f31 /fc-scan
parent4074fd254e5ad707448d3665a034e0fbdf6de033 (diff)
Add fc-scan too that runs FcFileScan/FcDirScan
This is quite similar to fc-query, but calling FcFileScan/FcDirScan instead of FcFreeTypeQuery.
Diffstat (limited to 'fc-scan')
-rw-r--r--fc-scan/Makefile.am59
-rw-r--r--fc-scan/fc-scan.c181
-rw-r--r--fc-scan/fc-scan.sgml176
3 files changed, 416 insertions, 0 deletions
diff --git a/fc-scan/Makefile.am b/fc-scan/Makefile.am
new file mode 100644
index 0000000..cb7f5ab
--- /dev/null
+++ b/fc-scan/Makefile.am
@@ -0,0 +1,59 @@
+#
+# fontconfig/fc-scan/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.
+#
+# 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.
+
+bin_PROGRAMS=fc-scan
+
+DOC2MAN = docbook2man
+
+FC_SCAN_SRC=${top_srcdir}/fc-scan
+
+SGML = ${FC_SCAN_SRC}/fc-scan.sgml
+
+INCLUDES=-I${top_srcdir} $(FREETYPE_CFLAGS) $(WARN_CFLAGS)
+
+BUILT_MANS=fc-scan.1
+
+if ENABLE_DOCS
+man_MANS=${BUILT_MANS}
+endif
+
+EXTRA_DIST=fc-scan.sgml $(BUILT_MANS)
+
+fc_scan_LDADD = ${top_builddir}/src/libfontconfig.la
+
+if USEDOCBOOK
+
+${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-scan/fc-scan.c b/fc-scan/fc-scan.c
new file mode 100644
index 0000000..573f7ef
--- /dev/null
+++ b/fc-scan/fc-scan.c
@@ -0,0 +1,181 @@
+/*
+ * fontconfig/fc-scan/fc-scan.c
+ *
+ * Copyright © 2003 Keith Packard
+ * Copyright © 2008 Red Hat, Inc.
+ * Red Hat Author(s): Behdad Esfahbod
+ *
+ * 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.
+ */
+
+#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 <fontconfig/fcfreetype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.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>
+static const struct option longopts[] = {
+ {"format", 1, 0, 'f'},
+ {"version", 0, 0, 'V'},
+ {"help", 0, 0, 'h'},
+ {NULL,0,0,0},
+};
+#else
+#if HAVE_GETOPT
+extern char *optarg;
+extern int optind, opterr, optopt;
+#endif
+#endif
+
+static void
+usage (char *program, int error)
+{
+ FILE *file = error ? stderr : stdout;
+#if HAVE_GETOPT_LONG
+ fprintf (file, "usage: %s [-Vh] [-f FORMAT] [--format FORMAT] [--version] [--help] font-file...\n",
+ program);
+#else
+ fprintf (file, "usage: %s [-Vh] [-f FORMAT] font-file...\n",
+ program);
+#endif
+ fprintf (file, "Scan font files and directories, and print resulting pattern(s)\n");
+ fprintf (file, "\n");
+#if HAVE_GETOPT_LONG
+ fprintf (file, " -f, --format=FORMAT use the given output format\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, " -f FORMAT (format) use the given output format\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);
+}
+
+int
+main (int argc, char **argv)
+{
+ FcChar8 *format = NULL;
+ int i;
+ FcFontSet *fs;
+#if HAVE_GETOPT_LONG || HAVE_GETOPT
+ int c;
+
+#if HAVE_GETOPT_LONG
+ while ((c = getopt_long (argc, argv, "f:Vh", longopts, NULL)) != -1)
+#else
+ while ((c = getopt (argc, argv, "f:Vh")) != -1)
+#endif
+ {
+ switch (c) {
+ case 'f':
+ format = (FcChar8 *) strdup (optarg);
+ break;
+ case 'V':
+ fprintf (stderr, "fontconfig version %d.%d.%d\n",
+ FC_MAJOR, FC_MINOR, FC_REVISION);
+ exit (0);
+ case 'h':
+ usage (argv[0], 0);
+ default:
+ usage (argv[0], 1);
+ }
+ }
+ i = optind;
+#else
+ i = 1;
+#endif
+
+ if (i == argc)
+ usage (argv[0], 1);
+
+ if (!FcInit ())
+ {
+ fprintf (stderr, "Can't init font config library\n");
+ return 1;
+ }
+
+ fs = FcFontSetCreate ();
+
+ for (; i < argc; i++)
+ {
+ const FcChar8 *file = (FcChar8*) argv[i];
+
+ if (!FcFileIsDir (file))
+ FcFileScan (fs, NULL, NULL, NULL, file, FcTrue);
+ else
+ {
+ FcStrSet *dirs = FcStrSetCreate ();
+ FcStrList *strlist = FcStrListCreate (dirs);
+ do
+ {
+ FcDirScan (fs, dirs, NULL, NULL, file, FcTrue);
+ }
+ while ((file = FcStrListNext (strlist)));
+ FcStrListDone (strlist);
+ FcStrSetDestroy (dirs);
+ }
+ }
+
+ for (i = 0; i < fs->nfont; i++)
+ {
+ FcPattern *pat;
+
+ pat = fs->fonts[i];
+
+ if (format)
+ {
+ FcChar8 *s;
+
+ s = FcPatternFormat (pat, format);
+ printf ("%s", s);
+ free (s);
+ }
+ else
+ {
+ FcPatternPrint (pat);
+ }
+ }
+
+ FcFontSetDestroy (fs);
+
+ FcFini ();
+ return i > 0 ? 0 : 1;
+}
diff --git a/fc-scan/fc-scan.sgml b/fc-scan/fc-scan.sgml
new file mode 100644
index 0000000..c527c56
--- /dev/null
+++ b/fc-scan/fc-scan.sgml
@@ -0,0 +1,176 @@
+<!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>Behdad</firstname>">
+ <!ENTITY dhsurname "<surname>Esfahbod</surname>">
+ <!-- Please adjust the date whenever revising the manpage. -->
+ <!ENTITY dhdate "<date>Jan 15, 2009</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>behdad@behdad.org</email>">
+ <!ENTITY dhusername "Behdad Esfahbod">
+ <!ENTITY dhucpackage "<refentrytitle>fc-scan</refentrytitle>">
+ <!ENTITY dhpackage "fc-scan">
+
+ <!ENTITY gnu "<acronym>GNU</acronym>">
+ <!ENTITY gpl "&gnu; <acronym>GPL</acronym>">
+]>
+
+<refentry>
+ <refentryinfo>
+ <address>
+ &dhemail;
+ </address>
+ <author>
+ &dhfirstname;
+ &dhsurname;
+ </author>
+ <copyright>
+ <year>2008</year>
+ <holder>&dhusername;</holder>
+ </copyright>
+ &dhdate;
+ </refentryinfo>
+ <refmeta>
+ &dhucpackage;
+
+ &dhsection;
+ </refmeta>
+ <refnamediv>
+ <refname>&dhpackage;</refname>
+
+ <refpurpose>scan font files or directories</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>&dhpackage;</command>
+
+ <arg><option>-Vh</option></arg>
+ <sbr>
+ <group>
+ <arg><option>-f</option> <option><replaceable>format</replaceable></option></arg>
+ <arg><option>--format</option> <option><replaceable>format</replaceable></option></arg>
+ </group>
+ <arg><option>--version</option></arg>
+ <arg><option>--help</option></arg>
+ <arg choice="req" rep="repeat"><option><replaceable>file</replaceable></option></arg>
+
+ </cmdsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>DESCRIPTION</title>
+
+ <para><command>&dhpackage;</command> scans
+ <replaceable>file</replaceable>(s) recursively
+ and prints out font pattern for each face found.
+
+ </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>-f</option>
+ <option>--format</option>
+ <option><replaceable>format</replaceable></option>
+ </term>
+ <listitem>
+ <para>Format output according to the format specifier
+ <replaceable>format</replaceable>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-V</option>
+ <option>--version</option>
+ </term>
+ <listitem>
+ <para>Show version of the program and exit.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>-h</option>
+ <option>--help</option>
+ </term>
+ <listitem>
+ <para>Show summary of options.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option><replaceable>file</replaceable></option>
+ </term>
+ <listitem>
+ <para>Scan <replaceable>file</replaceable> recursively for font faces.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>RETURN CODES</title>
+ <para><command>fc-scan</command> returns error code 0 if at least one font
+ was found or 1 otherwise.</para>
+ </refsect1>
+
+ <refsect1>
+ <title>SEE ALSO</title>
+
+ <para>
+ <command>fc-query</command>(1)
+ <function>FcFileScan</function>(3)
+ <function>FcDirScan</function>(3)
+ <function>FcPatternFormat</function>(3)
+ <command>fc-cat</command>(1)
+ <command>fc-cache</command>(1)
+ <command>fc-list</command>(1)
+ <command>fc-match</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 updated 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:
+-->