static void session_hier_delete(struct topic_node *node, void *usr_cl)
{
    struct topic_node *prev = NULL;
    u32 cl_map = cl_bmap_get(usr_cl);

    while(node) {
        i32 i = 0;
        for(i = 0; i < 3; i++) {
            if(node->cl_map[i] & cl_map) {
                node->cl_map[i] &= ~cl_map;
                cl_sub_count_del(usr_cl);
                /* Client/Topic/QID 1-to-1 map */
                break;
            }
        }

        if(node->dn_nhbr)
            stack_add(node->dn_nhbr, 0, 0);

        prev = node;
        node = node->dn_hier;
    }

    if(prev)
        try_node_delete(prev);
}
/* Search node tree, created by PUB retention, for the branch combo, whose
   absolute sub-topic sequence 'matches', in entirety, the topic, which is
   being subscribed. The 'match' criteria is met either through the
   wildcard sub-topics or exact compare.

   The hierarchical search starts at the specified 'base' node and ends at
   the leaf node. If the sequence of 'base-to-leaf' sub-topics 'match' the
   'topSUB', then the leaf node is returned, otherwise a NULL is returned.

   As part of hierarchical search, neighbouring nodes, if any, are logged
   for subsequent iteration of the routine.
*/
static struct topic_node *pub_hier_search(const c8 *topSUB,
        const struct topic_node *base,
        struct topbuf_desc *mk_pubtop)
{
    const struct topic_node *node = base, *prev = NULL;
    const c8 *next_subtop = topSUB;
    c8 subtop[MAX_SUBTOP_LEN];

    while(next_subtop && node) {
        if(subtop_read(topSUB, subtop, MAX_SUBTOP_LEN,
                       &next_subtop) <= 0)
            break;

        if(node->dn_nhbr)
            stack_add(node->dn_nhbr, (u32)topSUB, mk_pubtop->offset);

        if(false == is_node_SUB_subtop(node, subtop))
            break;    /* Node doesn't form part of published topic */

        if(false == topbuf_add(mk_pubtop, node))
            break;

        prev = node;
        node = node->dn_hier;

        topSUB = next_subtop;
    }

    if(NULL != next_subtop)
        node = NULL;
    else
        node = prev;

    return (struct topic_node *)node;
}
/* Search node tree, created by subscriptions, for the branch combo, whose
   sub-topic sequence 'matches', in entirety, the absolute topic, to which
   data has been published. The 'match' criteria is met either through the
   wildcard sub-topics or exact compare.

   The hierarchical search starts at the specified 'base' node and ends at
   the leaf node. If the sequence of 'base-to-leaf' sub-topics 'match' the
   'topPUB', then the leaf node is returned, otherwise a NULL is returned.

   As part of hierarchical search, neighbouring nodes, if any, are logged
   for subsequent iteration of the routine.
*/
static struct topic_node *SUB_leaf_search(const c8 *topPUB,
        const struct topic_node *base)
{
    const struct topic_node *node = base, *prev = NULL;
    const c8 *next_subtop = topPUB;
    c8 subtop[MAX_SUBTOP_LEN];

    while(next_subtop && node) {
        if(subtop_read(topPUB, subtop, MAX_SUBTOP_LEN,
                       &next_subtop) <= 0)
            break;

        if(node->dn_nhbr)
            stack_add(node->dn_nhbr, (u32)topPUB, 0);

        if(0 == strcmp("#", node->subtop))
            goto SUB_leaf_search_exit1;

        if(false == is_node_PUB_subtop(node, subtop, !next_subtop))
            break; /* Node doesn't form part of published topic */

        prev = node;
        node = node->dn_hier;

        topPUB = next_subtop;
    }

    if(NULL != next_subtop)
        node = NULL;
    else
        node = prev;

SUB_leaf_search_exit1:
    return (struct topic_node*) node; // Bad
}
Beispiel #4
0
static void signal2_connect(signal2_t *obj, slot2_t *slot2)
{
	PTR_CHECK(obj, "signal2");

	if (signal2_is_connected(obj, slot2))
		return;

	stack_add(obj->slot2s_stack, (BUFFER_PTR)&slot2);
}
Beispiel #5
0
void event_maprequest( xcb_generic_event_t* e ) {
    printf( "yawn: maprequest\n" );

    xcb_map_request_event_t* ev = (xcb_map_request_event_t*)e;
    stack_add( ev->window );
    client_manage( ev->window );
    stack_tile();
    window_current_update();
}
void session_tree_delete(void *usr_cl)
{
    u32 stack_ref = stack_idx;

    if(NULL != root_node)
        stack_add(root_node, 0, 0);

    while(stack_ref < stack_idx) {
        struct _node_stack *stack = stack_pop();
        session_hier_delete(stack->node, usr_cl);
    }
}
Beispiel #7
0
void iter_inorder(node)
{
	//use stack
	STACK stack[MAX];
	for(;;)
	{
		for(;node;node->left)
			stack_add(&stack,node);
		node a = pop(&stack)
		if(stack.empty())
			break;
		output;
		node=node->right;
	}
}
Beispiel #8
0
int main(){
  stack_init();
  printf("%d\n", stack_count());
  stack_push(5);
  stack_push(2);
  stack_push(10);
  printf("%d\n", stack_count());
 
  stack_dup();
  stack_add();
  printf("%d\n", stack_count());
  int x;
  puts("");
  while(!stack_empty()){
    x = stack_pop();
    printf("%d\n", x);
  }
  
  return 0;
}
static
void proc_sub_tree_topPUB(const c8 *topPUB,   const struct utf8_string *topic,
                          const u8 *data_buf, u32 data_len, enum mqtt_qos qos,
                          bool retain)
{
    struct topic_node *leaf = NULL;
    u32 stack_ref = stack_idx;

    if(NULL != root_node)
        stack_add(root_node, (u32)topPUB, 0 /* Not used */);

    while(stack_ref < stack_idx) {
        struct _node_stack *stack = stack_pop();

        /* Find leaf node of SUB that matches the PUB topic */
        leaf = SUB_leaf_search((c8*)stack->val1, stack->node);
        if(leaf)
            leaf_msg_send(leaf, topic, data_buf, data_len,
                          false, qos, retain);
    }
}
/* Multi-level wild-card subscription - search of all of the tree i.e.
   "no topic" ('no_top') in particular and publish it to client, if
   the hierarchy has no wild-card node. */
