aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/linkedlists.h
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-28 18:34:18 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-28 18:34:18 +0000
commit4b7b8dd790147d834373bef43b57034fcec3d1a0 (patch)
tree5f64d6331a0260404d5b6d96513d0c28bb76b770 /include/asterisk/linkedlists.h
parent3894ede3a1a894660486867ee5af813d25d9aa6b (diff)
Backport unit test API to 1.4.
Review: https://reviewboard.asterisk.org/r/750/ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@272878 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/linkedlists.h')
-rw-r--r--include/asterisk/linkedlists.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/asterisk/linkedlists.h b/include/asterisk/linkedlists.h
index a41ba857b..6810deea8 100644
--- a/include/asterisk/linkedlists.h
+++ b/include/asterisk/linkedlists.h
@@ -449,6 +449,7 @@ struct { \
\li AST_LIST_INSERT_AFTER()
\li AST_LIST_INSERT_HEAD()
\li AST_LIST_INSERT_TAIL()
+ \li AST_LIST_INSERT_SORTALPHA()
*/
#define AST_LIST_TRAVERSE(head,var,field) \
for((var) = (head)->first; (var); (var) = (var)->field.next)
@@ -681,6 +682,35 @@ struct { \
#define AST_RWLIST_INSERT_TAIL AST_LIST_INSERT_TAIL
/*!
+ * \brief Inserts a list entry into a alphabetically sorted list
+ * \param head Pointer to the list head structure
+ * \param elm Pointer to the entry to be inserted
+ * \param field Name of the list entry field (declared using AST_LIST_ENTRY())
+ * \param sortfield Name of the field on which the list is sorted
+ */
+#define AST_LIST_INSERT_SORTALPHA(head, elm, field, sortfield) do { \
+ if (!(head)->first) { \
+ (head)->first = (elm); \
+ (head)->last = (elm); \
+ } else { \
+ typeof((head)->first) cur = (head)->first, prev = NULL; \
+ while (cur && strcmp(cur->sortfield, elm->sortfield) < 0) { \
+ prev = cur; \
+ cur = cur->field.next; \
+ } \
+ if (!prev) { \
+ AST_LIST_INSERT_HEAD(head, elm, field); \
+ } else if (!cur) { \
+ AST_LIST_INSERT_TAIL(head, elm, field); \
+ } else { \
+ AST_LIST_INSERT_AFTER(head, prev, elm, field); \
+ } \
+ } \
+} while (0)
+
+#define AST_RWLIST_INSERT_SORTALPHA AST_LIST_INSERT_SORTALPHA
+
+/*!
\brief Appends a whole list to the tail of a list.
\param head This is a pointer to the list head structure
\param list This is a pointer to the list to be appended.