]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcxml.c
Add "same" binding for edits to inherit binding from matched element
[fontconfig.git] / src / fcxml.c
index e265fa53ff620b92e966d5af63261138d957a2f2..257b6cc146acaa63d8c08d40862d7f89eb77eec8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.17 2002/07/31 01:36:37 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.21 2002/08/22 18:53:22 keithp Exp $
  *
  * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
  *
 #include <stdarg.h>
 #include "fcint.h"
 
-#ifndef HAVE_EXPAT
-#define HAVE_EXPAT 1
-#endif
-
-#ifndef HAVE_XML2
-#define HAVE_XML2 0
-#endif
-
-#if HAVE_EXPAT
 #ifndef HAVE_XMLPARSE_H
 #define HAVE_XMLPARSE_H 0
 #endif
+
 #if HAVE_XMLPARSE_H
 #include <xmlparse.h>
 #else
 #include <expat.h>
 #endif
-#endif
-
-#if HAVE_XML2
-#include "fclibxml2.h"
-#endif
 
 FcTest *
 FcTestCreate (FcMatchKind   kind, 
@@ -59,6 +46,7 @@ FcTestCreate (FcMatchKind   kind,
 
     if (test)
     {
+       FcMemAlloc (FC_MEM_TEST, sizeof (FcTest));
        test->next = 0;
        test->kind = kind;
        test->qual = qual;
@@ -76,6 +64,7 @@ FcTestDestroy (FcTest *test)
        FcTestDestroy (test->next);
     FcExprDestroy (test->expr);
     FcStrFree ((FcChar8 *) test->field);
+    FcMemFree (FC_MEM_TEST, sizeof (FcTest));
     free (test);
 }
 
@@ -86,6 +75,7 @@ FcExprCreateInteger (int i)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpInteger;
        e->u.ival = i;
     }
@@ -99,6 +89,7 @@ FcExprCreateDouble (double d)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpDouble;
        e->u.dval = d;
     }
@@ -112,6 +103,7 @@ FcExprCreateString (const FcChar8 *s)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpString;
        e->u.sval = FcStrCopy (s);
     }
@@ -125,6 +117,7 @@ FcExprCreateMatrix (const FcMatrix *m)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpMatrix;
        e->u.mval = FcMatrixCopy (m);
     }
@@ -138,6 +131,7 @@ FcExprCreateBool (FcBool b)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpBool;
        e->u.bval = b;
     }
@@ -151,6 +145,7 @@ FcExprCreateNil (void)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpNil;
     }
     return e;
@@ -163,6 +158,7 @@ FcExprCreateField (const char *field)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpField;
        e->u.field = (char *) FcStrCopy ((FcChar8 *) field);
     }
@@ -176,6 +172,7 @@ FcExprCreateConst (const FcChar8 *constant)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpConst;
        e->u.constant = FcStrCopy (constant);
     }
@@ -189,6 +186,7 @@ FcExprCreateOp (FcExpr *left, FcOp op, FcExpr *right)
 
     if (e)
     {
+       FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = op;
        e->u.tree.left = left;
        e->u.tree.right = right;
@@ -231,12 +229,13 @@ FcExprDestroy (FcExpr *e)
     case FcOpOr:
     case FcOpAnd:
     case FcOpEqual:
-    case FcOpContains:
     case FcOpNotEqual:
     case FcOpLess:
     case FcOpLessEqual:
     case FcOpMore:
     case FcOpMoreEqual:
+    case FcOpContains:
+    case FcOpNotContains:
     case FcOpPlus:
     case FcOpMinus:
     case FcOpTimes:
@@ -252,6 +251,7 @@ FcExprDestroy (FcExpr *e)
     case FcOpInvalid:
        break;
     }
+    FcMemFree (FC_MEM_EXPR, sizeof (FcExpr));
     free (e);
 }
 
@@ -323,6 +323,8 @@ typedef enum _FcElement {
     FcElementLessEq,
     FcElementMore,
     FcElementMoreEq,
+    FcElementContains,
+    FcElementNotContains,
     FcElementPlus,
     FcElementMinus,
     FcElementTimes,
@@ -373,6 +375,8 @@ FcElementMap (const XML_Char *name)
        { "less_eq",    FcElementLessEq },
        { "more",       FcElementMore },
        { "more_eq",    FcElementMoreEq },
+       { "contains",   FcElementContains },
+       { "not_contains",FcElementNotContains },
        { "plus",       FcElementPlus },
        { "minus",      FcElementMinus },
        { "times",      FcElementTimes },
@@ -499,6 +503,7 @@ FcVStackCreate (void)
     new = malloc (sizeof (FcVStack));
     if (!new)
        return 0;
+    FcMemAlloc (FC_MEM_VSTACK, sizeof (FcVStack));
     new->tag = FcVStackNone;
     new->prev = 0;
     return new;
@@ -542,6 +547,7 @@ FcVStackDestroy (FcVStack *vstack)
            FcEditDestroy (vstack->u.edit);
            break;
        }