static
u8 proc_pub_hier_no_top(struct topic_node *base, struct topbuf_desc *mk_pubtop,
                        enum mqtt_qos qos, void *usr_cl)
{
    struct topic_node *node = base, *leaf = NULL;
    u8 ack = QOS_VALUE(qos);

    /* 1. Find the leaf node of a non wildcard branch-combo */
    while(node) {
        if(node->dn_nhbr)
            stack_add(node->dn_nhbr, 0, mk_pubtop->offset);

        if(has_a_wildcard(node))
            break;

        if(false == topbuf_add(mk_pubtop, node))
            break;

        leaf = node;
        node = node->dn_hier;
    }

    /* A non NULL value of 'node' would indicate a hierarchy with a
       wildcard (sub-)topic (the 'node') - not suitable for PUB. */

    if(NULL == node) {
        /* 2. Send retained data, if any, to SUB Client */
        struct utf8_string topic = {mk_pubtop->buffer,
                   mk_pubtop->offset
        };

        /* In this version, at this juncture, the 'leaf'
           will not be NULL. Nevertheless a check (for
           the sake of static analytical tools).........*/
        if(leaf)
            ack = proc_pub_leaf(leaf, &topic, qos, usr_cl);
    }

    return ack;
}
/* Multi-level wild-card subscription - search of all of the tree i.e.
   "no topic" ('no_top') in particular and publish it to client, if
   a hierarchy in the tree has no wild-card node. */
static
u8 proc_pub_tree_no_top(struct topic_node *base, struct topbuf_desc *mk_pubtop,
                        enum mqtt_qos qos, void *usr_cl)
{
    u32 stack_ref = stack_idx;
    u8 min = QOS_VALUE(qos);

    if(base != NULL)
        stack_add(base, 0, mk_pubtop->offset);

    while(stack_ref < stack_idx) {
        struct _node_stack *stack = stack_pop();
        u8 ack;

        mk_pubtop->offset = (u16) stack->val2;

        ack = proc_pub_hier_no_top(stack->node, mk_pubtop, qos, usr_cl);
        if(ack < min)
            min = ack;
    }

    return min;
}
static u8 proc_sub_ml_wc_tree(c8 *grandpa_topSUB, c8 *parent_subtop,
                              struct topic_node *base,
                              enum mqtt_qos qos, void *usr_cl)
{
    struct topbuf_desc mk_pubtop = {work_buf, WBUF_LEN, 0 /* offset */};
    u32 stack_ref = stack_idx;
    u8 min = QOS_VALUE(qos);

    if(NULL != base)
        stack_add(base, (u32)grandpa_topSUB, mk_pubtop.offset);

    while(stack_ref < stack_idx) {
        struct _node_stack *stack = stack_pop();
        u8 ack;

        mk_pubtop.offset = stack->val2;
        ack = proc_sub_ml_wc_hier((c8*)stack->val1, parent_subtop,
                                  stack->node, &mk_pubtop, qos, usr_cl);
        if(ack < min)
            min = ack;
    }

