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 | |
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')
-rw-r--r-- | src/grecs.hin | 2 | ||||
-rw-r--r-- | src/list.c | 25 | ||||
-rw-r--r-- | src/wordsplit.c | 2 | ||||
-rw-r--r-- | src/wordsplit.h | 2 |
4 files changed, 29 insertions, 2 deletions
diff --git a/src/grecs.hin b/src/grecs.hin index b82f45a..48e2937 100644 --- a/src/grecs.hin +++ b/src/grecs.hin | |||
@@ -409,6 +409,7 @@ void grecs_list_remove_entry(struct grecs_list *lp, | |||
409 | void grecs_list_clear(struct grecs_list *lp); | 409 | void grecs_list_clear(struct grecs_list *lp); |
410 | void grecs_list_free(struct grecs_list *lp); | 410 | void grecs_list_free(struct grecs_list *lp); |
411 | void grecs_list_add(struct grecs_list *dst, struct grecs_list *src); | 411 | void grecs_list_add(struct grecs_list *dst, struct grecs_list *src); |
412 | int grecs_list_compare(struct grecs_list *a, struct grecs_list *b); | ||
412 | 413 | ||
413 | int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap); | 414 | int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap); |
414 | int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...); | 415 | int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...); |
@@ -464,6 +465,7 @@ unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize); | |||
464 | void grecs_value_free(struct grecs_value *val); | 465 | void grecs_value_free(struct grecs_value *val); |
465 | void grecs_value_free_content(struct grecs_value *val); | 466 | void grecs_value_free_content(struct grecs_value *val); |
466 | void grecs_node_free(struct grecs_node *node); | 467 | void grecs_node_free(struct grecs_node *node); |
468 | int grecs_node_unlink(struct grecs_node *node); | ||
467 | int grecs_tree_free(struct grecs_node *node); | 469 | int grecs_tree_free(struct grecs_node *node); |
468 | 470 | ||
469 | enum grecs_tree_recurse_op { | 471 | enum grecs_tree_recurse_op { |
@@ -200,3 +200,28 @@ grecs_list_index(struct grecs_list *lp, size_t idx) | |||
200 | return ep ? ep->data : NULL; | 200 | return ep ? ep->data : NULL; |
201 | } | 201 | } |
202 | 202 | ||
203 | int | ||
204 | grecs_list_compare(struct grecs_list *a, struct grecs_list *b) | ||
205 | { | ||
206 | struct grecs_list_entry *ap, *bp; | ||
207 | int (*cmp)(const void *, const void *); | ||
208 | |||
209 | if (!a) | ||
210 | return !!b; | ||
211 | else if (!b) | ||
212 | return 1; | ||
213 | |||
214 | if (grecs_list_size(a) != grecs_list_size(b)) | ||
215 | return 1; | ||
216 | if (a->cmp != b->cmp) | ||
217 | return 1; | ||
218 | |||
219 | cmp = a->cmp ? a->cmp : _ptrcmp; | ||
220 | |||
221 | for (ap = a->head, bp = b->head; ap; ap = ap->next, bp = bp->next) | ||
222 | if (cmp (ap->data, bp->data)) | ||
223 | return 1; | ||
224 | |||
225 | return 0; | ||
226 | } | ||
227 | |||
diff --git a/src/wordsplit.c b/src/wordsplit.c index 86d4f4b..1045ca8 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c | |||
@@ -2283,7 +2283,7 @@ wordsplit_free (struct wordsplit *ws) | |||
2283 | } | 2283 | } |
2284 | 2284 | ||
2285 | void | 2285 | void |
2286 | wordsplit_getwords (struct wordsplit *ws, int *wordc, char ***wordv) | 2286 | wordsplit_getwords (struct wordsplit *ws, size_t *wordc, char ***wordv) |
2287 | { | 2287 | { |
2288 | char **p = realloc (ws->ws_wordv, | 2288 | char **p = realloc (ws->ws_wordv, |
2289 | (ws->ws_wordc + 1) * sizeof (ws->ws_wordv[0])); | 2289 | (ws->ws_wordc + 1) * sizeof (ws->ws_wordv[0])); |
diff --git a/src/wordsplit.h b/src/wordsplit.h index 53503a4..41b09e2 100644 --- a/src/wordsplit.h +++ b/src/wordsplit.h | |||
@@ -235,7 +235,7 @@ int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, int flags); | |||
235 | void wordsplit_free (wordsplit_t *ws); | 235 | void wordsplit_free (wordsplit_t *ws); |
236 | void wordsplit_free_words (wordsplit_t *ws); | 236 | void wordsplit_free_words (wordsplit_t *ws); |
237 | void wordsplit_free_envbuf (wordsplit_t *ws); | 237 | void wordsplit_free_envbuf (wordsplit_t *ws); |
238 | void wordsplit_getwords (wordsplit_t *ws, int *wordc, char ***wordv); | 238 | void wordsplit_getwords (wordsplit_t *ws, size_t *wordc, char ***wordv); |
239 | 239 | ||
240 | int wordsplit_c_unquote_char (int c); | 240 | int wordsplit_c_unquote_char (int c); |
241 | int wordsplit_c_quote_char (int c); | 241 | int wordsplit_c_quote_char (int c); |