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