Пример #1
0
struct token *expect(struct token *token, int op, const char *where)
{
	if (!match_op(token, op)) {
		static struct token bad_token;
		if (token != &bad_token) {
			bad_token.next = token;
			sparse_error(token->pos, "Expected %s %s", show_special(op), where);
			sparse_error(token->pos, "got %s", show_token(token));
		}
		if (op == ';')
			return skip_to(token, op);
		return &bad_token;
	}
	return token->next;
}
Пример #2
0
static void cstr_realloc(SCTX_ CString *cstr, int new_size)
{
	int size;
	void *data;

	size = cstr->size_allocated;
	if (size == 0)
		size = 8; /* no need to allocate a too small first string */
	while (size < new_size)
		size = size * 2;
	data = realloc(cstr->data_allocated, size);
	if (!data) {
		struct position pos;
		pos.stream = -1;
		sparse_error(sctx_ pos, "memory full");
	}
	cstr->data_allocated = data;
	cstr->size_allocated = size;
	cstr->data = data;
}