Debian Codegraph @

subprojects/fontconfig/fc-conflist/fc-conflist.c

raw
1 /*
2 * fontconfig/fc-conflist/fc-conflist.c
3 *
4 * Copyright © 2003 Keith Packard
5 * Copyright © 2014 Red Hat, Inc.
6 * Red Hat Author(s): Akira TAGOH
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 the author(s) not be used in
13 * advertising or publicity pertaining to distribution of the software without
14 * specific, written prior permission. The authors make 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 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE AUTHOR(S) 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
38 #include <stdio.h>
39 #ifdef HAVE_UNISTD_H
40 # include <unistd.h>
41 #endif
42 #include <locale.h>
43 #include <stdlib.h>
44 #include <string.h>
45
46 #ifdef ENABLE_NLS
47 # include <libintl.h>
48 # define _(x) (dgettext (GETTEXT_PACKAGE, x))
49 #else
50 # define dgettext(d, s) (s)
51 # define _(x) (x)
52 #endif
53
54 #ifndef HAVE_GETOPT
55 # define HAVE_GETOPT 0
56 #endif
57 #ifndef HAVE_GETOPT_LONG
58 # define HAVE_GETOPT_LONG 0
59 #endif
60
61 #if HAVE_GETOPT_LONG
62 # undef _GNU_SOURCE
63 # define _GNU_SOURCE
64 # include <getopt.h>
65 static const struct option longopts[] = {
66 { "version", 0, 0, 'V' },
67 { "help", 0, 0, 'h' },
68 { NULL, 0, 0, 0 },
69 };
70 #else
71 # if HAVE_GETOPT
72 extern char *optarg;
73 extern int optind, opterr, optopt;
74 # endif
75 #endif
76
77 static void
78 usage (char *program, int error)
79 {
80 FILE *file = error ? stderr : stdout;
81 #if HAVE_GETOPT_LONG
82 fprintf (file, _("usage: %s [-Vh] [--version] [--help]\n"),
83 program);
84 #else
85 fprintf (file, _("usage: %s [-Vh]\n"),
86 program);
87 #endif
88 fprintf (file, _("Show the ruleset files information on the system\n"));
89 fprintf (file, "\n");
90 #if HAVE_GETOPT_LONG
91 fprintf (file, _(" -V, --version display font config version and exit\n"));
92 fprintf (file, _(" -h, --help display this help and exit\n"));
93 #else
94 fprintf (file, _(" -V (version) display font config version and exit\n"));
95 fprintf (file, _(" -h (help) display this help and exit\n"));
96 #endif
97 exit (error);
98 }
99
100 int
101 main (int argc, char **argv)
102 {
103 FcConfig *config;
104 FcConfigFileInfoIter iter;
105
106 #if HAVE_GETOPT_LONG || HAVE_GETOPT
107 int c;
108
109 setlocale (LC_ALL, "");
110 # if HAVE_GETOPT_LONG
111 while ((c = getopt_long (argc, argv, "Vh", longopts, NULL)) != -1)
112 # else
113 while ((c = getopt (argc, argv, "Vh")) != -1)
114 # endif
115 {
116 switch (c) {
117 case 'V':
118 fprintf (stderr, "fontconfig version %d.%d.%d\n",
119 FC_MAJOR, FC_MINOR, FC_REVISION);
120 exit (0);
121 case 'h':
122 usage (argv[0], 0);
123 default:
124 usage (argv[0], 1);
125 }
126 }
127 #endif
128
129 config = FcConfigGetCurrent();
130 FcConfigFileInfoIterInit (config, &iter);
131 do {
132 FcChar8 *name, *desc;
133 FcBool enabled;
134
135 if (FcConfigFileInfoIterGet (config, &iter, &name, &desc, &enabled)) {
136 printf ("%c %s: %s\n", enabled ? '+' : '-', name, desc);
137 FcStrFree (name);
138 FcStrFree (desc);
139 }
140 } while (FcConfigFileInfoIterNext (config, &iter));
141
142 FcFini();
143
144 return 0;
145 }