]> git.wh0rd.org - fontconfig.git/blame - fc-query/fc-query.c
Cleanup copyright notices to replace "Keith Packard" with "the author(s)"
[fontconfig.git] / fc-query / fc-query.c
CommitLineData
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
5aaf466d 12 * documentation, and that the name of the author(s) not be used in
77c0d8bc 13 * advertising or publicity pertaining to distribution of the software without
5aaf466d 14 * specific, written prior permission. The authors make no
77c0d8bc
BE
15 * representations about the suitability of this software for any purpose. It
16 * is provided "as is" without express or implied warranty.
17 *
3074a73b 18 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
77c0d8bc 19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
3074a73b 20 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
77c0d8bc
BE
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>
54static const struct option longopts[] = {
55 {"index", 1, 0, 'i'},
0c93b91d 56 {"format", 1, 0, 'f'},
77c0d8bc 57 {"version", 0, 0, 'V'},
1439c8f2 58 {"help", 0, 0, 'h'},
77c0d8bc
BE
59 {NULL,0,0,0},
60};
61#else
62#if HAVE_GETOPT
63extern char *optarg;
64extern int optind, opterr, optopt;
65#endif
66#endif
67
1439c8f2
BE
68static void
69usage (char *program, int error)
77c0d8bc 70{
1439c8f2 71 FILE *file = error ? stderr : stdout;
77c0d8bc 72#if HAVE_GETOPT_LONG
0c93b91d 73 fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] [--index index] [--format FORMAT] [--version] [--help] font-file...\n",
77c0d8bc
BE
74 program);
75#else
0c93b91d 76 fprintf (file, "usage: %s [-Vh] [-i index] [-f FORMAT] font-file...\n",
77c0d8bc
BE
77 program);
78#endif
1439c8f2
BE
79 fprintf (file, "Query font files and print resulting pattern(s)\n");
80 fprintf (file, "\n");
77c0d8bc 81#if HAVE_GETOPT_LONG
1439c8f2 82 fprintf (file, " -i, --index INDEX display the INDEX face of each font file only\n");
0c93b91d 83 fprintf (file, " -f, --format=FORMAT use the given output format\n");
1439c8f2
BE
84 fprintf (file, " -V, --version display font config version and exit\n");
85 fprintf (file, " -h, --help display this help and exit\n");
77c0d8bc 86#else
1439c8f2 87 fprintf (file, " -i INDEX (index) display the INDEX face of each font file only\n");
0c93b91d 88 fprintf (file, " -f FORMAT (format) use the given output format\n");
1439c8f2
BE
89 fprintf (file, " -V (version) display font config version and exit\n");
90 fprintf (file, " -h (help) display this help and exit\n");
77c0d8bc 91#endif
1439c8f2 92 exit (error);
77c0d8bc
BE
93}
94
95int
96main (int argc, char **argv)
97{
98 int index_set = 0;
99 int set_index = 0;
0c93b91d 100 FcChar8 *format = NULL;
77c0d8bc
BE
101 int err = 0;
102 int i;
103 FcBlanks *blanks;
104#if HAVE_GETOPT_LONG || HAVE_GETOPT
105 int c;
106
107#if HAVE_GETOPT_LONG
46e405cb 108 while ((c = getopt_long (argc, argv, "i:f:Vh", longopts, NULL)) != -1)
77c0d8bc 109#else
46e405cb 110 while ((c = getopt (argc, argv, "i:f:Vh")) != -1)
77c0d8bc
BE
111#endif
112 {
113 switch (c) {
114 case 'i':
115 index_set = 1;
116 set_index = atoi (optarg);
117 break;
0c93b91d
BE
118 case 'f':
119 format = (FcChar8 *) strdup (optarg);
120 break;
77c0d8bc
BE
121 case 'V':
122 fprintf (stderr, "fontconfig version %d.%d.%d\n",
123 FC_MAJOR, FC_MINOR, FC_REVISION);
124 exit (0);
1439c8f2
BE
125 case 'h':
126 usage (argv[0], 0);
77c0d8bc 127 default:
1439c8f2 128 usage (argv[0], 1);
77c0d8bc
BE
129 }
130 }
131 i = optind;
132#else
133 i = 1;
134#endif
135
136 if (i == argc)
1439c8f2 137 usage (argv[0], 1);
77c0d8bc
BE
138
139 if (!FcInit ())
140 {
141 fprintf (stderr, "Can't init font config library\n");
142 return 1;
143 }
144
145 blanks = FcConfigGetBlanks (NULL);
146
147 for (; i < argc; i++)
148 {
149 int index;
150 int count = 0;
151
152 index = set_index;
153
154 do {
155 FcPattern *pat;
156
157 pat = FcFreeTypeQuery ((FcChar8 *) argv[i], index, blanks, &count);
158 if (pat)
159 {
0c93b91d
BE
160 if (format)
161 {
162 FcChar8 *s;
163
164 s = FcPatternFormat (pat, format);
8c31a243
BE
165 if (s)
166 {
167 printf ("%s", s);
168 free (s);
169 }
0c93b91d
BE
170 }
171 else
172 {
173 FcPatternPrint (pat);
174 }
175
77c0d8bc
BE
176 FcPatternDestroy (pat);
177 }
178 else
179 {
180 fprintf (stderr, "Can't query face %d of font file %s\n",
181 index, argv[i]);
182 err = 1;
183 }
184
185 index++;
186 } while (!index_set && index < count);
187 }
188
189 FcFini ();
190 return err;
191}