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 | |||
@@ -406,12 +406,13 @@ void *grecs_list_index(struct grecs_list *lp, size_t idx); | |||
406 | void *grecs_list_remove_tail(struct grecs_list *lp); | 406 | void *grecs_list_remove_tail(struct grecs_list *lp); |
407 | void grecs_list_remove_entry(struct grecs_list *lp, | 407 | void grecs_list_remove_entry(struct grecs_list *lp, |
408 | struct grecs_list_entry *ent); | 408 | struct grecs_list_entry *ent); |
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, ...); |
415 | 416 | ||
416 | #define GRECS_TXTACC_BUFSIZE 1024 | 417 | #define GRECS_TXTACC_BUFSIZE 1024 |
417 | struct grecs_txtacc *grecs_txtacc_create(void); | 418 | struct grecs_txtacc *grecs_txtacc_create(void); |
@@ -461,12 +462,13 @@ unsigned grecs_hash_string(const char *name, unsigned long hashsize); | |||
461 | unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize); | 462 | unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize); |
462 | 463 | ||
463 | 464 | ||
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 { |
470 | grecs_tree_recurse_set, | 472 | grecs_tree_recurse_set, |
471 | grecs_tree_recurse_pre, | 473 | grecs_tree_recurse_pre, |
472 | grecs_tree_recurse_post | 474 | grecs_tree_recurse_post |
@@ -197,6 +197,31 @@ grecs_list_index(struct grecs_list *lp, size_t idx) | |||
197 | 197 | ||
198 | for (ep = lp->head; ep && idx; ep = ep->next, idx--) | 198 | for (ep = lp->head; ep && idx; ep = ep->next, idx--) |
199 | ; | 199 | ; |
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 | |||
@@ -2280,13 +2280,13 @@ wordsplit_free (struct wordsplit *ws) | |||
2280 | free (ws->ws_wordv); | 2280 | free (ws->ws_wordv); |
2281 | ws->ws_wordv = NULL; | 2281 | ws->ws_wordv = NULL; |
2282 | wordsplit_free_envbuf (ws); | 2282 | wordsplit_free_envbuf (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])); |
2290 | *wordv = p ? p : ws->ws_wordv; | 2290 | *wordv = p ? p : ws->ws_wordv; |
2291 | *wordc = ws->ws_wordc; | 2291 | *wordc = ws->ws_wordc; |
2292 | ws->ws_wordv = NULL; | 2292 | ws->ws_wordv = NULL; |
diff --git a/src/wordsplit.h b/src/wordsplit.h index 53503a4..41b09e2 100644 --- a/src/wordsplit.h +++ b/src/wordsplit.h | |||
@@ -232,13 +232,13 @@ struct wordsplit | |||
232 | 232 | ||
233 | int wordsplit (const char *s, wordsplit_t *ws, int flags); | 233 | int wordsplit (const char *s, wordsplit_t *ws, int flags); |
234 | int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, int flags); | 234 | 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); |
242 | size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote); | 242 | size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote); |
243 | void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); | 243 | void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); |
244 | 244 | ||