    return min;
}
/* used by sl or no wc */
static u8 proc_pub_tree_SUBtop(const c8 *topSUB, struct topic_node *base,
                               struct topbuf_desc *mk_pubtop,
                               enum mqtt_qos qos, void *usr_cl)
{
    u32 stack_ref = stack_idx;
    u8 min = QOS_VALUE(qos);

    if(NULL != base)
        stack_add(base, (u32)topSUB, mk_pubtop->offset);

    while(stack_ref < stack_idx) {
        struct _node_stack *stack = stack_pop();
        u8 ack;

        mk_pubtop->offset = stack->val2;
        ack = proc_pub_hier_SUBtop((c8*)stack->val1,  stack->node,
                                   mk_pubtop, qos, usr_cl);

        if(ack < min)
            min = ack;
    }

    return min;
}
Beispiel #14
0
int scan(char *s)
{
	unsigned char *p = (unsigned char*)s;
	unsigned char *t;
	int res = 0;
	
#define YYCTYPE         unsigned char
#define YYCURSOR        p
	
	while(!res)
	{
		t = p;

#line 69 "main.c"
		{
			YYCTYPE yych;

			yych = *YYCURSOR;
			switch (yych) {
			case 0x00:	goto yy11;
			case '\t':
			case ' ':	goto yy2;
			case '+':	goto yy7;
			case '-':	goto yy9;
			case '0':	goto yy4;
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy6;
			default:	goto yy13;
			}
yy2:
			++YYCURSOR;
			yych = *YYCURSOR;
			goto yy21;
yy3:
#line 80 "main.re"
			{ continue; }
#line 99 "main.c"
yy4:
			++YYCURSOR;
			switch ((yych = *YYCURSOR)) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy17;
			default:	goto yy5;
			}
yy5:
#line 82 "main.re"
			{ res = push_num(t, p, 10); continue; }
#line 118 "main.c"
yy6:
			yych = *++YYCURSOR;
			goto yy16;
yy7:
			++YYCURSOR;
#line 83 "main.re"
			{ res = stack_add();		continue; }
#line 126 "main.c"
yy9:
			++YYCURSOR;
#line 84 "main.re"
			{ res = stack_sub();		continue; }
#line 131 "main.c"
yy11:
			++YYCURSOR;
#line 85 "main.re"
			{ res = depth == 1 ? 0 : 2;	break; }
#line 136 "main.c"
yy13:
			++YYCURSOR;
#line 86 "main.re"
			{ res = 1; 					continue; }
#line 141 "main.c"
yy15:
			++YYCURSOR;
			yych = *YYCURSOR;
yy16:
			switch (yych) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy15;
			default:	goto yy5;
			}
yy17:
			++YYCURSOR;
			yych = *YYCURSOR;
			switch (yych) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy17;
			default:	goto yy19;
			}
yy19:
#line 81 "main.re"
			{ res = push_num(t, p, 8);	continue; }
#line 178 "main.c"
yy20:
			++YYCURSOR;
			yych = *YYCURSOR;
yy21:
			switch (yych) {
			case '\t':
			case ' ':	goto yy20;
			default:	goto yy3;
			}
		}
