1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | #ifdef HAVE_CONFIG_H1 |
26 | #include <config.h> |
27 | #else |
28 | #ifdef linux |
29 | #define HAVE_GETOPT_LONG1 1 |
30 | #endif |
31 | #define HAVE_GETOPT1 1 |
32 | #endif |
33 | |
34 | #include <fontconfig/fontconfig.h> |
35 | #include <stdio.h> |
36 | #include <unistd.h> |
37 | #include <stdlib.h> |
38 | #include <string.h> |
39 | |
40 | #ifndef HAVE_GETOPT1 |
41 | #define HAVE_GETOPT1 0 |
42 | #endif |
43 | #ifndef HAVE_GETOPT_LONG1 |
44 | #define HAVE_GETOPT_LONG1 0 |
45 | #endif |
46 | |
47 | #if HAVE_GETOPT_LONG1 |
48 | #undef _GNU_SOURCE |
49 | #define _GNU_SOURCE |
50 | #include <getopt.h> |
51 | static const struct option longopts[] = { |
52 | {"config", 0, 0, 'c'}, |
53 | {"default", 0, 0, 'd'}, |
54 | {"format", 1, 0, 'f'}, |
55 | {"version", 0, 0, 'V'}, |
56 | {"help", 0, 0, 'h'}, |
57 | {NULL((void *)0),0,0,0}, |
58 | }; |
59 | #else |
60 | #if HAVE_GETOPT1 |
61 | extern char *optarg; |
62 | extern int optind, opterr, optopt; |
63 | #endif |
64 | #endif |
65 | |
66 | static void |
67 | usage (char *program, int error) |
68 | { |
69 | FILE *file = error ? stderr__stderrp : stdout__stdoutp; |
70 | #if HAVE_GETOPT_LONG1 |
71 | fprintf (file, "usage: %s [-cdVh] [-f FORMAT] [--config] [--default] [--verbose] [--format=FORMAT] [--version] [--help] [pattern] {element...}\n", |
72 | program); |
73 | #else |
74 | fprintf (file, "usage: %s [-cdVh] [-f FORMAT] [pattern] {element...}\n", |
75 | program); |
76 | #endif |
77 | fprintf (file, "List best font matching [pattern]\n"); |
78 | fprintf (file, "\n"); |
79 | #if HAVE_GETOPT_LONG1 |
80 | fprintf (file, " -c, --config perform config substitution on pattern\n"); |
81 | fprintf (file, " -d, -default perform default substitution on pattern\n"); |
82 | fprintf (file, " -f, --format=FORMAT use the given output format\n"); |
83 | fprintf (file, " -V, --version display font config version and exit\n"); |
84 | fprintf (file, " -h, --help display this help and exit\n"); |
85 | #else |
86 | fprintf (file, " -c, (config) perform config substitution on pattern\n"); |
87 | fprintf (file, " -d, (default) perform default substitution on pattern\n"); |
88 | fprintf (file, " -f FORMAT (format) use the given output format\n"); |
89 | fprintf (file, " -V (version) display font config version and exit\n"); |
90 | fprintf (file, " -h (help) display this help and exit\n"); |
91 | #endif |
92 | exit (error); |
93 | } |
94 | |
95 | int |
96 | main (int argc, char **argv) |
97 | { |
98 | int do_config = 0, do_default = 0; |
99 | FcChar8 *format = NULL((void *)0); |
100 | int i; |
101 | FcObjectSet *os = 0; |
102 | FcPattern *pat; |
103 | #if HAVE_GETOPT_LONG1 || HAVE_GETOPT1 |
104 | int c; |
105 | |
106 | #if HAVE_GETOPT_LONG1 |
107 | while ((c = getopt_long (argc, argv, "cdf:Vh", longopts, NULL((void *)0))) != -1) |
| 1 | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is false. Execution continues on line 132 | |
|
108 | #else |
109 | while ((c = getopt (argc, argv, "cdf:Vh")) != -1) |
110 | #endif |
111 | { |
112 | switch (c) { |
| 2 | | Control jumps to 'case 102:' at line 119 | |
|
113 | case 'c': |
114 | do_config = 1; |
115 | break; |
116 | case 'd': |
117 | do_default = 1; |
118 | break; |
119 | case 'f': |
120 | format = (FcChar8 *) strdup (optarg); |
| |
121 | break; |
| 4 | | Execution continues on line 107 | |
|
122 | case 'V': |
123 | fprintf (stderr__stderrp, "fontconfig version %d.%d.%d\n", |
124 | FC_MAJOR2, FC_MINOR11, FC_REVISION95); |
125 | exit (0); |
126 | case 'h': |
127 | usage (argv[0], 0); |
128 | default: |
129 | usage (argv[0], 1); |
130 | } |
131 | } |
132 | i = optind; |
133 | #else |
134 | i = 1; |
135 | #endif |
136 | |
137 | if (argv[i]) |
| |
138 | { |
139 | pat = FcNameParse ((FcChar8 *) argv[i]); |
140 | if (!pat) |
141 | { |
142 | fputs ("Unable to parse the pattern\n", stderr__stderrp); |
143 | return 1; |
144 | } |
145 | while (argv[++i]) |
146 | { |
147 | if (!os) |
148 | os = FcObjectSetCreate (); |
149 | FcObjectSetAdd (os, argv[i]); |
150 | } |
151 | } |
152 | else |
153 | pat = FcPatternCreate (); |
154 | |
155 | if (!pat) |
| |
| |
156 | return 1; |
| 9 | | Potential leak of memory pointed to by 'format' |
|
157 | |
158 | if (do_config) |
159 | FcConfigSubstitute (0, pat, FcMatchPattern); |
160 | if (do_default) |
161 | FcDefaultSubstitute (pat); |
162 | |
163 | if (os) |
164 | { |
165 | FcPattern *new; |
166 | new = FcPatternFilter (pat, os); |
167 | FcPatternDestroy (pat); |
168 | pat = new; |
169 | } |
170 | |
171 | if (format) |
172 | { |
173 | FcChar8 *s; |
174 | |
175 | s = FcPatternFormat (pat, format); |
176 | if (s) |
177 | { |
178 | printf ("%s", s); |
179 | FcStrFree (s); |
180 | } |
181 | } |
182 | else |
183 | { |
184 | FcPatternPrint (pat); |
185 | } |
186 | |
187 | FcPatternDestroy (pat); |
188 | |
189 | if (os) |
190 | FcObjectSetDestroy (os); |
191 | |
192 | FcFini (); |
193 | |
194 | return 0; |
195 | } |