* PERFORMANCE OF THIS SOFTWARE.
*/
+#include <fcntl.h>
#include <stdarg.h>
#include "fcint.h"
#include <dirent.h>
+#if ENABLE_LIBXML2
+
+#include <libxml/parser.h>
+
+#define XML_Char xmlChar
+#define XML_Parser xmlParserCtxtPtr
+#define XML_ParserFree xmlFreeParserCtxt
+#define XML_GetCurrentLineNumber xmlSAX2GetLineNumber
+#define XML_GetErrorCode xmlCtxtGetLastError
+#define XML_ErrorString(Error) (Error)->message
+
+#else /* ENABLE_LIBXML2 */
+
#ifndef HAVE_XMLPARSE_H
#define HAVE_XMLPARSE_H 0
#endif
#include <expat.h>
#endif
+#endif /* ENABLE_LIBXML2 */
+
#ifdef _WIN32
#define STRICT
#include <windows.h>
FcElementUnknown
} FcElement;
+static struct {
+ const char name[16];
+ FcElement element;
+} fcElementMap[] = {
+ { "fontconfig", FcElementFontconfig },
+ { "dir", FcElementDir },
+ { "cache", FcElementCache },
+ { "include", FcElementInclude },
+ { "config", FcElementConfig },
+ { "match", FcElementMatch },
+ { "alias", FcElementAlias },
+
+ { "blank", FcElementBlank },
+ { "rescan", FcElementRescan },
+
+ { "prefer", FcElementPrefer },
+ { "accept", FcElementAccept },
+ { "default", FcElementDefault },
+ { "family", FcElementFamily },
+
+ { "selectfont", FcElementSelectfont },
+ { "acceptfont", FcElementAcceptfont },
+ { "rejectfont", FcElementRejectfont },
+ { "glob", FcElementGlob },
+ { "pattern", FcElementPattern },
+ { "patelt", FcElementPatelt },
+
+ { "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 },
+ { "contains", FcElementContains },
+ { "not_contains", FcElementNotContains },
+ { "plus", FcElementPlus },
+ { "minus", FcElementMinus },
+ { "times", FcElementTimes },
+ { "divide", FcElementDivide },
+ { "not", FcElementNot },
+ { "if", FcElementIf },
+ { "floor", FcElementFloor },
+ { "ceil", FcElementCeil },
+ { "round", FcElementRound },
+ { "trunc", FcElementTrunc },
+};
+#define NUM_ELEMENT_MAPS (int) (sizeof fcElementMap / sizeof fcElementMap[0])
+
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 },
- { "rescan", FcElementRescan },
-
- { "prefer", FcElementPrefer },
- { "accept", FcElementAccept },
- { "default", FcElementDefault },
- { "family", FcElementFamily },
-
- { "selectfont", FcElementSelectfont },
- { "acceptfont", FcElementAcceptfont },
- { "rejectfont", FcElementRejectfont },
- { "glob", FcElementGlob },
- { "pattern", FcElementPattern },
- { "patelt", FcElementPatelt },
-
- { "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 },
- { "contains", FcElementContains },
- { "not_contains",FcElementNotContains },
- { "plus", FcElementPlus },
- { "minus", FcElementMinus },
- { "times", FcElementTimes },
- { "divide", FcElementDivide },
- { "not", FcElementNot },
- { "if", FcElementIf },
- { "floor", FcElementFloor },
- { "ceil", FcElementCeil },
- { "round", FcElementRound },
- { "trunc", FcElementTrunc },
-
- { 0, 0 }
- };
int i;
- for (i = 0; fcElementMap[i].name; i++)
+ for (i = 0; i < NUM_ELEMENT_MAPS; i++)
if (!strcmp ((char *) name, fcElementMap[i].name))
return fcElementMap[i].element;
return FcElementUnknown;
} FcConfigSeverity;
static void
-FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, char *fmt, ...)
+FcConfigMessage (FcConfigParse *parse, FcConfigSeverity severe, const char *fmt, ...)
{
- char *s = "unknown";
+ const char *s = "unknown";
va_list args;
va_start (args, fmt);
}
-static char *
+static const char *
FcTypeName (FcType type)
{
switch (type) {
if (o)
FcTypecheckValue (parse, o->type, type);
}
+ else
+ FcConfigMessage (parse, FcSevereWarning,
+ "invalid constant used : %s",
+ expr->u.constant);
break;
case FcOpQuest:
FcTypecheckExpr (parse, expr->u.tree.left, FcTypeBool);
return 0;
slen = 0;
for (i = 0; attr[i]; i++)
- slen += strlen (attr[i]) + 1;
+ slen += strlen ((char *) attr[i]) + 1;
n = i;
new = malloc ((i + 1) * sizeof (FcChar8 *) + slen);
if (!new)
}
static const FcChar8 *
-FcConfigGetAttribute (FcConfigParse *parse, char *attr)
+FcConfigGetAttribute (FcConfigParse *parse, const char *attr)
{
FcChar8 **attrs;
if (!parse->pstack)
return 0;
attrs = parse->pstack->attr;
+ if (!attrs)
+ return 0;
+
while (*attrs)
{
if (!strcmp ((char *) *attrs, attr))
int slen = strlen (s);
int dlen = strlen (locale_data->decimal_point);
- if (slen + dlen > sizeof (buf))
+ if (slen + dlen > (int) sizeof (buf))
{
if (end)
*end = s;
}
typedef struct _FcOpMap {
- char *name;
+ char name[16];
FcOp op;
} FcOpMap;
{ "not_contains", FcOpNotContains }
};
-#define NUM_COMPARE_OPS (sizeof fcCompareOps / sizeof fcCompareOps[0])
+#define NUM_COMPARE_OPS (int) (sizeof fcCompareOps / sizeof fcCompareOps[0])
static FcOp
FcConfigLexCompare (const FcChar8 *compare)
{ "append_last", FcOpAppendLast },
};
-#define NUM_MODE_OPS (sizeof fcModeOps / sizeof fcModeOps[0])
+#define NUM_MODE_OPS (int) (sizeof fcModeOps / sizeof fcModeOps[0])
static FcOp
FcConfigLexMode (const FcChar8 *mode)
return;
}
- name = FcConfigGetAttribute (parse, "name");
+ name = (char *) FcConfigGetAttribute (parse, "name");
if (!name)
{
FcConfigMessage (parse, FcSevereWarning, "missing pattern element name");
if (!FcStrUsesHome (data) || FcConfigHome ())
{
if (!FcConfigAddDir (parse->config, data))
- FcConfigMessage (parse, FcSevereError, "out of memory");
+ FcConfigMessage (parse, FcSevereError, "out of memory; cannot add directory %s", data);
}
FcStrFree (data);
break;
FcConfigMessage (parse, FcSevereError, "invalid doctype \"%s\"", doctypeName);
}
+#if ENABLE_LIBXML2
+
+static void
+FcInternalSubsetDecl (void *userData,
+ const XML_Char *doctypeName,
+ const XML_Char *sysid,
+ const XML_Char *pubid)
+{
+ FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 1);
+}
+
+static void
+FcExternalSubsetDecl (void *userData,
+ const XML_Char *doctypeName,
+ const XML_Char *sysid,
+ const XML_Char *pubid)
+{
+ FcStartDoctypeDecl (userData, doctypeName, sysid, pubid, 0);
+}
+
+#else /* ENABLE_LIBXML2 */
+
static void
FcEndDoctypeDecl (void *userData)
{
}
+#endif /* ENABLE_LIBXML2 */
+
static FcBool
FcConfigParseAndLoadDir (FcConfig *config,
const FcChar8 *name,
while (ret && (e = readdir (d)))
{
+ int d_len;
+#define TAIL ".conf"
+#define TAIL_LEN 5
/*
- * Add all files of the form [0-9]*
+ * Add all files of the form [0-9]*.conf
*/
if ('0' <= e->d_name[0] && e->d_name[0] <= '9' &&
- strlen (e->d_name) < FC_MAX_FILE_LEN)
+ (d_len = strlen (e->d_name)) < FC_MAX_FILE_LEN &&
+ d_len > TAIL_LEN &&
+ strcmp (e->d_name + d_len - TAIL_LEN, TAIL) == 0)
{
strcpy ((char *) base, (char *) e->d_name);
if (!FcStrSetAdd (files, file))
XML_Parser p;
FcChar8 *filename;
- FILE *f;
+ int fd;
int len;
- void *buf;
FcConfigParse parse;
FcBool error = FcTrue;
+#if ENABLE_LIBXML2
+ xmlSAXHandler sax;
+ char buf[BUFSIZ];
+#else
+ void *buf;
+#endif
+
filename = FcConfigFilename (name);
if (!filename)
goto bail0;
+ if (FcStrSetMember (config->configFiles, filename))
+ {
+ FcStrFree (filename);
+ return FcTrue;
+ }
+
if (!FcStrSetAdd (config->configFiles, filename))
{
FcStrFree (filename);
if (FcDebug () & FC_DBG_CONFIG)
printf ("\tLoading config file %s\n", filename);
- f = fopen ((char *) filename, "r");
- FcStrFree (filename);
- if (!f)
+ fd = open ((char *) filename, O_RDONLY);
+ if (fd == -1) {
+ FcStrFree (filename);
goto bail0;
+ }
+#if ENABLE_LIBXML2
+ memset(&sax, 0, sizeof(sax));
+
+ sax.internalSubset = FcInternalSubsetDecl;
+ sax.externalSubset = FcExternalSubsetDecl;
+ sax.startElement = FcStartElement;
+ sax.endElement = FcEndElement;
+ sax.characters = FcCharacterData;
+
+ p = xmlCreatePushParserCtxt (&sax, &parse, NULL, 0, (const char *) filename);
+#else
p = XML_ParserCreate ("UTF-8");
+#endif
+ FcStrFree (filename);
+
if (!p)
goto bail1;
if (!FcConfigInit (&parse, name, config, p))
goto bail2;
+#if !ENABLE_LIBXML2
+
XML_SetUserData (p, &parse);
XML_SetDoctypeDeclHandler (p, FcStartDoctypeDecl, FcEndDoctypeDecl);
XML_SetElementHandler (p, FcStartElement, FcEndElement);
XML_SetCharacterDataHandler (p, FcCharacterData);
+#endif /* ENABLE_LIBXML2 */
+
do {
+#if !ENABLE_LIBXML2
buf = XML_GetBuffer (p, BUFSIZ);
if (!buf)
{
FcConfigMessage (&parse, FcSevereError, "cannot get parse buffer");
goto bail3;
}
- len = fread (buf, 1, BUFSIZ, f);
+#endif
+ len = read (fd, buf, BUFSIZ);
if (len < 0)
{
FcConfigMessage (&parse, FcSevereError, "failed reading config file");
goto bail3;
}
+
+#if ENABLE_LIBXML2
+ if (xmlParseChunk (p, buf, len, len == 0))
+#else
if (!XML_ParseBuffer (p, len, len == 0))
+#endif
{
FcConfigMessage (&parse, FcSevereError, "%s",
XML_ErrorString (XML_GetErrorCode (p)));
bail2:
XML_ParserFree (p);
bail1:
- fclose (f);
+ close (fd);
+ fd = -1;
bail0:
if (error && complain)
{