~strahinja/poe

bb801db2331e478970428f191b82eaec09973515 — Страхиња Радић 1 year, 1 month ago 9dd90b0
WIP Obsolete items bugfix

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

M draw.c
M po.c
M poe.c
M draw.c => draw.c +10 -3
@@ 800,12 800,19 @@ draw_list_visible(const struct DrawState* state)
	int cy			      = 0;
	size_t i		      = state->first_shown_msgid;

	while (i <= state->msgid_count && cy < max_screen_entries)
	while (i <= state->real_msgid_count && cy < max_screen_entries)
	{
		int sel;
		char flags_buf[MAXFLAGSBUF];

		current = state->entries + i - 1;
		if (current->obsolete)
		{
			i++;
			continue;
		}

		int sel = i == state->msgid_number;
		char flags_buf[MAXFLAGSBUF];
		sel = i == state->msgid_number;

		if (sel)
			draw_rect(0, state->maxx - 1, cy, cy + 1, LIST_SEL_FG,

M po.c => po.c +26 -0
@@ 494,14 494,40 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
	update_statistics(dstate->entries, dstate, entry);
	dstate->real_msgid_count = dstate->msgid_count + dstate->obsolete_count;

	//FILE* logfile = fopen("logfile.log", "w");
	current = dstate->entries;
	while (current != dstate->entries + dstate->real_msgid_count)
	{
		char u8buf[4096];
		*u8buf = 0;
		if (current->msgid)
			unicode_string_to_u8(u8buf, current->msgid,
				4096);
		/*fprintf(logfile, "ENTRY #%lu\n",
			current - dstate->entries);
		fprintf(logfile, "ENTRY: msgid={%s}\n",
			*u8buf ? (char*)u8buf : "(NULL)");*/
		*u8buf = 0;
		if (current->msgstr && current->msgstr[0])
			unicode_string_to_u8(u8buf, current->msgstr[0],
				4096);
		/*fprintf(logfile, "ENTRY: msgstr={%s}\n",
			*u8buf ? (char*)u8buf : "(NULL)");*/
		*u8buf = 0;
		if (current->comments && current->comments[0])
			unicode_string_to_u8(u8buf, current->comments[0],
				4096);
		/*fprintf(logfile, "ENTRY: comments={%s}\n",
			*u8buf ? (char*)u8buf : "(NULL)");
		fprintf(logfile, "ENTRY: obsolete? %s\n",
			current->obsolete ? "YES" : "NO");*/
		if (!current->obsolete && current->msgid && current->msgstr)
			update_warning(current->msgid, *current->msgstr,
				&current->warning);
		//fprintf(logfile, "\n");
		current++;
	}
	//fclose(logfile);

	return LOAD_ERR_NONE;
}

M poe.c => poe.c +91 -24
@@ 39,6 39,7 @@ 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);
void overwrite_copy_msgid_callback(struct DrawState* state, struct tb_event* ev);
void overwrite_paste_callback(struct DrawState* state, struct tb_event* ev);
int print_error(const int code, const char* msg, ...);


