Просмотр исходного кода

libdpkg: Add new namevalue_find_by_name function

Guillem Jover лет назад: 15
Родитель
Сommit
e66836854e
4 измененных файлов с 46 добавлено и 1 удалено
  1. 1 0
      lib/dpkg/Makefile.am
  2. 3 0
      lib/dpkg/libdpkg.Versions
  3. 38 0
      lib/dpkg/namevalue.c
  4. 4 1
      lib/dpkg/namevalue.h

+ 1 - 0
lib/dpkg/Makefile.am

@@ -41,6 +41,7 @@ libdpkg_a_SOURCES = \
 	md5.c md5.h \
 	mlib.c \
 	myopt.c \
+	namevalue.c \
 	nfmalloc.c \
 	parse.c \
 	parsehelp.c \

+ 3 - 0
lib/dpkg/libdpkg.Versions

@@ -77,6 +77,9 @@ LIBDPKG_PRIVATE {
 	glob_list_prepend;
 	glob_list_free;
 
+	# Data structure functions
+	namevalue_find_by_name;
+
 	# Buffer I/O functions
 	buffer_init;
 	buffer_read;

+ 38 - 0
lib/dpkg/namevalue.c

@@ -0,0 +1,38 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * namevalue.c - name value structure handling
+ *
+ * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <stddef.h>
+
+#include <dpkg/namevalue.h>
+
+const struct namevalue *
+namevalue_find_by_name(const struct namevalue *head, const char *str)
+{
+	const struct namevalue *nv;
+
+	for (nv = head; nv->name; nv++)
+		if (strncasecmp(str, nv->name, nv->length) == 0)
+			return nv;
+
+	return NULL;
+}

+ 4 - 1
lib/dpkg/namevalue.h

@@ -3,7 +3,7 @@
  * namevalue.h - name value structure handling
  *
  * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
- * Copyright © 2009 Guillem Jover <guillem@debian.org>
+ * Copyright © 2009-2010 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -35,6 +35,9 @@ struct namevalue {
 #define NAMEVALUE_DEF(n, v) \
 	[v] = { .name = n, .value = v, .length = sizeof(n) - 1 }
 
+const struct namevalue *namevalue_find_by_name(const struct namevalue *head,
+                                               const char *str);
+
 DPKG_END_DECLS
 
 #endif /* LIBDPKG_NAMEVALUE_H */