Ejemplo n.º 1
0
/* Tries to add more characters from the fp file, but not exceed length of the
 * line buffer (the len parameter) and maximum number of printable character
 * positions (the max parameter).  Returns new length of the line buffer. */
static size_t
add_to_line(FILE *fp, size_t max, char line[], size_t len)
{
	size_t n_len = get_normal_utf8_string_length(line) - esc_str_overhead(line);
	size_t curr_len = strlen(line);
	while(n_len < max && line[curr_len - 1] != '\n' && !feof(fp))
	{
		if(get_line(fp, line + curr_len, len - curr_len) == NULL)
		{
			break;
		}
		n_len = get_normal_utf8_string_length(line) - esc_str_overhead(line);
		curr_len = strlen(line);
	}
	return curr_len;
}
Ejemplo n.º 2
0
/* Returns number of character positions allocated by the string on the
 * screen.  On issues will try to do the best, to make visible at least
 * something. */
static size_t
get_width_on_screen(const char str[])
{
	size_t length = (size_t)-1;
	wchar_t *const wide = to_wide(str);
	if(wide != NULL)
	{
		length = wcswidth(wide, (size_t)-1);
		free(wide);
	}
	if(length == (size_t)-1)
	{
		length = get_normal_utf8_string_length(str);
	}
	return length;
}