@@ 57,7 58,21 @@ cancel_callback(struct DrawState* state, struct tb_event* ev)
void
goto_msgid(struct DrawState* state, const size_t msgid_number)
{
	/* TODO: position_to for msgid list;
	 * Basically, every motion of current entry pointer would need to call
	 * this function. Sigh... */
	FILE* logfile = fopen("logfile.log", "a");
	fprintf(logfile, "state->real_msgid_count = %lu; "
		"state->msgid_count = %lu; msgid_number = %lu\n",
		state->real_msgid_count, state->msgid_count, msgid_number);
	fclose(logfile);
	if (msgid_number > state->real_msgid_count+1)
		return;
	state->msgid_number = msgid_number;
	logfile = fopen("logfile.log", "a");
	fprintf(logfile, "state->msgid_number = m2r(%lu)==%lu\n",
		msgid_number, state->msgid_number);
	fclose(logfile);
	if (state->msgid_number < (state->maxy - 1) / 2)
		state->first_shown_msgid = state->msgid_count > 0 ? 1 : 0;
	else if (state->msgid_count - state->msgid_number


@@ 475,6 490,73 @@ load_info(struct DrawState* state)
	return state->info_buffer;
}

size_t
next_msgid(struct DrawState* state)
{
	/* TODO: Add parameter delta */
	size_t ret = state->msgid_number;

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

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

size_t
prev_msgid(struct DrawState* state)
{
	/* TODO: Add parameter delta */
	size_t ret = state->msgid_number;

	while (ret > 0)
	{
		ret--;
		if (ret == 0 || !state->entries[ret-1].obsolete)
			break;
	}

	return ret == 0 ? state->msgid_number : 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)
		{
			FILE* logfile = fopen("logfile.log", "a");
			fprintf(logfile, "%lu == %lu?\n", i, msgid);
			fclose(logfile);
			if (i == msgid)
			{
				FILE* logfile = fopen("logfile.log", "a");
				fprintf(logfile, "yes, m2r(%lu)==%lu\n",
					msgid, ret);
				fclose(logfile);
				return ret;
			}
			i++;
			logfile = fopen("logfile.log", "a");
			fprintf(logfile, "i++ = %lu\n", i);
			fclose(logfile);
		}
		ret++;
	} while (ret < state->real_msgid_count);

	FILE* logfile = fopen("logfile.log", "a");
	fprintf(logfile, "fallback: m2r(%lu)==0\n", msgid);
	fclose(logfile);
	return 0;
}

struct BufferLine*
load_msgstr(struct DrawState* state)
{


@@ 1227,31 1309,21 @@ move_left(struct DrawState* state)
int
move_list_down(struct DrawState* state)
{
	if (state->msgid_number < state->msgid_count)
	{
		*state->error = 0;
		state->msgid_number++;
		if (state->msgid_number - state->first_shown_msgid
			> state->maxy - 2)
			state->first_shown_msgid++;
	}
	goto_msgid(state, next_msgid(state));
	return 0;
}

int
move_list_end(struct DrawState* state)
{
	*state->error		 = 0;
	state->msgid_number	 = state->msgid_count;
	state->first_shown_msgid = state->msgid_count > 0
		? MAX(1, state->msgid_number - (state->maxy - 2))
		: 0;
	goto_msgid(state, state->real_msgid_count);
	return 0;
}

int
move_list_page_down(struct DrawState* state)
{
	/* TODO: Convert to next_msgid */
	*state->error = 0;
	if (state->msgid_number < state->msgid_count - state->maxy - 2)
	{


@@ 1269,6 1341,7 @@ move_list_page_down(struct DrawState* state)
int
move_list_page_up(struct DrawState* state)
{
	/* TODO: Convert to prev_msgid */
	*state->error = 0;
	if (state->msgid_number > state->maxy - 2)
	{


@@ 1284,22 1357,14 @@ move_list_page_up(struct DrawState* state)
int
move_list_start(struct DrawState* state)
{
	*state->error		 = 0;
	state->msgid_number	 = state->msgid_count > 0 ? 1 : 0;
	state->first_shown_msgid = state->msgid_number;
	goto_msgid(state, 1);
	return 0;
}

int
move_list_up(struct DrawState* state)
{
	if (state->msgid_number > 1)
	{
		*state->error = 0;
		state->msgid_number--;
		if (state->msgid_number < state->first_shown_msgid)
			state->first_shown_msgid--;
	}
	goto_msgid(state, prev_msgid(state));
	return 0;
}



@@ 1605,9 1670,11 @@ next_match(struct DrawState* state)

	*state->error		= 0;
	struct PoEntry* current = NULL;
	for (size_t e = state->msgid_number; e < state->msgid_count; e++)
	for (size_t e = state->msgid_number; e < state->real_msgid_count; e++)
	{
		current = state->entries + e;
		if (current->obsolete)
			continue;
		if ((current->msgid && *current->msgid
			    && u32_strstr(current->msgid, state->search))
			|| (current->msgstr && *current->msgstr