Bug 23757 - Add mode="delete" to <edit>
authorAkira TAGOH <akira@tagoh.org>
Tue, 29 Jan 2013 11:19:36 +0000 (20:19 +0900)
committerAkira TAGOH <akira@tagoh.org>
Fri, 1 Feb 2013 03:56:14 +0000 (12:56 +0900)
Add two edit mode, "delete" and "delete_all".
what values are being deleted depends on <test> as documented.
if the target object is same to what is tested, matching value there
will be deleted. otherwise all of values in the object will be deleted.
so this would means both edit mode will not take any expressions.

e.g.

Given that the testing is always true here, the following rules:

  <match>
    <test name="foo" compare="eq">
      <string>bar</string>
    </test>
    <edit name="foo" mode="delete"/>
  </match>

will removes "bar" string from "foo" object. and:

  <match>
    <test name="foo" compare="eq">
      <string>foo</string>
    </test>
    <edit name="bar" mode="delete"/>
  </match>

will removes all of values in "bar" object.

doc/fontconfig-user.sgml
fonts.dtd
src/fccfg.c
src/fcdbg.c
src/fcint.h
src/fcxml.c

index 90e246b..eeff69a 100644 (file)
@@ -425,6 +425,8 @@ with "same" binding using the value from the matched pattern element.
   "prepend_first"         Insert at head of list  Insert at head of list
   "append"                Append after matching   Append at end of list
   "append_last"           Append at end of list   Append at end of list
+  "delete"                Delete matching value   Delete all values
+  "delete_all"            Delete all values       Delete all values
     </programlisting>
   </para></refsect2>
   <refsect2><title><literal>&lt;int&gt;</literal>, <literal>&lt;double&gt;</literal>, <literal>&lt;string&gt;</literal>, <literal>&lt;bool&gt;</literal></title><para>
index 664467d..4c38e77 100644 (file)
--- a/fonts.dtd
+++ b/fonts.dtd
 <!ELEMENT edit (%expr;)*>
 <!ATTLIST edit
          name CDATA        #REQUIRED
-         mode (assign|assign_replace|prepend|append|prepend_first|append_last) "assign"
+         mode (assign|assign_replace|prepend|append|prepend_first|append_last|delete|delete_all) "assign"
          binding (weak|strong|same) "weak">
 
 <!--
index 12d7e1a..db878d5 100644 (file)
@@ -1701,6 +1701,16 @@ FcConfigSubstituteWithPat (FcConfig    *config,
            case FcOpAppendLast:
                FcConfigPatternAdd (p, e->object, l, FcTrue);
                break;
+           case FcOpDelete:
+               if (t)
+               {
+                   FcConfigDel (&st[i].elt->values, st[i].value);
+                   break;
+               }
+               /* fall through ... */
+           case FcOpDeleteAll:
+               FcConfigPatternDel (p, e->object);
+               break;
            default:
                 FcValueListDestroy (l);
                break;
index 270d791..9d02f5a 100644 (file)
@@ -79,7 +79,7 @@ void
 FcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark)
 {
     if (show_pos_mark)
-       printf (" [insert here] ");
+       printf (" [marker] ");
     else
        printf (" ");
     _FcValuePrintFile (stdout, v);
@@ -110,7 +110,7 @@ FcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos)
        FcValueBindingPrint (l);
     }
     if (!pos)
-       printf (" [insert here]");
+       printf (" [marker]");
 }
 
 void
@@ -222,6 +222,8 @@ FcOpPrint (FcOp op_)
     case FcOpPrependFirst: printf ("PrependFirst"); break;
     case FcOpAppend: printf ("Append"); break;
     case FcOpAppendLast: printf ("AppendLast"); break;
+    case FcOpDelete: printf ("Delete"); break;
+    case FcOpDeleteAll: printf ("DeleteAll"); break;
     case FcOpQuest: printf ("Quest"); break;
     case FcOpOr: printf ("Or"); break;
     case FcOpAnd: printf ("And"); break;
index 71b7341..fceb8cc 100644 (file)
@@ -208,6 +208,7 @@ typedef enum _FcOp {
     FcOpField, FcOpConst,
     FcOpAssign, FcOpAssignReplace,
     FcOpPrependFirst, FcOpPrepend, FcOpAppend, FcOpAppendLast,
+    FcOpDelete, FcOpDeleteAll,
     FcOpQuest,
     FcOpOr, FcOpAnd, FcOpEqual, FcOpNotEqual,
     FcOpContains, FcOpListing, FcOpNotContains,
index 5981ea9..470e44f 100644 (file)
@@ -260,6 +260,8 @@ FcExprDestroy (FcExpr *e)
     case FcOpPrependFirst:
     case FcOpAppend:
     case FcOpAppendLast:
+    case FcOpDelete:
+    case FcOpDeleteAll:
        break;
     case FcOpOr:
     case FcOpAnd:
@@ -2321,6 +2323,8 @@ static const FcOpMap fcModeOps[] = {
     { "prepend_first", FcOpPrependFirst    },
     { "append",                FcOpAppend          },
     { "append_last",   FcOpAppendLast      },
+    { "delete",                FcOpDelete          },
+    { "delete_all",    FcOpDeleteAll       },
 };
 
 #define NUM_MODE_OPS (int) (sizeof fcModeOps / sizeof fcModeOps[0])
@@ -2363,6 +2367,13 @@ FcParseEdit (FcConfigParse *parse)
        return;
 
     expr = FcPopBinary (parse, FcOpComma);
+    if ((mode == FcOpDelete || mode == FcOpDeleteAll) &&
+       expr != NULL)
+    {
+       FcConfigMessage (parse, FcSevereWarning, "Expression doesn't take any effects for delete and delete_all");
+       FcExprDestroy (expr);
+       expr = NULL;
+    }
     edit = FcEditCreate (parse, FcObjectFromName ((char *) name),
                         mode, expr, binding);
     if (!edit)