--- stack/stack.c 2002/02/02 18:36:19 1.23 +++ stack/stack.c 2002/02/02 19:30:07 1.24 @@ -286,27 +286,27 @@ void* delimiter; stackitem *iterator, *temp, *pack; - if((*stack_head)==NULL) { - printerr("Stack empty"); - return; - } - delimiter= (*stack_head)->content.ptr; /* Get delimiter */ toss(stack_head); iterator= *stack_head; - /* Search for first delimiter */ - while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) - iterator= iterator->next; - - /* Extract list */ - temp= *stack_head; - *stack_head= iterator->next; - iterator->next= NULL; - - if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) + if(iterator==NULL || iterator->content.ptr==delimiter) { + temp= NULL; toss(stack_head); + } else { + /* Search for first delimiter */ + while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) + iterator= iterator->next; + + /* Extract list */ + temp= *stack_head; + *stack_head= iterator->next; + iterator->next= NULL; + + if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) + toss(stack_head); + } /* Push list */ pack= malloc(sizeof(stackitem)); @@ -407,6 +407,9 @@ new_head= temp= (*stack_head)->content.ptr; toss(stack_head); + if(temp==NULL) + return; + /* Search the end of the list */ while(temp->next!=NULL) temp= temp->next; @@ -503,6 +506,13 @@ exit(EXIT_SUCCESS); } +/* Clear stack */ +extern void clear(stackitem** stack_head) +{ + while(*stack_head!=NULL) + toss(stack_head); +} + int main() { stackitem* s= NULL;