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 Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD 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>
33 #define HAVE_GETOPT_LONG 1
41 #ifndef HAVE_GETOPT_LONG
42 #define HAVE_GETOPT_LONG 0
49 const struct option longopts[] = {
50 {"version", 0, 0, 'V'},
51 {"verbose", 0, 0, 'v'},
58 extern int optind, opterr, optopt;
63 usage (char *program, int error)
65 FILE *file = error ? stderr : stdout;
67 fprintf (file, "usage: %s [-vVh] [--verbose] [--version] [--help] [pattern] {element ...} \n",
70 fprintf (file, "usage: %s [-vVh] [pattern] {element ...} \n",
73 fprintf (file, "List fonts matching [pattern]\n");
76 fprintf (file, " -v, --verbose display entire font pattern\n");
77 fprintf (file, " -V, --version display font config version and exit\n");
78 fprintf (file, " -h, --help display this help and exit\n");
80 fprintf (file, " -v (verbose) display entire font pattern\n");
81 fprintf (file, " -V (version) display font config version and exit\n");
82 fprintf (file, " -h (help) display this help and exit\n");
88 main (int argc, char **argv)
95 #if HAVE_GETOPT_LONG || HAVE_GETOPT
99 while ((c = getopt_long (argc, argv, "Vvh", longopts, NULL)) != -1)
101 while ((c = getopt (argc, argv, "Vvh")) != -1)
106 fprintf (stderr, "fontconfig version %d.%d.%d\n",
107 FC_MAJOR, FC_MINOR, FC_REVISION);
125 fprintf (stderr, "Can't init font config library\n");
130 pat = FcNameParse ((FcChar8 *) argv[i]);
135 os = FcObjectSetCreate ();
136 FcObjectSetAdd (os, argv[i]);
140 pat = FcPatternCreate ();
143 os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
144 fs = FcFontList (0, pat, os);
146 FcObjectSetDestroy (os);
148 FcPatternDestroy (pat);
154 for (j = 0; j < fs->nfont; j++)
160 FcPatternPrint (fs->fonts[j]);
163 font = FcNameUnparse (fs->fonts[j]);
164 if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
165 printf ("%s: ", file);
166 printf ("%s\n", font);
170 FcFontSetDestroy (fs);