]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcxml.c
Verify documentation covers exposed symbols.
[fontconfig.git] / src / fcxml.c
index f92bf567ce36a6a1b5416e793290d6ff3a045b58..e8cfe1fbdbaa078d2c74a139196f5fdd86639c2d 100644 (file)
@@ -65,7 +65,6 @@ FcTestDestroy (FcTest *test)
     if (test->next)
        FcTestDestroy (test->next);
     FcExprDestroy (test->expr);
-    FcStrFree ((FcChar8 *) test->field);
     FcMemFree (FC_MEM_TEST, sizeof (FcTest));
     free (test);
 }
@@ -162,7 +161,7 @@ FcExprCreateField (const char *field)
     {
        FcMemAlloc (FC_MEM_EXPR, sizeof (FcExpr));
        e->op = FcOpField;
-       e->u.field = (char *) FcStrCopy ((FcChar8 *) field);
+       e->u.object = FcObjectFromName (field);
     }
     return e;
 }
@@ -218,7 +217,6 @@ FcExprDestroy (FcExpr *e)
     case FcOpBool:
        break;
     case FcOpField:
-       FcStrFree ((FcChar8 *) e->u.field);
        break;
     case FcOpConst:
        FcStrFree (e->u.constant);
@@ -269,7 +267,6 @@ FcEditDestroy (FcEdit *e)
 {
     if (e->next)
        FcEditDestroy (e->next);
-    FcStrFree ((FcChar8 *) e->field);
     if (e->expr)
        FcExprDestroy (e->expr);
     free (e);
@@ -285,6 +282,7 @@ typedef enum _FcElement {
     FcElementNone,
     FcElementFontconfig,
     FcElementDir,
+    FcElementCacheDir,
     FcElementCache,
     FcElementInclude,
     FcElementConfig,
@@ -345,6 +343,7 @@ static const struct {
 } fcElementMap[] = {
     { "fontconfig",    FcElementFontconfig },
     { "dir",           FcElementDir },
+    { "cachedir",      FcElementCacheDir },
     { "cache",         FcElementCache },
     { "include",       FcElementInclude },
     { "config",                FcElementConfig },
@@ -546,6 +545,8 @@ FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type)
        if ((value == FcTypeLangSet && type == FcTypeString) ||
            (value == FcTypeString && type == FcTypeLangSet))
            return;
+       if (type == (FcType) -1)
+           return;
        FcConfigMessage (parse, FcSevereWarning, "saw %s, expected %s",
                         FcTypeName (value), FcTypeName (type));
     }
@@ -557,6 +558,10 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
     const FcObjectType *o;
     const FcConstant   *c;
     
+    /* If parsing the expression failed, some nodes may be NULL */
+    if (!expr)
+       return;
+
     switch (expr->op) {
     case FcOpInteger:
     case FcOpDouble:
@@ -577,7 +582,7 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
     case FcOpNil:
        break;
     case FcOpField:
-       o = FcNameGetObjectType (expr->u.field);
+       o = FcNameGetObjectType (FcObjectName (expr->u.object));
        if (o)
            FcTypecheckValue (parse, o->type, type);
        break;
@@ -657,10 +662,10 @@ FcTestCreate (FcConfigParse *parse,
        test->next = 0;
        test->kind = kind;
        test->qual = qual;
-       test->field = (char *) FcStrCopy (field);
+       test->object = FcObjectFromName ((const char *) field);
        test->op = compare;
        test->expr = expr;
-       o = FcNameGetObjectType (test->field);
+       o = FcNameGetObjectType (FcObjectName (test->object));
        if (o)
            FcTypecheckExpr (parse, expr, o->type);
     }
@@ -669,7 +674,7 @@ FcTestCreate (FcConfigParse *parse,
 
 static FcEdit *
 FcEditCreate (FcConfigParse    *parse,
-             const char        *field,
+             FcObject          object,
              FcOp              op,
              FcExpr            *expr,
              FcValueBinding    binding)
@@ -681,11 +686,11 @@ FcEditCreate (FcConfigParse       *parse,
        const FcObjectType      *o;
 
        e->next = 0;
-       e->field = field;   /* already saved in grammar */
+       e->object = object;
        e->op = op;
        e->expr = expr;
        e->binding = binding;
-       o = FcNameGetObjectType (e->field);
+       o = FcNameGetObjectType (FcObjectName (e->object));
        if (o)
            FcTypecheckExpr (parse, expr, o->type);
     }
@@ -1283,6 +1288,33 @@ FcParseBool (FcConfigParse *parse)
     FcStrFree (s);
 }
 
+static FcBool
+FcConfigLexBinding (FcConfigParse   *parse,
+                   const FcChar8   *binding_string,
+                   FcValueBinding  *binding_ret)
+{
+    FcValueBinding binding;
+    
+    if (!binding_string)
+       binding = FcValueBindingWeak;
+    else
+    {
+       if (!strcmp ((char *) binding_string, "weak"))
+           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 binding \"%s\"", binding_string);
+           return FcFalse;
+       }
+    }
+    *binding_ret = binding;
+    return FcTrue;
+}
+
 static void
 FcParseFamilies (FcConfigParse *parse, FcVStackTag tag)
 {
@@ -1352,7 +1384,10 @@ FcParseAlias (FcConfigParse *parse)
     FcEdit     *edit = 0, *next;
     FcVStack   *vstack;
     FcTest     *test;
+    FcValueBinding  binding;
 
+    if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
+       return;
     while ((vstack = FcVStackPop (parse))) 
     {
        switch (vstack->tag) {
@@ -1411,10 +1446,10 @@ FcParseAlias (FcConfigParse *parse)
     if (prefer)
     {
        edit = FcEditCreate (parse, 
-                            FcConfigSaveField ("family"),
+                            FC_FAMILY_OBJECT,
                             FcOpPrepend,
                             prefer,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = 0;
        else
@@ -1424,10 +1459,10 @@ FcParseAlias (FcConfigParse *parse)
     {
        next = edit;
        edit = FcEditCreate (parse,
-                            FcConfigSaveField ("family"),
+                            FC_FAMILY_OBJECT,
                             FcOpAppend,
                             accept,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1437,10 +1472,10 @@ FcParseAlias (FcConfigParse *parse)
     {
        next = edit;
        edit = FcEditCreate (parse,
-                            FcConfigSaveField ("family"),
+                            FC_FAMILY_OBJECT,
                             FcOpAppendLast,
                             def,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1645,7 +1680,6 @@ FcConfigLexCompare (const FcChar8 *compare)
     return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS);
 }
 
-
 static void
 FcParseTest (FcConfigParse *parse)
 {
@@ -1668,6 +1702,8 @@ FcParseTest (FcConfigParse *parse)
            kind = FcMatchPattern;
        else if (!strcmp ((char *) kind_string, "font"))
            kind = FcMatchFont;
+       else if (!strcmp ((char *) kind_string, "scan"))
+           kind = FcMatchScan;
        else if (!strcmp ((char *) kind_string, "default"))
            kind = FcMatchDefault;
        else
@@ -1750,7 +1786,6 @@ FcParseEdit (FcConfigParse *parse)
 {
     const FcChar8   *name;
     const FcChar8   *mode_string;
-    const FcChar8   *binding_string;
     FcOp           mode;
     FcValueBinding  binding;
     FcExpr         *expr;
@@ -1774,25 +1809,12 @@ FcParseEdit (FcConfigParse *parse)
            return;
        }
     }
-    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;
-       else if (!strcmp ((char *) binding_string, "same"))
-           binding = FcValueBindingSame;
-       else
-       {
-           FcConfigMessage (parse, FcSevereWarning, "invalid edit binding \"%s\"", binding_string);
-           return;
-       }
-    }
+    if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
+       return;
+
     expr = FcPopBinary (parse, FcOpComma);
-    edit = FcEditCreate (parse, (char *) FcStrCopy (name), mode, expr, binding);
+    edit = FcEditCreate (parse, FcObjectFromName ((char *) name),
+                        mode, expr, binding);
     if (!edit)
     {
        FcConfigMessage (parse, FcSevereError, "out of memory");
@@ -1821,6 +1843,8 @@ FcParseMatch (FcConfigParse *parse)
            kind = FcMatchPattern;
        else if (!strcmp ((char *) kind_name, "font"))
            kind = FcMatchFont;
+       else if (!strcmp ((char *) kind_name, "scan"))
+           kind = FcMatchScan;
        else
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid match target \"%s\"", kind_name);
@@ -1839,6 +1863,12 @@ FcParseMatch (FcConfigParse *parse)
            vstack->u.edit->next = edit;
            edit = vstack->u.edit;
            vstack->tag = FcVStackNone;
+           if (kind == FcMatchScan && edit->object > FC_MAX_BASE_OBJECT)
+           {
+               FcConfigMessage (parse, FcSevereError, 
+                                "<match target=\"scan\"> cannot edit user-defined object \"%s\"",
+                                FcObjectName(edit->object));
+           }
            break;
        default:
            FcConfigMessage (parse, FcSevereWarning, "invalid match element");
@@ -1966,8 +1996,7 @@ FcParsePatelt (FcConfigParse *parse)
        }
     }
 
-    FcVStackPushPattern (parse, FcPatternFreeze(pattern));
-    FcPatternDestroy (pattern);
+    FcVStackPushPattern (parse, pattern);
 }
 
 static void
@@ -2054,7 +2083,7 @@ FcEndElement(void *userData, const XML_Char *name)
        }
        FcStrFree (data);
        break;
-    case FcElementCache:
+    case FcElementCacheDir:
        data = FcStrBufDone (&parse->pstack->str);
        if (!data)
        {
@@ -2063,11 +2092,22 @@ FcEndElement(void *userData, const XML_Char *name)
        }
        if (!FcStrUsesHome (data) || FcConfigHome ())
        {
-           if (!FcConfigSetCache (parse->config, data))
-               FcConfigMessage (parse, FcSevereError, "out of memory");
+           if (!FcConfigAddCacheDir (parse->config, data))
+               FcConfigMessage (parse, FcSevereError, "out of memory; cannot add cache directory %s", data);
        }
        FcStrFree (data);
        break;
+       
+    case FcElementCache:
+       data = FcStrBufDone (&parse->pstack->str);
+       if (!data)
+       {
+           FcConfigMessage (parse, FcSevereError, "out of memory");
+           break;
+       }
+       /* discard this data; no longer used */
+       FcStrFree (data);
+       break;
     case FcElementInclude:
        FcParseInclude (parse);
        break;
@@ -2265,6 +2305,14 @@ FcEndDoctypeDecl (void *userData)
 
 #endif /* ENABLE_LIBXML2 */
 
+static int
+FcSortCmpStr (const void *a, const void *b)
+{
+    const FcChar8    *as = *((FcChar8 **) a);
+    const FcChar8    *bs = *((FcChar8 **) b);
+    return FcStrCmp (as, bs);
+}
+
 static FcBool
 FcConfigParseAndLoadDir (FcConfig      *config,
                         const FcChar8  *name,
@@ -2334,7 +2382,7 @@ FcConfigParseAndLoadDir (FcConfig *config,
     {
        int i;
        qsort (files->strs, files->num, sizeof (FcChar8 *), 
-              (int (*)(const void *, const void *)) FcStrCmp);
+              (int (*)(const void *, const void *)) FcSortCmpStr);
        for (i = 0; ret && i < files->num; i++)
            ret = FcConfigParseAndLoad (config, files->strs[i], complain);
     }
@@ -2477,3 +2525,6 @@ bail0:
     }
     return FcTrue;
 }
+#define __fcxml__
+#include "fcaliastail.h"
+#undef __fcxml__