diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-04-30 12:06:47 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-04-30 12:06:47 +0300 |
commit | bd4a203ab453d78e87e29d11017b35248c9babca (patch) | |
tree | 739ddb735fdfb6aaf668ca1b2ff994004e63d6a0 /src/grecs-gram.y | |
parent | 3f02a6139ea4ed7635453cbcdd600e815a5c2208 (diff) | |
download | grecs-bd4a203ab453d78e87e29d11017b35248c9babca.tar.gz grecs-bd4a203ab453d78e87e29d11017b35248c9babca.tar.bz2 |
Remove dependency on xlists.
* gnulib.modules (linked-list, xlist): Remove.
* src/list.c: New file.
* src/Makefile.am (libgrecs_a_SOURCES): Add list.c
* src/grecs-gram.y: Use grecs_list functions.
* src/preproc.c: Likewise.
* src/grecs.h (grecs_list_entry, grecs_list): New structs.
(grecs_value): use struct grecs_list* for the v.list member.
(grecs_log_to_stderr): Change type to int.
(grecs_list_create, grecs_list_size, grecs_list_push)
(grecs_list_pop, grecs_list_locate, grecs_list_index)
(grecs_list_remove_tail): New protos.
Diffstat (limited to 'src/grecs-gram.y')
-rw-r--r-- | src/grecs-gram.y | 181 |
1 files changed, 86 insertions, 95 deletions
diff --git a/src/grecs-gram.y b/src/grecs-gram.y index 0fe8443..e36865d 100644 --- a/src/grecs-gram.y +++ b/src/grecs-gram.y @@ -51,7 +51,7 @@ typedef union static struct grecs_keyword config_keywords; static struct grecs_keyword *cursect; #define CURRENT_BASE ((char*)(cursect ? cursect->callback_data : NULL)) -static gl_list_t sections; +static struct grecs_list *sections; int grecs_error_count; int grecs_default_port = 0; @@ -62,13 +62,13 @@ static void stmt_end (struct grecs_keyword *kwp); static struct grecs_keyword *find_keyword (const char *ident); static void process_ident (struct grecs_keyword *kwp, grecs_value_t *value); -static gl_list_t simple_list_create (int dispose); +static struct grecs_list *simple_list_create (int dispose); %} %union { char *string; grecs_value_t value; - gl_list_t list; + struct grecs_list *list; struct grecs_keyword *kw; } @@ -124,32 +124,33 @@ vallist : vlist { size_t n; - if ((n = gl_list_size ($1)) == 1) + if ((n = grecs_list_size ($1)) == 1) { - $$ = *(grecs_value_t *)gl_list_get_at ($1, 0); + $$ = *(grecs_value_t *)grecs_list_index ($1, 0); } else { size_t i; + struct grecs_list_entry *ep; $$.type = GRECS_TYPE_ARRAY; $$.v.arg.c = n; $$.v.arg.v = xcalloc (n, sizeof ($$.v.arg.v[0])); - for (i = 0; i < n; i++) - $$.v.arg.v[i] = *(grecs_value_t *)gl_list_get_at ($1, i); + for (i = 0, ep = $1->head; ep; i++, ep = ep->next) + $$.v.arg.v[i] = *(grecs_value_t *)ep->data; } - gl_list_free ($1); + grecs_list_free ($1); } ; vlist : value { $$ = simple_list_create (0); - gl_list_add_last ($$, grecs_value_dup (&$1)); + grecs_list_append ($$, grecs_value_dup (&$1)); } | vlist value { - gl_list_add_last ($1, grecs_value_dup (&$2)); + grecs_list_append ($1, grecs_value_dup (&$2)); } ; @@ -177,26 +178,25 @@ string : STRING slist : slist0 { + struct grecs_list_entry *ep; const void *p; - gl_list_iterator_t itr = gl_list_iterator ($1); - + grecs_line_begin (); - while (gl_list_iterator_next (&itr, &p, NULL)) - grecs_line_add (p, strlen (p)); + for (ep = $1->head; ep; ep = ep->next) + grecs_line_add (ep->data, strlen (ep->data)); $$ = grecs_line_finish (); - gl_list_iterator_free (&itr); - gl_list_free ($1); + grecs_list_free ($1); } ; slist0 : QSTRING { $$ = simple_list_create (0); - gl_list_add_last ($$, $1); + grecs_list_append ($$, $1); } | slist0 QSTRING { - gl_list_add_last ($1, $2); + grecs_list_append ($1, $2); $$ = $1; } ; @@ -218,11 +218,11 @@ list : '(' ')' values : value { $$ = simple_list_create (0); - gl_list_add_last ($$, grecs_value_dup (&$1)); + grecs_list_append ($$, grecs_value_dup (&$1)); } | values ',' value { - gl_list_add_last ($1, grecs_value_dup (&$3)); + grecs_list_append ($1, grecs_value_dup (&$3)); $$ = $1; } ; @@ -241,19 +241,18 @@ yyerror(char *s) } static void -listel_dispose(const void *el) +listel_dispose (void *el) { - free((void*)el); + free (el); } -static gl_list_t +static struct grecs_list * simple_list_create (int dispose) { - return gl_list_create_empty(&gl_linked_list_implementation, - NULL, - NULL, - dispose ? listel_dispose : NULL, - 0); + struct grecs_list *lp = grecs_list_create (); + if (dispose) + lp->free_entry = listel_dispose; + return lp; } @@ -299,7 +298,7 @@ grecs_parse (const char *name) cursect = &config_keywords; if (sections) { - gl_list_free (sections); + grecs_list_free (sections); sections = NULL; } rc = yyparse (); @@ -356,8 +355,8 @@ stmt_begin (struct grecs_keyword *kwp, grecs_value_t tag) void *target; if (!sections) - sections = simple_list_create (0); - gl_list_add_first (sections, cursect); + sections = grecs_list_create (); + grecs_list_push (sections, cursect); if (kwp) { target = target_ptr (kwp, CURRENT_BASE); @@ -386,10 +385,9 @@ stmt_end (struct grecs_keyword *kwp) dataptr = &cursect->callback_data; } - if (gl_list_size (sections) == 0) + cursect = (struct grecs_keyword *) grecs_list_pop (sections); + if (!cursect) abort (); - cursect = (struct grecs_keyword *) gl_list_get_at (sections, 0); - gl_list_remove_at (sections, 0); if (callback) callback (grecs_callback_section_end, &grecs_current_locus, /* FIXME */ @@ -712,54 +710,54 @@ grecs_string_convert (void *target, enum grecs_data_type type, struct grecs_prop { size_t size; - gl_listelement_equals_fn eqfn; + int (*cmp) (const void *, const void *); }; -static bool -string_eq (const void *elt1, const void *elt2) +static int +string_cmp (const void *elt1, const void *elt2) { - return strcmp ((const char *)elt1, (const char *)elt2) == 0; + return strcmp ((const char *)elt1, (const char *)elt2); } #define __grecs_name_cat__(a,b) a ## b -#define NUMEQ(type) __grecs_name_cat__(type,_eq) -#define __DECL_NUMEQ(type,ctype) \ - static bool \ - NUMEQ(type) (const void *elt1, const void *elt2) \ +#define NUMCMP(type) __grecs_name_cat__(type,_cmp) +#define __DECL_NUMCMP(type,ctype) \ + static int \ + NUMCMP(type) (const void *elt1, const void *elt2) \ { \ - return memcmp (elt1, elt2, sizeof (ctype)) == 0; \ + return memcmp (elt1, elt2, sizeof (ctype)); \ } -#define DECL_NUMEQ(type) __DECL_NUMEQ(type,type) - -DECL_NUMEQ(short) -DECL_NUMEQ(int) -DECL_NUMEQ(long) -DECL_NUMEQ(size_t) -DECL_NUMEQ(uintmax_t) -DECL_NUMEQ(intmax_t) -DECL_NUMEQ(time_t) -__DECL_NUMEQ(in_addr, struct in_addr) -__DECL_NUMEQ(grecs_sockaddr, struct grecs_sockaddr) +#define DECL_NUMCMP(type) __DECL_NUMCMP(type,type) + +DECL_NUMCMP(short) +DECL_NUMCMP(int) +DECL_NUMCMP(long) +DECL_NUMCMP(size_t) +DECL_NUMCMP(uintmax_t) +DECL_NUMCMP(intmax_t) +DECL_NUMCMP(time_t) +__DECL_NUMCMP(in_addr, struct in_addr) +__DECL_NUMCMP(grecs_sockaddr, struct grecs_sockaddr) struct grecs_prop grecs_prop_tab[] = { { 0, NULL }, /* grecs_type_void */ - { sizeof (char*), string_eq }, /* grecs_type_string */ - { sizeof (short), NUMEQ (short) }, /* grecs_type_short */ - { sizeof (unsigned short), NUMEQ (short) }, /* grecs_type_ushort */ - { sizeof (int), NUMEQ (int) }, /* grecs_type_int */ - { sizeof (unsigned int), NUMEQ (int) }, /* grecs_type_uint */ - { sizeof (long), NUMEQ (long) }, /* grecs_type_long */ - { sizeof (unsigned long), NUMEQ (long) }, /* grecs_type_ulong */ - { sizeof (size_t), NUMEQ (size_t) }, /* grecs_type_size */ + { sizeof (char*), string_cmp }, /* grecs_type_string */ + { sizeof (short), NUMCMP (short) }, /* grecs_type_short */ + { sizeof (unsigned short), NUMCMP (short) }, /* grecs_type_ushort */ + { sizeof (int), NUMCMP (int) }, /* grecs_type_int */ + { sizeof (unsigned int), NUMCMP (int) }, /* grecs_type_uint */ + { sizeof (long), NUMCMP (long) }, /* grecs_type_long */ + { sizeof (unsigned long), NUMCMP (long) }, /* grecs_type_ulong */ + { sizeof (size_t), NUMCMP (size_t) }, /* grecs_type_size */ /* grecs_type_off,*/ - { sizeof (uintmax_t), NUMEQ (uintmax_t) }, /* grecs_type_uintmax */ - { sizeof (intmax_t), NUMEQ (intmax_t) }, /* grecs_type_intmax */ - { sizeof (time_t), NUMEQ (time_t) }, /* grecs_type_time */ - { sizeof (int), NUMEQ (int) }, /* grecs_type_bool */ - { sizeof (struct in_addr), NUMEQ (in_addr) }, /* grecs_type_ipv4 */ + { sizeof (uintmax_t), NUMCMP (uintmax_t) }, /* grecs_type_uintmax */ + { sizeof (intmax_t), NUMCMP (intmax_t) }, /* grecs_type_intmax */ + { sizeof (time_t), NUMCMP (time_t) }, /* grecs_type_time */ + { sizeof (int), NUMCMP (int) }, /* grecs_type_bool */ + { sizeof (struct in_addr), NUMCMP (in_addr) }, /* grecs_type_ipv4 */ { 0, NULL }, /* FIXME: grecs_type_cidr */ - { sizeof (struct in_addr), NUMEQ (in_addr) }, /* grecs_type_host */ - { sizeof (struct grecs_sockaddr), NUMEQ (grecs_sockaddr) }, + { sizeof (struct in_addr), NUMCMP (in_addr) }, /* grecs_type_host */ + { sizeof (struct grecs_sockaddr), NUMCMP (grecs_sockaddr) }, /* grecs_type_sockaddr */ { 0, NULL } /* grecs_type_section */ }; @@ -794,11 +792,10 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value, { if (GRECS_IS_LIST (kwp->type)) { - gl_list_iterator_t itr = gl_list_iterator (value->v.list); + struct grecs_list_entry *ep; enum grecs_data_type type = GRECS_TYPE (kwp->type); int num = 1; - const void *p; - gl_list_t list; + struct grecs_list *list; size_t size; if (type >= grecs_prop_count @@ -811,34 +808,30 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value, abort (); } - list = gl_list_create_empty (&gl_linked_list_implementation, - grecs_prop_tab[type].eqfn, - NULL, - NULL, - 0); - - while (gl_list_iterator_next (&itr, &p, NULL)) + list = grecs_list_create (); + list->cmp = grecs_prop_tab[type].cmp; + + for (ep = value->v.list->head; ep; ep = ep->next) { - const grecs_value_t *vp = p; + const grecs_value_t *vp = ep->data; if (vp->type != GRECS_TYPE_STRING) grecs_error (locus, 0, _("%s: incompatible data type in list item #%d"), kwp->ident, num); else if (type == grecs_type_string) - gl_list_add_last (list, vp->v.string); + grecs_list_append (list, (void*) vp->v.string); else { void *ptr = xmalloc (size); if (grecs_string_convert (ptr, type, vp->v.string, locus) == 0) - gl_list_add_last (list, ptr); + grecs_list_append (list, ptr); else free (ptr); } } - gl_list_iterator_free (&itr); - *(gl_list_t*)target = list; + *(struct grecs_list**)target = list; } else { @@ -850,7 +843,7 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value, } else if (GRECS_IS_LIST (kwp->type)) { - gl_list_t list; + struct grecs_list *list; enum grecs_data_type type = GRECS_TYPE (kwp->type); size_t size; void *ptr; @@ -863,26 +856,24 @@ grecs_process_ident (struct grecs_keyword *kwp, grecs_value_t *value, __FILE__, __LINE__, type); abort(); } - - list = gl_list_create_empty (&gl_linked_list_implementation, - grecs_prop_tab[type].eqfn, - NULL, - listel_dispose, - 0); + + list = grecs_list_create (); + list->cmp = grecs_prop_tab[type].cmp; + list->free_entry = listel_dispose; if (type == grecs_type_string) - gl_list_add_last (list, value->v.string); + grecs_list_append (list, value->v.string); else { ptr = xmalloc (size); if (grecs_string_convert (ptr, type, value->v.string, locus)) { free (ptr); - gl_list_free (list); + grecs_list_free (list); return; } - gl_list_add_last (list, ptr); + grecs_list_append (list, ptr); } - *(gl_list_t*)target = list; + *(struct grecs_list**)target = list; } else grecs_string_convert (target, GRECS_TYPE (kwp->type), value->v.string, |