]> git.wh0rd.org Git - fontconfig.git/blob - fc-cache/fc-cache.c
Warning fixes
[fontconfig.git] / fc-cache / fc-cache.c
1 /*
2  * $XFree86: xc/lib/fontconfig/fc-cache/fc-cache.c,v 1.2 2002/02/15 07:36:14 keithp Exp $
3  *
4  * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of Keith Packard not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  Keith Packard makes no
13  * representations about the suitability of this software for any purpose.  It
14  * is provided "as is" without express or implied warranty.
15  *
16  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24
25 #include <fontconfig/fontconfig.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #else
31 #ifdef linux
32 #define HAVE_GETOPT_LONG 1
33 #endif
34 #define HAVE_GETOPT 1
35 #endif
36
37 #ifndef HAVE_GETOPT
38 #define HAVE_GETOPT 0
39 #endif
40 #ifndef HAVE_GETOPT_LONG
41 #define HAVE_GETOPT_LONG 0
42 #endif
43
44 #if HAVE_GETOPT_LONG
45 #undef  _GNU_SOURCE
46 #define _GNU_SOURCE
47 #include <getopt.h>
48 const struct option longopts[] = {
49     {"version", 0, 0, 'V'},
50     {"verbose", 0, 0, 'v'},
51     {"help", 0, 0, '?'},
52     {NULL,0,0,0},
53 };
54 #else
55 #if HAVE_GETOPT
56 extern char *optarg;
57 extern int optind, opterr, optopt;
58 #endif
59 #endif
60
61 static void
62 usage (char *program)
63 {
64     fprintf (stderr, "usage: %s [-vV?] [--verbose] [--version] [--help] [dirs]\n",
65              program);
66     fprintf (stderr, "Build font information caches in [dirs]\n"
67              "(all directories in font configuration by default).\n");
68     fprintf (stderr, "\n");
69     fprintf (stderr, "  -v, --verbose        display status information while busy\n");
70     fprintf (stderr, "  -V, --version        display font config version and exit\n");
71     fprintf (stderr, "  -?, --help           display this help and exit\n");
72     exit (1);
73 }
74
75 int
76 main (int argc, char **argv)
77 {
78     int         ret = 0;
79     FcFontSet   *set;
80     FcChar8     **dirs;
81     int         verbose = 0;
82     int         i;
83 #if HAVE_GETOPT_LONG || HAVE_GETOPT
84     int         c;
85
86 #if HAVE_GETOPT_LONG
87     while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
88 #else
89     while ((c = getopt (argc, argv, "Vv?")) != -1)
90 #endif
91     {
92         switch (c) {
93         case 'V':
94             fprintf (stderr, "fontconfig version %d.%d.%d\n", 
95                      FC_MAJOR, FC_MINOR, FC_REVISION);
96             exit (0);
97         case 'v':
98             verbose = 1;
99             break;
100         default:
101             usage (argv[0]);
102         }
103     }
104     i = optind;
105 #else
106     i = 1;
107 #endif
108
109     if (!FcInitConfig ())
110     {
111         fprintf (stderr, "Can't init font config library\n");
112         return 1;
113     }
114     if (argv[i])
115         dirs = (FcChar8 **) (argv+i);
116     else
117         dirs = FcConfigGetDirs (0);
118     /*
119      * Now scan all of the directories into separate databases
120      * and write out the results
121      */
122     while (dirs && *dirs)
123     {
124         if (verbose)
125             printf ("%s: Scanning directory \"%s\"\n", argv[0], *dirs);
126         set = FcFontSetCreate ();
127         if (!set)
128         {
129             fprintf (stderr, "Out of memory in \"%s\"\n", *dirs);
130             ret++;
131         }
132         else
133         {
134             if (!FcDirScan (set, 0, FcConfigGetBlanks (0), *dirs, FcTrue))
135             {
136                 fprintf (stderr, "Can't scan directory \"%s\"\n", *dirs);
137                 ret++;
138             }
139             else
140             {
141                 if (verbose)
142                     printf ("%s: Saving %d font names for \"%s\"\n", 
143                             argv[0], set->nfont, *dirs);
144                 if (!FcDirSave (set, *dirs))
145                 {
146                     fprintf (stderr, "Can't save cache in \"%s\"\n", *dirs);
147                     ret++;
148                 }
149             }
150             FcFontSetDestroy (set);
151         }
152         ++dirs;
153     }
154     if (verbose)
155         printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded");
156     return ret;
157 }