~strahinja/poe

d6b533b50a6aec9d100453c7d1cd6ee680262771 — Страхиња Радић 5 months ago bb801db v1.7.0
Done WIP obsolete items bugfix

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

M TODO
M TODO.done
M draw.c
M draw.h
M poe.c
M TODO => TODO +0 -7
@@ 3,13 3,6 @@ TODO

[ ] Bugfix: C-W offscreen (check if there is an equivalent of position_to)

[ ] Bugfix: obsolete msgstrs followed by non-obsolete ones
	- msgid list handling was built entirely around the idea of obsolete
	  entries being at the end of .po file. Since I came across .po files
	  which have obsolete entries among the normal entries, this needs
	  adjusting, which has to incur a performance hit when navigating the
	  list.

[ ] Replace strn* -> strc*: like str[^n]*, but with configurable string
    ending character (for msgstr, which has multiple lines delimited
    with '\n')

M TODO.done => TODO.done +7 -0
@@ 1,6 1,13 @@
Done todos
==========

[x] Bugfix: obsolete msgstrs followed by non-obsolete ones
	- msgid list handling was built entirely around the idea of obsolete
	  entries being at the end of .po file. Since I came across .po files
	  which have obsolete entries among the normal entries, this needs
	  adjusting, which has to incur a performance hit when navigating the
	  list.

[x] Add config.h options:
	[x] Enable/disable automatic addition of dot
	[x] Enable/disable automatic addition of Plural-Forms

M draw.c => draw.c +4 -1
@@ 163,6 163,8 @@ format_filename(char* result, size_t result_size, const char* format,
				 : (state->dirty ? "*" : ""));
}

size_t real_msgid_to_display_msgid(const struct DrawState* state);

void
format_msgs(char* result, size_t result_size, const char* format,
	const struct DrawState* state)


@@ 170,7 172,8 @@ format_msgs(char* result, size_t result_size, const char* format,
	if (!result)
		return;

	snprintf(result, result_size, format, state ? state->msgid_number : 0,
	snprintf(result, result_size, format, state ?
	real_msgid_to_display_msgid(state) : 0,
		state ? state->msgid_count : 0,
		state ? state->untranslated_count : 0,
		state ? state->fuzzy_count : 0,

M draw.h => draw.h +2 -2
@@ 79,8 79,8 @@ struct DrawState {
	int show_search;
	int maxx;
	int maxy;
	size_t msgid_number;
	size_t msgid_count;
	size_t msgid_number;	/* "real" msgid (inc. obsolete msgids) */
	size_t msgid_count;	/* without obsolete msgids */
	size_t msgid_size;
	size_t fuzzy_count;
	size_t untranslated_count;

M poe.c => poe.c +52 -51
@@ 44,6 44,7 @@ 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, ...);
void quit_callback(struct DrawState* state, struct tb_event* ev);
size_t real_msgid_to_display_msgid(const struct DrawState* state);

void
cancel_callback(struct DrawState* state, struct tb_event* ev)


@@ 58,30 59,23 @@ 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
		< (state->maxy - 1) / 2)
	if (state->msgid_number < state->first_shown_msgid)
		state->first_shown_msgid = state->msgid_number;
	else if (state->msgid_number
		> state->first_shown_msgid + state->maxy - 2)
		state->first_shown_msgid = state->msgid_number
			- (state->maxy - 2);
	else if (state->real_msgid_count
		< state->msgid_number + state->maxy - 2)
		state->first_shown_msgid
			= MAX(1, state->msgid_count - (state->maxy - 2));
			= (state->real_msgid_count > state->maxy - 2
				? state->real_msgid_count - (state->maxy - 2)
				: 1);
	else
		state->first_shown_msgid
			= MAX(1, state->msgid_number - (state->maxy - 1) / 2);
		;
}

void


@@ 491,35 485,40 @@ load_info(struct DrawState* state)
}

size_t
next_msgid(struct DrawState* state)
next_msgid(struct DrawState* state, const int delta)
{
	/* TODO: Add parameter 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)
		if (!state->entries[ret-1].obsolete
			&& ret >= start + delta)
			break;
	}

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

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

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

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

	return ret == 0 ? state->msgid_number : ret;
	return ret;
}

size_t


@@ 532,28 531,13 @@ msgid_to_real_msgid(struct DrawState* state, const size_t msgid)
	{
		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;
}



@@ 658,6 642,23 @@ quit_callback(struct DrawState* state, struct tb_event* ev)
	state->running	       = 0;
}

size_t
real_msgid_to_display_msgid(const struct DrawState* state)
{
	struct PoEntry* current = state->entries;
	size_t ret = state->msgid_count ? 1 : 0;

	while (current != state->entries + state->msgid_number - 1)
	{
		if (!current->obsolete && current != state->entries +
		state->msgid_number - 1)
			ret++;
		current++;
	}

	return ret;
}

int
cancel_close(struct DrawState* state)
{


@@ 1309,7 1310,7 @@ move_left(struct DrawState* state)
int
move_list_down(struct DrawState* state)
{
	goto_msgid(state, next_msgid(state));
	goto_msgid(state, next_msgid(state, 1));
	return 0;
}



@@ 1323,9 1324,9 @@ move_list_end(struct DrawState* state)
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)
	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


@@ 1334,23 1335,23 @@ move_list_page_down(struct DrawState* state)
				= state->msgid_number - (state->maxy - 2);
	}
	else
		return move_list_end(state);
		return move_list_end(state);*/
	return 0;
}

int
move_list_page_up(struct DrawState* state)
{
	/* TODO: Convert to prev_msgid */
	*state->error = 0;
	if (state->msgid_number > state->maxy - 2)
	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 move_list_start(state);*/
	return 0;
}



@@ 1364,7 1365,7 @@ move_list_start(struct DrawState* state)
int
move_list_up(struct DrawState* state)
{
	goto_msgid(state, prev_msgid(state));
	goto_msgid(state, prev_msgid(state, 1));
	return 0;
}