--- stack/stack.c 2002/03/10 20:08:47 1.102 +++ stack/stack.c 2002/03/11 08:52:59 1.103 @@ -78,7 +78,7 @@ return; } - env->head= env->head->cdr->content.c; /* Remove the top stack item */ + env->head= env->head->cdr->content.c; /* Remove the top stack item */ free(temp); /* Free the old top stack item */ } @@ -475,7 +475,7 @@ break; case tcons: /* A list is just a stack, so make stack_head point to it */ - stack_head=(cons*)(stack_head->car->content.ptr); + stack_head=stack_head->car->content.c; printf("[ "); while(stack_head != NULL) { print_h(stack_head, noquote); @@ -567,7 +567,7 @@ cons *temp= env->head; if(env->head==NULL || env->head->cdr->content.c==NULL - || env->head->cdr->content.c->cdr->content.c==NULL) { + || env->head->cdr->content.c->cdr->content.c==NULL) { printerr("Too Few Arguments"); env->err=1; return; @@ -660,13 +660,19 @@ toss(env); if(env->err) return; - if(iterator->cdr->content.c==NULL){ + if(iterator->cdr->content.ptr==NULL){ goto eval_start; } eval(env); if(env->err) return; } - iterator= iterator->cdr->content.c; + if (iterator->cdr->type == tcons) + iterator= iterator->cdr->content.c; + else { + printerr("Bad Argument Type"); /* Improper list */ + env->err= 2; + return; + } } unprotect(temp_val); return; @@ -693,7 +699,7 @@ return; } - old_head= (cons*)(env->head->car->content.ptr); + old_head= env->head->car->content.c; new_head= NULL; while(old_head!=NULL) { item= old_head; @@ -723,7 +729,7 @@ /* Search for first delimiter */ while(iterator->cdr->content.c!=NULL && (iterator->cdr->content.c->car->type!=symb - || ((symbol*)(iterator->cdr->content.c->car->content.ptr))->id[0] + || ((symbol*)(iterator->cdr->content.c->car->content.ptr))->id[0] !='[')) iterator= iterator->cdr->content.c; @@ -770,13 +776,20 @@ return; /* The first list element is the new stack head */ - new_head= temp= env->head->car->content.ptr; + new_head= temp= env->head->car->content.c; toss(env); /* Find the end of the list */ - while(temp->cdr->content.c!=NULL) - temp= temp->cdr->content.c; + while(temp->cdr->content.ptr != NULL) { + if (temp->cdr->type == tcons) + temp= temp->cdr->content.c; + else { + printerr("Bad Argument Type"); /* Improper list */ + env->err= 2; + return; + } + } /* Connect the tail of the list with the old stack head */ temp->cdr->content.c= env->head; @@ -987,7 +1000,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.102 $\n\ + printf("Stack version $Revision: 1.103 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ Stack comes with ABSOLUTELY NO WARRANTY; for details type `warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\ @@ -1269,22 +1282,13 @@ new_value->content.ptr= NULL; prev_item= NULL; - old_item= (cons*)(old_value->content.ptr); + old_item= old_value->content.c; - while(old_item != NULL) { /* While list is not empty */ + if(old_value->content.ptr != NULL) { /* if list is not empty */ new_item= malloc(sizeof(cons)); new_item->car= copy_val(env, old_item->car); /* recurse */ - new_item->cdr= new_val(env); - new_item->cdr->type= tcons; - new_item->cdr->content.c= NULL; - if(prev_item != NULL) /* If this wasn't the first item */ - prev_item->cdr->content.c= new_item; /* point the previous item to the - new item */ - else - new_value->content.ptr= new_item; - old_item= old_item->cdr->content.c; - prev_item= new_item; - } + new_item->cdr= copy_val(env, old_item->cdr); /* recurse */ + } break; } @@ -1491,13 +1495,19 @@ protect(foo); toss(env); if(env->err) return; - iterator= foo->content.ptr; + iterator= foo->content.c; while(iterator!=NULL) { push_val(env, iterator->car); push_val(env, loop); eval(env); if(env->err) return; - iterator= iterator->cdr->content.c; + if (iterator->cdr->type == tcons){ + iterator= iterator->cdr->content.c; + } else { + printerr("Bad Argument Type"); /* Improper list */ + env->err= 2; + break; + } } unprotect(loop); unprotect(foo); } @@ -1543,16 +1553,16 @@ if(iterator==NULL || (iterator->car->type==symb - && ((symbol*)(iterator->car->content.ptr))->id[0]=='[')) { + && ((symbol*)(iterator->car->content.ptr))->id[0]=='[')) { temp= NULL; toss(env); } else { /* Search for first delimiter */ while(iterator->cdr->content.c!=NULL && (iterator->cdr->content.c->car->type!=symb - || ((symbol*)(iterator->cdr->content.c->car->content.ptr))->id[0] + || ((symbol*)(iterator->cdr->content.c->car->content.ptr))->id[0] !='[')) - iterator= iterator->cdr->content.c; + iterator= iterator->cdr->content.ptr; /* Extract list */ temp= env->head;