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