From: Behdad Esfahbod Date: Wed, 21 Apr 2010 03:18:00 +0000 (-0400) Subject: Add fc-pattern cmdline tool X-Git-Tag: root-2~52 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ba7b50ab3324887e1680a4a8961487706705c739;p=fontconfig.git Add fc-pattern cmdline tool --- diff --git a/Makefile.am b/Makefile.am index 1cde132..2309a19 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,8 @@ DOCSRC=@DOCSRC@ SUBDIRS=fontconfig fc-case fc-lang fc-glyphname fc-arch src \ - fc-cache fc-cat fc-list fc-match fc-query fc-scan conf.d $(DOCSRC) test + fc-cache fc-cat fc-list fc-match fc-pattern fc-query fc-scan \ + conf.d $(DOCSRC) test EXTRA_DIST = \ fontconfig.pc.in \ diff --git a/configure.in b/configure.in index aba9d82..f8ae501 100644 --- a/configure.in +++ b/configure.in @@ -542,6 +542,7 @@ fc-cache/Makefile fc-cat/Makefile fc-list/Makefile fc-match/Makefile +fc-pattern/Makefile fc-query/Makefile fc-scan/Makefile doc/Makefile diff --git a/fc-cache/fc-cache.sgml b/fc-cache/fc-cache.sgml index 26c745d..3740be7 100644 --- a/fc-cache/fc-cache.sgml +++ b/fc-cache/fc-cache.sgml @@ -184,6 +184,7 @@ manpage.1: manpage.sgml fc-cat(1) fc-list(1) fc-match(1) + fc-pattern(1) fc-query(1) fc-scan(1) diff --git a/fc-cat/fc-cat.sgml b/fc-cat/fc-cat.sgml index b042dc6..ce4736d 100644 --- a/fc-cat/fc-cat.sgml +++ b/fc-cat/fc-cat.sgml @@ -134,6 +134,7 @@ manpage.1: manpage.sgml fc-cache(1) fc-list(1) fc-match(1) + fc-pattern(1) fc-query(1) fc-scan(1) diff --git a/fc-list/fc-list.sgml b/fc-list/fc-list.sgml index ffa0891..c4a82cd 100644 --- a/fc-list/fc-list.sgml +++ b/fc-list/fc-list.sgml @@ -179,6 +179,7 @@ manpage.1: manpage.sgml FcPatternFormat(3) fc-cat(1) fc-cache(1) + fc-pattern(1) fc-query(1) fc-scan(1) diff --git a/fc-match/fc-match.sgml b/fc-match/fc-match.sgml index 9f78b29..f66a021 100644 --- a/fc-match/fc-match.sgml +++ b/fc-match/fc-match.sgml @@ -182,6 +182,7 @@ output is requested. FcPatternFormat(3) fc-cat(1) fc-cache(1) + fc-pattern(1) fc-query(1) fc-scan(1) diff --git a/fc-pattern/Makefile.am b/fc-pattern/Makefile.am new file mode 100644 index 0000000..4460d4a --- /dev/null +++ b/fc-pattern/Makefile.am @@ -0,0 +1,59 @@ +# +# fontconfig/fc-pattern/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. + +bin_PROGRAMS=fc-pattern + +DOC2MAN = docbook2man + +FC_PATTERN_SRC=${top_srcdir}/fc-pattern + +SGML = ${FC_PATTERN_SRC}/fc-pattern.sgml + +INCLUDES=-I${top_srcdir} $(WARN_CFLAGS) + +BUILT_MANS=fc-pattern.1 + +if ENABLE_DOCS +man_MANS=${BUILT_MANS} +endif + +EXTRA_DIST=fc-pattern.sgml $(BUILT_MANS) + +fc_pattern_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/fc-pattern/fc-pattern.c b/fc-pattern/fc-pattern.c new file mode 100644 index 0000000..1ac5887 --- /dev/null +++ b/fc-pattern/fc-pattern.c @@ -0,0 +1,195 @@ +/* + * fontconfig/fc-pattern/fc-pattern.c + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include +#else +#ifdef linux +#define HAVE_GETOPT_LONG 1 +#endif +#define HAVE_GETOPT 1 +#endif + +#include +#include +#include +#include +#include + +#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 +static const struct option longopts[] = { + {"config", 0, 0, 'c'}, + {"default", 0, 0, 'd'}, + {"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 [-cdVh] [-f FORMAT] [--config] [--default] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n", + program); +#else + fprintf (file, "usage: %s [-cdVh] [-f FORMAT] [pattern] {element...}\n", + program); +#endif + fprintf (file, "List best font matching [pattern]\n"); + fprintf (file, "\n"); +#if HAVE_GETOPT_LONG + fprintf (file, " -c, --config perform config substitution on pattern\n"); + fprintf (file, " -d, -default perform default substitution on pattern\n"); + 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, " -c, (config) perform config substitution on pattern\n"); + fprintf (file, " -d, (default) perform default substitution on pattern\n"); + 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) +{ + int do_config = 0, do_default = 0; + FcChar8 *format = NULL; + int i; + FcObjectSet *os = 0; + FcPattern *pat; +#if HAVE_GETOPT_LONG || HAVE_GETOPT + int c; + +#if HAVE_GETOPT_LONG + while ((c = getopt_long (argc, argv, "cdf:Vh", longopts, NULL)) != -1) +#else + while ((c = getopt (argc, argv, "cdf:Vh")) != -1) +#endif + { + switch (c) { + case 'c': + do_config = 1; + break; + case 'd': + do_default = 1; + break; + 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 (!FcInit ()) + { + fprintf (stderr, "Can't init font config library\n"); + return 1; + } + if (argv[i]) + { + pat = FcNameParse ((FcChar8 *) argv[i]); + while (argv[++i]) + { + if (!os) + os = FcObjectSetCreate (); + FcObjectSetAdd (os, argv[i]); + } + } + else + pat = FcPatternCreate (); + + if (!pat) + return 1; + + if (do_config) + FcConfigSubstitute (0, pat, FcMatchPattern); + if (do_default) + FcDefaultSubstitute (pat); + + if (os) + { + FcPattern *new; + new = FcPatternFilter (pat, os); + FcPatternDestroy (pat); + pat = new; + } + + if (format) + { + FcChar8 *s; + + s = FcPatternFormat (pat, format); + if (s) + { + printf ("%s", s); + free (s); + } + } + else + { + FcPatternPrint (pat); + } + + FcPatternDestroy (pat); + + if (os) + FcObjectSetDestroy (os); + + FcFini (); + + return 0; +} diff --git a/fc-pattern/fc-pattern.sgml b/fc-pattern/fc-pattern.sgml new file mode 100644 index 0000000..65a75ed --- /dev/null +++ b/fc-pattern/fc-pattern.sgml @@ -0,0 +1,204 @@ + 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. + + --> + + + Behdad"> + Esfahbod"> + + Apr 20, 2010"> + + 1"> + behdad@behdad.org"> + + fc-pattern"> + + + Debian"> + GNU"> + GPL"> +]> + + + +
+ &dhemail; +
+ + &dhfirstname; + &dhsurname; + + + 2010 + &dhusername; + + &dhdate; +
+ + &dhucpackage; + + &dhsection; + + + &dhpackage; + + parse and show pattern + + + + &dhpackage; + + + + + + + + + + + + + + + + + DESCRIPTION + + &dhpackage; parses + pattern (empty +pattern by default) and shows the parsed result. +If is given, config substitution is performed on the +pattern before being displayed. +If is given, default substitution is performed on the +pattern before being displayed. +If any elements are specified, only those are printed. + + + OPTIONS + + This program follows the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + + + + + + + + Perform config substitution on pattern. + + + + + + + + Perform default substitution on pattern. + + + + + + + + + Format output according to the format specifier + format. + + + + + + + + Show version of the program and exit. + + + + + + + + Show summary of options. + + + + + + + Parses and displays pattern (uses empty pattern by default). + + + + + + + If set, the element property + is displayed for parsed pattern. + + + + + + + SEE ALSO + + + FcNameParse(3) + FcConfigSubstitute(3) + FcDefaultSubstitute(3) + FcPatternPrint(3) + FcPatternFormat(3) + fc-cat(1) + fc-cache(1) + fc-list(1) + fc-match(1) + fc-query(1) + fc-scan(1) + + + The fontconfig user's guide, in HTML format: + /usr/share/doc/fontconfig/fontconfig-user.html. + + + + AUTHOR + + This manual page was updated by &dhusername; &dhemail;. + + +
+ + diff --git a/fc-query/fc-query.sgml b/fc-query/fc-query.sgml index 59fd635..5351d1e 100644 --- a/fc-query/fc-query.sgml +++ b/fc-query/fc-query.sgml @@ -159,6 +159,7 @@ manpage.1: manpage.sgml fc-cache(1) fc-list(1) fc-match(1) + fc-pattern(1) The fontconfig user's guide, in HTML format: diff --git a/fc-scan/fc-scan.sgml b/fc-scan/fc-scan.sgml index b9f7714..9af403c 100644 --- a/fc-scan/fc-scan.sgml +++ b/fc-scan/fc-scan.sgml @@ -144,6 +144,7 @@ manpage.1: manpage.sgml fc-cache(1) fc-list(1) fc-match(1) + fc-pattern(1) The fontconfig user's guide, in HTML format: