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 @@ -400,24 +400,25 @@ struct grecs_list *grecs_list_create(void); size_t grecs_list_size(struct grecs_list *lp); void grecs_list_append(struct grecs_list *lp, void *val); void grecs_list_push(struct grecs_list *lp, void *val); void *grecs_list_pop(struct grecs_list *lp); void *grecs_list_locate(struct grecs_list *lp, void *data); 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); void grecs_txtacc_free(struct grecs_txtacc *acc); void grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size); void grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf); void grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc, const char *buf); #define grecs_txtacc_grow_char(acc,c) \ @@ -455,24 +456,25 @@ int grecs_symtab_replace(struct grecs_symtab *st, void *ent, void **old_ent); int grecs_symtab_enumerate(struct grecs_symtab *st, grecs_symtab_enumerator_t fun, void *data); size_t grecs_symtab_count_entries(struct grecs_symtab *st); 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 }; enum grecs_tree_recurse_res { grecs_tree_recurse_ok, grecs_tree_recurse_fail, grecs_tree_recurse_skip, @@ -191,12 +191,37 @@ grecs_list_locate(struct grecs_list *lp, void *data) } void * grecs_list_index(struct grecs_list *lp, size_t idx) { struct grecs_list_entry *ep; 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 @@ -2274,25 +2274,25 @@ wordsplit_clearerr (struct wordsplit *ws) } void wordsplit_free (struct wordsplit *ws) { wordsplit_free_words (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; ws->ws_wordc = 0; ws->ws_wordn = 0; } const char *_wordsplit_errstr[] = { N_("no error"), diff --git a/src/wordsplit.h b/src/wordsplit.h index 53503a4..41b09e2 100644 --- a/src/wordsplit.h +++ b/src/wordsplit.h @@ -226,25 +226,25 @@ struct wordsplit #define WRDSE_CBRACE 4 #define WRDSE_UNDEF 5 #define WRDSE_NOINPUT 6 #define WRDSE_PAREN 7 #define WRDSE_GLOBERR 8 #define WRDSE_USERERR 9 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); void wordsplit_perror (wordsplit_t *ws); const char *wordsplit_strerror (wordsplit_t *ws); void wordsplit_clearerr (wordsplit_t *ws); #endif |