]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcxml.c
Add binding property to edit element
[fontconfig.git] / src / fcxml.c
index ef116d05aa08d4c749734defee29094f75c3a525..5fea07cf3c906b5923e40e72c2ca112e989fe1a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.8 2002/05/22 04:12:35 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.16 2002/07/12 19:19:16 keithp Exp $
  *
  * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -251,7 +251,7 @@ FcExprDestroy (FcExpr *e)
 }
 
 FcEdit *
-FcEditCreate (const char *field, FcOp op, FcExpr *expr)
+FcEditCreate (const char *field, FcOp op, FcExpr *expr, FcValueBinding binding)
 {
     FcEdit *e = (FcEdit *) malloc (sizeof (FcEdit));
 
@@ -261,6 +261,7 @@ FcEditCreate (const char *field, FcOp op, FcExpr *expr)
        e->field = field;   /* already saved in grammar */
        e->op = op;
        e->expr = expr;
+       e->binding = binding;
     }
     return e;
 }
@@ -879,6 +880,61 @@ FcParseInt (FcConfigParse *parse)
     FcStrFree (s);
 }
 
+/*
+ * 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)
+               buf_end = s + (buf_end - buf);
+           if (end)
+               *end = buf_end;
+       }
+    }
+    else
+       v = strtod (s, end);
+    return v;
+}
+
 static void
 FcParseDouble (FcConfigParse *parse)
 {
@@ -894,7 +950,7 @@ FcParseDouble (FcConfigParse *parse)
        return;
     }
     end = 0;
-    d = strtod ((char *) s, (char **)&end);
+    d = FcStrtod ((char *) s, (char **)&end);
     if (end != s + strlen ((char *) s))
        FcConfigMessage (parse, FcSevereError, "\"%s\": not a valid double", s);
     else
@@ -1115,7 +1171,8 @@ FcParseAlias (FcConfigParse *parse)
     {
        edit = FcEditCreate (FcConfigSaveField ("family"),
                             FcOpPrepend,
-                            prefer);
+                            prefer,
+                            FcValueBindingWeak);
        if (edit)
            edit->next = 0;
        else
@@ -1126,7 +1183,8 @@ FcParseAlias (FcConfigParse *parse)
        next = edit;
        edit = FcEditCreate (FcConfigSaveField ("family"),
                             FcOpAppend,
-                            accept);
+                            accept,
+                            FcValueBindingWeak);
        if (edit)
            edit->next = next;
        else
@@ -1136,8 +1194,9 @@ FcParseAlias (FcConfigParse *parse)
     {
        next = edit;
        edit = FcEditCreate (FcConfigSaveField ("family"),
-                             FcOpAppendLast,
-                             def);
+                            FcOpAppendLast,
+                            def,
+                            FcValueBindingWeak);
        if (edit)
            edit->next = next;
        else
@@ -1146,7 +1205,7 @@ FcParseAlias (FcConfigParse *parse)
     if (edit)
     {
        test = FcTestCreate (FcQualAny,
-                            FC_FAMILY,
+                            (FcChar8 *) FC_FAMILY,
                             FcOpEqual,
                             family);
        if (test)
@@ -1316,17 +1375,21 @@ FcParseTest (FcConfigParse *parse)
            qual = FcQualAny;
        else if (!strcmp ((char *) qual_string, "all"))
            qual = FcQualAll;
+       else if (!strcmp ((char *) qual_string, "first"))
+           qual = FcQualFirst;
+       else if (!strcmp ((char *) qual_string, "not_first"))
+           qual = FcQualNotFirst;
        else
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid test qual \"%s\"", qual_string);
-           qual = FcQualAny;
+           return;
        }
     }
     name = FcConfigGetAttribute (parse, "name");
     if (!name)
     {
        FcConfigMessage (parse, FcSevereWarning, "missing test name");
-       name = (FcChar8 *) FC_FAMILY;
+       return;
     }
     compare_string = FcConfigGetAttribute (parse, "compare");
     if (!compare_string)
@@ -1337,7 +1400,7 @@ FcParseTest (FcConfigParse *parse)
        if (compare == FcOpInvalid)
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid test compare \"%s\"", compare_string);
-           compare = FcOpEqual;
+           return;
        }
     }
     expr = FcPopExprs (parse, FcOpComma);
@@ -1377,7 +1440,9 @@ FcParseEdit (FcConfigParse *parse)
 {
     const FcChar8   *name;
     const FcChar8   *mode_string;
+    const FcChar8   *binding_string;
     FcOp           mode;
+    FcValueBinding  binding;
     FcExpr         *expr;
     FcEdit         *edit;
 
@@ -1385,7 +1450,7 @@ FcParseEdit (FcConfigParse *parse)
     if (!name)
     {
        FcConfigMessage (parse, FcSevereWarning, "missing edit name");
-       name = (FcChar8 *) FC_FAMILY;
+       return;
     }
     mode_string = FcConfigGetAttribute (parse, "mode");
     if (!mode_string)
@@ -1396,11 +1461,26 @@ FcParseEdit (FcConfigParse *parse)
        if (mode == FcOpInvalid)
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid edit mode \"%s\"", mode_string);
-           mode = FcOpAssign;
+           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
+       {
+           FcConfigMessage (parse, FcSevereWarning, "invalid edit binding \"%s\"", binding_string);
+           return;
        }
     }
     expr = FcPopExprs (parse, FcOpComma);
-    edit = FcEditCreate ((char *) FcStrCopy (name), mode, expr);
+    edit = FcEditCreate ((char *) FcStrCopy (name), mode, expr, binding);
     if (!edit)
     {
        FcConfigMessage (parse, FcSevereError, "out of memory");
@@ -1432,7 +1512,7 @@ FcParseMatch (FcConfigParse *parse)
        else
        {
            FcConfigMessage (parse, FcSevereWarning, "invalid match target \"%s\"", kind_name);
-           kind = FcMatchPattern;
+           return;
        }
     }
     while ((vstack = FcVStackPop (parse)))
@@ -1651,6 +1731,10 @@ FcConfigParseAndLoad (FcConfig       *config,
     filename = FcConfigFilename (name);
     if (!filename)
        goto bail0;
+    
+    if (!FcStrSetAdd (config->configFiles, filename))
+       goto bail0;
+
     f = fopen ((char *) filename, "r");
     free (filename);
     if (!f)