aboutsummaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-10-27 11:58:10 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2005-10-27 11:58:10 +0000
commita0e015b98f58f9edf5ce4f40bc3ac5a46e228dfc (patch)
tree2f00f95bd5881314f26aa7f9625551e417ac1072 /src/index.c
parentb51f222f79a78045b8ffd98fc50bfdc33fda1a25 (diff)
when we add an item at a certain index that exceeds the number of elements,
we resize the array to be able to hold the new index. use of "verbose()" svn path=/trunk/externals/zexy/; revision=3769
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/index.c b/src/index.c
index 99ce4ae..51d19f4 100644
--- a/src/index.c
+++ b/src/index.c
@@ -126,11 +126,11 @@ static void index_add(t_index *x, t_symbol *s, t_float f)
{
int newentry=(int)f;
int ok = 0;
-
+
if (! (find_item(s, x->names, x->maxentries)+1) ) {
- if (x->auto_resize && x->entries==x->maxentries){
+ if (x->auto_resize && (x->entries==x->maxentries || newentry>=x->maxentries)){
/* do some resizing */
- int maxentries=x->maxentries*2;
+ int maxentries=(newentry>x->maxentries)?newentry:(x->maxentries*2);
int i;
t_symbol**buf=(t_symbol **)getbytes(sizeof(t_symbol *) * maxentries);
if(buf!=0){
@@ -148,24 +148,22 @@ static void index_add(t_index *x, t_symbol *s, t_float f)
if(newentry>0){
newentry--;
if(x->names[newentry]){ /* it is already taken! */
- error("index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1);
+ verbose(1, "index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1);
outlet_float(x->x_obj.ob_outlet, -1.f);
return;
}
- } else
+ } else {
newentry=find_free(x->names, x->maxentries);
-
+ }
if (newentry + 1) {
x->entries++;
x->names[newentry]=s;
-
outlet_float(x->x_obj.ob_outlet, (t_float)newentry+1);
return;
} else error("index :: couldn't find any place for new entry");
} else error("index :: max number of elements (%d) reached !", x->maxentries);
- } else post("index :: element '%s' already exists", s->s_name);
-
+ } else verbose(1, "index :: element '%s' already exists", s->s_name);
/* couldn't add the symbol to our index table */
outlet_float(x->x_obj.ob_outlet, -1.f);
}
@@ -192,7 +190,7 @@ static void index_delete(t_index *x, t_symbol *s, int argc, t_atom*argv)
x->entries--;
outlet_float(x->x_obj.ob_outlet, 0.0);
} else {
- post("index :: couldn't find element");
+ verbose(1, "index :: couldn't find element");
outlet_float(x->x_obj.ob_outlet, -1.0);
}
}
@@ -222,7 +220,6 @@ static void index_dump(t_index *x)
{
t_atom ap[2];
int i=0;
-
for(i=0; i<x->maxentries; i++){
if(x->names[i]){
SETSYMBOL(ap, x->names[i]);