Ejemplo n.º 1
0
static int add_token(struct parser_state *state, const yystype *token)
{
	if(tokens_ensure_capacity(&state->tokens, state->tokens.cnt + 1))
		return -1;
	state->tokens.data[state->tokens.cnt++] = *token;
	return 0;
}
Ejemplo n.º 2
0
static int append_tokens(struct tokens *dst, const struct tokens *src)
{
	if(!dst || !src)
		return CL_ENULLARG;
	if(tokens_ensure_capacity(dst, dst->cnt + src->cnt))
		return CL_EMEM;
	cli_dbgmsg(MODULE "Appending %lu tokens\n", (unsigned long)(src->cnt));
	memcpy(&dst->data[dst->cnt], src->data, src->cnt * sizeof(dst->data[0]));
	dst->cnt += src->cnt;
	return CL_SUCCESS;
}
Ejemplo n.º 3
0
static int replace_token_range(struct tokens *dst, size_t start, size_t end, const struct tokens *with)
{
	const size_t len = with ? with->cnt : 0;
	size_t i;
	cli_dbgmsg(MODULE "Replacing tokens %lu - %lu with %lu tokens\n",start, end, len);
	if(start >= dst->cnt || end > dst->cnt)
		return -1;
	for(i=start;i<end;i++) {
		free_token(&dst->data[i]);
	}
	if(tokens_ensure_capacity(dst, dst->cnt - (end-start) + len))
		return CL_EMEM;
	memmove(&dst->data[start+len], &dst->data[end], (dst->cnt - end) * sizeof(dst->data[0]));
	if(with && len > 0) {
		memcpy(&dst->data[start], with->data, len * sizeof(dst->data[0]));
	}
	dst->cnt = dst->cnt - (end-start) + len;
	return CL_SUCCESS;
}