]>
git.wh0rd.org - fontconfig.git/blob - fc-list/fc-list.c
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>
34 #define HAVE_GETOPT_LONG 1
42 #ifndef HAVE_GETOPT_LONG
43 #define HAVE_GETOPT_LONG 0
50 const struct option longopts
[] = {
51 {"verbose", 0, 0, 'v'},
52 {"format", 1, 0, 'f'},
54 {"version", 0, 0, 'V'},
61 extern int optind
, opterr
, optopt
;
66 usage (char *program
, int error
)
68 FILE *file
= error
? stderr
: stdout
;
70 fprintf (file
, "usage: %s [-vqVh] [-f FORMAT] [--verbose] [--format=FORMAT] [--quiet] [--version] [--help] [pattern] {element ...} \n",
73 fprintf (file
, "usage: %s [-vqVh] [-f FORMAT] [pattern] {element ...} \n",
76 fprintf (file
, "List fonts matching [pattern]\n");
79 fprintf (file
, " -v, --verbose display entire font pattern\n");
80 fprintf (file
, " -f, --format=FORMAT use the given output format\n");
81 fprintf (file
, " -q, --quiet suppress all normal output, exit 1 if no fonts matched\n");
82 fprintf (file
, " -V, --version display font config version and exit\n");
83 fprintf (file
, " -h, --help display this help and exit\n");
85 fprintf (file
, " -v (verbose) display entire font pattern\n");
86 fprintf (file
, " -f FORMAT (format) use the given output format\n");
87 fprintf (file
, " -q, (quiet) suppress all normal output, exit 1 if no fonts matched\n");
88 fprintf (file
, " -V (version) display font config version and exit\n");
89 fprintf (file
, " -h (help) display this help and exit\n");
95 main (int argc
, char **argv
)
99 FcChar8
*format
= NULL
;
105 #if HAVE_GETOPT_LONG || HAVE_GETOPT
109 while ((c
= getopt_long (argc
, argv
, "vf:qVh", longopts
, NULL
)) != -1)
111 while ((c
= getopt (argc
, argv
, "vf:qVh")) != -1)
119 format
= (FcChar8
*) strdup (optarg
);
125 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
126 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
141 fprintf (stderr
, "Can't init font config library\n");
146 pat
= FcNameParse ((FcChar8
*) argv
[i
]);
151 os
= FcObjectSetCreate ();
152 FcObjectSetAdd (os
, argv
[i
]);
156 pat
= FcPatternCreate ();
158 os
= FcObjectSetCreate ();
159 if (!verbose
&& !format
&& !os
)
160 os
= FcObjectSetBuild (FC_FAMILY
, FC_STYLE
, (char *) 0);
161 fs
= FcFontList (0, pat
, os
);
163 FcObjectSetDestroy (os
);
165 FcPatternDestroy (pat
);
171 for (j
= 0; j
< fs
->nfont
; j
++)
178 FcPatternPrint (fs
->fonts
[j
]);
184 s
= FcPatternFormat (fs
->fonts
[j
], format
);
190 font
= FcNameUnparse (fs
->fonts
[j
]);
191 if (FcPatternGetString (fs
->fonts
[j
], FC_FILE
, 0, &file
) == FcResultMatch
)
192 printf ("%s: ", file
);
193 printf ("%s\n", font
);
201 FcFontSetDestroy (fs
);
206 return quiet
? (nfont
== 0 ? 1 : 0) : 0;