Exemplo n.º 1
0
static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[]) {
	RGraphEdge *edg;

	RStack *s = r_stack_new (2 * g->n_edges + 1);
	if (!s) {
		return;
	}
	edg = R_NEW0 (RGraphEdge);
	if (!edg) {
		r_stack_free (s);
		return;
	}
	edg->from = NULL;
	edg->to = n;
	r_stack_push (s, edg);
	while (!r_stack_is_empty (s)) {
		RGraphEdge *cur_edge = (RGraphEdge *)r_stack_pop (s);
		RGraphNode *v, *cur = cur_edge->to, *from = cur_edge->from;
		const RList *neighbours;
		RListIter *it;
		int i;

		if (from && cur) {
			if (color[cur->idx] == WHITE_COLOR && vis->tree_edge)
				vis->tree_edge (cur_edge, vis);
			else if (color[cur->idx] == GRAY_COLOR && vis->back_edge)
				vis->back_edge (cur_edge, vis);
			else if (color[cur->idx] == BLACK_COLOR && vis->fcross_edge)
				vis->fcross_edge (cur_edge, vis);
		} else if (!cur && from) {
			if (color[from->idx] != BLACK_COLOR && vis->finish_node)
				vis->finish_node (from, vis);
			color[from->idx] = BLACK_COLOR;
		}
		free (cur_edge);
		if (!cur || color[cur->idx] != WHITE_COLOR) {
			continue;
		}
		if (color[cur->idx] == WHITE_COLOR && vis->discover_node) {
			vis->discover_node (cur, vis);
		}
		color[cur->idx] = GRAY_COLOR;

		edg = R_NEW0 (RGraphEdge);
		edg->from = cur;
		r_stack_push (s, edg);

		i = 0;
		neighbours = r_graph_get_neighbours (g, cur);
		r_list_foreach (neighbours, it, v) {
			edg = R_NEW (RGraphEdge);
			edg->from = cur;
			edg->to = v;
			edg->nth = i++;
			r_stack_push (s, edg);
		}
	}
Exemplo n.º 2
0
R_API void r_cons_push() {
	if (I.cons_stack) {
		RConsStack *data = R_NEW0 (RConsStack);
		data->buf = malloc (I.buffer_len);
		if (!data->buf) {
			free (data);
			return;
		}
		memcpy (data->buf, I.buffer, I.buffer_len);
		data->buf_len = I.buffer_len;
		data->buf_size = I.buffer_sz;
		data->grep = R_NEW0 (RConsGrep);
		if (data->grep) {
			memcpy (data->grep, &I.grep, sizeof (RConsGrep));
			if (I.grep.str) {
				data->grep->str = strdup (I.grep.str);
			}
		}
		r_stack_push (I.cons_stack, data);
		I.buffer_len = 0;
		if (I.buffer) {
			memset (I.buffer, 0, I.buffer_sz);
		}
	}
}
Exemplo n.º 3
0
void addTarget(RCore *core, RStack *stack, Sdb *db, ut64 addr) {
	if (!sdb_num_get (db, Fhandled(addr), NULL)) {
		ut64* value = (ut64*) malloc (1 * sizeof(ut64));
		if (!value) {
			eprintf ("Failed to allocate memory for address stack\n");
			return;
		}
		*value = addr;
		if (!r_stack_push (stack, (void*)value)) {
			eprintf ("Failed to push address on stack\n");
			free (value);
			return;
		}
		sdb_num_set (db, Fhandled(addr), 1, 0);
	}
}
Exemplo n.º 4
0
R_API void r_cons_push() {
	if (I.cons_stack) {
		RConsStack *data = R_NEW0 (RConsStack);
		data->buf = malloc (I.buffer_len);
		if (!data->buf) {
			free (data);
			return;
		}
		memcpy (data->buf, I.buffer, I.buffer_len);
		data->buf_len = I.buffer_len;
		data->buf_size = I.buffer_sz;
		r_stack_push (I.cons_stack, data);
		I.buffer_len = 0;
		memset (I.buffer, 0, I.buffer_sz);
	}
}
Exemplo n.º 5
0
R_API void r_cons_break_push(RConsBreak cb, void *user) {
	if (I.break_stack) {
		//if we don't have any element in the stack start the signal
		RConsBreakStack *b = R_NEW0 (RConsBreakStack);
		if (!b) return;
		if (r_stack_is_empty (I.break_stack)) {
#if __UNIX__ || __CYGWIN__
			signal (SIGINT, break_signal);
#endif
			I.breaked = false;
		}
		//save the actual state
		b->event_interrupt = I.event_interrupt;
		b->data = I.data;
		r_stack_push (I.break_stack, b);
		//configure break
		I.event_interrupt = cb;
		I.data = user;
	}
}
Exemplo n.º 6
0
R_API int r_str_word_set0_stack(char *str) {
	int i;
	char *p, *q;
	RStack *s;
	void *pop;
	if (!str || !*str) {
		return 0;
	}
	for (i = 0; str[i] && str[i+1]; i++) {
		if (i > 0 && str[i-1] == ' ' && str[i] == ' ') {
			int len = strlen (str+i) + 1;
			memmove (str+i, str+i+1, len);
			i--;
		}
		if (i == 0 && str[i] == ' ') {
			memmove (str+i, str+i+1, strlen (str+i) + 1);
		}
	}
	if (str[i] == ' ') {
		str[i] = 0;
	}
	s = r_stack_new (5); //Some random number
	for (i = 1, p = str; *p; p++) {
		q = p - 1;
		if (p > str && (*q == '\\')) {
			memmove (q, p, strlen (p) + 1);
			p--;
			continue;
		}
		switch (*p) {
		case '(':
		case '{':
		case '[':
			r_stack_push (s, (void *)p);
			continue;
		case '\'':
		case '"':
			pop = r_stack_pop (s);
			if (pop && *(char *)pop != *p) {
				r_stack_push (s, pop);
				r_stack_push (s, (void *)p);
			} else if (!pop) {
				r_stack_push (s, (void *)p);
			}
			continue;
		case ')':
		case '}':
	    case ']':
			pop = r_stack_pop (s);
			if (pop) {
				if ((*(char *)pop == '(' && *p == ')') ||
					(*(char *)pop == '{' && *p == '}') ||
					(*(char *)pop == '[' && *p == ']')) {
					continue;
				}
			}
			break;
		case ' ':
			if (p > str && !*q) {
				memmove (p, p+1, strlen (p+1) + 1);
				if (*q == '\\') {
					*q = ' ';
					continue;
				}
				p--;
			}
			if (r_stack_is_empty (s)) {
				i++;
				*p = '\0';
			}
		default:
			break;
		}
	}
	r_stack_free (s);
	return i;
}