2002-02-15 00:34:13 +01:00
|
|
|
|
/*
|
2003-03-05 06:51:27 +01:00
|
|
|
|
* $RCSId: xc/lib/fontconfig/src/fcxml.c,v 1.21 2002/08/22 18:53:22 keithp Exp $
|
2002-02-15 00:34:13 +01:00
|
|
|
|
*
|
2003-03-05 06:51:27 +01:00
|
|
|
|
* Copyright <EFBFBD> 2002 Keith Packard
|
2002-02-15 00:34:13 +01:00
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of Keith Packard not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
|
* specific, written prior permission. Keith Packard makes no
|
|
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
|
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include "fcint.h"
|
2002-05-22 06:37:07 +02:00
|
|
|
|
|
2002-06-08 19:32:05 +02:00
|
|
|
|
#ifndef HAVE_XMLPARSE_H
|
|
|
|
|
#define HAVE_XMLPARSE_H 0
|
|
|
|
|
#endif
|
2002-08-19 21:32:05 +02:00
|
|
|
|
|
2002-05-21 19:06:22 +02:00
|
|
|
|
#if HAVE_XMLPARSE_H
|
|
|
|
|
#include <xmlparse.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <expat.h>
|
|
|
|
|
#endif
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2003-03-22 22:25:34 +01:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define STRICT
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#undef STRICT
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcTest *
|
2002-08-11 20:11:04 +02:00
|
|
|
|
FcTestCreate (FcMatchKind kind,
|
|
|
|
|
FcQual qual,
|
|
|
|
|
const FcChar8 *field,
|
|
|
|
|
FcOp compare,
|
|
|
|
|
FcExpr *expr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcTest *test = (FcTest *) malloc (sizeof (FcTest));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
|
|
if (test)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_TEST, sizeof (FcTest));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
test->next = 0;
|
2002-08-11 20:11:04 +02:00
|
|
|
|
test->kind = kind;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
test->qual = qual;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
test->field = (char *) FcStrCopy (field);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
test->op = compare;
|
|
|
|
|
test->expr = expr;
|
|
|
|
|
}
|
|
|
|
|
return test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FcTestDestroy (FcTest *test)
|
|
|
|
|
{
|
|
|
|
|
if (test->next)
|
|
|
|
|
FcTestDestroy (test->next);
|
|
|
|
|
FcExprDestroy (test->expr);
|
|
|
|
|
FcStrFree ((FcChar8 *) test->field);
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemFree (FC_MEM_TEST, sizeof (FcTest));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
free (test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateInteger (int i)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpInteger;
|
|
|
|
|
e->u.ival = i;
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateDouble (double d)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpDouble;
|
|
|
|
|
e->u.dval = d;
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
2002-02-15 07:01:28 +01:00
|
|
|
|
FcExprCreateString (const FcChar8 *s)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpString;
|
|
|
|
|
e->u.sval = FcStrCopy (s);
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateMatrix (const FcMatrix *m)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpMatrix;
|
|
|
|
|
e->u.mval = FcMatrixCopy (m);
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateBool (FcBool b)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpBool;
|
|
|
|
|
e->u.bval = b;
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateNil (void)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpNil;
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateField (const char *field)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpField;
|
2002-02-15 07:01:28 +01:00
|
|
|
|
e->u.field = (char *) FcStrCopy ((FcChar8 *) field);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
2002-02-15 07:01:28 +01:00
|
|
|
|
FcExprCreateConst (const FcChar8 *constant)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = FcOpConst;
|
|
|
|
|
e->u.constant = FcStrCopy (constant);
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcExpr *
|
|
|
|
|
FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *e = (FcExpr *) malloc (sizeof (FcExpr));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
e->op = op;
|
|
|
|
|
e->u.tree.left = left;
|
|
|
|
|
e->u.tree.right = right;
|
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FcExprDestroy (FcExpr *e)
|
|
|
|
|
{
|
2003-04-16 01:38:06 +02:00
|
|
|
|
if (!e)
|
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
switch (e->op) {
|
|
|
|
|
case FcOpInteger:
|
|
|
|
|
break;
|
|
|
|
|
case FcOpDouble:
|
|
|
|
|
break;
|
|
|
|
|
case FcOpString:
|
|
|
|
|
FcStrFree (e->u.sval);
|
|
|
|
|
break;
|
|
|
|
|
case FcOpMatrix:
|
|
|
|
|
FcMatrixFree (e->u.mval);
|
|
|
|
|
break;
|
|
|
|
|
case FcOpCharSet:
|
|
|
|
|
FcCharSetDestroy (e->u.cval);
|
|
|
|
|
break;
|
|
|
|
|
case FcOpBool:
|
|
|
|
|
break;
|
|
|
|
|
case FcOpField:
|
2002-02-15 07:01:28 +01:00
|
|
|
|
FcStrFree ((FcChar8 *) e->u.field);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcOpConst:
|
|
|
|
|
FcStrFree (e->u.constant);
|
|
|
|
|
break;
|
|
|
|
|
case FcOpAssign:
|
|
|
|
|
case FcOpAssignReplace:
|
|
|
|
|
case FcOpPrepend:
|
|
|
|
|
case FcOpPrependFirst:
|
|
|
|
|
case FcOpAppend:
|
|
|
|
|
case FcOpAppendLast:
|
|
|
|
|
break;
|
|
|
|
|
case FcOpOr:
|
|
|
|
|
case FcOpAnd:
|
|
|
|
|
case FcOpEqual:
|
|
|
|
|
case FcOpNotEqual:
|
|
|
|
|
case FcOpLess:
|
|
|
|
|
case FcOpLessEqual:
|
|
|
|
|
case FcOpMore:
|
|
|
|
|
case FcOpMoreEqual:
|
2002-08-22 20:53:22 +02:00
|
|
|
|
case FcOpContains:
|
2003-07-20 18:06:18 +02:00
|
|
|
|
case FcOpListing:
|
2002-08-22 20:53:22 +02:00
|
|
|
|
case FcOpNotContains:
|
2002-02-15 00:34:13 +01:00
|
|
|
|
case FcOpPlus:
|
|
|
|
|
case FcOpMinus:
|
|
|
|
|
case FcOpTimes:
|
|
|
|
|
case FcOpDivide:
|
|
|
|
|
case FcOpQuest:
|
|
|
|
|
case FcOpComma:
|
|
|
|
|
FcExprDestroy (e->u.tree.right);
|
|
|
|
|
/* fall through */
|
|
|
|
|
case FcOpNot:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
case FcOpFloor:
|
|
|
|
|
case FcOpCeil:
|
|
|
|
|
case FcOpRound:
|
|
|
|
|
case FcOpTrunc:
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcExprDestroy (e->u.tree.left);
|
|
|
|
|
break;
|
|
|
|
|
case FcOpNil:
|
|
|
|
|
case FcOpInvalid:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemFree (FC_MEM_EXPR, sizeof (FcExpr));
|
2002-02-15 00:34:13 +01:00
|
|
|
|
free (e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcEdit *
|
2002-07-31 03:36:37 +02:00
|
|
|
|
FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
|
|
|
|
FcEdit *e = (FcEdit *) malloc (sizeof (FcEdit));
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
{
|
|
|
|
|
e->next = 0;
|
|
|
|
|
e->field = field; /* already saved in grammar */
|
|
|
|
|
e->op = op;
|
|
|
|
|
e->expr = expr;
|
2002-07-31 03:36:37 +02:00
|
|
|
|
e->binding = binding;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FcEditDestroy (FcEdit *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->next)
|
|
|
|
|
FcEditDestroy (e->next);
|
|
|
|
|
FcStrFree ((FcChar8 *) e->field);
|
|
|
|
|
if (e->expr)
|
|
|
|
|
FcExprDestroy (e->expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
FcConfigSaveField (const char *field)
|
|
|
|
|
{
|
2002-02-15 07:01:28 +01:00
|
|
|
|
return (char *) FcStrCopy ((FcChar8 *) field);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
typedef enum _FcElement {
|
|
|
|
|
FcElementNone,
|
|
|
|
|
FcElementFontconfig,
|
|
|
|
|
FcElementDir,
|
|
|
|
|
FcElementCache,
|
|
|
|
|
FcElementInclude,
|
|
|
|
|
FcElementConfig,
|
|
|
|
|
FcElementMatch,
|
|
|
|
|
FcElementAlias,
|
|
|
|
|
|
|
|
|
|
FcElementBlank,
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcElementRescan,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
FcElementPrefer,
|
|
|
|
|
FcElementAccept,
|
|
|
|
|
FcElementDefault,
|
|
|
|
|
FcElementFamily,
|
|
|
|
|
|
2003-05-07 18:13:24 +02:00
|
|
|
|
FcElementSelectfont,
|
|
|
|
|
FcElementAcceptfont,
|
|
|
|
|
FcElementRejectfont,
|
|
|
|
|
FcElementGlob,
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcElementTest,
|
|
|
|
|
FcElementEdit,
|
|
|
|
|
FcElementInt,
|
|
|
|
|
FcElementDouble,
|
|
|
|
|
FcElementString,
|
|
|
|
|
FcElementMatrix,
|
|
|
|
|
FcElementBool,
|
|
|
|
|
FcElementCharset,
|
|
|
|
|
FcElementName,
|
|
|
|
|
FcElementConst,
|
|
|
|
|
FcElementOr,
|
|
|
|
|
FcElementAnd,
|
|
|
|
|
FcElementEq,
|
|
|
|
|
FcElementNotEq,
|
|
|
|
|
FcElementLess,
|
|
|
|
|
FcElementLessEq,
|
|
|
|
|
FcElementMore,
|
|
|
|
|
FcElementMoreEq,
|
2002-08-22 20:53:22 +02:00
|
|
|
|
FcElementContains,
|
|
|
|
|
FcElementNotContains,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcElementPlus,
|
|
|
|
|
FcElementMinus,
|
|
|
|
|
FcElementTimes,
|
|
|
|
|
FcElementDivide,
|
|
|
|
|
FcElementNot,
|
|
|
|
|
FcElementIf,
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcElementFloor,
|
|
|
|
|
FcElementCeil,
|
|
|
|
|
FcElementRound,
|
|
|
|
|
FcElementTrunc,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcElementUnknown
|
|
|
|
|
} FcElement;
|
|
|
|
|
|
|
|
|
|
static FcElement
|
|
|
|
|
FcElementMap (const XML_Char *name)
|
|
|
|
|
{
|
|
|
|
|
static struct {
|
|
|
|
|
char *name;
|
|
|
|
|
FcElement element;
|
|
|
|
|
} fcElementMap[] = {
|
|
|
|
|
{ "fontconfig", FcElementFontconfig },
|
|
|
|
|
{ "dir", FcElementDir },
|
|
|
|
|
{ "cache", FcElementCache },
|
|
|
|
|
{ "include", FcElementInclude },
|
|
|
|
|
{ "config", FcElementConfig },
|
|
|
|
|
{ "match", FcElementMatch },
|
|
|
|
|
{ "alias", FcElementAlias },
|
|
|
|
|
|
|
|
|
|
{ "blank", FcElementBlank },
|
2002-05-21 19:06:22 +02:00
|
|
|
|
{ "rescan", FcElementRescan },
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
{ "prefer", FcElementPrefer },
|
|
|
|
|
{ "accept", FcElementAccept },
|
|
|
|
|
{ "default", FcElementDefault },
|
|
|
|
|
{ "family", FcElementFamily },
|
|
|
|
|
|
2003-05-07 18:13:24 +02:00
|
|
|
|
{ "selectfont", FcElementSelectfont },
|
|
|
|
|
{ "acceptfont", FcElementAcceptfont },
|
|
|
|
|
{ "rejectfont", FcElementRejectfont },
|
|
|
|
|
{ "glob", FcElementGlob },
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
{ "test", FcElementTest },
|
|
|
|
|
{ "edit", FcElementEdit },
|
|
|
|
|
{ "int", FcElementInt },
|
|
|
|
|
{ "double", FcElementDouble },
|
|
|
|
|
{ "string", FcElementString },
|
|
|
|
|
{ "matrix", FcElementMatrix },
|
|
|
|
|
{ "bool", FcElementBool },
|
|
|
|
|
{ "charset", FcElementCharset },
|
|
|
|
|
{ "name", FcElementName },
|
|
|
|
|
{ "const", FcElementConst },
|
|
|
|
|
{ "or", FcElementOr },
|
|
|
|
|
{ "and", FcElementAnd },
|
|
|
|
|
{ "eq", FcElementEq },
|
|
|
|
|
{ "not_eq", FcElementNotEq },
|
|
|
|
|
{ "less", FcElementLess },
|
|
|
|
|
{ "less_eq", FcElementLessEq },
|
|
|
|
|
{ "more", FcElementMore },
|
|
|
|
|
{ "more_eq", FcElementMoreEq },
|
2002-08-22 20:53:22 +02:00
|
|
|
|
{ "contains", FcElementContains },
|
|
|
|
|
{ "not_contains",FcElementNotContains },
|
2002-02-18 23:29:28 +01:00
|
|
|
|
{ "plus", FcElementPlus },
|
|
|
|
|
{ "minus", FcElementMinus },
|
|
|
|
|
{ "times", FcElementTimes },
|
|
|
|
|
{ "divide", FcElementDivide },
|
|
|
|
|
{ "not", FcElementNot },
|
|
|
|
|
{ "if", FcElementIf },
|
2003-04-16 01:38:06 +02:00
|
|
|
|
{ "floor", FcElementFloor },
|
|
|
|
|
{ "ceil", FcElementCeil },
|
|
|
|
|
{ "round", FcElementRound },
|
|
|
|
|
{ "trunc", FcElementTrunc },
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; fcElementMap[i].name; i++)
|
|
|
|
|
if (!strcmp ((char *) name, fcElementMap[i].name))
|
|
|
|
|
return fcElementMap[i].element;
|
|
|
|
|
return FcElementUnknown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct _FcPStack {
|
|
|
|
|
struct _FcPStack *prev;
|
|
|
|
|
FcElement element;
|
|
|
|
|
FcChar8 **attr;
|
|
|
|
|
FcStrBuf str;
|
|
|
|
|
} FcPStack;
|
|
|
|
|
|
|
|
|
|
typedef enum _FcVStackTag {
|
|
|
|
|
FcVStackNone,
|
|
|
|
|
|
|
|
|
|
FcVStackString,
|
|
|
|
|
FcVStackFamily,
|
|
|
|
|
FcVStackField,
|
|
|
|
|
FcVStackConstant,
|
2003-05-07 18:13:24 +02:00
|
|
|
|
FcVStackGlob,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
FcVStackPrefer,
|
|
|
|
|
FcVStackAccept,
|
|
|
|
|
FcVStackDefault,
|
|
|
|
|
|
|
|
|
|
FcVStackInteger,
|
|
|
|
|
FcVStackDouble,
|
|
|
|
|
FcVStackMatrix,
|
|
|
|
|
FcVStackBool,
|
|
|
|
|
|
|
|
|
|
FcVStackTest,
|
|
|
|
|
FcVStackExpr,
|
|
|
|
|
FcVStackEdit
|
|
|
|
|
} FcVStackTag;
|
|
|
|
|
|
|
|
|
|
typedef struct _FcVStack {
|
|
|
|
|
struct _FcVStack *prev;
|
|
|
|
|
FcPStack *pstack; /* related parse element */
|
|
|
|
|
FcVStackTag tag;
|
|
|
|
|
union {
|
|
|
|
|
FcChar8 *string;
|
|
|
|
|
|
|
|
|
|
int integer;
|
|
|
|
|
double _double;
|
|
|
|
|
FcMatrix *matrix;
|
|
|
|
|
FcBool bool;
|
|
|
|
|
|
|
|
|
|
FcTest *test;
|
|
|
|
|
FcQual qual;
|
|
|
|
|
FcOp op;
|
|
|
|
|
FcExpr *expr;
|
|
|
|
|
FcEdit *edit;
|
|
|
|
|
} u;
|
|
|
|
|
} FcVStack;
|
|
|
|
|
|
|
|
|
|
typedef struct _FcConfigParse {
|
|
|
|
|
FcPStack *pstack;
|
|
|
|
|
FcVStack *vstack;
|
|
|
|
|
FcBool error;
|
|
|
|
|
const FcChar8 *name;
|
|
|
|
|
FcConfig *config;
|
|
|
|
|
XML_Parser parser;
|
|
|
|
|
} FcConfigParse;
|
|
|
|
|
|
2002-05-21 19:06:22 +02:00
|
|
|
|
typedef enum _FcConfigSeverity {
|
|
|
|
|
FcSevereInfo, FcSevereWarning, FcSevereError
|
|
|
|
|
} FcConfigSeverity;
|
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
|
static void
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, char *fmt, ...)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
char *s = "unknown";
|
2002-02-15 00:34:13 +01:00
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
2002-05-21 19:06:22 +02:00
|
|
|
|
|
|
|
|
|
switch (severe) {
|
|
|
|
|
case FcSevereInfo: s = "info"; break;
|
|
|
|
|
case FcSevereWarning: s = "warning"; break;
|
|
|
|
|
case FcSevereError: s = "error"; break;
|
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (parse)
|
|
|
|
|
{
|
|
|
|
|
if (parse->name)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
fprintf (stderr, "Fontconfig %s: \"%s\", line %d: ", s,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
parse->name, XML_GetCurrentLineNumber (parse->parser));
|
|
|
|
|
else
|
2002-05-21 19:06:22 +02:00
|
|
|
|
fprintf (stderr, "Fontconfig %s: line %d: ", s,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
XML_GetCurrentLineNumber (parse->parser));
|
2002-05-21 19:06:22 +02:00
|
|
|
|
if (severe >= FcSevereError)
|
|
|
|
|
parse->error = FcTrue;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2002-05-21 19:06:22 +02:00
|
|
|
|
fprintf (stderr, "Fontconfig %s: ", s);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
vfprintf (stderr, fmt, args);
|
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcVStackPush (FcConfigParse *parse, FcVStack *vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->prev = parse->vstack;
|
|
|
|
|
vstack->pstack = parse->pstack ? parse->pstack->prev : 0;
|
|
|
|
|
parse->vstack = vstack;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcVStack *
|
|
|
|
|
FcVStackCreate (void)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *new;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new = malloc (sizeof (FcVStack));
|
|
|
|
|
if (!new)
|
|
|
|
|
return 0;
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_VSTACK, sizeof (FcVStack));
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new->tag = FcVStackNone;
|
|
|
|
|
new->prev = 0;
|
|
|
|
|
return new;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcVStackDestroy (FcVStack *vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *prev;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
for (; vstack; vstack = prev)
|
|
|
|
|
{
|
|
|
|
|
prev = vstack->prev;
|
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackNone:
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackString:
|
|
|
|
|
case FcVStackFamily:
|
|
|
|
|
case FcVStackField:
|
|
|
|
|
case FcVStackConstant:
|
2003-05-07 18:13:24 +02:00
|
|
|
|
case FcVStackGlob:
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcStrFree (vstack->u.string);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackInteger:
|
|
|
|
|
case FcVStackDouble:
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackMatrix:
|
|
|
|
|
FcMatrixFree (vstack->u.matrix);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackBool:
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackTest:
|
|
|
|
|
FcTestDestroy (vstack->u.test);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackExpr:
|
|
|
|
|
case FcVStackPrefer:
|
|
|
|
|
case FcVStackAccept:
|
|
|
|
|
case FcVStackDefault:
|
|
|
|
|
FcExprDestroy (vstack->u.expr);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackEdit:
|
|
|
|
|
FcEditDestroy (vstack->u.edit);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemFree (FC_MEM_VSTACK, sizeof (FcVStack));
|
2002-02-18 23:29:28 +01:00
|
|
|
|
free (vstack);
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushString (FcConfigParse *parse, FcVStackTag tag, FcChar8 *string)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
|
|
|
|
return FcFalse;
|
|
|
|
|
vstack->u.string = string;
|
|
|
|
|
vstack->tag = tag;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushInteger (FcConfigParse *parse, int integer)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->u.integer = integer;
|
|
|
|
|
vstack->tag = FcVStackInteger;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushDouble (FcConfigParse *parse, double _double)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->u._double = _double;
|
|
|
|
|
vstack->tag = FcVStackDouble;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushMatrix (FcConfigParse *parse, FcMatrix *matrix)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
matrix = FcMatrixCopy (matrix);
|
|
|
|
|
if (!matrix)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
return FcFalse;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->u.matrix = matrix;
|
|
|
|
|
vstack->tag = FcVStackMatrix;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushBool (FcConfigParse *parse, FcBool bool)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
|
|
|
|
return FcFalse;
|
|
|
|
|
vstack->u.bool = bool;
|
|
|
|
|
vstack->tag = FcVStackBool;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcBool
|
|
|
|
|
FcVStackPushTest (FcConfigParse *parse, FcTest *test)
|
|
|
|
|
{
|
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->u.test = test;
|
|
|
|
|
vstack->tag = FcVStackTest;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushExpr (FcConfigParse *parse, FcVStackTag tag, FcExpr *expr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
|
|
|
|
return FcFalse;
|
|
|
|
|
vstack->u.expr = expr;
|
|
|
|
|
vstack->tag = tag;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcBool
|
|
|
|
|
FcVStackPushEdit (FcConfigParse *parse, FcEdit *edit)
|
|
|
|
|
{
|
|
|
|
|
FcVStack *vstack = FcVStackCreate ();
|
|
|
|
|
if (!vstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
vstack->u.edit = edit;
|
|
|
|
|
vstack->tag = FcVStackEdit;
|
|
|
|
|
FcVStackPush (parse, vstack);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcVStack *
|
|
|
|
|
FcVStackFetch (FcConfigParse *parse, int off)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
for (vstack = parse->vstack; vstack && off-- > 0; vstack = vstack->prev);
|
|
|
|
|
return vstack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcVStackClear (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
while (parse->vstack && parse->vstack->pstack == parse->pstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = parse->vstack;
|
|
|
|
|
parse->vstack = vstack->prev;
|
|
|
|
|
vstack->prev = 0;
|
|
|
|
|
FcVStackDestroy (vstack);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcVStack *
|
|
|
|
|
FcVStackPop (FcConfigParse *parse)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = parse->vstack;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!vstack || vstack->pstack != parse->pstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return 0;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
parse->vstack = vstack->prev;
|
|
|
|
|
vstack->prev = 0;
|
|
|
|
|
return vstack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
FcVStackElements (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
int h = 0;
|
|
|
|
|
FcVStack *vstack = parse->vstack;
|
|
|
|
|
while (vstack && vstack->pstack == parse->pstack)
|
|
|
|
|
{
|
|
|
|
|
h++;
|
|
|
|
|
vstack = vstack->prev;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return h;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcChar8 **
|
|
|
|
|
FcConfigSaveAttr (const XML_Char **attr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
int n;
|
|
|
|
|
int slen;
|
|
|
|
|
int i;
|
|
|
|
|
FcChar8 **new;
|
|
|
|
|
FcChar8 *s;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!attr)
|
|
|
|
|
return 0;
|
|
|
|
|
slen = 0;
|
|
|
|
|
for (i = 0; attr[i]; i++)
|
|
|
|
|
slen += strlen (attr[i]) + 1;
|
|
|
|
|
n = i;
|
|
|
|
|
new = malloc ((i + 1) * sizeof (FcChar8 *) + slen);
|
|
|
|
|
if (!new)
|
|
|
|
|
return 0;
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_ATTR, 1); /* size is too expensive */
|
2002-02-18 23:29:28 +01:00
|
|
|
|
s = (FcChar8 *) (new + (i + 1));
|
|
|
|
|
for (i = 0; attr[i]; i++)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new[i] = s;
|
|
|
|
|
strcpy ((char *) s, (char *) attr[i]);
|
|
|
|
|
s += strlen ((char *) s) + 1;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new[i] = 0;
|
|
|
|
|
return new;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcBool
|
|
|
|
|
FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
|
|
|
|
|
{
|
|
|
|
|
FcPStack *new = malloc (sizeof (FcPStack));
|
|
|
|
|
|
|
|
|
|
if (!new)
|
|
|
|
|
return FcFalse;
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack));
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new->prev = parse->pstack;
|
|
|
|
|
new->element = element;
|
|
|
|
|
if (attr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new->attr = FcConfigSaveAttr (attr);
|
|
|
|
|
if (!new->attr)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
new->attr = 0;
|
|
|
|
|
FcStrBufInit (&new->str, 0, 0);
|
|
|
|
|
parse->pstack = new;
|
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcBool
|
|
|
|
|
FcPStackPop (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcPStack *old;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "mismatching element");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return FcFalse;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackClear (parse);
|
|
|
|
|
old = parse->pstack;
|
|
|
|
|
parse->pstack = old->prev;
|
|
|
|
|
FcStrBufDestroy (&old->str);
|
|
|
|
|
if (old->attr)
|
2002-09-01 00:17:32 +02:00
|
|
|
|
{
|
|
|
|
|
FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
|
2002-02-18 23:29:28 +01:00
|
|
|
|
free (old->attr);
|
2002-09-01 00:17:32 +02:00
|
|
|
|
}
|
|
|
|
|
FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
|
2002-02-18 23:29:28 +01:00
|
|
|
|
free (old);
|
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcBool
|
|
|
|
|
FcConfigInit (FcConfigParse *parse, const FcChar8 *name, FcConfig *config, XML_Parser parser)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
parse->pstack = 0;
|
|
|
|
|
parse->vstack = 0;
|
|
|
|
|
parse->error = FcFalse;
|
|
|
|
|
parse->name = name;
|
|
|
|
|
parse->config = config;
|
|
|
|
|
parse->parser = parser;
|
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcConfigCleanup (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
while (parse->pstack)
|
|
|
|
|
FcPStackPop (parse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const FcChar8 *
|
|
|
|
|
FcConfigGetAttribute (FcConfigParse *parse, char *attr)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 **attrs;
|
|
|
|
|
if (!parse->pstack)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
attrs = parse->pstack->attr;
|
|
|
|
|
while (*attrs)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!strcmp ((char *) *attrs, attr))
|
|
|
|
|
return attrs[1];
|
|
|
|
|
attrs += 2;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcStartElement(void *userData, const XML_Char *name, const XML_Char **attr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcConfigParse *parse = userData;
|
|
|
|
|
FcElement element;
|
|
|
|
|
|
|
|
|
|
element = FcElementMap (name);
|
|
|
|
|
if (element == FcElementUnknown)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "unknown element \"%s\"", name);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
if (!FcPStackPush (parse, element, attr))
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcParseBlank (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
int n = FcVStackElements (parse);
|
|
|
|
|
while (n-- > 0)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *v = FcVStackFetch (parse, n);
|
|
|
|
|
if (v->tag != FcVStackInteger)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "non-integer blank");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!parse->config->blanks)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
parse->config->blanks = FcBlanksCreate ();
|
|
|
|
|
if (!parse->config->blanks)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!FcBlanksAdd (parse->config->blanks, v->u.integer))
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-05-21 19:06:22 +02:00
|
|
|
|
static void
|
|
|
|
|
FcParseRescan (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
int n = FcVStackElements (parse);
|
|
|
|
|
while (n-- > 0)
|
|
|
|
|
{
|
|
|
|
|
FcVStack *v = FcVStackFetch (parse, n);
|
|
|
|
|
if (v->tag != FcVStackInteger)
|
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "non-integer rescan");
|
|
|
|
|
else
|
|
|
|
|
parse->config->rescanInterval = v->u.integer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcParseInt (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 *s, *end;
|
|
|
|
|
int l;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
end = 0;
|
|
|
|
|
l = (int) strtol ((char *) s, (char **)&end, 0);
|
|
|
|
|
if (end != s + strlen ((char *) s))
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid integer", s);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcVStackPushInteger (parse, l);
|
|
|
|
|
FcStrFree (s);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-26 18:11:29 +02:00
|
|
|
|
/*
|
|
|
|
|
* idea copied from glib g_ascii_strtod with
|
|
|
|
|
* permission of the author (Alexander Larsson)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
|
|
static double
|
|
|
|
|
FcStrtod (char *s, char **end)
|
|
|
|
|
{
|
|
|
|
|
struct lconv *locale_data;
|
|
|
|
|
char *dot;
|
|
|
|
|
double v;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Have to swap the decimal point to match the current locale
|
|
|
|
|
* if that locale doesn't use 0x2e
|
|
|
|
|
*/
|
|
|
|
|
if ((dot = strchr (s, 0x2e)) &&
|
|
|
|
|
(locale_data = localeconv ()) &&
|
|
|
|
|
(locale_data->decimal_point[0] != 0x2e ||
|
|
|
|
|
locale_data->decimal_point[1] != 0))
|
|
|
|
|
{
|
|
|
|
|
char buf[128];
|
|
|
|
|
int slen = strlen (s);
|
|
|
|
|
int dlen = strlen (locale_data->decimal_point);
|
|
|
|
|
|
|
|
|
|
if (slen + dlen > sizeof (buf))
|
|
|
|
|
{
|
|
|
|
|
if (end)
|
|
|
|
|
*end = s;
|
|
|
|
|
v = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *buf_end;
|
|
|
|
|
/* mantissa */
|
|
|
|
|
strncpy (buf, s, dot - s);
|
|
|
|
|
/* decimal point */
|
|
|
|
|
strcpy (buf + (dot - s), locale_data->decimal_point);
|
|
|
|
|
/* rest of number */
|
|
|
|
|
strcpy (buf + (dot - s) + dlen, dot + 1);
|
|
|
|
|
buf_end = 0;
|
|
|
|
|
v = strtod (buf, &buf_end);
|
|
|
|
|
if (buf_end)
|
2003-07-09 19:04:17 +02:00
|
|
|
|
buf_end = s + (buf_end - buf) + 1 - dlen;
|
2002-06-26 18:11:29 +02:00
|
|
|
|
if (end)
|
|
|
|
|
*end = buf_end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
v = strtod (s, end);
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcParseDouble (FcConfigParse *parse)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcChar8 *s, *end;
|
|
|
|
|
double d;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
end = 0;
|
2002-06-26 18:11:29 +02:00
|
|
|
|
d = FcStrtod ((char *) s, (char **)&end);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (end != s + strlen ((char *) s))
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid double", s);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
else
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStackPushDouble (parse, d);
|
|
|
|
|
FcStrFree (s);
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcParseString (FcConfigParse *parse, FcVStackTag tag)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 *s;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!FcVStackPushString (parse, tag, s))
|
|
|
|
|
FcStrFree (s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseMatrix (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcVStack *vstack;
|
|
|
|
|
enum { m_done, m_xx, m_xy, m_yx, m_yy } matrix_state = m_yy;
|
|
|
|
|
FcMatrix m;
|
|
|
|
|
|
|
|
|
|
while ((vstack = FcVStackPop (parse)))
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
double v;
|
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackInteger:
|
|
|
|
|
v = vstack->u.integer;
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackDouble:
|
|
|
|
|
v = vstack->u._double;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "non-double matrix element");
|
|
|
|
|
v = 1.0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (matrix_state) {
|
|
|
|
|
case m_xx: m.xx = v; break;
|
|
|
|
|
case m_xy: m.xy = v; break;
|
|
|
|
|
case m_yx: m.yx = v; break;
|
|
|
|
|
case m_yy: m.yy = v; break;
|
|
|
|
|
default: break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
2002-08-21 01:17:03 +02:00
|
|
|
|
FcVStackDestroy (vstack);
|
2002-05-21 19:06:22 +02:00
|
|
|
|
matrix_state--;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
if (matrix_state != m_done)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "wrong number of matrix elements");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcVStackPushMatrix (parse, &m);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FcBool
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcConfigLexBool (const FcChar8 *bool)
|
|
|
|
|
{
|
|
|
|
|
if (*bool == 't' || *bool == 'T')
|
|
|
|
|
return FcTrue;
|
|
|
|
|
if (*bool == 'y' || *bool == 'Y')
|
|
|
|
|
return FcTrue;
|
|
|
|
|
if (*bool == '1')
|
|
|
|
|
return FcTrue;
|
|
|
|
|
return FcFalse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseBool (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 *s;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FcVStackPushBool (parse, FcConfigLexBool (s));
|
|
|
|
|
FcStrFree (s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseFamilies (FcConfigParse *parse, FcVStackTag tag)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack;
|
|
|
|
|
FcExpr *left, *expr = 0, *new;
|
|
|
|
|
|
|
|
|
|
while ((vstack = FcVStackPop (parse)))
|
|
|
|
|
{
|
|
|
|
|
if (vstack->tag != FcVStackFamily)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "non-family");
|
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
continue;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
left = vstack->u.expr;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
if (expr)
|
|
|
|
|
{
|
|
|
|
|
new = FcExprCreateOp (left, FcOpComma, expr);
|
|
|
|
|
if (!new)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcExprDestroy (left);
|
|
|
|
|
FcExprDestroy (expr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
expr = new;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
expr = left;
|
|
|
|
|
}
|
|
|
|
|
if (expr)
|
|
|
|
|
{
|
|
|
|
|
if (!FcVStackPushExpr (parse, tag, expr))
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (expr)
|
|
|
|
|
FcExprDestroy (expr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseFamily (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 *s;
|
|
|
|
|
FcExpr *expr;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
expr = FcExprCreateString (s);
|
|
|
|
|
FcStrFree (s);
|
|
|
|
|
if (expr)
|
|
|
|
|
FcVStackPushExpr (parse, FcVStackFamily, expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseAlias (FcConfigParse *parse)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcExpr *family = 0, *accept = 0, *prefer = 0, *def = 0, *new = 0;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcEdit *edit = 0, *next;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcTest *test;
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
while ((vstack = FcVStackPop (parse)))
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackFamily:
|
|
|
|
|
if (family)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
{
|
|
|
|
|
new = FcExprCreateOp (vstack->u.expr, FcOpComma, family);
|
|
|
|
|
if (!new)
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
else
|
|
|
|
|
family = new;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
new = vstack->u.expr;
|
|
|
|
|
if (new)
|
|
|
|
|
{
|
|
|
|
|
family = new;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcVStackPrefer:
|
|
|
|
|
if (prefer)
|
|
|
|
|
FcExprDestroy (prefer);
|
|
|
|
|
prefer = vstack->u.expr;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackAccept:
|
|
|
|
|
if (accept)
|
|
|
|
|
FcExprDestroy (accept);
|
|
|
|
|
accept = vstack->u.expr;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackDefault:
|
|
|
|
|
if (def)
|
|
|
|
|
FcExprDestroy (def);
|
|
|
|
|
def = vstack->u.expr;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "bad alias");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FcVStackDestroy (vstack);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-15 07:01:28 +01:00
|
|
|
|
if (!family)
|
2002-02-18 23:29:28 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "missing family in alias");
|
|
|
|
|
if (prefer)
|
|
|
|
|
FcExprDestroy (prefer);
|
|
|
|
|
if (accept)
|
|
|
|
|
FcExprDestroy (accept);
|
|
|
|
|
if (def)
|
|
|
|
|
FcExprDestroy (def);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-02-15 00:34:13 +01:00
|
|
|
|
if (prefer)
|
|
|
|
|
{
|
|
|
|
|
edit = FcEditCreate (FcConfigSaveField ("family"),
|
|
|
|
|
FcOpPrepend,
|
2002-07-31 03:36:37 +02:00
|
|
|
|
prefer,
|
|
|
|
|
FcValueBindingWeak);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
if (edit)
|
|
|
|
|
edit->next = 0;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcExprDestroy (prefer);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
if (accept)
|
|
|
|
|
{
|
|
|
|
|
next = edit;
|
|
|
|
|
edit = FcEditCreate (FcConfigSaveField ("family"),
|
|
|
|
|
FcOpAppend,
|
2002-07-31 03:36:37 +02:00
|
|
|
|
accept,
|
|
|
|
|
FcValueBindingWeak);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
if (edit)
|
|
|
|
|
edit->next = next;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcExprDestroy (accept);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
if (def)
|
|
|
|
|
{
|
|
|
|
|
next = edit;
|
|
|
|
|
edit = FcEditCreate (FcConfigSaveField ("family"),
|
2002-07-31 03:36:37 +02:00
|
|
|
|
FcOpAppendLast,
|
|
|
|
|
def,
|
|
|
|
|
FcValueBindingWeak);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
if (edit)
|
|
|
|
|
edit->next = next;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcExprDestroy (def);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
if (edit)
|
|
|
|
|
{
|
2002-08-11 20:11:04 +02:00
|
|
|
|
test = FcTestCreate (FcMatchPattern,
|
|
|
|
|
FcQualAny,
|
2002-06-18 18:47:33 +02:00
|
|
|
|
(FcChar8 *) FC_FAMILY,
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcOpEqual,
|
|
|
|
|
family);
|
|
|
|
|
if (test)
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!FcConfigAddEdit (parse->config, test, edit, FcMatchPattern))
|
|
|
|
|
FcTestDestroy (test);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
FcExprDestroy (family);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcExpr *
|
|
|
|
|
FcPopExpr (FcConfigParse *parse)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcVStack *vstack = FcVStackPop (parse);
|
|
|
|
|
FcExpr *expr = 0;
|
|
|
|
|
if (!vstack)
|
|
|
|
|
return 0;
|
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackNone:
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackString:
|
|
|
|
|
case FcVStackFamily:
|
2002-02-22 19:54:07 +01:00
|
|
|
|
expr = FcExprCreateString (vstack->u.string);
|
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
case FcVStackField:
|
2002-02-22 19:54:07 +01:00
|
|
|
|
expr = FcExprCreateField ((char *) vstack->u.string);
|
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
case FcVStackConstant:
|
2002-02-22 19:54:07 +01:00
|
|
|
|
expr = FcExprCreateConst (vstack->u.string);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcVStackPrefer:
|
|
|
|
|
case FcVStackAccept:
|
|
|
|
|
case FcVStackDefault:
|
|
|
|
|
expr = vstack->u.expr;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackInteger:
|
|
|
|
|
expr = FcExprCreateInteger (vstack->u.integer);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackDouble:
|
|
|
|
|
expr = FcExprCreateDouble (vstack->u._double);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackMatrix:
|
|
|
|
|
expr = FcExprCreateMatrix (vstack->u.matrix);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackBool:
|
|
|
|
|
expr = FcExprCreateBool (vstack->u.bool);
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackTest:
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackExpr:
|
|
|
|
|
expr = vstack->u.expr;
|
2002-06-02 21:51:36 +02:00
|
|
|
|
vstack->tag = FcVStackNone;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcVStackEdit:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-16 01:38:06 +02:00
|
|
|
|
/*
|
|
|
|
|
* This builds a tree of binary operations. Note
|
|
|
|
|
* that every operator is defined so that if only
|
|
|
|
|
* a single operand is contained, the value of the
|
|
|
|
|
* whole expression is the value of the operand.
|
|
|
|
|
*
|
|
|
|
|
* This code reduces in that case to returning that
|
|
|
|
|
* operand.
|
|
|
|
|
*/
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static FcExpr *
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcPopBinary (FcConfigParse *parse, FcOp op)
|
2002-02-18 23:29:28 +01:00
|
|
|
|
{
|
|
|
|
|
FcExpr *left, *expr = 0, *new;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
while ((left = FcPopExpr (parse)))
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (expr)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
new = FcExprCreateOp (left, op, expr);
|
|
|
|
|
if (!new)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcExprDestroy (left);
|
|
|
|
|
FcExprDestroy (expr);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
expr = new;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
expr = left;
|
|
|
|
|
}
|
|
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (FcConfigParse *parse, FcOp op)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *expr = FcPopBinary (parse, op);
|
|
|
|
|
if (expr)
|
|
|
|
|
FcVStackPushExpr (parse, FcVStackExpr, expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This builds a a unary operator, it consumes only
|
|
|
|
|
* a single operand
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static FcExpr *
|
|
|
|
|
FcPopUnary (FcConfigParse *parse, FcOp op)
|
|
|
|
|
{
|
|
|
|
|
FcExpr *operand, *new = 0;
|
|
|
|
|
|
|
|
|
|
if ((operand = FcPopExpr (parse)))
|
|
|
|
|
{
|
|
|
|
|
new = FcExprCreateOp (operand, op, 0);
|
|
|
|
|
if (!new)
|
|
|
|
|
{
|
|
|
|
|
FcExprDestroy (operand);
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseUnary (FcConfigParse *parse, FcOp op)
|
2002-02-18 23:29:28 +01:00
|
|
|
|
{
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcExpr *expr = FcPopUnary (parse, op);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (expr)
|
|
|
|
|
FcVStackPushExpr (parse, FcVStackExpr, expr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseInclude (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
FcChar8 *s;
|
|
|
|
|
const FcChar8 *i;
|
|
|
|
|
FcBool ignore_missing = FcFalse;
|
|
|
|
|
|
|
|
|
|
s = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!s)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
i = FcConfigGetAttribute (parse, "ignore_missing");
|
|
|
|
|
if (i && FcConfigLexBool ((FcChar8 *) i) == FcTrue)
|
|
|
|
|
ignore_missing = FcTrue;
|
2002-02-20 01:32:30 +01:00
|
|
|
|
if (!FcConfigParseAndLoad (parse->config, s, !ignore_missing))
|
2002-02-18 23:29:28 +01:00
|
|
|
|
parse->error = FcTrue;
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcStrFree (s);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct _FcOpMap {
|
|
|
|
|
char *name;
|
|
|
|
|
FcOp op;
|
|
|
|
|
} FcOpMap;
|
|
|
|
|
|
|
|
|
|
static FcOp
|
|
|
|
|
FcConfigLexOp (const FcChar8 *op, const FcOpMap *map, int nmap)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nmap; i++)
|
|
|
|
|
if (!strcmp ((char *) op, map[i].name))
|
|
|
|
|
return map[i].op;
|
|
|
|
|
return FcOpInvalid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const FcOpMap fcCompareOps[] = {
|
|
|
|
|
{ "eq", FcOpEqual },
|
|
|
|
|
{ "not_eq", FcOpNotEqual },
|
|
|
|
|
{ "less", FcOpLess },
|
|
|
|
|
{ "less_eq", FcOpLessEqual },
|
|
|
|
|
{ "more", FcOpMore },
|
2002-08-22 20:53:22 +02:00
|
|
|
|
{ "more_eq", FcOpMoreEqual },
|
|
|
|
|
{ "contains", FcOpContains },
|
|
|
|
|
{ "not_contains", FcOpNotContains }
|
2002-02-18 23:29:28 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define NUM_COMPARE_OPS (sizeof fcCompareOps / sizeof fcCompareOps[0])
|
|
|
|
|
|
|
|
|
|
static FcOp
|
|
|
|
|
FcConfigLexCompare (const FcChar8 *compare)
|
|
|
|
|
{
|
|
|
|
|
return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseTest (FcConfigParse *parse)
|
|
|
|
|
{
|
2002-08-11 20:11:04 +02:00
|
|
|
|
const FcChar8 *kind_string;
|
|
|
|
|
FcMatchKind kind;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
const FcChar8 *qual_string;
|
|
|
|
|
FcQual qual;
|
|
|
|
|
const FcChar8 *name;
|
|
|
|
|
const FcChar8 *compare_string;
|
|
|
|
|
FcOp compare;
|
|
|
|
|
FcExpr *expr;
|
|
|
|
|
FcTest *test;
|
|
|
|
|
|
2002-08-11 20:11:04 +02:00
|
|
|
|
kind_string = FcConfigGetAttribute (parse, "target");
|
|
|
|
|
if (!kind_string)
|
|
|
|
|
kind = FcMatchDefault;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp ((char *) kind_string, "pattern"))
|
|
|
|
|
kind = FcMatchPattern;
|
|
|
|
|
else if (!strcmp ((char *) kind_string, "font"))
|
|
|
|
|
kind = FcMatchFont;
|
|
|
|
|
else if (!strcmp ((char *) kind_string, "default"))
|
|
|
|
|
kind = FcMatchDefault;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid test target \"%s\"", kind_string);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
qual_string = FcConfigGetAttribute (parse, "qual");
|
|
|
|
|
if (!qual_string)
|
|
|
|
|
qual = FcQualAny;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp ((char *) qual_string, "any"))
|
|
|
|
|
qual = FcQualAny;
|
|
|
|
|
else if (!strcmp ((char *) qual_string, "all"))
|
|
|
|
|
qual = FcQualAll;
|
2002-06-19 22:08:22 +02:00
|
|
|
|
else if (!strcmp ((char *) qual_string, "first"))
|
|
|
|
|
qual = FcQualFirst;
|
|
|
|
|
else if (!strcmp ((char *) qual_string, "not_first"))
|
|
|
|
|
qual = FcQualNotFirst;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid test qual \"%s\"", qual_string);
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
name = FcConfigGetAttribute (parse, "name");
|
|
|
|
|
if (!name)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "missing test name");
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
compare_string = FcConfigGetAttribute (parse, "compare");
|
|
|
|
|
if (!compare_string)
|
|
|
|
|
compare = FcOpEqual;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
compare = FcConfigLexCompare (compare_string);
|
|
|
|
|
if (compare == FcOpInvalid)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid test compare \"%s\"", compare_string);
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
2003-04-16 01:38:06 +02:00
|
|
|
|
expr = FcPopBinary (parse, FcOpComma);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!expr)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "missing test expression");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-08-11 20:11:04 +02:00
|
|
|
|
test = FcTestCreate (kind, qual, name, compare, expr);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!test)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FcVStackPushTest (parse, test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const FcOpMap fcModeOps[] = {
|
|
|
|
|
{ "assign", FcOpAssign },
|
|
|
|
|
{ "assign_replace", FcOpAssignReplace },
|
|
|
|
|
{ "prepend", FcOpPrepend },
|
|
|
|
|
{ "prepend_first", FcOpPrependFirst },
|
|
|
|
|
{ "append", FcOpAppend },
|
|
|
|
|
{ "append_last", FcOpAppendLast },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define NUM_MODE_OPS (sizeof fcModeOps / sizeof fcModeOps[0])
|
|
|
|
|
|
|
|
|
|
static FcOp
|
|
|
|
|
FcConfigLexMode (const FcChar8 *mode)
|
|
|
|
|
{
|
|
|
|
|
return FcConfigLexOp (mode, fcModeOps, NUM_MODE_OPS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseEdit (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
const FcChar8 *name;
|
|
|
|
|
const FcChar8 *mode_string;
|
2002-07-31 03:36:37 +02:00
|
|
|
|
const FcChar8 *binding_string;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcOp mode;
|
2002-07-31 03:36:37 +02:00
|
|
|
|
FcValueBinding binding;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcExpr *expr;
|
|
|
|
|
FcEdit *edit;
|
|
|
|
|
|
|
|
|
|
name = FcConfigGetAttribute (parse, "name");
|
|
|
|
|
if (!name)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "missing edit name");
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
mode_string = FcConfigGetAttribute (parse, "mode");
|
|
|
|
|
if (!mode_string)
|
2002-06-02 21:51:36 +02:00
|
|
|
|
mode = FcOpAssign;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mode = FcConfigLexMode (mode_string);
|
|
|
|
|
if (mode == FcOpInvalid)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid edit mode \"%s\"", mode_string);
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
2002-07-31 03:36:37 +02:00
|
|
|
|
binding_string = FcConfigGetAttribute (parse, "binding");
|
|
|
|
|
if (!binding_string)
|
|
|
|
|
binding = FcValueBindingWeak;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp ((char *) binding_string, "weak"))
|
|
|
|
|
binding = FcValueBindingWeak;
|
|
|
|
|
else if (!strcmp ((char *) binding_string, "strong"))
|
|
|
|
|
binding = FcValueBindingStrong;
|
2003-02-12 19:22:12 +01:00
|
|
|
|
else if (!strcmp ((char *) binding_string, "same"))
|
|
|
|
|
binding = FcValueBindingSame;
|
2002-07-31 03:36:37 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid edit binding \"%s\"", binding_string);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-16 01:38:06 +02:00
|
|
|
|
expr = FcPopBinary (parse, FcOpComma);
|
2002-07-31 03:36:37 +02:00
|
|
|
|
edit = FcEditCreate ((char *) FcStrCopy (name), mode, expr, binding);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!edit)
|
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
FcExprDestroy (expr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!FcVStackPushEdit (parse, edit))
|
|
|
|
|
FcEditDestroy (edit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcParseMatch (FcConfigParse *parse)
|
|
|
|
|
{
|
|
|
|
|
const FcChar8 *kind_name;
|
|
|
|
|
FcMatchKind kind;
|
|
|
|
|
FcTest *test = 0;
|
|
|
|
|
FcEdit *edit = 0;
|
|
|
|
|
FcVStack *vstack;
|
|
|
|
|
|
|
|
|
|
kind_name = FcConfigGetAttribute (parse, "target");
|
|
|
|
|
if (!kind_name)
|
|
|
|
|
kind = FcMatchPattern;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp ((char *) kind_name, "pattern"))
|
|
|
|
|
kind = FcMatchPattern;
|
|
|
|
|
else if (!strcmp ((char *) kind_name, "font"))
|
|
|
|
|
kind = FcMatchFont;
|
|
|
|
|
else
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid match target \"%s\"", kind_name);
|
2002-07-12 21:19:16 +02:00
|
|
|
|
return;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
while ((vstack = FcVStackPop (parse)))
|
|
|
|
|
{
|
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackTest:
|
|
|
|
|
vstack->u.test->next = test;
|
|
|
|
|
test = vstack->u.test;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
case FcVStackEdit:
|
|
|
|
|
vstack->u.edit->next = edit;
|
|
|
|
|
edit = vstack->u.edit;
|
|
|
|
|
vstack->tag = FcVStackNone;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "invalid match element");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
}
|
|
|
|
|
if (!FcConfigAddEdit (parse->config, test, edit, kind))
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-07 18:13:24 +02:00
|
|
|
|
static void
|
|
|
|
|
FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element)
|
|
|
|
|
{
|
|
|
|
|
FcVStack *vstack;
|
|
|
|
|
|
|
|
|
|
while ((vstack = FcVStackPop (parse)))
|
|
|
|
|
{
|
|
|
|
|
switch (vstack->tag) {
|
|
|
|
|
case FcVStackGlob:
|
|
|
|
|
if (!FcConfigGlobAdd (parse->config,
|
|
|
|
|
vstack->u.string,
|
|
|
|
|
element == FcElementAcceptfont))
|
|
|
|
|
{
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
FcConfigMessage (parse, FcSevereWarning, "bad font selector");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FcVStackDestroy (vstack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
static void
|
|
|
|
|
FcEndElement(void *userData, const XML_Char *name)
|
|
|
|
|
{
|
|
|
|
|
FcConfigParse *parse = userData;
|
|
|
|
|
FcChar8 *data;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
switch (parse->pstack->element) {
|
|
|
|
|
case FcElementNone:
|
|
|
|
|
break;
|
|
|
|
|
case FcElementFontconfig:
|
|
|
|
|
break;
|
|
|
|
|
case FcElementDir:
|
|
|
|
|
data = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!data)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2003-03-22 22:25:34 +01:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (strcmp (data, "WINDOWSFONTDIR") == 0)
|
|
|
|
|
{
|
|
|
|
|
int rc;
|
|
|
|
|
FcStrFree (data);
|
|
|
|
|
data = malloc (1000);
|
|
|
|
|
if (!data)
|
|
|
|
|
{
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FcMemAlloc (FC_MEM_STRING, 1000);
|
|
|
|
|
rc = GetWindowsDirectory (data, 800);
|
|
|
|
|
if (rc == 0 || rc > 800)
|
|
|
|
|
{
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "GetWindowsDirectory failed");
|
|
|
|
|
FcStrFree (data);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (data [strlen (data) - 1] != '\\')
|
|
|
|
|
strcat (data, "\\");
|
|
|
|
|
strcat (data, "fonts");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2003-03-02 20:12:23 +01:00
|
|
|
|
if (!FcStrUsesHome (data) || FcConfigHome ())
|
|
|
|
|
{
|
|
|
|
|
if (!FcConfigAddDir (parse->config, data))
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
}
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcStrFree (data);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementCache:
|
|
|
|
|
data = FcStrBufDone (&parse->pstack->str);
|
|
|
|
|
if (!data)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-15 00:34:13 +01:00
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
2003-03-02 20:12:23 +01:00
|
|
|
|
if (!FcStrUsesHome (data) || FcConfigHome ())
|
|
|
|
|
{
|
|
|
|
|
if (!FcConfigSetCache (parse->config, data))
|
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
|
|
|
|
}
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcStrFree (data);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementInclude:
|
|
|
|
|
FcParseInclude (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementConfig:
|
|
|
|
|
break;
|
|
|
|
|
case FcElementMatch:
|
|
|
|
|
FcParseMatch (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementAlias:
|
|
|
|
|
FcParseAlias (parse);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FcElementBlank:
|
|
|
|
|
FcParseBlank (parse);
|
|
|
|
|
break;
|
2002-05-21 19:06:22 +02:00
|
|
|
|
case FcElementRescan:
|
|
|
|
|
FcParseRescan (parse);
|
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
|
|
|
|
|
case FcElementPrefer:
|
|
|
|
|
FcParseFamilies (parse, FcVStackPrefer);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementAccept:
|
|
|
|
|
FcParseFamilies (parse, FcVStackAccept);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementDefault:
|
|
|
|
|
FcParseFamilies (parse, FcVStackDefault);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementFamily:
|
|
|
|
|
FcParseFamily (parse);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FcElementTest:
|
|
|
|
|
FcParseTest (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementEdit:
|
|
|
|
|
FcParseEdit (parse);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FcElementInt:
|
|
|
|
|
FcParseInt (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementDouble:
|
|
|
|
|
FcParseDouble (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementString:
|
|
|
|
|
FcParseString (parse, FcVStackString);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementMatrix:
|
|
|
|
|
FcParseMatrix (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementBool:
|
|
|
|
|
FcParseBool (parse);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementCharset:
|
|
|
|
|
/* FcParseCharset (parse); */
|
|
|
|
|
break;
|
2003-05-07 18:13:24 +02:00
|
|
|
|
case FcElementSelectfont:
|
|
|
|
|
break;
|
|
|
|
|
case FcElementAcceptfont:
|
|
|
|
|
case FcElementRejectfont:
|
|
|
|
|
FcParseAcceptRejectFont (parse, parse->pstack->element);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementGlob:
|
|
|
|
|
FcParseString (parse, FcVStackGlob);
|
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
case FcElementName:
|
|
|
|
|
FcParseString (parse, FcVStackField);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementConst:
|
|
|
|
|
FcParseString (parse, FcVStackConstant);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementOr:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpOr);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementAnd:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpAnd);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementEq:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpEqual);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementNotEq:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpNotEqual);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementLess:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpLess);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementLessEq:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpLessEqual);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementMore:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpMore);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementMoreEq:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpMoreEqual);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
2002-08-22 20:53:22 +02:00
|
|
|
|
case FcElementContains:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpContains);
|
2002-08-22 20:53:22 +02:00
|
|
|
|
break;
|
|
|
|
|
case FcElementNotContains:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpNotContains);
|
2002-08-22 20:53:22 +02:00
|
|
|
|
break;
|
2002-02-18 23:29:28 +01:00
|
|
|
|
case FcElementPlus:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpPlus);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementMinus:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpMinus);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementTimes:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpTimes);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementDivide:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpDivide);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementNot:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseUnary (parse, FcOpNot);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementIf:
|
2003-04-16 01:38:06 +02:00
|
|
|
|
FcParseBinary (parse, FcOpQuest);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementFloor:
|
|
|
|
|
FcParseUnary (parse, FcOpFloor);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementCeil:
|
|
|
|
|
FcParseUnary (parse, FcOpCeil);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementRound:
|
|
|
|
|
FcParseUnary (parse, FcOpRound);
|
|
|
|
|
break;
|
|
|
|
|
case FcElementTrunc:
|
|
|
|
|
FcParseUnary (parse, FcOpTrunc);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
break;
|
|
|
|
|
case FcElementUnknown:
|
|
|
|
|
break;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
(void) FcPStackPop (parse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcCharacterData (void *userData, const XML_Char *s, int len)
|
|
|
|
|
{
|
|
|
|
|
FcConfigParse *parse = userData;
|
|
|
|
|
|
|
|
|
|
if (!parse->pstack)
|
|
|
|
|
return;
|
|
|
|
|
if (!FcStrBufData (&parse->pstack->str, (FcChar8 *) s, len))
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "out of memory");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcStartDoctypeDecl (void *userData,
|
|
|
|
|
const XML_Char *doctypeName,
|
|
|
|
|
const XML_Char *sysid,
|
|
|
|
|
const XML_Char *pubid,
|
|
|
|
|
int has_internal_subset)
|
|
|
|
|
{
|
|
|
|
|
FcConfigParse *parse = userData;
|
|
|
|
|
|
|
|
|
|
if (strcmp ((char *) doctypeName, "fontconfig") != 0)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (parse, FcSevereError, "invalid doctype \"%s\"", doctypeName);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
FcEndDoctypeDecl (void *userData)
|
|
|
|
|
{
|
2002-02-15 00:34:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
|
FcConfigParseAndLoad (FcConfig *config,
|
2002-02-18 23:29:28 +01:00
|
|
|
|
const FcChar8 *name,
|
2002-02-15 00:34:13 +01:00
|
|
|
|
FcBool complain)
|
|
|
|
|
{
|
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
XML_Parser p;
|
|
|
|
|
FcChar8 *filename;
|
|
|
|
|
FILE *f;
|
|
|
|
|
int len;
|
|
|
|
|
void *buf;
|
|
|
|
|
FcConfigParse parse;
|
|
|
|
|
FcBool error = FcTrue;
|
|
|
|
|
|
|
|
|
|
filename = FcConfigFilename (name);
|
|
|
|
|
if (!filename)
|
|
|
|
|
goto bail0;
|
2002-06-21 09:01:11 +02:00
|
|
|
|
|
|
|
|
|
if (!FcStrSetAdd (config->configFiles, filename))
|
2002-09-01 00:17:32 +02:00
|
|
|
|
{
|
|
|
|
|
FcStrFree (filename);
|
2002-06-21 09:01:11 +02:00
|
|
|
|
goto bail0;
|
2002-09-01 00:17:32 +02:00
|
|
|
|
}
|
2002-06-21 09:01:11 +02:00
|
|
|
|
|
2002-02-18 23:29:28 +01:00
|
|
|
|
f = fopen ((char *) filename, "r");
|
2002-09-01 00:17:32 +02:00
|
|
|
|
FcStrFree (filename);
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!f)
|
|
|
|
|
goto bail0;
|
|
|
|
|
|
|
|
|
|
p = XML_ParserCreate ("UTF-8");
|
|
|
|
|
if (!p)
|
|
|
|
|
goto bail1;
|
|
|
|
|
|
|
|
|
|
if (!FcConfigInit (&parse, name, config, p))
|
|
|
|
|
goto bail2;
|
|
|
|
|
|
|
|
|
|
XML_SetUserData (p, &parse);
|
|
|
|
|
|
|
|
|
|
XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl);
|
|
|
|
|
XML_SetElementHandler (p, FcStartElement, FcEndElement);
|
|
|
|
|
XML_SetCharacterDataHandler (p, FcCharacterData);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
buf = XML_GetBuffer (p, BUFSIZ);
|
|
|
|
|
if (!buf)
|
2002-02-28 17:51:48 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (&parse, FcSevereError, "cannot get parse buffer");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
goto bail3;
|
2002-02-28 17:51:48 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
len = fread (buf, 1, BUFSIZ, f);
|
|
|
|
|
if (len < 0)
|
2002-02-28 17:51:48 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (&parse, FcSevereError, "failed reading config file");
|
2002-02-18 23:29:28 +01:00
|
|
|
|
goto bail3;
|
2002-02-28 17:51:48 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (!XML_ParseBuffer (p, len, len == 0))
|
2002-02-28 17:51:48 +01:00
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (&parse, FcSevereError, "%s",
|
2002-02-28 17:51:48 +01:00
|
|
|
|
XML_ErrorString (XML_GetErrorCode (p)));
|
2002-02-18 23:29:28 +01:00
|
|
|
|
goto bail3;
|
2002-02-28 17:51:48 +01:00
|
|
|
|
}
|
2002-02-18 23:29:28 +01:00
|
|
|
|
} while (len != 0);
|
|
|
|
|
error = parse.error;
|
|
|
|
|
bail3:
|
|
|
|
|
FcConfigCleanup (&parse);
|
|
|
|
|
bail2:
|
|
|
|
|
XML_ParserFree (p);
|
|
|
|
|
bail1:
|
|
|
|
|
fclose (f);
|
|
|
|
|
bail0:
|
|
|
|
|
if (error && complain)
|
2002-02-15 00:34:13 +01:00
|
|
|
|
{
|
2002-02-18 23:29:28 +01:00
|
|
|
|
if (name)
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (0, FcSevereError, "Cannot load config file \"%s\"", name);
|
2002-02-15 00:34:13 +01:00
|
|
|
|
else
|
2002-05-21 19:06:22 +02:00
|
|
|
|
FcConfigMessage (0, FcSevereError, "Cannot load default config file");
|
2002-02-15 00:34:13 +01:00
|
|
|
|
return FcFalse;
|
|
|
|
|
}
|
|
|
|
|
return FcTrue;
|
|
|
|
|
}
|