]> git.wh0rd.org - fontconfig.git/blob - src/fcint.h
Add new FcAtomic datatype for config file locking
[fontconfig.git] / src / fcint.h
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.4 2002/02/19 08:33:23 keithp Exp $
3 *
4 * Copyright © 2000 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 #ifndef _FCINT_H_
26 #define _FCINT_H_
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fontconfig/fontconfig.h>
37 #include <fontconfig/fcprivate.h>
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 typedef struct _FcMatcher {
43 char *object;
44 double (*compare) (char *object, FcValue value1, FcValue value2);
45 } FcMatcher;
46
47 typedef struct _FcSymbolic {
48 const char *name;
49 int value;
50 } FcSymbolic;
51
52 #ifndef FC_CONFIG_PATH
53 #define FC_CONFIG_PATH "fonts.conf"
54 #endif
55
56 #define FC_DBG_MATCH 1
57 #define FC_DBG_MATCHV 2
58 #define FC_DBG_EDIT 4
59 #define FC_DBG_FONTSET 8
60 #define FC_DBG_CACHE 16
61 #define FC_DBG_CACHEV 32
62 #define FC_DBG_PARSE 64
63 #define FC_DBG_SCAN 128
64 #define FC_DBG_MEMORY 512
65
66 #define FC_MEM_CHARSET 0
67 #define FC_MEM_CHARNODE 1
68 #define FC_MEM_FONTSET 2
69 #define FC_MEM_FONTPTR 3
70 #define FC_MEM_OBJECTSET 4
71 #define FC_MEM_OBJECTPTR 5
72 #define FC_MEM_MATRIX 6
73 #define FC_MEM_PATTERN 7
74 #define FC_MEM_PATELT 8
75 #define FC_MEM_VALLIST 9
76 #define FC_MEM_SUBSTATE 10
77 #define FC_MEM_STRING 11
78 #define FC_MEM_LISTBUCK 12
79 #define FC_MEM_NUM 13
80
81 typedef struct _FcValueList {
82 struct _FcValueList *next;
83 FcValue value;
84 } FcValueList;
85
86 typedef struct _FcPatternElt {
87 const char *object;
88 FcValueList *values;
89 } FcPatternElt;
90
91 struct _FcPattern {
92 int num;
93 int size;
94 FcPatternElt *elts;
95 };
96
97 typedef enum _FcOp {
98 FcOpInteger, FcOpDouble, FcOpString, FcOpMatrix, FcOpBool, FcOpCharSet,
99 FcOpNil,
100 FcOpField, FcOpConst,
101 FcOpAssign, FcOpAssignReplace,
102 FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
103 FcOpQuest,
104 FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual, FcOpContains,
105 FcOpLess, FcOpLessEqual, FcOpMore, FcOpMoreEqual,
106 FcOpPlus, FcOpMinus, FcOpTimes, FcOpDivide,
107 FcOpNot, FcOpComma, FcOpInvalid
108 } FcOp;
109
110 typedef struct _FcExpr {
111 FcOp op;
112 union {
113 int ival;
114 double dval;
115 FcChar8 *sval;
116 FcMatrix *mval;
117 FcBool bval;
118 FcCharSet *cval;
119 char *field;
120 FcChar8 *constant;
121 struct {
122 struct _FcExpr *left, *right;
123 } tree;
124 } u;
125 } FcExpr;
126
127 typedef enum _FcQual {
128 FcQualAny, FcQualAll
129 } FcQual;
130
131 typedef struct _FcTest {
132 struct _FcTest *next;
133 FcQual qual;
134 const char *field;
135 FcOp op;
136 FcExpr *expr;
137 } FcTest;
138
139 typedef struct _FcEdit {
140 struct _FcEdit *next;
141 const char *field;
142 FcOp op;
143 FcExpr *expr;
144 } FcEdit;
145
146 typedef struct _FcSubst {
147 struct _FcSubst *next;
148 FcTest *test;
149 FcEdit *edit;
150 } FcSubst;
151
152 typedef struct _FcCharLeaf FcCharLeaf;
153 typedef struct _FcCharBranch FcCharBranch;
154 typedef union _FcCharNode FcCharNode;
155
156 struct _FcCharLeaf {
157 FcChar32 map[256/32];
158 };
159
160 union _FcCharNode {
161 FcCharBranch *branch;
162 FcCharLeaf *leaf;
163 };
164
165 struct _FcCharBranch {
166 FcCharNode nodes[256];
167 };
168
169 struct _FcCharSet {
170 int levels;
171 int ref; /* reference count */
172 FcBool constant; /* shared constant */
173 FcCharNode node;
174 };
175
176 typedef struct _FcStrBuf {
177 FcChar8 *buf;
178 FcBool allocated;
179 FcBool failed;
180 int len;
181 int size;
182 } FcStrBuf;
183
184 typedef struct _FcFileCacheEnt {
185 struct _FcFileCacheEnt *next;
186 unsigned int hash;
187 FcChar8 *file;
188 int id;
189 time_t time;
190 FcChar8 *name;
191 FcBool referenced;
192 } FcFileCacheEnt;
193
194 #define FC_FILE_CACHE_HASH_SIZE 509
195
196 struct _FcFileCache {
197 FcFileCacheEnt *ents[FC_FILE_CACHE_HASH_SIZE];
198 FcBool updated;
199 int entries;
200 int referenced;
201 };
202
203 struct _FcAtomic {
204 FcChar8 *file; /* original file name */
205 FcChar8 *new; /* temp file name -- write data here */
206 FcChar8 *lck; /* lockfile name (used for locking) */
207 FcChar8 *tmp; /* tmpfile name (used for locking) */
208 };
209
210 struct _FcBlanks {
211 int nblank;
212 int sblank;
213 FcChar32 *blanks;
214 };
215
216 struct _FcConfig {
217 /*
218 * File names loaded from the configuration -- saved here as the
219 * cache file must be consulted before the directories are scanned,
220 * and those directives may occur in any order
221 */
222 FcChar8 **dirs; /* directories containing fonts */
223 FcChar8 *cache; /* name of per-user cache file */
224 /*
225 * Set of allowed blank chars -- used to
226 * trim fonts of bogus glyphs
227 */
228 FcBlanks *blanks;
229 /*
230 * Names of all of the configuration files used
231 * to create this configuration
232 */
233 FcChar8 **configFiles; /* config files loaded */
234 /*
235 * Substitution instructions for patterns and fonts;
236 * maxObjects is used to allocate appropriate intermediate storage
237 * while performing a whole set of substitutions
238 */
239 FcSubst *substPattern; /* substitutions for patterns */
240 FcSubst *substFont; /* substitutions for fonts */
241 int maxObjects; /* maximum number of tests in all substs */
242 /*
243 * The set of fonts loaded from the listed directories; the
244 * order within the set does not determine the font selection,
245 * except in the case of identical matches in which case earlier fonts
246 * match preferrentially
247 */
248 FcFontSet *fonts[FcSetApplication + 1];
249 };
250
251 extern FcConfig *_fcConfig;
252
253 /* fcblanks.c */
254
255 /* fccache.c */
256
257 FcFileCache *
258 FcFileCacheCreate (void);
259
260 FcChar8 *
261 FcFileCacheFind (FcFileCache *cache,
262 const FcChar8 *file,
263 int id,
264 int *count);
265
266 void
267 FcFileCacheDestroy (FcFileCache *cache);
268
269 void
270 FcFileCacheLoad (FcFileCache *cache,
271 const FcChar8 *cache_file);
272
273 FcBool
274 FcFileCacheUpdate (FcFileCache *cache,
275 const FcChar8 *file,
276 int id,
277 const FcChar8 *name);
278
279 FcBool
280 FcFileCacheSave (FcFileCache *cache,
281 const FcChar8 *cache_file);
282
283 FcBool
284 FcFileCacheReadDir (FcFontSet *set, const FcChar8 *cache_file);
285
286 FcBool
287 FcFileCacheWriteDir (FcFontSet *set, const FcChar8 *cache_file);
288
289 /* fccfg.c */
290
291 FcBool
292 FcConfigAddDir (FcConfig *config,
293 const FcChar8 *d);
294
295 FcBool
296 FcConfigAddConfigFile (FcConfig *config,
297 const FcChar8 *f);
298
299 FcBool
300 FcConfigSetCache (FcConfig *config,
301 const FcChar8 *c);
302
303 FcBool
304 FcConfigAddBlank (FcConfig *config,
305 FcChar32 blank);
306
307 FcBool
308 FcConfigAddEdit (FcConfig *config,
309 FcTest *test,
310 FcEdit *edit,
311 FcMatchKind kind);
312
313 void
314 FcConfigSetFonts (FcConfig *config,
315 FcFontSet *fonts,
316 FcSetName set);
317
318 FcBool
319 FcConfigCompareValue (const FcValue m,
320 FcOp op,
321 const FcValue v);
322
323 /* fccharset.c */
324 FcBool
325 FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
326
327 FcCharSet *
328 FcNameParseCharSet (FcChar8 *string);
329
330 /* fcdbg.c */
331 void
332 FcValuePrint (FcValue v);
333
334 void
335 FcValueListPrint (FcValueList *l);
336
337 void
338 FcOpPrint (FcOp op);
339
340 void
341 FcTestPrint (FcTest *test);
342
343 void
344 FcExprPrint (FcExpr *expr);
345
346 void
347 FcEditPrint (FcEdit *edit);
348
349 void
350 FcSubstPrint (FcSubst *subst);
351
352 void
353 FcFontSetPrint (FcFontSet *s);
354
355 int
356 FcDebug (void);
357
358 /* fcdir.c */
359
360 /* fcfont.c */
361 int
362 FcFontDebug (void);
363
364 /* fcfs.c */
365 /* fcgram.y */
366 int
367 FcConfigparse (void);
368
369 int
370 FcConfigwrap (void);
371
372 void
373 FcConfigerror (char *fmt, ...);
374
375 char *
376 FcConfigSaveField (const char *field);
377
378 FcTest *
379 FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr);
380
381 void
382 FcTestDestroy (FcTest *test);
383
384 FcExpr *
385 FcExprCreateInteger (int i);
386
387 FcExpr *
388 FcExprCreateDouble (double d);
389
390 FcExpr *
391 FcExprCreateString (const FcChar8 *s);
392
393 FcExpr *
394 FcExprCreateMatrix (const FcMatrix *m);
395
396 FcExpr *
397 FcExprCreateBool (FcBool b);
398
399 FcExpr *
400 FcExprCreateNil (void);
401
402 FcExpr *
403 FcExprCreateField (const char *field);
404
405 FcExpr *
406 FcExprCreateConst (const FcChar8 *constant);
407
408 FcExpr *
409 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right);
410
411 void
412 FcExprDestroy (FcExpr *e);
413
414 FcEdit *
415 FcEditCreate (const char *field, FcOp op, FcExpr *expr);
416
417 void
418 FcEditDestroy (FcEdit *e);
419
420 /* fcinit.c */
421
422 void
423 FcMemReport (void);
424
425 void
426 FcMemAlloc (int kind, int size);
427
428 void
429 FcMemFree (int kind, int size);
430
431 /* fclist.c */
432
433 /* fcmatch.c */
434
435 /* fcname.c */
436
437 FcBool
438 FcNameBool (FcChar8 *v, FcBool *result);
439
440 /* fcpat.c */
441 void
442 FcValueListDestroy (FcValueList *l);
443
444 FcPatternElt *
445 FcPatternFind (FcPattern *p, const char *object, FcBool insert);
446
447 /* fcrender.c */
448
449 /* fcmatrix.c */
450 void
451 FcMatrixFree (FcMatrix *mat);
452
453 /* fcstr.c */
454 FcChar8 *
455 FcStrPlus (const FcChar8 *s1, const FcChar8 *s2);
456
457 void
458 FcStrFree (FcChar8 *s);
459
460 void
461 FcStrBufInit (FcStrBuf *buf, FcChar8 *init, int size);
462
463 void
464 FcStrBufDestroy (FcStrBuf *buf);
465
466 FcChar8 *
467 FcStrBufDone (FcStrBuf *buf);
468
469 FcBool
470 FcStrBufChar (FcStrBuf *buf, FcChar8 c);
471
472 FcBool
473 FcStrBufString (FcStrBuf *buf, const FcChar8 *s);
474
475 FcBool
476 FcStrBufData (FcStrBuf *buf, const FcChar8 *s, int len);
477
478 #endif /* _FC_INT_H_ */