]> git.wh0rd.org - fontconfig.git/blob - fc-list/fc-list.c
Initial revision
[fontconfig.git] / fc-list / fc-list.c
1 /*
2 * $XFree86: $
3 *
4 * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
5 *
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.
15 *
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.
23 */
24
25 #include <fontconfig/fontconfig.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #else
31 #define HAVE_GETOPT 1
32 #endif
33
34 #if HAVE_GETOPT_LONG
35 #define _GNU_SOURCE
36 #include <getopt.h>
37 const struct option longopts[] = {
38 {"version", 0, 0, 'V'},
39 {"verbose", 0, 0, 'v'},
40 {"help", 0, 0, '?'},
41 {NULL,0,0,0},
42 };
43 #else
44 #if HAVE_GETOPT
45 extern char *optarg;
46 extern int optind, opterr, optopt;
47 #endif
48 #endif
49
50 void usage (char *program)
51 {
52 fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
53 program);
54 fprintf (stderr, "Build font information caches in [dirs]\n"
55 "(all directories in font configuration by default).\n");
56 fprintf (stderr, "\n");
57 fprintf (stderr, " -v, --verbose display status information while busy\n");
58 fprintf (stderr, " -V, --version display font config version and exit\n");
59 fprintf (stderr, " -?, --help display this help and exit\n");
60 exit (1);
61 }
62
63 int
64 main (int argc, char **argv)
65 {
66 int ret = 0;
67 FcFontSet *set;
68 int verbose = 0;
69 int i;
70 FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_LANG, 0);
71 FcFontSet *fs;
72 FcPattern *pat;
73 #if HAVE_GETOPT_LONG || HAVE_GETOPT
74 int c;
75
76 #if HAVE_GETOPT_LONG
77 while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
78 #else
79 while ((c = getopt (argc, argv, "Vv?")) != -1)
80 #endif
81 {
82 switch (c) {
83 case 'V':
84 fprintf (stderr, "fontconfig version %d.%d.%d\n",
85 FC_MAJOR, FC_MINOR, FC_REVISION);
86 exit (0);
87 case 'v':
88 verbose = 1;
89 break;
90 default:
91 usage (argv[0]);
92 }
93 }
94 i = optind;
95 #else
96 i = 1;
97 #endif
98
99 if (!FcInit ())
100 {
101 fprintf (stderr, "Can't init font config library\n");
102 return 1;
103 }
104 if (argv[i])
105 pat = FcNameParse (argv[i]);
106 else
107 pat = FcPatternCreate ();
108
109 fs = FcFontList (0, pat, os);
110 if (pat)
111 FcPatternDestroy (pat);
112
113 if (fs)
114 {
115 int j;
116
117 for (j = 0; j < fs->nfont; j++)
118 {
119 FcChar8 *font;
120
121 font = FcNameUnparse (fs->fonts[j]);
122 printf ("%s\n", font);
123 free (font);
124 }
125 FcFontSetDestroy (fs);
126 }
127 return 0;
128 }