~strahinja/poe

87ef5b164c3ec8491f81380cb7a8a474a9ed0c5d — Страхиња Радић 5 months ago 006680f
Sort functions; remove redundant msgid_to_real_msgid and commented old code

Signed-off-by: Страхиња Радић <contact@strahinja.org>
1 files changed, 38 insertions(+), 75 deletions(-)

M poe.c
M poe.c => poe.c +38 -75
@@ 39,9 39,10 @@ struct DrawState* join_lines(struct DrawState* state, size_t first_line,
	int forward);
struct BufferLine* load_info(struct DrawState* state);
struct BufferLine* load_msgstr(struct DrawState* state);
size_t msgid_to_real_msgid(struct DrawState* state, const size_t msgid);
size_t next_msgid(struct DrawState* state, const int delta);
void overwrite_copy_msgid_callback(struct DrawState* state, struct tb_event* ev);
void overwrite_paste_callback(struct DrawState* state, struct tb_event* ev);
size_t prev_msgid(struct DrawState* state, const int delta);
int print_error(const int code, const char* msg, ...);
void quit_callback(struct DrawState* state, struct tb_event* ev);
size_t real_msgid_to_display_msgid(const struct DrawState* state);


@@ 483,62 484,6 @@ load_info(struct DrawState* state)
	return state->info_buffer;
}

size_t
next_msgid(struct DrawState* state, const int delta)
{
	size_t ret   = state->msgid_number;
	size_t start = ret;

	while (ret < state->real_msgid_count + 1)
	{
		ret++;
		if (!state->entries[ret - 1].obsolete && ret >= start + delta)
			break;
	}

	return ret == state->real_msgid_count + 1 ? state->real_msgid_count
						  : ret;
}

size_t
prev_msgid(struct DrawState* state, const int delta)
{
	size_t ret   = state->msgid_number;
	size_t start = ret;

	if (start < delta)
		return state->real_msgid_count ? 1 : 0;

	while (ret > 1)
	{
		ret--;
		if (!state->entries[ret - 1].obsolete && ret <= start - delta)
			break;
	}

	return ret;
}

size_t
msgid_to_real_msgid(struct DrawState* state, const size_t msgid)
{
	size_t ret = 0;
	size_t i   = 0;

	do
	{
		if (!state->entries[ret].obsolete)
		{
			if (i == msgid)
				return ret;
			i++;
		}
		ret++;
	} while (ret < state->real_msgid_count);

	return 0;
}

struct BufferLine*
load_msgstr(struct DrawState* state)
{


@@ 603,6 548,23 @@ load_msgstr(struct DrawState* state)
	return state->input_buffer;
}

size_t
next_msgid(struct DrawState* state, const int delta)
{
	size_t ret   = state->msgid_number;
	size_t start = ret;

	while (ret < state->real_msgid_count + 1)
	{
		ret++;
		if (!state->entries[ret - 1].obsolete && ret >= start + delta)
			break;
	}

	return ret == state->real_msgid_count + 1 ? state->real_msgid_count
						  : ret;
}

void
overwrite_copy_msgid_callback(struct DrawState* state, struct tb_event* ev)
{


@@ 619,6 581,25 @@ overwrite_paste_callback(struct DrawState* state, struct tb_event* ev)
	state->prompt_callback = NULL;
}

size_t
prev_msgid(struct DrawState* state, const int delta)
{
	size_t ret   = state->msgid_number;
	size_t start = ret;

	if (start < delta)
		return state->real_msgid_count ? 1 : 0;

	while (ret > 1)
	{
		ret--;
		if (!state->entries[ret - 1].obsolete && ret <= start - delta)
			break;
	}

	return ret;
}

int
print_error(const int code, const char* msg, ...)
{


@@ 1324,16 1305,6 @@ move_list_page_down(struct DrawState* state)
{
	*state->error = 0;
	goto_msgid(state, next_msgid(state, state->maxy - 2));
	/*if (state->msgid_number < state->msgid_count - state->maxy - 2)
	{
		state->msgid_number += state->maxy - 2;
		if (state->msgid_number - state->first_shown_msgid
			> state->maxy - 2)
			state->first_shown_msgid
				= state->msgid_number - (state->maxy - 2);
	}
	else
		return move_list_end(state);*/
	return 0;
}



@@ 1342,14 1313,6 @@ move_list_page_up(struct DrawState* state)
{
	*state->error = 0;
	goto_msgid(state, prev_msgid(state, state->maxy - 2));
	/*if (state->msgid_number > state->maxy - 2)
	{
		state->msgid_number -= state->maxy - 2;
		if (state->msgid_number < state->first_shown_msgid)
			state->first_shown_msgid = state->msgid_number;
	}
	else
		return move_list_start(state);*/
	return 0;
}