]> git.wh0rd.org Git - fontconfig.git/commitdiff
Add fc-scan too that runs FcFileScan/FcDirScan
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 15 Jan 2009 23:39:48 +0000 (18:39 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 14 Feb 2009 00:54:06 +0000 (16:54 -0800)
This is quite similar to fc-query, but calling FcFileScan/FcDirScan instead
of FcFreeTypeQuery.

12 files changed:
.gitignore
Makefile.am
configure.in
doc/fcfile.fncs
fc-cache/fc-cache.sgml
fc-cat/fc-cat.sgml
fc-list/fc-list.sgml
fc-match/fc-match.sgml
fc-query/fc-query.sgml
fc-scan/Makefile.am [new file with mode: 0644]
fc-scan/fc-scan.c [new file with mode: 0644]
fc-scan/fc-scan.sgml [new file with mode: 0644]

index 1c443922f269ef8729a65a4009ac400ac138d3ff..3879fa3f71cdf31ebf653b0621edb497d1d17af4 100644 (file)
@@ -86,6 +86,8 @@ fc-match/fc-match
 fc-match/fc-match.1
 fc-query/fc-query
 fc-query/fc-query.1
+fc-scan/fc-scan
+fc-scan/fc-scan.1
 src/fontconfig.def
 fcalias.h
 fcaliastail.h
index 45c71bc1d1a4207270214603319bbd3e5c3bdf45..e982dd22dbcb06795a1fa66cc1c4db8b62bcf006 100644 (file)
@@ -23,7 +23,7 @@
 
 DOCSRC=@DOCSRC@
 SUBDIRS=fontconfig fc-case fc-lang fc-glyphname fc-arch src \
-       fc-cache fc-cat fc-list fc-match fc-query conf.d $(DOCSRC) test
+       fc-cache fc-cat fc-list fc-match fc-query fc-scan conf.d $(DOCSRC) test
         
 EXTRA_DIST = \
         fontconfig.pc.in \
index bd843a29294a9613578cda3b86842b3e33ff2f91..bbca05ad6a255366a7fe6a257e62f4065dbce1b9 100644 (file)
@@ -565,6 +565,7 @@ fc-cat/Makefile
 fc-list/Makefile
 fc-match/Makefile
 fc-query/Makefile
+fc-scan/Makefile
 doc/Makefile
 doc/version.sgml
 test/Makefile
index 7a980447a4063c5dbde29ce348b0153852229564..1f324b1d8c121716d497bf545f07a1085f41e8dc 100644 (file)
@@ -29,7 +29,7 @@
 @TYPE3@                FcFileCache *                   @ARG3@          cache   
 @TYPE4@                FcBlanks *                      @ARG4@          blanks  
 @TYPE5@                const FcChar8 *                 @ARG5@          file    
-@TYPE6@                FcBool%                                 @ARG6@          force   
+@TYPE6@                FcBool%                         @ARG6@          force
 @PURPOSE@      scan a font file
 @DESC@
 Scans a single file and adds all fonts found to <parameter>set</parameter>.
@@ -61,15 +61,15 @@ returns FcFalse.
 @TYPE3@                FcFileCache *                   @ARG3@          cache   
 @TYPE4@                FcBlanks *                      @ARG4@          blanks  
 @TYPE5@                const FcChar8 *                 @ARG5@          dir     
-@TYPE6@                FcBool%                                 @ARG6@          force   
-@PURPOSE@      DEPRECATED: formerly used to scan a font directory
+@TYPE6@                FcBool%                         @ARG6@          force
+@PURPOSE@      scan a font directory without caching it
 @DESC@
-This function does nothing aside from returning FcFalse. It used to scan an
-entire directory and add all fonts found to
-<parameter>set</parameter>.  If <parameter>force</parameter> was FcTrue, then
-the directory and all files within it were scanned even if information was
-present in the per-directory cache file or <parameter>cache</parameter>. Any
-subdirectories found were added to <parameter>dirs</parameter>.
+If <parameter>cache</parameter> is not zero or if <parameter>force</parameter>
+is FcFalse, this function currently returns FcFalse.  Otherwise, it scans an
+entire directory and adds all fonts found to <parameter>set</parameter>.
+Any subdirectories found are added to <parameter>dirs</parameter>.  Calling
+this function does not create any cache files.  Use FcDirCacheRead() if
+caching is desired.
 @@
 
 @RET@          FcBool  
index 20a7e85cc51ccea08e2f58681bf50ffc109f36a2..fb9f96d9733b78ae9cddbaca0ffe8fcb6cc34789 100644 (file)
@@ -179,6 +179,7 @@ manpage.1: manpage.sgml
       <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:
index 69482b57c74cda52a3826109b1769345ad2102c3..b042dc65f27fb0434fa88a5b583e879766733fa0 100644 (file)
@@ -135,6 +135,7 @@ manpage.1: manpage.sgml
       <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:
index 5807ed1ab6b174988fe8f356346b2984ce741378..cc98779427dbb755e7f3590a53425243513759d2 100644 (file)
@@ -174,12 +174,13 @@ manpage.1: manpage.sgml
     <title>SEE ALSO</title>
 
     <para>
-      <command>fc-cat</command>(1)
-      <command>fc-cache</command>(1)
       <command>fc-match</command>(1)
-      <command>fc-query</command>(1)
       <function>FcFontList</function>(3)
       <function>FcPatternFormat</function>(3)
+      <command>fc-cat</command>(1)
+      <command>fc-cache</command>(1)
+      <command>fc-query</command>(1)
+      <command>fc-scan</command>(1)
     </para>
 
     <para>The fontconfig user's guide, in HTML format:
index bb0d84ec99fae2387447e9a4bc10d90f788ba38f..8c710330fbabed69c8a1e0f93197e7c934578edb 100644 (file)
@@ -164,13 +164,14 @@ are printed.  The <option>--all</option> option works like
     <title>SEE ALSO</title>
 
     <para>
-      <command>fc-cat</command>(1)
-      <command>fc-cache</command>(1)
       <command>fc-list</command>(1)
-      <command>fc-query</command>(1)
       <function>FcFontMatch</function>(3)
       <function>FcFontSort</function>(3)
       <function>FcPatternFormat</function>(3)
+      <command>fc-cat</command>(1)
+      <command>fc-cache</command>(1)
+      <command>fc-query</command>(1)
+      <command>fc-scal</command>(1)
     </para>
 
     <para>The fontconfig user's guide, in HTML format:
index e363db51287c144629549ed951a66ef7e50c5806..59fd6354827924afb692fb53a7b90870e0cd28cf 100644 (file)
@@ -152,12 +152,13 @@ manpage.1: manpage.sgml
     <title>SEE ALSO</title>
 
     <para>
+      <command>fc-scan</command>(1)
+      <function>FcFreeTypeQuery</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)
-      <function>FcFreeTypeQuery</function>(3)
-      <function>FcPatternFormat</function>(3)
     </para>
 
     <para>The fontconfig user's guide, in HTML format:
diff --git a/fc-scan/Makefile.am b/fc-scan/Makefile.am
new file mode 100644 (file)
index 0000000..cb7f5ab
--- /dev/null
@@ -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 (file)
index 0000000..573f7ef
--- /dev/null
@@ -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 (file)
index 0000000..c527c56
--- /dev/null
@@ -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:
+-->