]>
Commit | Line | Data |
---|---|---|
77c0d8bc BE |
1 | /* |
2 | * fontconfig/fc-query/fc-query.c | |
3 | * | |
4 | * Copyright © 2003 Keith Packard | |
5 | * Copyright © 2008 Red Hat, Inc. | |
6 | * Red Hat Author(s): Behdad Esfahbod | |
7 | * | |
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 Keith Packard not be used in | |
13 | * advertising or publicity pertaining to distribution of the software without | |
14 | * specific, written prior permission. Keith Packard makes no | |
15 | * representations about the suitability of this software for any purpose. It | |
16 | * is provided "as is" without express or implied warranty. | |
17 | * | |
18 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |
20 | * EVENT SHALL KEITH PACKARD 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. | |
25 | */ | |
26 | ||
27 | #ifdef HAVE_CONFIG_H | |
28 | #include <config.h> | |
29 | #else | |
30 | #ifdef linux | |
31 | #define HAVE_GETOPT_LONG 1 | |
32 | #endif | |
33 | #define HAVE_GETOPT 1 | |
34 | #endif | |
35 | ||
36 | #include <fontconfig/fontconfig.h> | |
37 | #include <fontconfig/fcfreetype.h> | |
38 | #include <stdio.h> | |
39 | #include <unistd.h> | |
40 | #include <stdlib.h> | |
41 | #include <string.h> | |
42 | ||
43 | #ifndef HAVE_GETOPT | |
44 | #define HAVE_GETOPT 0 | |
45 | #endif | |
46 | #ifndef HAVE_GETOPT_LONG | |
47 | #define HAVE_GETOPT_LONG 0 | |
48 | #endif | |
49 | ||
50 | #if HAVE_GETOPT_LONG | |
51 | #undef _GNU_SOURCE | |
52 | #define _GNU_SOURCE | |
53 | #include <getopt.h> | |
54 | static const struct option longopts[] = { | |
55 | {"index", 1, 0, 'i'}, | |
56 | {"version", 0, 0, 'V'}, | |
1439c8f2 | 57 | {"help", 0, 0, 'h'}, |
77c0d8bc BE |
58 | {NULL,0,0,0}, |
59 | }; | |
60 | #else | |
61 | #if HAVE_GETOPT | |
62 | extern char *optarg; | |
63 | extern int optind, opterr, optopt; | |
64 | #endif | |
65 | #endif | |
66 | ||
1439c8f2 BE |
67 | static void |
68 | usage (char *program, int error) | |
77c0d8bc | 69 | { |
1439c8f2 | 70 | FILE *file = error ? stderr : stdout; |
77c0d8bc | 71 | #if HAVE_GETOPT_LONG |
1439c8f2 | 72 | fprintf (file, "usage: %s [-Vh] [-i index] [--index index] [--version] [--help] font-file...\n", |
77c0d8bc BE |
73 | program); |
74 | #else | |
1439c8f2 | 75 | fprintf (file, "usage: %s [-Vh] [-i index] font-file...\n", |
77c0d8bc BE |
76 | program); |
77 | #endif | |
1439c8f2 BE |
78 | fprintf (file, "Query font files and print resulting pattern(s)\n"); |
79 | fprintf (file, "\n"); | |
77c0d8bc | 80 | #if HAVE_GETOPT_LONG |
1439c8f2 BE |
81 | fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\n"); |
82 | fprintf (file, " -V, --version display font config version and exit\n"); | |
83 | fprintf (file, " -h, --help display this help and exit\n"); | |
77c0d8bc | 84 | #else |
1439c8f2 BE |
85 | fprintf (file, " -i INDEX (index) display the INDEX face of each font file only\n"); |
86 | fprintf (file, " -a (all) display unpruned sorted list of matches\n"); | |
87 | fprintf (file, " -V (version) display font config version and exit\n"); | |
88 | fprintf (file, " -h (help) display this help and exit\n"); | |
77c0d8bc | 89 | #endif |
1439c8f2 | 90 | exit (error); |
77c0d8bc BE |
91 | } |
92 | ||
93 | int | |
94 | main (int argc, char **argv) | |
95 | { | |
96 | int index_set = 0; | |
97 | int set_index = 0; | |
98 | int err = 0; | |
99 | int i; | |
100 | FcBlanks *blanks; | |
101 | #if HAVE_GETOPT_LONG || HAVE_GETOPT | |
102 | int c; | |
103 | ||
104 | #if HAVE_GETOPT_LONG | |
1439c8f2 | 105 | while ((c = getopt_long (argc, argv, "i:sVvh", longopts, NULL)) != -1) |
77c0d8bc | 106 | #else |
1439c8f2 | 107 | while ((c = getopt (argc, argv, "i:asVvh")) != -1) |
77c0d8bc BE |
108 | #endif |
109 | { | |
110 | switch (c) { | |
111 | case 'i': | |
112 | index_set = 1; | |
113 | set_index = atoi (optarg); | |
114 | break; | |
115 | case 'V': | |
116 | fprintf (stderr, "fontconfig version %d.%d.%d\n", | |
117 | FC_MAJOR, FC_MINOR, FC_REVISION); | |
118 | exit (0); | |
1439c8f2 BE |
119 | case 'h': |
120 | usage (argv[0], 0); | |
77c0d8bc | 121 | default: |
1439c8f2 | 122 | usage (argv[0], 1); |
77c0d8bc BE |
123 | } |
124 | } | |
125 | i = optind; | |
126 | #else | |
127 | i = 1; | |
128 | #endif | |
129 | ||
130 | if (i == argc) | |
1439c8f2 | 131 | usage (argv[0], 1); |
77c0d8bc BE |
132 | |
133 | if (!FcInit ()) | |
134 | { | |
135 | fprintf (stderr, "Can't init font config library\n"); | |
136 | return 1; | |
137 | } | |
138 | ||
139 | blanks = FcConfigGetBlanks (NULL); | |
140 | ||
141 | for (; i < argc; i++) | |
142 | { | |
143 | int index; | |
144 | int count = 0; | |
145 | ||
146 | index = set_index; | |
147 | ||
148 | do { | |
149 | FcPattern *pat; | |
150 | ||
151 | pat = FcFreeTypeQuery ((FcChar8 *) argv[i], index, blanks, &count); | |
152 | if (pat) | |
153 | { | |
154 | FcPatternPrint (pat); | |
155 | FcPatternDestroy (pat); | |
156 | } | |
157 | else | |
158 | { | |
159 | fprintf (stderr, "Can't query face %d of font file %s\n", | |
160 | index, argv[i]); | |
161 | err = 1; | |
162 | } | |
163 | ||
164 | index++; | |
165 | } while (!index_set && index < count); | |
166 | } | |
167 | ||
168 | FcFini (); | |
169 | return err; | |
170 | } |