2 * fontconfig/fc-pattern/fc-pattern.c
4 * Copyright © 2003 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 #define HAVE_GETOPT_LONG 1
34 #include <fontconfig/fontconfig.h>
43 #define _(x) (dgettext(GETTEXT_PACKAGE, x))
45 #define dgettext(d, s) (s)
52 #ifndef HAVE_GETOPT_LONG
53 #define HAVE_GETOPT_LONG 0
60 static const struct option longopts[] = {
61 {"config", 0, 0, 'c'},
62 {"default", 0, 0, 'd'},
63 {"format", 1, 0, 'f'},
64 {"version", 0, 0, 'V'},
71 extern int optind, opterr, optopt;
76 usage (char *program, int error)
78 FILE *file = error ? stderr : stdout;
80 fprintf (file, _("usage: %s [-cdVh] [-f FORMAT] [--config] [--default] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n"),
83 fprintf (file, _("usage: %s [-cdVh] [-f FORMAT] [pattern] {element...}\n"),
86 fprintf (file, _("List best font matching [pattern]\n"));
89 fprintf (file, _(" -c, --config perform config substitution on pattern\n"));
90 fprintf (file, _(" -d, --default perform default substitution on pattern\n"));
91 fprintf (file, _(" -f, --format=FORMAT use the given output format\n"));
92 fprintf (file, _(" -V, --version display font config version and exit\n"));
93 fprintf (file, _(" -h, --help display this help and exit\n"));
95 fprintf (file, _(" -c, (config) perform config substitution on pattern\n"));
96 fprintf (file, _(" -d, (default) perform default substitution on pattern\n"));
97 fprintf (file, _(" -f FORMAT (format) use the given output format\n"));
98 fprintf (file, _(" -V (version) display font config version and exit\n"));
99 fprintf (file, _(" -h (help) display this help and exit\n"));
105 main (int argc, char **argv)
107 int do_config = 0, do_default = 0;
108 FcChar8 *format = NULL;
112 #if HAVE_GETOPT_LONG || HAVE_GETOPT
115 setlocale (LC_ALL, "");
117 while ((c = getopt_long (argc, argv, "cdf:Vh", longopts, NULL)) != -1)
119 while ((c = getopt (argc, argv, "cdf:Vh")) != -1)
130 format = (FcChar8 *) strdup (optarg);
133 fprintf (stderr, "fontconfig version %d.%d.%d\n",
134 FC_MAJOR, FC_MINOR, FC_REVISION);
149 pat = FcNameParse ((FcChar8 *) argv[i]);
152 fprintf (stderr, _("Unable to parse the pattern\n"));
158 os = FcObjectSetCreate ();
159 FcObjectSetAdd (os, argv[i]);
163 pat = FcPatternCreate ();
169 FcConfigSubstitute (0, pat, FcMatchPattern);
171 FcDefaultSubstitute (pat);
176 new = FcPatternFilter (pat, os);
177 FcPatternDestroy (pat);
185 s = FcPatternFormat (pat, format);
194 FcPatternPrint (pat);
197 FcPatternDestroy (pat);
200 FcObjectSetDestroy (os);