aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-01-21 08:19:17 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-01-21 08:19:17 +0200
commit08070e48d83cd34cddb08be33cf4993fc096c9c4 (patch)
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')
-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);
406void *grecs_list_remove_tail(struct grecs_list *lp); 406void *grecs_list_remove_tail(struct grecs_list *lp);
407void grecs_list_remove_entry(struct grecs_list *lp, 407void grecs_list_remove_entry(struct grecs_list *lp,
408 struct grecs_list_entry *ent); 408 struct grecs_list_entry *ent);
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, ...);
415 416
416#define GRECS_TXTACC_BUFSIZE 1024 417#define GRECS_TXTACC_BUFSIZE 1024
417struct grecs_txtacc *grecs_txtacc_create(void); 418struct grecs_txtacc *grecs_txtacc_create(void);
@@ -461,12 +462,13 @@ unsigned grecs_hash_string(const char *name, unsigned long hashsize);
461unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize); 462unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize);
462 463
463 464
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 {
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
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)
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
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
@@ -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
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]));
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
233int wordsplit (const char *s, wordsplit_t *ws, int flags); 233int wordsplit (const char *s, wordsplit_t *ws, int flags);
234int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, int flags); 234int 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);
242size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote); 242size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote);
243void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); 243void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
244 244

Return to:

Send suggestions and report system problems to the System administrator.