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) (unidiff)
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
@@ -409,6 +409,7 @@ void grecs_list_remove_entry(struct grecs_list *lp,
409void grecs_list_clear(struct grecs_list *lp); 409void grecs_list_clear(struct grecs_list *lp);
410void grecs_list_free(struct grecs_list *lp); 410void grecs_list_free(struct grecs_list *lp);
411void grecs_list_add(struct grecs_list *dst, struct grecs_list *src); 411void grecs_list_add(struct grecs_list *dst, struct grecs_list *src);
412int grecs_list_compare(struct grecs_list *a, struct grecs_list *b);
412 413
413int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap); 414int grecs_vasprintf(char **pbuf, size_t *psize, const char *fmt, va_list ap);
414int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...); 415int 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);
464void grecs_value_free(struct grecs_value *val); 465void grecs_value_free(struct grecs_value *val);
465void grecs_value_free_content(struct grecs_value *val); 466void grecs_value_free_content(struct grecs_value *val);
466void grecs_node_free(struct grecs_node *node); 467void grecs_node_free(struct grecs_node *node);
468int grecs_node_unlink(struct grecs_node *node);
467int grecs_tree_free(struct grecs_node *node); 469int grecs_tree_free(struct grecs_node *node);
468 470
469enum grecs_tree_recurse_op { 471enum grecs_tree_recurse_op {
diff --git a/src/list.c b/src/list.c
index 2d57fe0..f6aa6ad 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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
203int
204grecs_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
2285void 2285void
2286wordsplit_getwords (struct wordsplit *ws, int *wordc, char ***wordv) 2286wordsplit_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);
235void wordsplit_free (wordsplit_t *ws); 235void wordsplit_free (wordsplit_t *ws);
236void wordsplit_free_words (wordsplit_t *ws); 236void wordsplit_free_words (wordsplit_t *ws);
237void wordsplit_free_envbuf (wordsplit_t *ws); 237void wordsplit_free_envbuf (wordsplit_t *ws);
238void wordsplit_getwords (wordsplit_t *ws, int *wordc, char ***wordv); 238void wordsplit_getwords (wordsplit_t *ws, size_t *wordc, char ***wordv);
239 239
240int wordsplit_c_unquote_char (int c); 240int wordsplit_c_unquote_char (int c);
241int wordsplit_c_quote_char (int c); 241int wordsplit_c_quote_char (int c);

Return to:

Send suggestions and report system problems to the System administrator.