diff options
Diffstat (limited to 'str_array.c')
-rw-r--r-- | str_array.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/str_array.c b/str_array.c index db6031d4..e5b3b400 100644 --- a/str_array.c +++ b/str_array.c @@ -55,9 +55,10 @@ static NODE **str_list(NODE *symbol, NODE *subs); static NODE **str_copy(NODE *symbol, NODE *newsymb); static NODE **str_dump(NODE *symbol, NODE *ndump); -array_ptr str_array_func[] = { +afunc_t str_array_func[] = { str_array_init, - (array_ptr) 0, + (afunc_t) 0, + null_length, str_lookup, str_exists, str_clear, @@ -65,6 +66,7 @@ array_ptr str_array_func[] = { str_list, str_copy, str_dump, + (afunc_t) 0, }; static inline NODE **str_find(NODE *symbol, NODE *s1, size_t code1, unsigned long hash1); @@ -77,18 +79,23 @@ static unsigned long awk_hash(const char *s, size_t len, unsigned long hsize, si unsigned long (*hash)(const char *s, size_t len, unsigned long hsize, size_t *code) = awk_hash; -/* str_array_init --- check relevant environment variables */ +/* str_array_init --- array initialization routine */ static NODE ** str_array_init(NODE *symbol ATTRIBUTE_UNUSED, NODE *subs ATTRIBUTE_UNUSED) { - long newval; - const char *val; + if (symbol == NULL) { /* first time */ + long newval; + const char *val; + + /* check relevant environment variables */ + if ((newval = getenv_long("STR_CHAIN_MAX")) > 0) + STR_CHAIN_MAX = newval; + if ((val = getenv("AWK_HASH")) != NULL && strcmp(val, "gst") == 0) + hash = gst_hash_string; + } else + null_array(symbol); - if ((newval = getenv_long("STR_CHAIN_MAX")) > 0) - STR_CHAIN_MAX = newval; - if ((val = getenv("AWK_HASH")) != NULL && strcmp(val, "gst") == 0) - hash = gst_hash_string; return (NODE **) ! NULL; } @@ -217,8 +224,7 @@ str_clear(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED) if (symbol->buckets != NULL) efree(symbol->buckets); - init_array(symbol); /* re-initialize symbol */ - symbol->flags &= ~ARRAYMAXED; + symbol->ainit(symbol, NULL); /* re-initialize symbol */ return NULL; } @@ -264,8 +270,7 @@ str_remove(NODE *symbol, NODE *subs) if (--symbol->table_size == 0) { if (symbol->buckets != NULL) efree(symbol->buckets); - init_array(symbol); /* re-initialize symbol */ - symbol->flags &= ~ARRAYMAXED; + symbol->ainit(symbol, NULL); /* re-initialize symbol */ } return (NODE **) ! NULL; /* return success */ @@ -327,6 +332,7 @@ str_copy(NODE *symbol, NODE *newsymb) newchain->ahcode = chain->ahcode; *pnew = newchain; + newchain->ahnext = NULL; pnew = & newchain->ahnext; } } @@ -349,16 +355,18 @@ str_list(NODE *symbol, NODE *t) BUCKET *b; unsigned long num_elems, list_size, i, k = 0; int elem_size = 1; + assoc_kind_t assoc_kind; if (symbol->table_size == 0) return NULL; - if ((t->flags & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) + assoc_kind = (assoc_kind_t) t->flags; + if ((assoc_kind & (AINDEX|AVALUE)) == (AINDEX|AVALUE)) elem_size = 2; /* allocate space for array */ num_elems = symbol->table_size; - if ((t->flags & (AINDEX|AVALUE|ADELETE)) == (AINDEX|ADELETE)) + if ((assoc_kind & (AINDEX|AVALUE|ADELETE)) == (AINDEX|ADELETE)) num_elems = 1; list_size = elem_size * num_elems; @@ -370,17 +378,17 @@ str_list(NODE *symbol, NODE *t) for (b = symbol->buckets[i]; b != NULL; b = b->ahnext) { /* index */ subs = b->ahname; - if ((t->flags & AINUM) != 0) + if ((assoc_kind & AINUM) != 0) (void) force_number(subs); list[k++] = dupnode(subs); /* value */ - if ((t->flags & AVALUE) != 0) { + if ((assoc_kind & AVALUE) != 0) { val = b->ahvalue; if (val->type == Node_val) { - if ((t->flags & AVNUM) != 0) + if ((assoc_kind & AVNUM) != 0) (void) force_number(val); - else if ((t->flags & AVSTR) != 0) + else if ((assoc_kind & AVSTR) != 0) val = force_string(val); } list[k++] = val; |