]> git.wh0rd.org - fontconfig.git/blame - src/fcinit.c
Eliminate .so PLT entries for local symbols. (thanks to Arjan van de Ven)
[fontconfig.git] / src / fcinit.c
CommitLineData
24330d27 1/*
4bd4418a 2 * $RCSId: xc/lib/fontconfig/src/fcinit.c,v 1.7 2002/08/22 07:36:44 keithp Exp $
24330d27 3 *
46b51147 4 * Copyright © 2001 Keith Packard
24330d27
KP
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
24330d27 25#include "fcint.h"
f045376c 26#include <stdlib.h>
24330d27 27
179c3995 28static FcConfig *
24330d27
KP
29FcInitFallbackConfig (void)
30{
31 FcConfig *config;
32
33 config = FcConfigCreate ();
34 if (!config)
35 goto bail0;
446bb9c9 36 if (!FcConfigAddDir (config, (FcChar8 *) FC_DEFAULT_FONTS))
24330d27 37 goto bail1;
7410e40b
PL
38 if (!FcConfigAddCacheDir (config, (FcChar8 *) FC_CACHEDIR))
39 goto bail1;
179c3995 40 return config;
24330d27
KP
41
42bail1:
43 FcConfigDestroy (config);
44bail0:
179c3995 45 return 0;
24330d27
KP
46}
47
48db40f6
KP
48int
49FcGetVersion (void)
50{
51 return FC_VERSION;
52}
53
24330d27 54/*
179c3995 55 * Load the configuration files
24330d27 56 */
179c3995
KP
57FcConfig *
58FcInitLoadConfig (void)
24330d27 59{
179c3995 60 FcConfig *config;
24330d27 61
b97a34b5 62 FcInitDebug ();
24330d27
KP
63 config = FcConfigCreate ();
64 if (!config)
65 return FcFalse;
66
67 if (!FcConfigParseAndLoad (config, 0, FcTrue))
68 {
69 FcConfigDestroy (config);
70 return FcInitFallbackConfig ();
71 }
179c3995
KP
72
73 return config;
74}
75
76/*
77 * Load the configuration files and scan for available fonts
78 */
79FcConfig *
80FcInitLoadConfigAndFonts (void)
81{
82 FcConfig *config = FcInitLoadConfig ();
83
b97a34b5 84 FcInitDebug ();
179c3995
KP
85 if (!config)
86 return 0;
87 if (!FcConfigBuildFonts (config))
88 {
89 FcConfigDestroy (config);
90 return 0;
91 }
92 return config;
93}
94
95/*
96 * Initialize the default library configuration
97 */
98FcBool
99FcInit (void)
100{
101 FcConfig *config;
102
103 if (_fcConfig)
104 return FcTrue;
105 config = FcInitLoadConfigAndFonts ();
106 if (!config)
107 return FcTrue;
108 FcConfigSetCurrent (config);
d8d73958
KP
109 if (FcDebug() & FC_DBG_MEMORY)
110 FcMemReport ();
179c3995
KP
111 return FcTrue;
112}
113
34cd0514
CW
114/*
115 * Free all library-allocated data structures.
116 */
117void
118FcFini (void)
119{
120 if (_fcConfig)
121 FcConfigDestroy (_fcConfig);
122
e1b9d091 123 FcPatternFini ();
8fe2104a 124 FcCacheFini ();
34cd0514
CW
125}
126
179c3995
KP
127/*
128 * Reread the configuration and available font lists
129 */
130FcBool
131FcInitReinitialize (void)
132{
133 FcConfig *config;
134
135 config = FcInitLoadConfigAndFonts ();
136 if (!config)
137 return FcFalse;
24330d27
KP
138 FcConfigSetCurrent (config);
139 return FcTrue;
140}
141
142FcBool
179c3995 143FcInitBringUptoDate (void)
24330d27 144{
179c3995
KP
145 FcConfig *config = FcConfigGetCurrent ();
146 time_t now;
147
148 /*
149 * rescanInterval == 0 disables automatic up to date
150 */
151 if (config->rescanInterval == 0)
152 return FcTrue;
153 /*
154 * Check no more often than rescanInterval seconds
155 */
156 now = time (0);
157 if (config->rescanTime + config->rescanInterval - now > 0)
158 return FcTrue;
159 /*
160 * If up to date, don't reload configuration
161 */
162 if (FcConfigUptoDate (0))
163 return FcTrue;
164 return FcInitReinitialize ();
24330d27
KP
165}
166
167static struct {
67accef4 168 char name[16];
24330d27
KP
169 int alloc_count;
170 int alloc_mem;
171 int free_count;
172 int free_mem;
173} FcInUse[FC_MEM_NUM] = {
9dac3c59
KP
174 { "charset" },
175 { "charleaf" },
176 { "fontset" },
177 { "fontptr" },
178 { "objectset" },
179 { "objectptr" },
180 { "matrix" },
181 { "pattern" },
182 { "patelt" },
183 { "vallist" },
184 { "substate" },
185 { "string" },
186 { "listbuck" },
187 { "strset" },
188 { "strlist" },
189 { "config" },
190 { "langset" },
191 { "atomic" },
192 { "blanks" },
193 { "cache" },
194 { "strbuf" },
195 { "subst" },
196 { "objecttype" },
197 { "constant" },
198 { "test" },
199 { "expr" },
200 { "vstack" },
201 { "attr" },
202 { "pstack" },
1c52c0f0 203 { "staticstr" },
24330d27
KP
204};
205
206static int FcAllocCount, FcAllocMem;
207static int FcFreeCount, FcFreeMem;
208
209static int FcMemNotice = 1*1024*1024;
210
211static int FcAllocNotify, FcFreeNotify;
212
213void
214FcMemReport (void)
215{
216 int i;
217 printf ("Fc Memory Usage:\n");
218 printf ("\t Which Alloc Free Active\n");
219 printf ("\t count bytes count bytes count bytes\n");
220 for (i = 0; i < FC_MEM_NUM; i++)
1c52c0f0 221 printf ("%16.16s%8d%8d%8d%8d%8d%8d\n",
24330d27
KP
222 FcInUse[i].name,
223 FcInUse[i].alloc_count, FcInUse[i].alloc_mem,
224 FcInUse[i].free_count, FcInUse[i].free_mem,
225 FcInUse[i].alloc_count - FcInUse[i].free_count,
226 FcInUse[i].alloc_mem - FcInUse[i].free_mem);
1c52c0f0 227 printf ("%16.16s%8d%8d%8d%8d%8d%8d\n",
24330d27
KP
228 "Total",
229 FcAllocCount, FcAllocMem,
230 FcFreeCount, FcFreeMem,
231 FcAllocCount - FcFreeCount,
232 FcAllocMem - FcFreeMem);
233 FcAllocNotify = 0;
234 FcFreeNotify = 0;
235}
236
237void
238FcMemAlloc (int kind, int size)
239{
240 if (FcDebug() & FC_DBG_MEMORY)
241 {
242 FcInUse[kind].alloc_count++;
243 FcInUse[kind].alloc_mem += size;
244 FcAllocCount++;
245 FcAllocMem += size;
246 FcAllocNotify += size;
247 if (FcAllocNotify > FcMemNotice)
248 FcMemReport ();
249 }
250}
251
252void
253FcMemFree (int kind, int size)
254{
255 if (FcDebug() & FC_DBG_MEMORY)
256 {
257 FcInUse[kind].free_count++;
258 FcInUse[kind].free_mem += size;
259 FcFreeCount++;
260 FcFreeMem += size;
261 FcFreeNotify += size;
262 if (FcFreeNotify > FcMemNotice)
263 FcMemReport ();
264 }
265}
23816bf9
KP
266#define __fcinit__
267#include "fcaliastail.h"
268#undef __fcinit__