2 * fontconfig/src/fcxml.c
4 * Copyright © 2002 Keith Packard
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.
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.
32 #include <libxml/parser.h>
34 #define XML_Char xmlChar
35 #define XML_Parser xmlParserCtxtPtr
36 #define XML_ParserFree xmlFreeParserCtxt
37 #define XML_GetCurrentLineNumber xmlSAX2GetLineNumber
38 #define XML_GetErrorCode xmlCtxtGetLastError
39 #define XML_ErrorString(Error) (Error)->message
41 #else /* ENABLE_LIBXML2 */
43 #ifndef HAVE_XMLPARSE_H
44 #define HAVE_XMLPARSE_H 0
53 #endif /* ENABLE_LIBXML2 */
63 FcTestDestroy (FcTest *test)
66 FcTestDestroy (test->next);
67 FcExprDestroy (test->expr);
68 FcMemFree (FC_MEM_TEST, sizeof (FcTest));
73 FcExprCreateInteger (int i)
75 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
79 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
87 FcExprCreateDouble (double d)
89 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
93 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
101 FcExprCreateString (const FcChar8 *s)
103 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
107 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
109 e->u.sval = FcStrCopy (s);
115 FcExprCreateMatrix (const FcMatrix *m)
117 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
121 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
123 e->u.mval = FcMatrixCopy (m);
129 FcExprCreateBool (FcBool b)
131 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
135 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
143 FcExprCreateNil (void)
145 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
149 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
156 FcExprCreateField (const char *field)
158 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
162 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
164 e->u.object = FcObjectFromName (field);
170 FcExprCreateConst (const FcChar8 *constant)
172 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
176 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
178 e->u.constant = FcStrCopy (constant);
184 FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right)
186 FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
190 FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
192 e->u.tree.left = left;
193 e->u.tree.right = right;
199 FcExprDestroy (FcExpr *e)
209 FcStrFree (e->u.sval);
212 FcMatrixFree (e->u.mval);
215 FcCharSetDestroy (e->u.cval);
222 FcStrFree (e->u.constant);
225 case FcOpAssignReplace:
227 case FcOpPrependFirst:
241 case FcOpNotContains:
248 FcExprDestroy (e->u.tree.right);
255 FcExprDestroy (e->u.tree.left);
261 FcMemFree (FC_MEM_EXPR, sizeof (FcExpr));
266 FcEditDestroy (FcEdit *e)
269 FcEditDestroy (e->next);
271 FcExprDestroy (e->expr);
276 FcConfigSaveField (const char *field)
278 return (char *) FcStrCopy ((FcChar8 *) field);
281 typedef enum _FcElement {
326 FcElementNotContains,
340 static const struct {
344 { "fontconfig", FcElementFontconfig },
345 { "dir", FcElementDir },
346 { "cachedir", FcElementCacheDir },
347 { "cache", FcElementCache },
348 { "include", FcElementInclude },
349 { "config", FcElementConfig },
350 { "match", FcElementMatch },
351 { "alias", FcElementAlias },
353 { "blank", FcElementBlank },
354 { "rescan", FcElementRescan },
356 { "prefer", FcElementPrefer },
357 { "accept", FcElementAccept },
358 { "default", FcElementDefault },
359 { "family", FcElementFamily },
361 { "selectfont", FcElementSelectfont },
362 { "acceptfont", FcElementAcceptfont },
363 { "rejectfont", FcElementRejectfont },
364 { "glob", FcElementGlob },
365 { "pattern", FcElementPattern },
366 { "patelt", FcElementPatelt },
368 { "test", FcElementTest },
369 { "edit", FcElementEdit },
370 { "int", FcElementInt },
371 { "double", FcElementDouble },
372 { "string", FcElementString },
373 { "matrix", FcElementMatrix },
374 { "bool", FcElementBool },
375 { "charset", FcElementCharset },
376 { "name", FcElementName },
377 { "const", FcElementConst },
378 { "or", FcElementOr },
379 { "and", FcElementAnd },
380 { "eq", FcElementEq },
381 { "not_eq", FcElementNotEq },
382 { "less", FcElementLess },
383 { "less_eq", FcElementLessEq },
384 { "more", FcElementMore },
385 { "more_eq", FcElementMoreEq },
386 { "contains", FcElementContains },
387 { "not_contains", FcElementNotContains },
388 { "plus", FcElementPlus },
389 { "minus", FcElementMinus },
390 { "times", FcElementTimes },
391 { "divide", FcElementDivide },
392 { "not", FcElementNot },
393 { "if", FcElementIf },
394 { "floor", FcElementFloor },
395 { "ceil", FcElementCeil },
396 { "round", FcElementRound },
397 { "trunc", FcElementTrunc },
399 #define NUM_ELEMENT_MAPS (int) (sizeof fcElementMap / sizeof fcElementMap[0])
402 FcElementMap (const XML_Char *name)
406 for (i = 0; i < NUM_ELEMENT_MAPS; i++)
407 if (!strcmp ((char *) name, fcElementMap[i].name))
408 return fcElementMap[i].element;
409 return FcElementUnknown;
412 typedef struct _FcPStack {
413 struct _FcPStack *prev;
419 typedef enum _FcVStackTag {
443 typedef struct _FcVStack {
444 struct _FcVStack *prev;
445 FcPStack *pstack; /* related parse element */
465 typedef struct _FcConfigParse {
474 typedef enum _FcConfigSeverity {
475 FcSevereInfo, FcSevereWarning, FcSevereError
479 FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, const char *fmt, ...)
481 const char *s = "unknown";
484 va_start (args, fmt);
487 case FcSevereInfo: s = "info"; break;
488 case FcSevereWarning: s = "warning"; break;
489 case FcSevereError: s = "error"; break;
494 fprintf (stderr, "Fontconfig %s: \"%s\", line %d: ", s,
495 parse->name, (int)XML_GetCurrentLineNumber (parse->parser));
497 fprintf (stderr, "Fontconfig %s: line %d: ", s,
498 (int)XML_GetCurrentLineNumber (parse->parser));
499 if (severe >= FcSevereError)
500 parse->error = FcTrue;
503 fprintf (stderr, "Fontconfig %s: ", s);
504 vfprintf (stderr, fmt, args);
505 fprintf (stderr, "\n");
511 FcTypeName (FcType type)
537 FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type)
539 if (value == FcTypeInteger)
540 value = FcTypeDouble;
541 if (type == FcTypeInteger)
545 if ((value == FcTypeLangSet && type == FcTypeString) ||
546 (value == FcTypeString && type == FcTypeLangSet))
548 if (type == (FcType) -1)
550 FcConfigMessage (parse, FcSevereWarning, "saw %s, expected %s",
551 FcTypeName (value), FcTypeName (type));
556 FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
558 const FcObjectType *o;
561 /* If parsing the expression failed, some nodes may be NULL */
568 FcTypecheckValue (parse, FcTypeDouble, type);
571 FcTypecheckValue (parse, FcTypeString, type);
574 FcTypecheckValue (parse, FcTypeMatrix, type);
577 FcTypecheckValue (parse, FcTypeBool, type);
580 FcTypecheckValue (parse, FcTypeCharSet, type);
585 o = FcNameGetObjectType (FcObjectName (expr->u.object));
587 FcTypecheckValue (parse, o->type, type);
590 c = FcNameGetConstant (expr->u.constant);
593 o = FcNameGetObjectType (c->object);
595 FcTypecheckValue (parse, o->type, type);
598 FcConfigMessage (parse, FcSevereWarning,
599 "invalid constant used : %s",
603 FcTypecheckExpr (parse, expr->u.tree.left, FcTypeBool);
604 FcTypecheckExpr (parse, expr->u.tree.right->u.tree.left, type);
605 FcTypecheckExpr (parse, expr->u.tree.right->u.tree.right, type);
608 case FcOpAssignReplace:
617 case FcOpNotContains:
619 FcTypecheckValue (parse, FcTypeBool, type);
628 FcTypecheckExpr (parse, expr->u.tree.left, type);
629 FcTypecheckExpr (parse, expr->u.tree.right, type);
632 FcTypecheckValue (parse, FcTypeBool, type);
633 FcTypecheckExpr (parse, expr->u.tree.left, FcTypeBool);
639 FcTypecheckValue (parse, FcTypeDouble, type);
640 FcTypecheckExpr (parse, expr->u.tree.left, FcTypeDouble);
648 FcTestCreate (FcConfigParse *parse,
651 const FcChar8 *field,
655 FcTest *test = (FcTest *) malloc (sizeof (FcTest));
659 const FcObjectType *o;
661 FcMemAlloc (FC_MEM_TEST, sizeof (FcTest));
665 test->object = FcObjectFromName ((const char *) field);
668 o = FcNameGetObjectType (FcObjectName (test->object));
670 FcTypecheckExpr (parse, expr, o->type);
676 FcEditCreate (FcConfigParse *parse,
680 FcValueBinding binding)
682 FcEdit *e = (FcEdit *) malloc (sizeof (FcEdit));
686 const FcObjectType *o;
692 e->binding = binding;
693 o = FcNameGetObjectType (FcObjectName (e->object));
695 FcTypecheckExpr (parse, expr, o->type);
701 FcVStackPush (FcConfigParse *parse, FcVStack *vstack)
703 vstack->prev = parse->vstack;
704 vstack->pstack = parse->pstack ? parse->pstack->prev : 0;
705 parse->vstack = vstack;
709 FcVStackCreate (void)
713 new = malloc (sizeof (FcVStack));
716 FcMemAlloc (FC_MEM_VSTACK, sizeof (FcVStack));
717 new->tag = FcVStackNone;
723 FcVStackDestroy (FcVStack *vstack)
727 for (; vstack; vstack = prev)
730 switch (vstack->tag) {
736 case FcVStackConstant:
738 FcStrFree (vstack->u.string);
740 case FcVStackPattern:
741 FcPatternDestroy (vstack->u.pattern);
743 case FcVStackInteger:
747 FcMatrixFree (vstack->u.matrix);
752 FcTestDestroy (vstack->u.test);
757 case FcVStackDefault:
758 FcExprDestroy (vstack->u.expr);
761 FcEditDestroy (vstack->u.edit);
764 FcMemFree (FC_MEM_VSTACK, sizeof (FcVStack));
770 FcVStackPushString (FcConfigParse *parse, FcVStackTag tag, FcChar8 *string)
772 FcVStack *vstack = FcVStackCreate ();
775 vstack->u.string = string;
777 FcVStackPush (parse, vstack);
782 FcVStackPushInteger (FcConfigParse *parse, int integer)
784 FcVStack *vstack = FcVStackCreate ();
787 vstack->u.integer = integer;
788 vstack->tag = FcVStackInteger;
789 FcVStackPush (parse, vstack);
794 FcVStackPushDouble (FcConfigParse *parse, double _double)
796 FcVStack *vstack = FcVStackCreate ();
799 vstack->u._double = _double;
800 vstack->tag = FcVStackDouble;
801 FcVStackPush (parse, vstack);
806 FcVStackPushMatrix (FcConfigParse *parse, FcMatrix *matrix)
808 FcVStack *vstack = FcVStackCreate ();
811 matrix = FcMatrixCopy (matrix);
814 FcVStackDestroy (vstack);
817 vstack->u.matrix = matrix;
818 vstack->tag = FcVStackMatrix;
819 FcVStackPush (parse, vstack);
824 FcVStackPushBool (FcConfigParse *parse, FcBool bool_)
826 FcVStack *vstack = FcVStackCreate ();
829 vstack->u.bool_ = bool_;
830 vstack->tag = FcVStackBool;
831 FcVStackPush (parse, vstack);
836 FcVStackPushTest (FcConfigParse *parse, FcTest *test)
838 FcVStack *vstack = FcVStackCreate ();
841 vstack->u.test = test;
842 vstack->tag = FcVStackTest;
843 FcVStackPush (parse, vstack);
848 FcVStackPushExpr (FcConfigParse *parse, FcVStackTag tag, FcExpr *expr)
850 FcVStack *vstack = FcVStackCreate ();
853 vstack->u.expr = expr;
855 FcVStackPush (parse, vstack);
860 FcVStackPushEdit (FcConfigParse *parse, FcEdit *edit)
862 FcVStack *vstack = FcVStackCreate ();
865 vstack->u.edit = edit;
866 vstack->tag = FcVStackEdit;
867 FcVStackPush (parse, vstack);
872 FcVStackPushPattern (FcConfigParse *parse, FcPattern *pattern)
874 FcVStack *vstack = FcVStackCreate ();
877 vstack->u.pattern = pattern;
878 vstack->tag = FcVStackPattern;
879 FcVStackPush (parse, vstack);
884 FcVStackFetch (FcConfigParse *parse, int off)
888 for (vstack = parse->vstack; vstack && off-- > 0; vstack = vstack->prev);
893 FcVStackClear (FcConfigParse *parse)
895 while (parse->vstack && parse->vstack->pstack == parse->pstack)
897 FcVStack *vstack = parse->vstack;
898 parse->vstack = vstack->prev;
900 FcVStackDestroy (vstack);
905 FcVStackPop (FcConfigParse *parse)
907 FcVStack *vstack = parse->vstack;
909 if (!vstack || vstack->pstack != parse->pstack)
911 parse->vstack = vstack->prev;
917 FcVStackElements (FcConfigParse *parse)
920 FcVStack *vstack = parse->vstack;
921 while (vstack && vstack->pstack == parse->pstack)
924 vstack = vstack->prev;
930 FcConfigSaveAttr (const XML_Char **attr)
940 for (i = 0; attr[i]; i++)
941 slen += strlen ((char *) attr[i]) + 1;
942 new = malloc ((i + 1) * sizeof (FcChar8 *) + slen);
945 FcMemAlloc (FC_MEM_ATTR, 1); /* size is too expensive */
946 s = (FcChar8 *) (new + (i + 1));
947 for (i = 0; attr[i]; i++)
950 strcpy ((char *) s, (char *) attr[i]);
951 s += strlen ((char *) s) + 1;
958 FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
960 FcPStack *new = malloc (sizeof (FcPStack));
964 FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack));
965 new->prev = parse->pstack;
966 new->element = element;
969 new->attr = FcConfigSaveAttr (attr);
972 FcConfigMessage (parse, FcSevereError, "out of memory");
973 FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
980 FcStrBufInit (&new->str, 0, 0);
986 FcPStackPop (FcConfigParse *parse)
992 FcConfigMessage (parse, FcSevereError, "mismatching element");
995 FcVStackClear (parse);
997 parse->pstack = old->prev;
998 FcStrBufDestroy (&old->str);
1001 FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
1004 FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
1010 FcConfigInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser)
1014 parse->error = FcFalse;
1016 parse->config = config;
1017 parse->parser = parser;
1022 FcConfigCleanup (FcConfigParse *parse)
1024 while (parse->pstack)
1025 FcPStackPop (parse);
1028 static const FcChar8 *
1029 FcConfigGetAttribute (FcConfigParse *parse, const char *attr)
1035 attrs = parse->pstack->attr;
1041 if (!strcmp ((char *) *attrs, attr))
1049 FcStartElement(void *userData, const XML_Char *name, const XML_Char **attr)
1051 FcConfigParse *parse = userData;
1054 element = FcElementMap (name);
1055 if (element == FcElementUnknown)
1056 FcConfigMessage (parse, FcSevereWarning, "unknown element \"%s\"", name);
1058 if (!FcPStackPush (parse, element, attr))
1060 FcConfigMessage (parse, FcSevereError, "out of memory");
1067 FcParseBlank (FcConfigParse *parse)
1069 int n = FcVStackElements (parse);
1072 FcVStack *v = FcVStackFetch (parse, n);
1073 if (v->tag != FcVStackInteger)
1074 FcConfigMessage (parse, FcSevereError, "non-integer blank");
1077 if (!parse->config->blanks)
1079 parse->config->blanks = FcBlanksCreate ();
1080 if (!parse->config->blanks)
1082 FcConfigMessage (parse, FcSevereError, "out of memory");
1086 if (!FcBlanksAdd (parse->config->blanks, v->u.integer))
1088 FcConfigMessage (parse, FcSevereError, "out of memory");
1096 FcParseRescan (FcConfigParse *parse)
1098 int n = FcVStackElements (parse);
1101 FcVStack *v = FcVStackFetch (parse, n);
1102 if (v->tag != FcVStackInteger)
1103 FcConfigMessage (parse, FcSevereWarning, "non-integer rescan");
1105 parse->config->rescanInterval = v->u.integer;
1110 FcParseInt (FcConfigParse *parse)
1117 s = FcStrBufDone (&parse->pstack->str);
1120 FcConfigMessage (parse, FcSevereError, "out of memory");
1124 l = (int) strtol ((char *) s, (char **)&end, 0);
1125 if (end != s + strlen ((char *) s))
1126 FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid integer", s);
1128 FcVStackPushInteger (parse, l);
1133 * idea copied from glib g_ascii_strtod with
1134 * permission of the author (Alexander Larsson)
1140 FcStrtod (char *s, char **end)
1142 struct lconv *locale_data;
1147 * Have to swap the decimal point to match the current locale
1148 * if that locale doesn't use 0x2e
1150 if ((dot = strchr (s, 0x2e)) &&
1151 (locale_data = localeconv ()) &&
1152 (locale_data->decimal_point[0] != 0x2e ||
1153 locale_data->decimal_point[1] != 0))
1156 int slen = strlen (s);
1157 int dlen = strlen (locale_data->decimal_point);
1159 if (slen + dlen > (int) sizeof (buf))
1169 strncpy (buf, s, dot - s);
1171 strcpy (buf + (dot - s), locale_data->decimal_point);
1172 /* rest of number */
1173 strcpy (buf + (dot - s) + dlen, dot + 1);
1175 v = strtod (buf, &buf_end);
1177 buf_end = s + (buf_end - buf);
1179 buf_end -= dlen - 1;
1186 v = strtod (s, end);
1191 FcParseDouble (FcConfigParse *parse)
1198 s = FcStrBufDone (&parse->pstack->str);
1201 FcConfigMessage (parse, FcSevereError, "out of memory");
1205 d = FcStrtod ((char *) s, (char **)&end);
1206 if (end != s + strlen ((char *) s))
1207 FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid double", s);
1209 FcVStackPushDouble (parse, d);
1214 FcParseString (FcConfigParse *parse, FcVStackTag tag)
1220 s = FcStrBufDone (&parse->pstack->str);
1223 FcConfigMessage (parse, FcSevereError, "out of memory");
1226 if (!FcVStackPushString (parse, tag, s))
1231 FcParseMatrix (FcConfigParse *parse)
1234 enum { m_done, m_xx, m_xy, m_yx, m_yy } matrix_state = m_yy;
1237 while ((vstack = FcVStackPop (parse)))
1240 switch (vstack->tag) {
1241 case FcVStackInteger:
1242 v = vstack->u.integer;
1244 case FcVStackDouble:
1245 v = vstack->u._double;
1248 FcConfigMessage (parse, FcSevereError, "non-double matrix element");
1252 switch (matrix_state) {
1253 case m_xx: m.xx = v; break;
1254 case m_xy: m.xy = v; break;
1255 case m_yx: m.yx = v; break;
1256 case m_yy: m.yy = v; break;
1259 FcVStackDestroy (vstack);
1262 if (matrix_state != m_done)
1263 FcConfigMessage (parse, FcSevereError, "wrong number of matrix elements");
1265 FcVStackPushMatrix (parse, &m);
1269 FcConfigLexBool (FcConfigParse *parse, const FcChar8 *bool_)
1271 FcBool result = FcFalse;
1273 if (!FcNameBool (bool_, &result))
1274 FcConfigMessage (parse, FcSevereWarning, "\"%s\" is not known boolean",
1280 FcParseBool (FcConfigParse *parse)
1286 s = FcStrBufDone (&parse->pstack->str);
1289 FcConfigMessage (parse, FcSevereError, "out of memory");
1292 FcVStackPushBool (parse, FcConfigLexBool (parse, s));
1297 FcConfigLexBinding (FcConfigParse *parse,
1298 const FcChar8 *binding_string,
1299 FcValueBinding *binding_ret)
1301 FcValueBinding binding;
1303 if (!binding_string)
1304 binding = FcValueBindingWeak;
1307 if (!strcmp ((char *) binding_string, "weak"))
1308 binding = FcValueBindingWeak;
1309 else if (!strcmp ((char *) binding_string, "strong"))
1310 binding = FcValueBindingStrong;
1311 else if (!strcmp ((char *) binding_string, "same"))
1312 binding = FcValueBindingSame;
1315 FcConfigMessage (parse, FcSevereWarning, "invalid binding \"%s\"", binding_string);
1319 *binding_ret = binding;
1324 FcParseFamilies (FcConfigParse *parse, FcVStackTag tag)
1327 FcExpr *left, *expr = 0, *new;
1329 while ((vstack = FcVStackPop (parse)))
1331 if (vstack->tag != FcVStackFamily)
1333 FcConfigMessage (parse, FcSevereWarning, "non-family");
1334 FcVStackDestroy (vstack);
1337 left = vstack->u.expr;
1338 vstack->tag = FcVStackNone;
1339 FcVStackDestroy (vstack);
1342 new = FcExprCreateOp (left, FcOpComma, expr);
1345 FcConfigMessage (parse, FcSevereError, "out of memory");
1346 FcExprDestroy (left);
1347 FcExprDestroy (expr);
1357 if (!FcVStackPushExpr (parse, tag, expr))
1359 FcConfigMessage (parse, FcSevereError, "out of memory");
1360 FcExprDestroy (expr);
1366 FcParseFamily (FcConfigParse *parse)
1373 s = FcStrBufDone (&parse->pstack->str);
1376 FcConfigMessage (parse, FcSevereError, "out of memory");
1379 expr = FcExprCreateString (s);
1382 FcVStackPushExpr (parse, FcVStackFamily, expr);
1386 FcParseAlias (FcConfigParse *parse)
1388 FcExpr *family = 0, *accept = 0, *prefer = 0, *def = 0, *new = 0;
1389 FcEdit *edit = 0, *next;
1392 FcValueBinding binding;
1394 if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
1396 while ((vstack = FcVStackPop (parse)))
1398 switch (vstack->tag) {
1399 case FcVStackFamily:
1402 new = FcExprCreateOp (vstack->u.expr, FcOpComma, family);
1404 FcConfigMessage (parse, FcSevereError, "out of memory");
1409 new = vstack->u.expr;
1413 vstack->tag = FcVStackNone;
1416 case FcVStackPrefer:
1418 FcExprDestroy (prefer);
1419 prefer = vstack->u.expr;
1420 vstack->tag = FcVStackNone;
1422 case FcVStackAccept:
1424 FcExprDestroy (accept);
1425 accept = vstack->u.expr;
1426 vstack->tag = FcVStackNone;
1428 case FcVStackDefault:
1430 FcExprDestroy (def);
1431 def = vstack->u.expr;
1432 vstack->tag = FcVStackNone;
1435 FcConfigMessage (parse, FcSevereWarning, "bad alias");
1438 FcVStackDestroy (vstack);
1442 FcConfigMessage (parse, FcSevereError, "missing family in alias");
1444 FcExprDestroy (prefer);
1446 FcExprDestroy (accept);
1448 FcExprDestroy (def);
1453 edit = FcEditCreate (parse,
1461 FcExprDestroy (prefer);
1466 edit = FcEditCreate (parse,
1474 FcExprDestroy (accept);
1479 edit = FcEditCreate (parse,
1487 FcExprDestroy (def);
1491 test = FcTestCreate (parse, FcMatchPattern,
1493 (FcChar8 *) FC_FAMILY,
1497 if (!FcConfigAddEdit (parse->config, test, edit, FcMatchPattern))
1498 FcTestDestroy (test);
1501 FcExprDestroy (family);
1505 FcPopExpr (FcConfigParse *parse)
1507 FcVStack *vstack = FcVStackPop (parse);
1511 switch (vstack->tag) {
1514 case FcVStackString:
1515 case FcVStackFamily:
1516 expr = FcExprCreateString (vstack->u.string);
1519 expr = FcExprCreateField ((char *) vstack->u.string);
1521 case FcVStackConstant:
1522 expr = FcExprCreateConst (vstack->u.string);
1525 /* XXX: What's the correct action here? (CDW) */
1527 case FcVStackPrefer:
1528 case FcVStackAccept:
1529 case FcVStackDefault:
1530 expr = vstack->u.expr;
1531 vstack->tag = FcVStackNone;
1533 case FcVStackInteger:
1534 expr = FcExprCreateInteger (vstack->u.integer);
1536 case FcVStackDouble:
1537 expr = FcExprCreateDouble (vstack->u._double);
1539 case FcVStackMatrix:
1540 expr = FcExprCreateMatrix (vstack->u.matrix);
1543 expr = FcExprCreateBool (vstack->u.bool_);
1548 expr = vstack->u.expr;
1549 vstack->tag = FcVStackNone;
1556 FcVStackDestroy (vstack);
1561 * This builds a tree of binary operations. Note
1562 * that every operator is defined so that if only
1563 * a single operand is contained, the value of the
1564 * whole expression is the value of the operand.
1566 * This code reduces in that case to returning that
1570 FcPopBinary (FcConfigParse *parse, FcOp op)
1572 FcExpr *left, *expr = 0, *new;
1574 while ((left = FcPopExpr (parse)))
1578 new = FcExprCreateOp (left, op, expr);
1581 FcConfigMessage (parse, FcSevereError, "out of memory");
1582 FcExprDestroy (left);
1583 FcExprDestroy (expr);
1595 FcParseBinary (FcConfigParse *parse, FcOp op)
1597 FcExpr *expr = FcPopBinary (parse, op);
1599 FcVStackPushExpr (parse, FcVStackExpr, expr);
1603 * This builds a a unary operator, it consumes only
1608 FcPopUnary (FcConfigParse *parse, FcOp op)
1610 FcExpr *operand, *new = 0;
1612 if ((operand = FcPopExpr (parse)))
1614 new = FcExprCreateOp (operand, op, 0);
1617 FcExprDestroy (operand);
1618 FcConfigMessage (parse, FcSevereError, "out of memory");
1625 FcParseUnary (FcConfigParse *parse, FcOp op)
1627 FcExpr *expr = FcPopUnary (parse, op);
1629 FcVStackPushExpr (parse, FcVStackExpr, expr);
1633 FcParseInclude (FcConfigParse *parse)
1637 FcBool ignore_missing = FcFalse;
1639 s = FcStrBufDone (&parse->pstack->str);
1642 FcConfigMessage (parse, FcSevereError, "out of memory");
1645 i = FcConfigGetAttribute (parse, "ignore_missing");
1646 if (i && FcConfigLexBool (parse, (FcChar8 *) i) == FcTrue)
1647 ignore_missing = FcTrue;
1648 if (!FcConfigParseAndLoad (parse->config, s, !ignore_missing))
1649 parse->error = FcTrue;
1653 typedef struct _FcOpMap {
1659 FcConfigLexOp (const FcChar8 *op, const FcOpMap *map, int nmap)
1663 for (i = 0; i < nmap; i++)
1664 if (!strcmp ((char *) op, map[i].name))
1669 static const FcOpMap fcCompareOps[] = {
1670 { "eq", FcOpEqual },
1671 { "not_eq", FcOpNotEqual },
1672 { "less", FcOpLess },
1673 { "less_eq", FcOpLessEqual },
1674 { "more", FcOpMore },
1675 { "more_eq", FcOpMoreEqual },
1676 { "contains", FcOpContains },
1677 { "not_contains", FcOpNotContains }
1680 #define NUM_COMPARE_OPS (int) (sizeof fcCompareOps / sizeof fcCompareOps[0])
1683 FcConfigLexCompare (const FcChar8 *compare)
1685 return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS);
1689 FcParseTest (FcConfigParse *parse)
1691 const FcChar8 *kind_string;
1693 const FcChar8 *qual_string;
1695 const FcChar8 *name;
1696 const FcChar8 *compare_string;
1701 kind_string = FcConfigGetAttribute (parse, "target");
1703 kind = FcMatchDefault;
1706 if (!strcmp ((char *) kind_string, "pattern"))
1707 kind = FcMatchPattern;
1708 else if (!strcmp ((char *) kind_string, "font"))
1710 else if (!strcmp ((char *) kind_string, "scan"))
1712 else if (!strcmp ((char *) kind_string, "default"))
1713 kind = FcMatchDefault;
1716 FcConfigMessage (parse, FcSevereWarning, "invalid test target \"%s\"", kind_string);
1720 qual_string = FcConfigGetAttribute (parse, "qual");
1725 if (!strcmp ((char *) qual_string, "any"))
1727 else if (!strcmp ((char *) qual_string, "all"))
1729 else if (!strcmp ((char *) qual_string, "first"))
1731 else if (!strcmp ((char *) qual_string, "not_first"))
1732 qual = FcQualNotFirst;
1735 FcConfigMessage (parse, FcSevereWarning, "invalid test qual \"%s\"", qual_string);
1739 name = FcConfigGetAttribute (parse, "name");
1742 FcConfigMessage (parse, FcSevereWarning, "missing test name");
1745 compare_string = FcConfigGetAttribute (parse, "compare");
1746 if (!compare_string)
1747 compare = FcOpEqual;
1750 compare = FcConfigLexCompare (compare_string);
1751 if (compare == FcOpInvalid)
1753 FcConfigMessage (parse, FcSevereWarning, "invalid test compare \"%s\"", compare_string);
1757 expr = FcPopBinary (parse, FcOpComma);
1760 FcConfigMessage (parse, FcSevereWarning, "missing test expression");
1763 test = FcTestCreate (parse, kind, qual, name, compare, expr);
1766 FcConfigMessage (parse, FcSevereError, "out of memory");
1769 FcVStackPushTest (parse, test);
1772 static const FcOpMap fcModeOps[] = {
1773 { "assign", FcOpAssign },
1774 { "assign_replace", FcOpAssignReplace },
1775 { "prepend", FcOpPrepend },
1776 { "prepend_first", FcOpPrependFirst },
1777 { "append", FcOpAppend },
1778 { "append_last", FcOpAppendLast },
1781 #define NUM_MODE_OPS (int) (sizeof fcModeOps / sizeof fcModeOps[0])
1784 FcConfigLexMode (const FcChar8 *mode)
1786 return FcConfigLexOp (mode, fcModeOps, NUM_MODE_OPS);
1790 FcParseEdit (FcConfigParse *parse)
1792 const FcChar8 *name;
1793 const FcChar8 *mode_string;
1795 FcValueBinding binding;
1799 name = FcConfigGetAttribute (parse, "name");
1802 FcConfigMessage (parse, FcSevereWarning, "missing edit name");
1805 mode_string = FcConfigGetAttribute (parse, "mode");
1810 mode = FcConfigLexMode (mode_string);
1811 if (mode == FcOpInvalid)
1813 FcConfigMessage (parse, FcSevereWarning, "invalid edit mode \"%s\"", mode_string);
1817 if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
1820 expr = FcPopBinary (parse, FcOpComma);
1821 edit = FcEditCreate (parse, FcObjectFromName ((char *) name),
1822 mode, expr, binding);
1825 FcConfigMessage (parse, FcSevereError, "out of memory");
1826 FcExprDestroy (expr);
1829 if (!FcVStackPushEdit (parse, edit))
1830 FcEditDestroy (edit);
1834 FcParseMatch (FcConfigParse *parse)
1836 const FcChar8 *kind_name;
1842 kind_name = FcConfigGetAttribute (parse, "target");
1844 kind = FcMatchPattern;
1847 if (!strcmp ((char *) kind_name, "pattern"))
1848 kind = FcMatchPattern;
1849 else if (!strcmp ((char *) kind_name, "font"))
1851 else if (!strcmp ((char *) kind_name, "scan"))
1855 FcConfigMessage (parse, FcSevereWarning, "invalid match target \"%s\"", kind_name);
1859 while ((vstack = FcVStackPop (parse)))
1861 switch (vstack->tag) {
1863 vstack->u.test->next = test;
1864 test = vstack->u.test;
1865 vstack->tag = FcVStackNone;
1868 vstack->u.edit->next = edit;
1869 edit = vstack->u.edit;
1870 vstack->tag = FcVStackNone;
1871 if (kind == FcMatchScan && edit->object > FC_MAX_BASE_OBJECT)
1873 FcConfigMessage (parse, FcSevereError,
1874 "<match target=\"scan\"> cannot edit user-defined object \"%s\"",
1875 FcObjectName(edit->object));
1879 FcConfigMessage (parse, FcSevereWarning, "invalid match element");
1882 FcVStackDestroy (vstack);
1884 if (!FcConfigAddEdit (parse->config, test, edit, kind))
1885 FcConfigMessage (parse, FcSevereError, "out of memory");
1889 FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element)
1893 while ((vstack = FcVStackPop (parse)))
1895 switch (vstack->tag) {
1897 if (!FcConfigGlobAdd (parse->config,
1899 element == FcElementAcceptfont))
1901 FcConfigMessage (parse, FcSevereError, "out of memory");
1904 case FcVStackPattern:
1905 if (!FcConfigPatternsAdd (parse->config,
1907 element == FcElementAcceptfont))
1909 FcConfigMessage (parse, FcSevereError, "out of memory");
1912 vstack->tag = FcVStackNone;
1915 FcConfigMessage (parse, FcSevereWarning, "bad font selector");
1918 FcVStackDestroy (vstack);
1924 FcPopValue (FcConfigParse *parse)
1926 FcVStack *vstack = FcVStackPop (parse);
1929 value.type = FcTypeVoid;
1934 switch (vstack->tag) {
1935 case FcVStackString:
1936 value.u.s = FcStrCopy (vstack->u.string);
1938 value.type = FcTypeString;
1940 case FcVStackConstant:
1941 if (FcNameConstant (vstack->u.string, &value.u.i))
1942 value.type = FcTypeInteger;
1944 case FcVStackInteger:
1945 value.u.i = vstack->u.integer;
1946 value.type = FcTypeInteger;
1948 case FcVStackDouble:
1949 value.u.d = vstack->u._double;
1950 value.type = FcTypeInteger;
1952 case FcVStackMatrix:
1953 value.u.m = FcMatrixCopy (vstack->u.matrix);
1955 value.type = FcTypeMatrix;
1958 value.u.b = vstack->u.bool_;
1959 value.type = FcTypeBool;
1962 FcConfigMessage (parse, FcSevereWarning, "unknown pattern element %d",
1966 FcVStackDestroy (vstack);
1972 FcParsePatelt (FcConfigParse *parse)
1975 FcPattern *pattern = FcPatternCreate ();
1980 FcConfigMessage (parse, FcSevereError, "out of memory");
1984 name = (char *) FcConfigGetAttribute (parse, "name");
1987 FcConfigMessage (parse, FcSevereWarning, "missing pattern element name");
1988 FcPatternDestroy (pattern);
1994 value = FcPopValue (parse);
1995 if (value.type == FcTypeVoid)
1997 if (!FcPatternAdd (pattern, name, value, FcTrue))
1999 FcConfigMessage (parse, FcSevereError, "out of memory");
2000 FcValueDestroy(value);
2003 FcValueDestroy(value);
2006 FcVStackPushPattern (parse, pattern);
2010 FcParsePattern (FcConfigParse *parse)
2013 FcPattern *pattern = FcPatternCreate ();
2017 FcConfigMessage (parse, FcSevereError, "out of memory");
2021 while ((vstack = FcVStackPop (parse)))
2023 switch (vstack->tag) {
2024 case FcVStackPattern:
2025 if (!FcPatternAppend (pattern, vstack->u.pattern))
2027 FcConfigMessage (parse, FcSevereError, "out of memory");
2028 FcPatternDestroy (pattern);
2033 FcConfigMessage (parse, FcSevereWarning, "unknown pattern element");
2036 FcVStackDestroy (vstack);
2039 FcVStackPushPattern (parse, pattern);
2043 FcEndElement(void *userData, const XML_Char *name)
2045 FcConfigParse *parse = userData;
2050 switch (parse->pstack->element) {
2053 case FcElementFontconfig:
2056 data = FcStrBufDone (&parse->pstack->str);
2059 FcConfigMessage (parse, FcSevereError, "out of memory");
2063 if (strcmp (data, "CUSTOMFONTDIR") == 0)
2067 data = malloc (1000);
2070 FcConfigMessage (parse, FcSevereError, "out of memory");
2073 FcMemAlloc (FC_MEM_STRING, 1000);
2074 if(!GetModuleFileName(NULL, data, 1000))
2076 FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
2080 p = strrchr (data, '\\');
2082 strcat (data, "\\fonts");
2084 else if (strcmp (data, "APPSHAREFONTDIR") == 0)
2088 data = malloc (1000);
2091 FcConfigMessage (parse, FcSevereError, "out of memory");
2094 FcMemAlloc (FC_MEM_STRING, 1000);
2095 if(!GetModuleFileName(NULL, data, 1000))
2097 FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
2101 p = strrchr (data, '\\');
2103 strcat (data, "\\..\\share\\fonts");
2105 else if (strcmp (data, "WINDOWSFONTDIR") == 0)
2109 data = malloc (1000);
2112 FcConfigMessage (parse, FcSevereError, "out of memory");
2115 FcMemAlloc (FC_MEM_STRING, 1000);
2116 rc = GetWindowsDirectory (data, 800);
2117 if (rc == 0 || rc > 800)
2119 FcConfigMessage (parse, FcSevereError, "GetWindowsDirectory failed");
2123 if (data [strlen (data) - 1] != '\\')
2124 strcat (data, "\\");
2125 strcat (data, "fonts");
2128 if (strlen ((char *) data) == 0)
2129 FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored");
2130 else if (!FcStrUsesHome (data) || FcConfigHome ())
2132 if (!FcConfigAddDir (parse->config, data))
2133 FcConfigMessage (parse, FcSevereError, "out of memory; cannot add directory %s", data);
2137 case FcElementCacheDir:
2138 data = FcStrBufDone (&parse->pstack->str);
2141 FcConfigMessage (parse, FcSevereError, "out of memory");
2145 if (strcmp (data, "WINDOWSTEMPDIR_FONTCONFIG_CACHE") == 0)
2149 data = malloc (1000);
2152 FcConfigMessage (parse, FcSevereError, "out of memory");
2155 FcMemAlloc (FC_MEM_STRING, 1000);
2156 rc = GetTempPath (800, data);
2157 if (rc == 0 || rc > 800)
2159 FcConfigMessage (parse, FcSevereError, "GetWindowsDirectory failed");
2163 if (data [strlen (data) - 1] != '\\')
2164 strcat (data, "\\");
2165 strcat (data, "fontconfig\\cache");
2168 if (!FcStrUsesHome (data) || FcConfigHome ())
2170 if (!FcConfigAddCacheDir (parse->config, data))
2171 FcConfigMessage (parse, FcSevereError, "out of memory; cannot add cache directory %s", data);
2176 case FcElementCache:
2177 data = FcStrBufDone (&parse->pstack->str);
2180 FcConfigMessage (parse, FcSevereError, "out of memory");
2183 /* discard this data; no longer used */
2186 case FcElementInclude:
2187 FcParseInclude (parse);
2189 case FcElementConfig:
2191 case FcElementMatch:
2192 FcParseMatch (parse);
2194 case FcElementAlias:
2195 FcParseAlias (parse);
2198 case FcElementBlank:
2199 FcParseBlank (parse);
2201 case FcElementRescan:
2202 FcParseRescan (parse);
2205 case FcElementPrefer:
2206 FcParseFamilies (parse, FcVStackPrefer);
2208 case FcElementAccept:
2209 FcParseFamilies (parse, FcVStackAccept);
2211 case FcElementDefault:
2212 FcParseFamilies (parse, FcVStackDefault);
2214 case FcElementFamily:
2215 FcParseFamily (parse);
2219 FcParseTest (parse);
2222 FcParseEdit (parse);
2228 case FcElementDouble:
2229 FcParseDouble (parse);
2231 case FcElementString:
2232 FcParseString (parse, FcVStackString);
2234 case FcElementMatrix:
2235 FcParseMatrix (parse);
2238 FcParseBool (parse);
2240 case FcElementCharset:
2241 /* FcParseCharset (parse); */
2243 case FcElementSelectfont:
2245 case FcElementAcceptfont:
2246 case FcElementRejectfont:
2247 FcParseAcceptRejectFont (parse, parse->pstack->element);
2250 FcParseString (parse, FcVStackGlob);
2252 case FcElementPattern:
2253 FcParsePattern (parse);
2255 case FcElementPatelt:
2256 FcParsePatelt (parse);
2259 FcParseString (parse, FcVStackField);
2261 case FcElementConst:
2262 FcParseString (parse, FcVStackConstant);
2265 FcParseBinary (parse, FcOpOr);
2268 FcParseBinary (parse, FcOpAnd);
2271 FcParseBinary (parse, FcOpEqual);
2273 case FcElementNotEq:
2274 FcParseBinary (parse, FcOpNotEqual);
2277 FcParseBinary (parse, FcOpLess);
2279 case FcElementLessEq:
2280 FcParseBinary (parse, FcOpLessEqual);
2283 FcParseBinary (parse, FcOpMore);
2285 case FcElementMoreEq:
2286 FcParseBinary (parse, FcOpMoreEqual);
2288 case FcElementContains:
2289 FcParseBinary (parse, FcOpContains);
2291 case FcElementNotContains:
2292 FcParseBinary (parse, FcOpNotContains);
2295 FcParseBinary (parse, FcOpPlus);
2297 case FcElementMinus:
2298 FcParseBinary (parse, FcOpMinus);
2300 case FcElementTimes:
2301 FcParseBinary (parse, FcOpTimes);
2303 case FcElementDivide:
2304 FcParseBinary (parse, FcOpDivide);
2307 FcParseUnary (parse, FcOpNot);
2310 FcParseBinary (parse, FcOpQuest);
2312 case FcElementFloor:
2313 FcParseUnary (parse, FcOpFloor);
2316 FcParseUnary (parse, FcOpCeil);
2318 case FcElementRound:
2319 FcParseUnary (parse, FcOpRound);
2321 case FcElementTrunc:
2322 FcParseUnary (parse, FcOpTrunc);
2324 case FcElementUnknown:
2327 (void) FcPStackPop (parse);
2331 FcCharacterData (void *userData, const XML_Char *s, int len)
2333 FcConfigParse *parse = userData;
2337 if (!FcStrBufData (&parse->pstack->str, (FcChar8 *) s, len))
2338 FcConfigMessage (parse, FcSevereError, "out of memory");
2342 FcStartDoctypeDecl (void *userData,
2343 const XML_Char *doctypeName,
2344 const XML_Char *sysid,
2345 const XML_Char *pubid,
2346 int has_internal_subset)
2348 FcConfigParse *parse = userData;
2350 if (strcmp ((char *) doctypeName, "fontconfig") != 0)
2351 FcConfigMessage (parse, FcSevereError, "invalid doctype \"%s\"", doctypeName);
2354 #ifdef ENABLE_LIBXML2
2357 FcInternalSubsetDecl (void *userData,
2358 const XML_Char *doctypeName,
2359 const XML_Char *sysid,
2360 const XML_Char *pubid)
2362 FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 1);
2366 FcExternalSubsetDecl (void *userData,
2367 const XML_Char *doctypeName,
2368 const XML_Char *sysid,
2369 const XML_Char *pubid)
2371 FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 0);
2374 #else /* ENABLE_LIBXML2 */
2377 FcEndDoctypeDecl (void *userData)
2381 #endif /* ENABLE_LIBXML2 */
2384 FcSortCmpStr (const void *a, const void *b)
2386 const FcChar8 *as = *((FcChar8 **) a);
2387 const FcChar8 *bs = *((FcChar8 **) b);
2388 return FcStrCmp (as, bs);
2392 FcConfigParseAndLoadDir (FcConfig *config,
2393 const FcChar8 *name,
2399 FcBool ret = FcTrue;
2404 d = opendir ((char *) dir);
2408 FcConfigMessage (0, FcSevereError, "Cannot open config dir \"%s\"",
2414 file = (FcChar8 *) malloc (strlen ((char *) dir) + 1 + FC_MAX_FILE_LEN + 1);
2421 strcpy ((char *) file, (char *) dir);
2422 strcat ((char *) file, "/");
2423 base = file + strlen ((char *) file);
2425 files = FcStrSetCreate ();
2432 if (FcDebug () & FC_DBG_CONFIG)
2433 printf ("\tScanning config dir %s\n", dir);
2435 while (ret && (e = readdir (d)))
2438 #define TAIL ".conf"
2441 * Add all files of the form [0-9]*.conf
2443 if ('0' <= e->d_name[0] && e->d_name[0] <= '9' &&
2444 (d_len = strlen (e->d_name)) < FC_MAX_FILE_LEN &&
2446 strcmp (e->d_name + d_len - TAIL_LEN, TAIL) == 0)
2448 strcpy ((char *) base, (char *) e->d_name);
2449 if (!FcStrSetAdd (files, file))
2459 qsort (files->strs, files->num, sizeof (FcChar8 *),
2460 (int (*)(const void *, const void *)) FcSortCmpStr);
2461 for (i = 0; ret && i < files->num; i++)
2462 ret = FcConfigParseAndLoad (config, files->strs[i], complain);
2465 FcStrSetDestroy (files);
2471 return ret || !complain;
2475 FcConfigParseAndLoad (FcConfig *config,
2476 const FcChar8 *name,
2484 FcConfigParse parse;
2485 FcBool error = FcTrue;
2487 #ifdef ENABLE_LIBXML2
2494 filename = FcConfigFilename (name);
2498 if (FcStrSetMember (config->configFiles, filename))
2500 FcStrFree (filename);
2504 if (!FcStrSetAdd (config->configFiles, filename))
2506 FcStrFree (filename);
2510 if (FcFileIsDir (filename))
2512 FcBool ret = FcConfigParseAndLoadDir (config, name, filename, complain);
2513 FcStrFree (filename);
2517 if (FcDebug () & FC_DBG_CONFIG)
2518 printf ("\tLoading config file %s\n", filename);
2520 fd = open ((char *) filename, O_RDONLY);
2522 FcStrFree (filename);
2526 #ifdef ENABLE_LIBXML2
2527 memset(&sax, 0, sizeof(sax));
2529 sax.internalSubset = FcInternalSubsetDecl;
2530 sax.externalSubset = FcExternalSubsetDecl;
2531 sax.startElement = FcStartElement;
2532 sax.endElement = FcEndElement;
2533 sax.characters = FcCharacterData;
2535 p = xmlCreatePushParserCtxt (&sax, &parse, NULL, 0, (const char *) filename);
2537 p = XML_ParserCreate ("UTF-8");
2539 FcStrFree (filename);
2544 if (!FcConfigInit (&parse, name, config, p))
2547 #ifndef ENABLE_LIBXML2
2549 XML_SetUserData (p, &parse);
2551 XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl);
2552 XML_SetElementHandler (p, FcStartElement, FcEndElement);
2553 XML_SetCharacterDataHandler (p, FcCharacterData);
2555 #endif /* ENABLE_LIBXML2 */
2558 #ifndef ENABLE_LIBXML2
2559 buf = XML_GetBuffer (p, BUFSIZ);
2562 FcConfigMessage (&parse, FcSevereError, "cannot get parse buffer");
2566 len = read (fd, buf, BUFSIZ);
2569 FcConfigMessage (&parse, FcSevereError, "failed reading config file");
2573 #ifdef ENABLE_LIBXML2
2574 if (xmlParseChunk (p, buf, len, len == 0))
2576 if (!XML_ParseBuffer (p, len, len == 0))
2579 FcConfigMessage (&parse, FcSevereError, "%s",
2580 XML_ErrorString (XML_GetErrorCode (p)));
2584 error = parse.error;
2586 FcConfigCleanup (&parse);
2593 if (error && complain)
2596 FcConfigMessage (0, FcSevereError, "Cannot load config file \"%s\"", name);
2598 FcConfigMessage (0, FcSevereError, "Cannot load default config file");
2604 #include "fcaliastail.h"