2 * fontconfig/fc-scan/fc-scan.c
4 * Copyright © 2003 Keith Packard
5 * Copyright © 2008 Red Hat, Inc.
6 * Red Hat Author(s): Behdad Esfahbod
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of the author(s) not be used in
13 * advertising or publicity pertaining to distribution of the software without
14 * specific, written prior permission. The authors make no
15 * representations about the suitability of this software for any purpose. It
16 * is provided "as is" without express or implied warranty.
18 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24 * PERFORMANCE OF THIS SOFTWARE.
31 #define HAVE_GETOPT_LONG 1
36 #include <fontconfig/fontconfig.h>
37 #include <fontconfig/fcfreetype.h>
46 #define _(x) (dgettext(GETTEXT_PACKAGE, x))
48 #define dgettext(d, s) (s)
55 #ifndef HAVE_GETOPT_LONG
56 #define HAVE_GETOPT_LONG 0
63 static const struct option longopts[] = {
65 {"format", 1, 0, 'f'},
66 {"version", 0, 0, 'V'},
73 extern int optind, opterr, optopt;
78 usage (char *program, int error)
80 FILE *file = error ? stderr : stdout;
82 fprintf (file, _("usage: %s [-bVh] [-f FORMAT] [--brief] [--format FORMAT] [--version] [--help] font-file...\n"),
85 fprintf (file, _("usage: %s [-bVh] [-f FORMAT] font-file...\n"),
88 fprintf (file, _("Scan font files and directories, and print resulting pattern(s)\n"));
91 fprintf (file, _(" -b, --brief display font pattern briefly\n"));
92 fprintf (file, _(" -f, --format=FORMAT use the given output format\n"));
93 fprintf (file, _(" -V, --version display font config version and exit\n"));
94 fprintf (file, _(" -h, --help display this help and exit\n"));
96 fprintf (file, _(" -b (brief) display font pattern briefly\n"));
97 fprintf (file, _(" -f FORMAT (format) use the given output format\n"));
98 fprintf (file, _(" -V (version) display font config version and exit\n"));
99 fprintf (file, _(" -h (help) display this help and exit\n"));
105 main (int argc, char **argv)
108 FcChar8 *format = NULL;
111 #if HAVE_GETOPT_LONG || HAVE_GETOPT
114 setlocale (LC_ALL, "");
116 while ((c = getopt_long (argc, argv, "bf:Vh", longopts, NULL)) != -1)
118 while ((c = getopt (argc, argv, "bf:Vh")) != -1)
126 format = (FcChar8 *) strdup (optarg);
129 fprintf (stderr, "fontconfig version %d.%d.%d\n",
130 FC_MAJOR, FC_MINOR, FC_REVISION);
146 fs = FcFontSetCreate ();
148 for (; i < argc; i++)
150 const FcChar8 *file = (FcChar8*) argv[i];
152 if (!FcFileIsDir (file))
153 FcFileScan (fs, NULL, NULL, NULL, file, FcTrue);
156 FcStrSet *dirs = FcStrSetCreate ();
157 FcStrList *strlist = FcStrListCreate (dirs);
160 FcDirScan (fs, dirs, NULL, NULL, file, FcTrue);
162 while ((file = FcStrListNext (strlist)));
163 FcStrListDone (strlist);
164 FcStrSetDestroy (dirs);
168 for (i = 0; i < fs->nfont; i++)
170 FcPattern *pat = fs->fonts[i];
174 FcPatternDel (pat, FC_CHARSET);
175 FcPatternDel (pat, FC_LANG);
182 s = FcPatternFormat (pat, format);
191 FcPatternPrint (pat);
195 FcFontSetDestroy (fs);
198 return i > 0 ? 0 : 1;