#line 87 "main.re"

	}
	return res;
}
int scan(char *s)
{
	unsigned char *p = (unsigned char*)s;
	unsigned char *t;
	int res = 0;
	
#define YYCTYPE         unsigned char
#define YYCURSOR        p
	
	while(!res)
	{
		t = p;

#line 69 "<stdout>"
		{
			YYCTYPE yych;
			static const unsigned char yybm[] = {
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0, 128,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				128,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				 64,  64,  64,  64,  64,  64,  64,  64, 
				 64,  64,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
				  0,   0,   0,   0,   0,   0,   0,   0, 
			};

			yych = *YYCURSOR;
			if (yych <= '*') {
				if (yych <= '\t') {
					if (yych <= 0x00) goto yy11;
					if (yych <= 0x08) goto yy13;
				} else {
					if (yych != ' ') goto yy13;
				}
			} else {
				if (yych <= '-') {
					if (yych <= '+') goto yy7;
					if (yych <= ',') goto yy13;
					goto yy9;
				} else {
					if (yych <= '/') goto yy13;
					if (yych <= '0') goto yy4;
					if (yych <= '9') goto yy6;
					goto yy13;
				}
			}
			++YYCURSOR;
			yych = *YYCURSOR;
			goto yy21;
yy3:
#line 80 "calc_007.b.re"
			{ continue; }
#line 133 "<stdout>"
yy4:
			++YYCURSOR;
			if ((yych = *YYCURSOR) <= '/') goto yy5;
			if (yych <= '9') goto yy17;
yy5:
#line 82 "calc_007.b.re"
			{ res = push_num(t, p, 10); continue; }
#line 141 "<stdout>"
yy6:
			yych = *++YYCURSOR;
			goto yy16;
yy7:
			++YYCURSOR;
#line 83 "calc_007.b.re"
			{ res = stack_add();		continue; }
#line 149 "<stdout>"
yy9:
			++YYCURSOR;
#line 84 "calc_007.b.re"
			{ res = stack_sub();		continue; }
#line 154 "<stdout>"
yy11:
			++YYCURSOR;
#line 85 "calc_007.b.re"
			{ res = depth == 1 ? 0 : 2;	break; }
#line 159 "<stdout>"
yy13:
			++YYCURSOR;
#line 86 "calc_007.b.re"
			{ res = 1; 					continue; }
#line 164 "<stdout>"
yy15:
			++YYCURSOR;
			yych = *YYCURSOR;
yy16:
			if (yybm[0+yych] & 64) {
				goto yy15;
			}
			goto yy5;
yy17:
			++YYCURSOR;
			yych = *YYCURSOR;
			if (yych <= '/') goto yy19;
			if (yych <= '9') goto yy17;
yy19:
#line 81 "calc_007.b.re"
			{ res = push_num(t, p, 8);	continue; }
#line 181 "<stdout>"
yy20:
			++YYCURSOR;
			yych = *YYCURSOR;
yy21:
			if (yybm[0+yych] & 128) {
				goto yy20;
			}
			goto yy3;
		}
#line 87 "calc_007.b.re"

	}
	return res;
}
Beispiel #16
0
int stack_push(stack_t* stack, void* e) {
  return stack_add(stack, e);
}
Beispiel #17
0
void stack_push (char a, stack* ctack) {
    stack_add (ctack);
    ctack->Stack[ctack->pointer] = a;
    ctack->pointer++;
}
Beispiel #18
0
int scan(char *s, int l)
{
	char *p = s;
	char *q = 0;
	char *t;
	int res = 0;

#define YYCTYPE         char
#define YYCURSOR        p
#define YYLIMIT         (s+l+1)
#define YYMARKER        q
#define YYFILL(n)		{ return depth == 1 ? 0 : 2; }
	
	while(!res)
	{
		t = p;

#line 71 "calc_005.c"
		{
			YYCTYPE yych;
			if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
			yych = *YYCURSOR;
			switch (yych) {
			case '\t':
			case ' ':	goto yy2;
			case '+':	goto yy7;
			case '-':	goto yy9;
			case '0':	goto yy4;
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy6;
			default:	goto yy11;
			}
yy2:
			++YYCURSOR;
			yych = *YYCURSOR;
			goto yy19;
yy3:
#line 91 "calc_005.re"
			{ continue; }
#line 100 "calc_005.c"
yy4:
			++YYCURSOR;
			switch ((yych = *YYCURSOR)) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy15;
			default:	goto yy5;
			}
yy5:
#line 93 "calc_005.re"
			{ res = push_num(t, p, 10); continue; }
#line 119 "calc_005.c"
yy6:
			yych = *++YYCURSOR;
			goto yy14;
yy7:
			++YYCURSOR;
#line 94 "calc_005.re"
			{ res = stack_add();		continue; }
#line 127 "calc_005.c"
yy9:
			++YYCURSOR;
#line 95 "calc_005.re"
			{ res = stack_sub();		continue; }
#line 132 "calc_005.c"
yy11:
			++YYCURSOR;
#line 96 "calc_005.re"
			{ res = 1; 					continue; }
#line 137 "calc_005.c"
yy13:
			++YYCURSOR;
			if (YYLIMIT <= YYCURSOR) YYFILL(1);
			yych = *YYCURSOR;
yy14:
			switch (yych) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy13;
			default:	goto yy5;
			}
yy15:
			++YYCURSOR;
			if (YYLIMIT <= YYCURSOR) YYFILL(1);
			yych = *YYCURSOR;
			switch (yych) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':	goto yy15;
			default:	goto yy17;
			}
yy17:
#line 92 "calc_005.re"
			{ res = push_num(t, p, 8);	continue; }
#line 176 "calc_005.c"
yy18:
			++YYCURSOR;
			if (YYLIMIT <= YYCURSOR) YYFILL(1);
			yych = *YYCURSOR;
yy19:
			switch (yych) {
			case '\t':
			case ' ':	goto yy18;
			default:	goto yy3;
			}
		}
#line 97 "calc_005.re"

	}
	return res;
}