aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2010-07-16 12:57:07 +0300
committerArnold D. Robbins <arnold@skeeve.com>2010-07-16 12:57:07 +0300
commit3ca7f0b16d0a5c105380b284a81c6a1b2c210908 (patch)
treec2153d226b9cba3ebca0c3556b19bf3e52cd20dd /array.c
parentf20ab7c3039a4023f41372bfe4bde3b16d481df7 (diff)
downloadegawk-3ca7f0b16d0a5c105380b284a81c6a1b2c210908.tar.gz
egawk-3ca7f0b16d0a5c105380b284a81c6a1b2c210908.tar.bz2
egawk-3ca7f0b16d0a5c105380b284a81c6a1b2c210908.zip
Move to gawk-3.0.5.
Diffstat (limited to 'array.c')
-rw-r--r--array.c91
1 files changed, 78 insertions, 13 deletions
diff --git a/array.c b/array.c
index 4906384d..2cbfae89 100644
--- a/array.c
+++ b/array.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-1999 the Free Software Foundation, Inc.
+ * Copyright (C) 1986, 1988, 1989, 1991-2000 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -61,8 +61,8 @@ register NODE *tree;
r = force_string(tree_eval(tree->lnode));
if (tree->rnode == NULL)
return r;
- subseplen = SUBSEP_node->lnode->stlen;
- subsep = SUBSEP_node->lnode->stptr;
+ subseplen = SUBSEP_node->var_value->stlen;
+ subsep = SUBSEP_node->var_value->stptr;
len = r->stlen + subseplen + 2;
emalloc(str, char *, len, "concat_exp");
memcpy(str, r->stptr, r->stlen+1);
@@ -214,10 +214,19 @@ register NODE *subs;
int hash1;
{
register NODE *bucket;
+ NODE *s1, *s2;
for (bucket = symbol->var_array[hash1]; bucket != NULL;
bucket = bucket->ahnext) {
- if (cmp_nodes(bucket->ahname, subs) == 0)
+ /*
+ * This used to use cmp_nodes() here. That's wrong.
+ * Array indexes are strings; compare as such, always!
+ */
+ s1 = bucket->ahname;
+ s2 = subs;
+
+ if (s1->stlen == s2->stlen
+ && STREQN(s1->stptr, s2->stptr, s1->stlen))
return bucket;
}
return NULL;
@@ -234,6 +243,8 @@ NODE *symbol, *subs;
if (symbol->type == Node_param_list)
symbol = stack_ptr[symbol->param_cnt];
+ if (symbol->type == Node_array_ref)
+ symbol = symbol->orig_array;
if ((symbol->flags & SCALAR) != 0)
fatal("attempt to use scalar as array");
/*
@@ -266,6 +277,8 @@ NODE *symbol, *subs;
register int hash1;
register NODE *bucket;
+ assert(symbol->type == Node_var_array || symbol->type == Node_var);
+
(void) force_string(subs);
if ((symbol->flags & SCALAR) != 0)
@@ -308,15 +321,7 @@ NODE *symbol, *subs;
getnode(bucket);
bucket->type = Node_ahash;
- if (subs->flags & TEMP)
- bucket->ahname = dupnode(subs);
- else {
- unsigned int saveflags = subs->flags;
-
- subs->flags &= ~MALLOC;
- bucket->ahname = dupnode(subs);
- subs->flags = saveflags;
- }
+ bucket->ahname = dupnode(subs);
free_temp(subs);
/* array subscripts are strings */
@@ -343,6 +348,8 @@ NODE *symbol, *tree;
if (symbol->type == Node_var)
return;
}
+ if (symbol->type == Node_array_ref)
+ symbol = symbol->orig_array;
if (symbol->type == Node_var_array) {
if (symbol->var_array == NULL)
return;
@@ -528,3 +535,61 @@ done:
symbol->var_array = new;
symbol->array_size = newsize;
}
+
+/* pr_node --- print simple node info */
+
+static void
+pr_node(n)
+NODE *n;
+{
+ if ((n->flags & (NUM|NUMBER)) != 0)
+ printf("%g", n->numbr);
+ else
+ printf("%.*s", (int) n->stlen, n->stptr);
+}
+
+/* assoc_dump --- dump the contents of an array */
+
+NODE *
+assoc_dump(symbol)
+NODE *symbol;
+{
+ int i;
+ NODE *bucket;
+
+ if (symbol->var_array == NULL) {
+ printf("%s: empty\n", symbol->vname);
+ return tmp_number((AWKNUM) 0);
+ }
+
+ for (i = 0; i < symbol->array_size; i++) {
+ for (bucket = symbol->var_array[i]; bucket != NULL;
+ bucket = bucket->ahnext) {
+ printf("%s: i: (%p, %ld, %s) %.*s, v: ",
+ symbol->vname,
+ bucket->ahname,
+ bucket->ahname->stref,
+ flags2str(bucket->ahname->flags),
+ (int) bucket->ahname->stlen,
+ bucket->ahname->stptr);
+ pr_node(bucket->ahvalue);
+ printf("\n");
+ }
+ }
+
+ return tmp_number((AWKNUM) 0);
+}
+
+/* do_adump --- dump an array: interface to assoc_dump */
+
+NODE *
+do_adump(tree)
+NODE *tree;
+{
+ NODE *r, *a;
+
+ a = tree->lnode;
+ r = assoc_dump(a);
+
+ return r;
+}