X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffcxml.c;h=d91e52275161bab71913ac24bb3c12b0e6b44e4c;hb=c2c6976d1a88cc35143ffcc34f3c38d0a28d34f4;hp=c9e44e375ec851732630345439207c6e661f9a4d;hpb=68355f38774fe55d8010268291a170492b241a71;p=fontconfig.git diff --git a/src/fcxml.c b/src/fcxml.c index c9e44e3..d91e522 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -22,12 +22,12 @@ * PERFORMANCE OF THIS SOFTWARE. */ +#include "fcint.h" #include #include -#include "fcint.h" #include -#if ENABLE_LIBXML2 +#ifdef ENABLE_LIBXML2 #include @@ -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, @@ -339,12 +337,13 @@ typedef enum _FcElement { FcElementUnknown } FcElement; -static struct { +static const struct { const char name[16]; FcElement element; } fcElementMap[] = { { "fontconfig", FcElementFontconfig }, { "dir", FcElementDir }, + { "cachedir", FcElementCacheDir }, { "cache", FcElementCache }, { "include", FcElementInclude }, { "config", FcElementConfig }, @@ -577,7 +576,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 +656,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 +668,7 @@ FcTestCreate (FcConfigParse *parse, static FcEdit * FcEditCreate (FcConfigParse *parse, - const char *field, + FcObject object, FcOp op, FcExpr *expr, FcValueBinding binding) @@ -681,11 +680,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); } @@ -924,7 +923,6 @@ FcVStackElements (FcConfigParse *parse) static FcChar8 ** FcConfigSaveAttr (const XML_Char **attr) { - int n; int slen; int i; FcChar8 **new; @@ -935,7 +933,6 @@ FcConfigSaveAttr (const XML_Char **attr) slen = 0; for (i = 0; attr[i]; i++) slen += strlen ((char *) attr[i]) + 1; - n = i; new = malloc ((i + 1) * sizeof (FcChar8 *) + slen); if (!new) return 0; @@ -1322,8 +1319,7 @@ FcParseFamilies (FcConfigParse *parse, FcVStackTag tag) if (!FcVStackPushExpr (parse, tag, expr)) { FcConfigMessage (parse, FcSevereError, "out of memory"); - if (expr) - FcExprDestroy (expr); + FcExprDestroy (expr); } } } @@ -1414,7 +1410,7 @@ FcParseAlias (FcConfigParse *parse) if (prefer) { edit = FcEditCreate (parse, - FcConfigSaveField ("family"), + FC_FAMILY_OBJECT, FcOpPrepend, prefer, FcValueBindingWeak); @@ -1427,7 +1423,7 @@ FcParseAlias (FcConfigParse *parse) { next = edit; edit = FcEditCreate (parse, - FcConfigSaveField ("family"), + FC_FAMILY_OBJECT, FcOpAppend, accept, FcValueBindingWeak); @@ -1440,7 +1436,7 @@ FcParseAlias (FcConfigParse *parse) { next = edit; edit = FcEditCreate (parse, - FcConfigSaveField ("family"), + FC_FAMILY_OBJECT, FcOpAppendLast, def, FcValueBindingWeak); @@ -1544,7 +1540,7 @@ FcPopBinary (FcConfigParse *parse, FcOp op) FcConfigMessage (parse, FcSevereError, "out of memory"); FcExprDestroy (left); FcExprDestroy (expr); - break; + return 0; } expr = new; } @@ -1671,6 +1667,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 @@ -1795,7 +1793,8 @@ FcParseEdit (FcConfigParse *parse) } } 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"); @@ -1824,6 +1823,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); @@ -1953,6 +1954,7 @@ FcParsePatelt (FcConfigParse *parse) if (!name) { FcConfigMessage (parse, FcSevereWarning, "missing pattern element name"); + FcPatternDestroy (pattern); return; } @@ -1990,6 +1992,7 @@ FcParsePattern (FcConfigParse *parse) if (!FcPatternAppend (pattern, vstack->u.pattern)) { FcConfigMessage (parse, FcSevereError, "out of memory"); + FcPatternDestroy (pattern); return; } break; @@ -2054,7 +2057,7 @@ FcEndElement(void *userData, const XML_Char *name) } FcStrFree (data); break; - case FcElementCache: + case FcElementCacheDir: data = FcStrBufDone (&parse->pstack->str); if (!data) { @@ -2063,9 +2066,20 @@ 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: @@ -2236,7 +2250,7 @@ FcStartDoctypeDecl (void *userData, FcConfigMessage (parse, FcSevereError, "invalid doctype \"%s\"", doctypeName); } -#if ENABLE_LIBXML2 +#ifdef ENABLE_LIBXML2 static void FcInternalSubsetDecl (void *userData, @@ -2361,7 +2375,7 @@ FcConfigParseAndLoad (FcConfig *config, FcConfigParse parse; FcBool error = FcTrue; -#if ENABLE_LIBXML2 +#ifdef ENABLE_LIBXML2 xmlSAXHandler sax; char buf[BUFSIZ]; #else @@ -2400,7 +2414,7 @@ FcConfigParseAndLoad (FcConfig *config, goto bail0; } -#if ENABLE_LIBXML2 +#ifdef ENABLE_LIBXML2 memset(&sax, 0, sizeof(sax)); sax.internalSubset = FcInternalSubsetDecl; @@ -2421,7 +2435,7 @@ FcConfigParseAndLoad (FcConfig *config, if (!FcConfigInit (&parse, name, config, p)) goto bail2; -#if !ENABLE_LIBXML2 +#ifndef ENABLE_LIBXML2 XML_SetUserData (p, &parse); @@ -2432,7 +2446,7 @@ FcConfigParseAndLoad (FcConfig *config, #endif /* ENABLE_LIBXML2 */ do { -#if !ENABLE_LIBXML2 +#ifndef ENABLE_LIBXML2 buf = XML_GetBuffer (p, BUFSIZ); if (!buf) { @@ -2447,7 +2461,7 @@ FcConfigParseAndLoad (FcConfig *config, goto bail3; } -#if ENABLE_LIBXML2 +#ifdef ENABLE_LIBXML2 if (xmlParseChunk (p, buf, len, len == 0)) #else if (!XML_ParseBuffer (p, len, len == 0))