The following commit has been merged in the master branch:
commit 902cc15dc86797966ea09f66b26a433c7c85c64f
Author: Guillem Jover <[email protected]>
Date:   Sun Feb 20 01:45:22 2011 +0100

    libdpkg: Add support for fallback namevalues
    
    This will allow to designate a namevalue entry as the fallback return
    value in case none of the rest did match.

diff --git a/lib/dpkg/namevalue.c b/lib/dpkg/namevalue.c
index f425c4c..cfcedca 100644
--- a/lib/dpkg/namevalue.c
+++ b/lib/dpkg/namevalue.c
@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * namevalue.c - name value structure handling
  *
- * Copyright © 2010 Guillem Jover <[email protected]>
+ * Copyright © 2010-2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,11 +28,16 @@
 const struct namevalue *
 namevalue_find_by_name(const struct namevalue *head, const char *str)
 {
-       const struct namevalue *nv;
+       const struct namevalue *nv, *nv_fallback = NULL;
 
-       for (nv = head; nv->name; nv++)
+       for (nv = head; nv->name; nv++) {
+               if (nv->length == 0) {
+                       nv_fallback = nv;
+                       continue;
+               }
                if (strncasecmp(str, nv->name, nv->length) == 0)
                        return nv;
+       }
 
-       return NULL;
+       return nv_fallback;
 }
diff --git a/lib/dpkg/namevalue.h b/lib/dpkg/namevalue.h
index c896e3e..3f17c4b 100644
--- a/lib/dpkg/namevalue.h
+++ b/lib/dpkg/namevalue.h
@@ -3,7 +3,7 @@
  * namevalue.h - name value structure handling
  *
  * Copyright © 1994,1995 Ian Jackson <[email protected]>
- * Copyright © 2009-2010 Guillem Jover <[email protected]>
+ * Copyright © 2009-2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,6 +34,8 @@ struct namevalue {
 
 #define NAMEVALUE_DEF(n, v) \
        [v] = { .name = n, .value = v, .length = sizeof(n) - 1 }
+#define NAMEVALUE_FALLBACK_DEF(n, v) \
+       [v] = { .name = n, .value = v, .length = 0 }
 
 const struct namevalue *namevalue_find_by_name(const struct namevalue *head,
                                                const char *str);

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to