hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Wed Mar 7 01:05:31 PST 2007


 doc/spec/hal-spec-fdi-files.xml |   10 ++++++++++
 hald/create_cache.c             |    2 ++
 hald/device_info.c              |   13 ++++++++++---
 hald/rule.h                     |    3 ++-
 4 files changed, 24 insertions(+), 4 deletions(-)

New commits:
diff-tree f284167711acb400aff1b22c16b9cc5368ca00ff (from c31c32b8b7c0fed9c871da947f35922e03ad6ed3)
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Wed Mar 7 10:05:22 2007 +0100

    added new fdi match attribute 'contains_not' for strings and strlist
    
    Added a new attribute for FDI file match tag for string lists (strlist)
    and strings. The new attribute named contains_not and allow you to match
    if a given string is not contained in the string list/strins as in such
    cases for example:
    
     <match key="info.callouts" contains_not="foobar">
      <append key="info.callouts" type="strlist">foobar</append>
     </match>
    
    This allow you to add e.g. callouts to the list without to double entries
    and allow some kind of if/else clause in FDI files

diff --git a/doc/spec/hal-spec-fdi-files.xml b/doc/spec/hal-spec-fdi-files.xml
index 4c6ce24..e2c8b4f 100644
--- a/doc/spec/hal-spec-fdi-files.xml
+++ b/doc/spec/hal-spec-fdi-files.xml
@@ -150,6 +150,16 @@
       </listitem>
       <listitem>
         <para>
+          <literal>contains_not</literal> - can only be used with strlist (string list) 
+	  and string properties.
+          For a string list this match if the given string is not match any of the
+          item of the list for a string this match of the property not contains the
+	  (sub-)string. You can use this attribute to construct if/else blocks together 
+	  with e.g. <literal>contains</literal>.
+        </para>
+      </listitem>
+      <listitem>
+        <para>
           <literal>contains_ncase</literal> - like <literal>contains</literal>
           but the property and the given key are converted to lowercase before check.
         </para>
diff --git a/hald/create_cache.c b/hald/create_cache.c
index 5374051..97349f9 100644
--- a/hald/create_cache.c
+++ b/hald/create_cache.c
@@ -134,6 +134,8 @@ get_match_type(const char *str)
 		return MATCH_COMPARE_GE;
 	if (strcmp (str, "compare_ne") == 0)
 		return MATCH_COMPARE_NE;
+	if (strcmp (str, "contains_not") == 0)
+		return MATCH_CONTAINS_NOT;
 	return MATCH_UNKNOWN;
 }
 
diff --git a/hald/device_info.c b/hald/device_info.c
index 09f6eb2..8355011 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -105,6 +105,8 @@ get_match_type_str (enum match_type type
 		return "compare_ne";
 	case MATCH_UNKNOWN:
 		return "unknown match type";
+	case MATCH_CONTAINS_NOT:
+		return "contains_not";
 	}
 	return "invalid match type";
 }
@@ -441,6 +443,7 @@ handle_match (struct rule *rule, HalDevi
 	}
 
 	case MATCH_CONTAINS:
+	case MATCH_CONTAINS_NOT:
 	{
 		dbus_bool_t contains = FALSE;
 
@@ -449,7 +452,7 @@ handle_match (struct rule *rule, HalDevi
 				const char *haystack;
 
 				haystack = hal_device_property_get_string (d, prop_to_check);
-				if (value != NULL && haystack != NULL && strstr (haystack, value))
+				if (value != NULL && haystack != NULL &&  (strstr(haystack, value) != NULL))
 					contains = TRUE;
 			}
 		} else if (hal_device_property_get_type (d, prop_to_check) == HAL_PROPERTY_TYPE_STRLIST && value != NULL) {
@@ -466,8 +469,12 @@ handle_match (struct rule *rule, HalDevi
 		} else {
 			return FALSE;
 		}
-
-		return contains;
+	
+		if (rule->type_match == MATCH_CONTAINS) {	
+			return contains;
+		} else {
+			return !contains; /* rule->type_match == MATCH_CONTAINS_NOT  */
+		}
 	}
 
 	case MATCH_SIBLING_CONTAINS:
diff --git a/hald/rule.h b/hald/rule.h
index b57d282..c73f4c6 100644
--- a/hald/rule.h
+++ b/hald/rule.h
@@ -78,7 +78,8 @@ typedef enum {
 	MATCH_COMPARE_GT,
 	MATCH_COMPARE_GE,
 	MATCH_SIBLING_CONTAINS,
-	MATCH_COMPARE_NE
+	MATCH_COMPARE_NE,
+	MATCH_CONTAINS_NOT
 } match_type;
 
 /* a "rule" structure that is a generic node of the fdi file */


More information about the hal-commit mailing list