]>
git.wh0rd.org - fontconfig.git/blob - fc-list/fc-list.c
89f4167b5fc44e6173cbc694bbf4ec6811b02320
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'},
59 extern int optind
, opterr
, optopt
;
64 usage (char *program
, int error
)
66 FILE *file
= error
? stderr
: stdout
;
68 fprintf (file
, "usage: %s [-vqVh] [--verbose] [--quiet] [--version] [--help] [pattern] {element ...} \n",
71 fprintf (file
, "usage: %s [-vqVh] [pattern] {element ...} \n",
74 fprintf (file
, "List fonts matching [pattern]\n");
77 fprintf (file
, " -v, --verbose display entire font pattern\n");
78 fprintf (file
, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\n");
79 fprintf (file
, " -V, --version display font config version and exit\n");
80 fprintf (file
, " -h, --help display this help and exit\n");
82 fprintf (file
, " -v (verbose) display entire font pattern\n");
83 fprintf (file
, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n");
84 fprintf (file
, " -V (version) display font config version and exit\n");
85 fprintf (file
, " -h (help) display this help and exit\n");
91 main (int argc
, char **argv
)
100 #if HAVE_GETOPT_LONG || HAVE_GETOPT
104 while ((c
= getopt_long (argc
, argv
, "Vqvh", longopts
, NULL
)) != -1)
106 while ((c
= getopt (argc
, argv
, "Vqvh")) != -1)
111 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
112 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
133 fprintf (stderr
, "Can't init font config library\n");
138 pat
= FcNameParse ((FcChar8
*) argv
[i
]);
143 os
= FcObjectSetCreate ();
144 FcObjectSetAdd (os
, argv
[i
]);
148 pat
= FcPatternCreate ();
150 os
= FcObjectSetCreate ();
152 os
= FcObjectSetBuild (FC_FAMILY
, FC_STYLE
, (char *) 0);
153 fs
= FcFontList (0, pat
, os
);
155 FcObjectSetDestroy (os
);
157 FcPatternDestroy (pat
);
163 for (j
= 0; j
< fs
->nfont
; j
++)
169 FcPatternPrint (fs
->fonts
[j
]);
172 font
= FcNameUnparse (fs
->fonts
[j
]);
173 if (FcPatternGetString (fs
->fonts
[j
], FC_FILE
, 0, &file
) == FcResultMatch
)
174 printf ("%s: ", file
);
175 printf ("%s\n", font
);
183 FcFontSetDestroy (fs
);
188 return quiet
? (nfont
== 0 ? 1 : 0) : 0;