~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/infr/stack.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 
  7 static List *stack = NULL;
  8 
  9 List *get_stack_ptr()
 10 {
 11    return( stack );
 12 }
 13 
 14 void put_stack_ptr( List *stack_ptr )
 15 {
 16    stack = stack_ptr;
 17 }
 18 
 19 
 20 void   *stack_pop(int *type)
 21 {
 22     void   *val;
 23 
 24     if (stack == NULL)
 25     {
 26         *type = (int) NULL;
 27         return (NULL);
 28     }
 29     *type = ((Pair *) stack->to)->type1;
 30     val = ((Pair *) stack->to)->to1;
 31     stack = link_rm(stack, rfree);
 32 
 33     return (val);
 34 }
 35 
 36 void   *stack_inspect(int *type)
 37 {
 38     if (stack == NULL)
 39     {
 40         *type = (int) NULL;
 41         return (NULL);
 42     }
 43     *type = ((Pair *) stack->to)->type1;
 44     return (((Pair *) stack->to)->to1);
 45 }
 46 
 47 #ifndef ANSIFYING
 48 #ifdef __STRICT_ANSI__
 49 
 50 Bool    stack_check_types(int type,...)
 51 {
 52     va_list ap;
 53     List   *ptr;
 54 
 55     ptr = stack;
 56     va_start(ap, type);
 57     while (type)
 58     {
 59         if (ptr == NULL || type != ((Pair *) ptr->to)->type1)
 60             return (false);
 61         ptr = ptr->next;
 62         type = va_arg(ap, int);
 63     }
 64     va_end(ap);
 65     return (true);
 66 }
 67 
 68 #else
 69 
 70 Bool    stack_check_types(va_alist)
 71         va_dcl
 72 {
 73     va_list ap;
 74     List   *ptr;
 75     int     type;
 76 
 77     ptr = stack;
 78     va_start(ap);
 79     while ((type = va_arg(ap, int)) != NULL)
 80     {
 81         if (ptr == NULL || type != ((Pair *) ptr->to)->type1)
 82             return (false);
 83         ptr = ptr->next;
 84     }
 85     va_end(ap);
 86     return (true);
 87 }
 88 
 89 #endif                          /* __STRICT_ANSI__ */
 90 #endif                          /* ANSIFYING */
 91 
 92 void    stack_push(void *val, int type, void (*freefunc) ( /* ??? */ ))
 93 {
 94     Pair   *stack_el;
 95 
 96     if (val == NULL)
 97         return;
 98 
 99     stack_el = ts_ralloc(Pair);
100     stack_el->to1 = val;
101     stack_el->type1 = type;
102     stack_el->to2 = (void *) freefunc;
103     stack_el->type2 = 0;
104     stack = ref_addtostart(stack, (void *) stack_el, PAIRS);
105 }
106 
107 /* Flip the top 2 elements on the stack */
108 void    stack_flip(void)
109 {
110     List   *temp;
111 
112     if (stack == NULL || stack->next == NULL)
113         return;
114 
115     temp = stack->next;
116     stack->next = stack->next->next;
117     temp->next = stack;
118     stack = temp;
119     stack->next->last = stack;
120     stack->last = NULL;
121 }
122 
123 static void  stack_el_free(Pair * stack_el)
124 {
125     if (stack_el->to1 != NULL && stack_el->to2 != NULL)
126         ((void (*) ()) stack_el->to2) (stack_el->to1);  /* apply saved freefunc */
127     rfree((void *) stack_el);
128 }
129 
130 void    stack_clear(void)
131 {
132     list_rm(stack, (void (*) ()) stack_el_free);
133     stack = NULL;
134 }
135 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.