summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2016-01-21 06:19:17 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-01-21 06:19:17 (GMT)
commit08070e48d83cd34cddb08be33cf4993fc096c9c4 (patch) (side-by-side diff)
treed030a0ce61e82f668c369420b68369cec3d3ab66 /src
parentca94270a5e30add9b364d32220fb38d457ebd3f2 (diff)
downloadgrecs-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/grecs.hin2
-rw-r--r--src/list.c25
-rw-r--r--src/wordsplit.c2
-rw-r--r--src/wordsplit.h2
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
diff --git a/src/list.c b/src/list.c
index 2d57fe0..f6aa6ad 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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);

Return to:

Send suggestions and report system problems to the System administrator.