--- stack/stack.c 2002/01/08 14:17:33 1.8 +++ stack/stack.c 2002/01/09 05:01:24 1.13 @@ -128,10 +128,10 @@ new_item->content.ptr= *hash(in_hash, in_string); new_item->type= ref; - if(handle==NULL) - handle= dlopen(NULL, RTLD_LAZY); - if(new_item->content.ptr==NULL) { + if(handle==NULL) + handle= dlopen(NULL, RTLD_LAZY); + symbol= dlsym(handle, in_string); if(dlerror()==NULL) def_func(in_hash, symbol, in_string); @@ -165,7 +165,7 @@ printf("\n"); } -void prin(stackitem** stack_head) +void print_(stackitem** stack_head) { if((*stack_head)==NULL) return; @@ -189,7 +189,7 @@ extern void print(stackitem** stack_head) { - prin(stack_head); + print_(stack_head); toss(stack_head); } @@ -200,7 +200,7 @@ print_st(stack_head->next, counter+1); printf("%ld: ", counter); - prin(&stack_head); + print_(&stack_head); nl(); } @@ -242,7 +242,9 @@ push_cstring(stack_head, temp); else if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest)) >= 1) push_val(stack_head, itemp); - else if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest)) >= 1) + else if((convert= sscanf(in_line, "\\%c%[^\n\r]", temp, rest)) >= 1) { + temp[1]= '\0'; push_ref(stack_head, in_hash, temp); + } else if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest)) >= 1) push_ref(stack_head, in_hash, temp); else if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) >= 1) if(*temp==';') @@ -308,6 +310,70 @@ *stack_head= new_head; } +extern void swap(stackitem** stack_head) +{ + stackitem* temp= (*stack_head); + + if((*stack_head)==NULL || (*stack_head)->next==NULL) + return; + + *stack_head= (*stack_head)->next; + temp->next= (*stack_head)->next; + (*stack_head)->next= temp; +} + +extern void eq(stackitem** stack_head) +{ + void *left, *right; + int result; + + if((*stack_head)==NULL || (*stack_head)->next==NULL) + return; + + left= (*stack_head)->content.ptr; + swap(stack_head); + right= (*stack_head)->content.ptr; + result= (left==right); + + toss(stack_head); toss(stack_head); + push_val(stack_head, (left==right)); +} + +extern void not(stackitem** stack_head) +{ + int value; + + if((*stack_head)==NULL) + return; + + value= (*stack_head)->content.val; + toss(stack_head); + push_val(stack_head, !value); +} + +extern void neq(stackitem** stack_head) +{ + eq(stack_head); + not(stack_head); +} + +extern void def(stackitem** stack_head) +{ + stackitem *temp, *value; + + if(*stack_head==NULL || (*stack_head)->next==NULL + || (*stack_head)->type!=ref) + return; + + temp= (*stack_head)->content.ptr; + value= (*stack_head)->next; + temp->content= value->content; + value->content.ptr=NULL; + temp->type= value->type; + + toss(stack_head); toss(stack_head); +} + extern void quit() { exit(EXIT_SUCCESS); @@ -328,8 +394,7 @@ printf("okidok\n "); } - - return EXIT_SUCCESS; + exit(EXIT_SUCCESS); } /* Local Variables: */