]>
git.wh0rd.org - fontconfig.git/blob - fc-match/fc-match.c
2 * $RCSId: xc/lib/fontconfig/fc-list/fc-list.c,v 1.5 2002/06/30 23:45:40 keithp Exp $
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 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.
29 #define HAVE_GETOPT_LONG 1
34 #include <fontconfig/fontconfig.h>
43 #ifndef HAVE_GETOPT_LONG
44 #define HAVE_GETOPT_LONG 0
51 static const struct option longopts
[] = {
53 {"version", 0, 0, 'V'},
54 {"verbose", 0, 0, 'v'},
61 extern int optind
, opterr
, optopt
;
65 static void usage (char *program
)
68 fprintf (stderr
, "usage: %s [-svV?] [--sort] [--verbose] [--version] [--help] [pattern]\n",
71 fprintf (stderr
, "usage: %s [-svV?] [pattern]\n",
74 fprintf (stderr
, "List fonts matching [pattern]\n");
75 fprintf (stderr
, "\n");
77 fprintf (stderr
, " -s, --sort display sorted list of matches\n");
78 fprintf (stderr
, " -v, --verbose display entire font pattern\n");
79 fprintf (stderr
, " -V, --version display font config version and exit\n");
80 fprintf (stderr
, " -?, --help display this help and exit\n");
82 fprintf (stderr
, " -s, (sort) display sorted list of matches\n");
83 fprintf (stderr
, " -v (verbose) display entire font pattern\n");
84 fprintf (stderr
, " -V (version) display font config version and exit\n");
85 fprintf (stderr
, " -? (help) display this help and exit\n");
91 main (int argc
, char **argv
)
99 #if HAVE_GETOPT_LONG || HAVE_GETOPT
103 while ((c
= getopt_long (argc
, argv
, "sVv?", longopts
, NULL
)) != -1)
105 while ((c
= getopt (argc
, argv
, "sVv?")) != -1)
113 fprintf (stderr
, "fontconfig version %d.%d.%d\n",
114 FC_MAJOR
, FC_MINOR
, FC_REVISION
);
130 fprintf (stderr
, "Can't init font config library\n");
134 pat
= FcNameParse ((FcChar8
*) argv
[i
]);
136 pat
= FcPatternCreate ();
141 FcConfigSubstitute (0, pat
, FcMatchPattern
);
142 FcDefaultSubstitute (pat
);
145 fs
= FcFontSort (0, pat
, FcTrue
, 0, &result
);
149 fs
= FcFontSetCreate ();
150 match
= FcFontMatch (0, pat
, &result
);
152 FcFontSetAdd (fs
, match
);
154 FcPatternDestroy (pat
);
160 for (j
= 0; j
< fs
->nfont
; j
++)
164 FcPatternPrint (fs
->fonts
[j
]);
172 if (FcPatternGetString (fs
->fonts
[j
], FC_FILE
, 0, &file
) != FcResultMatch
)
173 file
= (FcChar8
*) "<unknown filename>";
176 FcChar8
*slash
= (FcChar8
*) strrchr ((char *) file
, '/');
180 if (FcPatternGetString (fs
->fonts
[j
], FC_FAMILY
, 0, &family
) != FcResultMatch
)
181 family
= (FcChar8
*) "<unknown family>";
182 if (FcPatternGetString (fs
->fonts
[j
], FC_STYLE
, 0, &style
) != FcResultMatch
)
183 file
= (FcChar8
*) "<unknown style>";
185 printf ("%s: \"%s\" \"%s\"\n", file
, family
, style
);
188 FcFontSetDestroy (fs
);