/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by masse, Tue Jan 8 14:17:33 2002 UTC revision 1.13 by masse, Wed Jan 9 05:01:24 2002 UTC
# Line 128  int push_ref(stackitem** stack_head, has Line 128  int push_ref(stackitem** stack_head, has
128    new_item->content.ptr= *hash(in_hash, in_string);    new_item->content.ptr= *hash(in_hash, in_string);
129    new_item->type= ref;    new_item->type= ref;
130    
   if(handle==NULL)  
     handle= dlopen(NULL, RTLD_LAZY);  
   
131    if(new_item->content.ptr==NULL) {    if(new_item->content.ptr==NULL) {
132        if(handle==NULL)
133          handle= dlopen(NULL, RTLD_LAZY);    
134    
135      symbol= dlsym(handle, in_string);      symbol= dlsym(handle, in_string);
136      if(dlerror()==NULL)      if(dlerror()==NULL)
137        def_func(in_hash, symbol, in_string);        def_func(in_hash, symbol, in_string);
# Line 165  extern void nl() Line 165  extern void nl()
165    printf("\n");    printf("\n");
166  }  }
167    
168  void prin(stackitem** stack_head)  void print_(stackitem** stack_head)
169  {  {
170    if((*stack_head)==NULL)    if((*stack_head)==NULL)
171      return;      return;
# Line 189  void prin(stackitem** stack_head) Line 189  void prin(stackitem** stack_head)
189    
190  extern void print(stackitem** stack_head)  extern void print(stackitem** stack_head)
191  {  {
192    prin(stack_head);    print_(stack_head);
193    toss(stack_head);    toss(stack_head);
194  }  }
195    
# Line 200  void print_st(stackitem* stack_head, lon Line 200  void print_st(stackitem* stack_head, lon
200      print_st(stack_head->next, counter+1);      print_st(stack_head->next, counter+1);
201    
202    printf("%ld: ", counter);    printf("%ld: ", counter);
203    prin(&stack_head);    print_(&stack_head);
204    nl();    nl();
205  }  }
206    
# Line 242  int stack_read(stackitem** stack_head, h Line 242  int stack_read(stackitem** stack_head, h
242      push_cstring(stack_head, temp);      push_cstring(stack_head, temp);
243    else if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest)) >= 1)    else if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest)) >= 1)
244      push_val(stack_head, itemp);      push_val(stack_head, itemp);
245    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) {
246        temp[1]= '\0'; push_ref(stack_head, in_hash, temp);
247      } else if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest)) >= 1)
248      push_ref(stack_head, in_hash, temp);      push_ref(stack_head, in_hash, temp);
249    else if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) >= 1)    else if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) >= 1)
250      if(*temp==';')      if(*temp==';')
# Line 308  extern void expand(stackitem** stack_hea Line 310  extern void expand(stackitem** stack_hea
310    *stack_head= new_head;    *stack_head= new_head;
311  }  }
312    
313    extern void swap(stackitem** stack_head)
314    {
315      stackitem* temp= (*stack_head);
316      
317      if((*stack_head)==NULL || (*stack_head)->next==NULL)
318        return;
319    
320      *stack_head= (*stack_head)->next;
321      temp->next= (*stack_head)->next;
322      (*stack_head)->next= temp;
323    }
324    
325    extern void eq(stackitem** stack_head)
326    {
327      void *left, *right;
328      int result;
329    
330      if((*stack_head)==NULL || (*stack_head)->next==NULL)
331        return;
332    
333      left= (*stack_head)->content.ptr;
334      swap(stack_head);
335      right= (*stack_head)->content.ptr;
336      result= (left==right);
337      
338      toss(stack_head); toss(stack_head);
339      push_val(stack_head, (left==right));
340    }
341    
342    extern void not(stackitem** stack_head)
343    {
344      int value;
345    
346      if((*stack_head)==NULL)
347        return;
348    
349      value= (*stack_head)->content.val;
350      toss(stack_head);
351      push_val(stack_head, !value);
352    }
353    
354    extern void neq(stackitem** stack_head)
355    {
356      eq(stack_head);
357      not(stack_head);
358    }
359    
360    extern void def(stackitem** stack_head)
361    {
362      stackitem *temp, *value;
363    
364      if(*stack_head==NULL || (*stack_head)->next==NULL
365         || (*stack_head)->type!=ref)
366        return;
367    
368      temp= (*stack_head)->content.ptr;
369      value= (*stack_head)->next;
370      temp->content= value->content;
371      value->content.ptr=NULL;
372      temp->type= value->type;
373    
374      toss(stack_head); toss(stack_head);
375    }
376    
377  extern void quit()  extern void quit()
378  {  {
379    exit(EXIT_SUCCESS);    exit(EXIT_SUCCESS);
# Line 328  int main() Line 394  int main()
394      printf("okidok\n ");      printf("okidok\n ");
395    }    }
396    
397      exit(EXIT_SUCCESS);
   return EXIT_SUCCESS;  
398  }  }
399    
400  /* Local Variables: */  /* Local Variables: */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.13

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26