fc-conflist.c revision a4e54154
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#include <stdio.h> 38#ifdef HAVE_UNISTD_H 39#include <unistd.h> 40#endif 41#include <stdlib.h> 42#include <string.h> 43#include <locale.h> 44 45#ifdef ENABLE_NLS 46#include <libintl.h> 47#define _(x) (dgettext(GETTEXT_PACKAGE, x)) 48#else 49#define dgettext(d, s) (s) 50#define _(x) (x) 51#endif 52 53#ifndef HAVE_GETOPT 54#define HAVE_GETOPT 0 55#endif 56#ifndef HAVE_GETOPT_LONG 57#define HAVE_GETOPT_LONG 0 58#endif 59 60#if HAVE_GETOPT_LONG 61#undef _GNU_SOURCE 62#define _GNU_SOURCE 63#include <getopt.h> 64static const struct option longopts[] = { 65 {"version", 0, 0, 'V'}, 66 {"help", 0, 0, 'h'}, 67 {NULL,0,0,0}, 68}; 69#else 70#if HAVE_GETOPT 71extern char *optarg; 72extern int optind, opterr, optopt; 73#endif 74#endif 75 76static void 77usage (char *program, int error) 78{ 79 FILE *file = error ? stderr : stdout; 80#if HAVE_GETOPT_LONG 81 fprintf (file, _("usage: %s [-Vh] [--version] [--help]\n"), 82 program); 83#else 84 fprintf (file, _("usage: %s [-Vh]\n"), 85 program); 86#endif 87 fprintf (file, _("Show the ruleset files information on the system\n")); 88 fprintf (file, "\n"); 89#if HAVE_GETOPT_LONG 90 fprintf (file, _(" -V, --version display font config version and exit\n")); 91 fprintf (file, _(" -h, --help display this help and exit\n")); 92#else 93 fprintf (file, _(" -V (version) display font config version and exit\n")); 94 fprintf (file, _(" -h (help) display this help and exit\n")); 95#endif 96 exit (error); 97} 98 99int 100main (int argc, char **argv) 101{ 102 FcConfig *config; 103 FcConfigFileInfoIter iter; 104 105#if HAVE_GETOPT_LONG || HAVE_GETOPT 106 int c; 107 108 setlocale (LC_ALL, ""); 109#if HAVE_GETOPT_LONG 110 while ((c = getopt_long (argc, argv, "Vh", longopts, NULL)) != -1) 111#else 112 while ((c = getopt (argc, argv, "Vh")) != -1) 113#endif 114 { 115 switch (c) { 116 case 'V': 117 fprintf (stderr, "fontconfig version %d.%d.%d\n", 118 FC_MAJOR, FC_MINOR, FC_REVISION); 119 exit (0); 120 case 'h': 121 usage (argv[0], 0); 122 default: 123 usage (argv[0], 1); 124 } 125 } 126#endif 127 128 config = FcConfigGetCurrent (); 129 FcConfigFileInfoIterInit (config, &iter); 130 do 131 { 132 FcChar8 *name, *desc; 133 FcBool enabled; 134 135 if (FcConfigFileInfoIterGet (config, &iter, &name, &desc, &enabled)) 136 { 137 printf ("%c %s: %s\n", enabled ? '+' : '-', name, desc); 138 FcStrFree (name); 139 FcStrFree (desc); 140 } 141 } while (FcConfigFileInfoIterNext (config, &iter)); 142 143 FcFini (); 144 145 return 0; 146} 147