+       FcMemFree (FC_MEM_VSTACK, sizeof (FcVStack));
        free (vstack);
     }
 }
@@ -712,6 +718,7 @@ FcConfigSaveAttr (const XML_Char **attr)
     new = malloc ((i + 1) * sizeof (FcChar8 *) + slen);
     if (!new)
        return 0;
+    FcMemAlloc (FC_MEM_ATTR, 1);    /* size is too expensive */
     s = (FcChar8 *) (new + (i + 1));
     for (i = 0; attr[i]; i++)
     {
@@ -730,6 +737,7 @@ FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
 
     if (!new)
        return FcFalse;
+    FcMemAlloc (FC_MEM_PSTACK, sizeof (FcPStack));
     new->prev = parse->pstack;
     new->element = element;
     if (attr)
@@ -760,7 +768,11 @@ FcPStackPop (FcConfigParse *parse)
     parse->pstack = old->prev;
     FcStrBufDestroy (&old->str);
     if (old->attr)
+    {
+       FcMemFree (FC_MEM_ATTR, 1); /* size is to expensive */
        free (old->attr);
+    }
+    FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
     free (old);
     return FcTrue;
 }
@@ -1009,6 +1021,7 @@ FcParseMatrix (FcConfigParse *parse)
        case m_yy: m.yy = v; break;
        default: break;
        }
+       FcVStackDestroy (vstack);
        matrix_state--;
     }
     if (matrix_state != m_done)
@@ -1324,7 +1337,7 @@ FcParseInclude (FcConfigParse *parse)
        ignore_missing = FcTrue;
     if (!FcConfigParseAndLoad (parse->config, s, !ignore_missing))
        parse->error = FcTrue;
-    free (s);
+    FcStrFree (s);
 }
 
 typedef struct _FcOpMap {
@@ -1349,7 +1362,9 @@ static const FcOpMap fcCompareOps[] = {
     { "less",          FcOpLess            },
     { "less_eq",       FcOpLessEqual       },
     { "more",          FcOpMore            },
-    { "more_eq",       FcOpMoreEqual       }
+    { "more_eq",       FcOpMoreEqual       },
+    { "contains",      FcOpContains        },
+    { "not_contains",  FcOpNotContains     }
 };
 
 #define NUM_COMPARE_OPS (sizeof fcCompareOps / sizeof fcCompareOps[0])
@@ -1498,6 +1513,8 @@ FcParseEdit (FcConfigParse *parse)
            binding = FcValueBindingWeak;
        else if (!strcmp ((char *) binding_string, "strong"))
            binding = FcValueBindingStrong;
+       else if (!strcmp ((char *) binding_string, "same"))
+           binding = FcValueBindingSame;
        else
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid edit binding \"%s\"", binding_string);
@@ -1585,7 +1602,7 @@ FcEndElement(void *userData, const XML_Char *name)
        }
        if (!FcConfigAddDir (parse->config, data))
            FcConfigMessage (parse, FcSevereError, "out of memory");
-       free (data);
+       FcStrFree (data);
        break;
     case FcElementCache:
        data = FcStrBufDone (&parse->pstack->str);
@@ -1596,7 +1613,7 @@ FcEndElement(void *userData, const XML_Char *name)
        }
        if (!FcConfigSetCache (parse->config, data))
            FcConfigMessage (parse, FcSevereError, "out of memory");
-       free (data);
+       FcStrFree (data);
        break;
     case FcElementInclude:
        FcParseInclude (parse);
@@ -1686,6 +1703,12 @@ FcEndElement(void *userData, const XML_Char *name)
     case FcElementMoreEq:
        FcParseExpr (parse, FcOpMoreEqual);
        break;
+    case FcElementContains:
+       FcParseExpr (parse, FcOpContains);
+       break;
+    case FcElementNotContains:
+       FcParseExpr (parse, FcOpNotContains);
+       break;
     case FcElementPlus:
        FcParseExpr (parse, FcOpPlus);
        break;
@@ -1758,10 +1781,13 @@ FcConfigParseAndLoad (FcConfig      *config,
        goto bail0;
     
     if (!FcStrSetAdd (config->configFiles, filename))
+    {
+       FcStrFree (filename);
        goto bail0;
+    }
 
     f = fopen ((char *) filename, "r");
-    free (filename);
+    FcStrFree (filename);
     if (!f)
        goto bail0;