diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-01-21 08:19:17 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-01-21 08:19:17 +0200 |
commit | 08070e48d83cd34cddb08be33cf4993fc096c9c4 (patch) | |
tree | d030a0ce61e82f668c369420b68369cec3d3ab66 /src/list.c | |
parent | ca94270a5e30add9b364d32220fb38d457ebd3f2 (diff) | |
download | grecs-08070e48d83cd34cddb08be33cf4993fc096c9c4.tar.gz grecs-08070e48d83cd34cddb08be33cf4993fc096c9c4.tar.bz2 |
Implement grecs_list_compare; other minor fixes.
* src/grecs.hin (grecs_list_compare)
(grecs_node_unlink): New protos.
* src/list.c (grecs_list_compare): New function.
* src/wordsplit.c (wordsplit_getwords): Word count is size_t
* src/wordsplit.h (wordsplit_getwords): Fix proto.
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -200,3 +200,28 @@ grecs_list_index(struct grecs_list *lp, size_t idx) return ep ? ep->data : NULL; } +int +grecs_list_compare(struct grecs_list *a, struct grecs_list *b) +{ + struct grecs_list_entry *ap, *bp; + int (*cmp)(const void *, const void *); + + if (!a) + return !!b; + else if (!b) + return 1; + + if (grecs_list_size(a) != grecs_list_size(b)) + return 1; + if (a->cmp != b->cmp) + return 1; + + cmp = a->cmp ? a->cmp : _ptrcmp; + + for (ap = a->head, bp = b->head; ap; ap = ap->next, bp = bp->next) + if (cmp (ap->data, bp->data)) + return 1; + + return 0; +} + |