diff options
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); void *grecs_list_remove_tail(struct grecs_list *lp); void grecs_list_remove_entry(struct grecs_list *lp, struct grecs_list_entry *ent); void grecs_list_clear(struct grecs_list *lp); void grecs_list_free(struct grecs_list *lp); void grecs_list_add(struct grecs_list *dst, struct grecs_list *src); +int grecs_list_compare(struct grecs_list *a, struct grecs_list *b); int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap); int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...); #define GRECS_TXTACC_BUFSIZE 1024 struct grecs_txtacc *grecs_txtacc_create(void); @@ -461,12 +462,13 @@ unsigned grecs_hash_string(const char *name, unsigned long hashsize); unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize); void grecs_value_free(struct grecs_value *val); void grecs_value_free_content(struct grecs_value *val); void grecs_node_free(struct grecs_node *node); +int grecs_node_unlink(struct grecs_node *node); int grecs_tree_free(struct grecs_node *node); enum grecs_tree_recurse_op { grecs_tree_recurse_set, grecs_tree_recurse_pre, grecs_tree_recurse_post @@ -197,6 +197,31 @@ grecs_list_index(struct grecs_list *lp, size_t idx) for (ep = lp->head; ep && idx; ep = ep->next, 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; +} + 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) free (ws->ws_wordv); ws->ws_wordv = NULL; wordsplit_free_envbuf (ws); } void -wordsplit_getwords (struct wordsplit *ws, int *wordc, char ***wordv) +wordsplit_getwords (struct wordsplit *ws, size_t *wordc, char ***wordv) { char **p = realloc (ws->ws_wordv, (ws->ws_wordc + 1) * sizeof (ws->ws_wordv[0])); *wordv = p ? p : ws->ws_wordv; *wordc = ws->ws_wordc; 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 int wordsplit (const char *s, wordsplit_t *ws, int flags); int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, int flags); void wordsplit_free (wordsplit_t *ws); void wordsplit_free_words (wordsplit_t *ws); void wordsplit_free_envbuf (wordsplit_t *ws); -void wordsplit_getwords (wordsplit_t *ws, int *wordc, char ***wordv); +void wordsplit_getwords (wordsplit_t *ws, size_t *wordc, char ***wordv); int wordsplit_c_unquote_char (int c); int wordsplit_c_quote_char (int c); size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote); void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); |