Remove unused upgrade script
[platform/upstream/fontconfig.git] / fc-scan / fc-scan.c
1 /*
2  * fontconfig/fc-scan/fc-scan.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
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 <fontconfig/fcfreetype.h>
38 #include <stdio.h>
39 #include <unistd.h>
40 #include <stdlib.h>
41 #include <string.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>
62 static const struct option longopts[] = {
63     {"brief", 0, 0, 'b'},
64     {"format", 1, 0, 'f'},
65     {"version", 0, 0, 'V'},
66     {"help", 0, 0, 'h'},
67     {NULL,0,0,0},
68 };
69 #else
70 #if HAVE_GETOPT
71 extern char *optarg;
72 extern int optind, opterr, optopt;
73 #endif
74 #endif
75
76 static void
77 usage (char *program, int error)
78 {
79     FILE *file = error ? stderr : stdout;
80 #if HAVE_GETOPT_LONG
81     fprintf (file, _("usage: %s [-bVh] [-f FORMAT] [--brief] [--format FORMAT] [--version] [--help] font-file...\n"),
82              program);
83 #else
84     fprintf (file, _("usage: %s [-bVh] [-f FORMAT] font-file...\n"),
85              program);
86 #endif
87     fprintf (file, _("Scan font files and directories, and print resulting pattern(s)\n"));
88     fprintf (file, "\n");
89 #if HAVE_GETOPT_LONG
90     fprintf (file, _("  -b, --brief          display font pattern briefly\n"));
91     fprintf (file, _("  -f, --format=FORMAT  use the given output format\n"));
92     fprintf (file, _("  -V, --version        display font config version and exit\n"));
93     fprintf (file, _("  -h, --help           display this help and exit\n"));
94 #else
95     fprintf (file, _("  -b         (brief)         display font pattern briefly\n"));
96     fprintf (file, _("  -f FORMAT  (format)        use the given output format\n"));
97     fprintf (file, _("  -V         (version)       display font config version and exit\n"));
98     fprintf (file, _("  -h         (help)          display this help and exit\n"));
99 #endif
100     exit (error);
101 }
102
103 int
104 main (int argc, char **argv)
105 {
106     int         brief = 0;
107     FcChar8     *format = NULL;
108     int         i;
109     FcFontSet   *fs;
110 #if HAVE_GETOPT_LONG || HAVE_GETOPT
111     int         c;
112
113 #if HAVE_GETOPT_LONG
114     while ((c = getopt_long (argc, argv, "bf:Vh", longopts, NULL)) != -1)
115 #else
116     while ((c = getopt (argc, argv, "bf:Vh")) != -1)
117 #endif
118     {
119         switch (c) {
120         case 'b':
121             brief = 1;
122             break;
123         case 'f':
124             format = (FcChar8 *) strdup (optarg);
125             break;
126         case 'V':
127             fprintf (stderr, "fontconfig version %d.%d.%d\n",
128                      FC_MAJOR, FC_MINOR, FC_REVISION);
129             exit (0);
130         case 'h':
131             usage (argv[0], 0);
132         default:
133             usage (argv[0], 1);
134         }
135     }
136     i = optind;
137 #else
138     i = 1;
139 #endif
140
141     if (i == argc)
142         usage (argv[0], 1);
143
144     fs = FcFontSetCreate ();
145
146     for (; i < argc; i++)
147     {
148         const FcChar8 *file = (FcChar8*) argv[i];
149
150         if (!FcFileIsDir (file))
151             FcFileScan (fs, NULL, NULL, NULL, file, FcTrue);
152         else
153         {
154             FcStrSet *dirs = FcStrSetCreate ();
155             FcStrList *strlist = FcStrListCreate (dirs);
156             do
157             {
158                 FcDirScan (fs, dirs, NULL, NULL, file, FcTrue);
159             }
160             while ((file = FcStrListNext (strlist)));
161             FcStrListDone (strlist);
162             FcStrSetDestroy (dirs);
163         }
164     }
165
166     for (i = 0; i < fs->nfont; i++)
167     {
168         FcPattern *pat = fs->fonts[i];
169
170         if (brief)
171         {
172             FcPatternDel (pat, FC_CHARSET);
173             FcPatternDel (pat, FC_LANG);
174         }
175
176         if (format)
177         {
178             FcChar8 *s;
179
180             s = FcPatternFormat (pat, format);
181             if (s)
182             {
183                 printf ("%s", s);
184                 FcStrFree (s);
185             }
186         }
187         else
188         {
189             FcPatternPrint (pat);
190         }
191     }
192
193     FcFontSetDestroy (fs);
194
195     FcFini ();
196     return i > 0 ? 0 : 1;
197 }