Esempio n. 1
0
END_TEST

START_TEST(test_str_from_cstr_len)
{
	const char *cstr = "12345";

	str_t *str = str_from_cstr_len(cstr, 5);
	CHECK_STR(str, == 5, == 5, "12345");
	str_free(str);

	str = str_from_cstr_len(cstr, 4);
	CHECK_STR(str, == 4, == 4, "1234");
	str_free(str);
}
Esempio n. 2
0
static str_t *extract_partial(struct msg_ac *msg)
{
	char *cursor;
	char *c = msg->buffer.addr;
	char *end = msg->buffer.addr + msg->buffer.sz;

	for (int line = 1; line < msg->line; line++) {
		while (1) {
			if (c == end)
				return 0;
			if (*c == '\n') {
				c++;
				break;
			}
			c++;
		}
	}

	cursor = c + (msg->col - 1);
	c += msg->col - 2;
	while (isident(*c))
		c--;
	c++;

	if (c == cursor)
		return 0;

	return str_from_cstr_len(c, cursor - c);
}
Esempio n. 3
0
static void try_load_dotccode(wordexp_t *wexp)
{
	void *buf;
	size_t size;

	wexp->we_wordc = 0;
	wexp->we_wordv = 0;

	if (read_file(&buf, &size, ".ccode") == -1) {
		return;
	}

	// TODO: fstr trim? cstr trim?
	str_t *contents = str_from_cstr_len(buf, (unsigned int)size);
	str_trim(contents);

	wordexp(contents->data, wexp, 0);
	str_free(contents);
	free(buf);
}