2 * fontconfig/fc-list/fc-list.c
4 * Copyright © 2002 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.
25 #include <fontconfig/fontconfig.h>
34 #define HAVE_GETOPT_LONG 1
41 #define _(x) (dgettext(GETTEXT_PACKAGE, x))
43 #define dgettext(d, s) (s)
50 #ifndef HAVE_GETOPT_LONG
51 #define HAVE_GETOPT_LONG 0
58 const struct option longopts[] = {
59 {"verbose", 0, 0, 'v'},
61 {"format", 1, 0, 'f'},
63 {"version", 0, 0, 'V'},
70 extern int optind, opterr, optopt;
75 usage (char *program, int error)
77 FILE *file = error ? stderr : stdout;
79 fprintf (file, _("usage: %s [-vbqVh] [-f FORMAT] [--verbose] [--brief] [--format=FORMAT] [--quiet] [--version] [--help] [pattern] {element ...} \n"),
82 fprintf (file, _("usage: %s [-vbqVh] [-f FORMAT] [pattern] {element ...} \n"),
85 fprintf (file, _("List fonts matching [pattern]\n"));
88 fprintf (file, _(" -v, --verbose display entire font pattern verbosely\n"));
89 fprintf (file, _(" -b, --brief display entire font pattern briefly\n"));
90 fprintf (file, _(" -f, --format=FORMAT use the given output format\n"));
91 fprintf (file, _(" -q, --quiet suppress all normal output, exit 1 if no fonts matched\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, _(" -v (verbose) display entire font pattern verbosely\n"));
96 fprintf (file, _(" -b (brief) display entire font pattern briefly\n"));
97 fprintf (file, _(" -f FORMAT (format) use the given output format\n"));
98 fprintf (file, _(" -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n"));
99 fprintf (file, _(" -V (version) display font config version and exit\n"));
100 fprintf (file, _(" -h (help) display this help and exit\n"));
106 main (int argc, char **argv)
111 const FcChar8 *format = NULL;
117 #if HAVE_GETOPT_LONG || HAVE_GETOPT
121 while ((c = getopt_long (argc, argv, "vbf:qVh", longopts, NULL)) != -1)
123 while ((c = getopt (argc, argv, "vbf:qVh")) != -1)
134 format = (FcChar8 *) strdup (optarg);
140 fprintf (stderr, "fontconfig version %d.%d.%d\n",
141 FC_MAJOR, FC_MINOR, FC_REVISION);
156 pat = FcNameParse ((FcChar8 *) argv[i]);
159 fprintf (stderr, _("Unable to parse the pattern\n"));
165 os = FcObjectSetCreate ();
166 FcObjectSetAdd (os, argv[i]);
170 pat = FcPatternCreate ();
172 os = FcObjectSetCreate ();
173 if (!verbose && !brief && !format && !os)
174 os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_FILE, (char *) 0);
176 format = (const FcChar8 *) "%{=fclist}\n";
177 fs = FcFontList (0, pat, os);
179 FcObjectSetDestroy (os);
181 FcPatternDestroy (pat);
187 for (j = 0; j < fs->nfont; j++)
189 if (verbose || brief)
193 FcPatternDel (fs->fonts[j], FC_CHARSET);
194 FcPatternDel (fs->fonts[j], FC_LANG);
196 FcPatternPrint (fs->fonts[j]);
202 s = FcPatternFormat (fs->fonts[j], format);
214 FcFontSetDestroy (fs);
219 return quiet ? (nfont == 0 ? 1 : 0) : 0;