чување ca0d4538e25739d5e1ad34efba441ea27c8e4bf3
родитељ 221a237cb22123f6adb83b440442082ecf44f69b
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 12 Nov 2023 09:42:54 +0100
Bugfix: Last bugfix broke moving to last msgid when obsolete entries are at end
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 4, додавања: 31(+), брисања: 25(-)
diff --git a/draw.c b/draw.c
@@ -127,6 +127,7 @@ init_drawstate(struct DrawState* state, char* error, char* filename,
state->fuzzy_count = 0;
state->untranslated_count = 0;
state->obsolete_count = 0;
+ state->obsolete_at_end_count = 0;
state->msgstr_index = 0;
state->first_shown_msgid = state->msgid_number;
}
diff --git a/draw.h b/draw.h
@@ -85,6 +85,7 @@ struct DrawState {
size_t fuzzy_count;
size_t untranslated_count;
size_t obsolete_count;
+ size_t obsolete_at_end_count;
size_t real_msgid_count; /* msgid_count + obsolete_count */
int msgstr_index; /* with msgstr[] */
size_t first_shown_msgid;
diff --git a/po.c b/po.c
@@ -412,6 +412,12 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
#ifndef PLURAL_STRING
int has_plural_msgid = 0;
#endif
+ FILE* input = NULL;
+ char input_line[MAXBUFLINE];
+ /* lines to tolerate the lack of msgid */
+ int msgid_counter = PO_DETECTION_LINES;
+ int msgstr_index = -1;
+ size_t non_obsolete_sofar = 0;
dstate->msgid_size = 0;
if (!newchunk)
@@ -423,13 +429,8 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
entry = dstate->entries;
dstate->untranslated_count++;
- FILE* input = NULL;
if (!(input = fopen(dstate->filename, "rt")))
return LOAD_ERR_CANT_OPEN_FILE;
- char input_line[MAXBUFLINE];
- /* lines to tolerate the lack of msgid */
- int msgid_counter = PO_DETECTION_LINES;
- int msgstr_index = -1;
while (!feof(input))
{
if (!fgets(input_line, MAXBUFLINE, input))
@@ -494,19 +495,15 @@ 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;
- current = dstate->entries;
+ current = dstate->entries;
+ dstate->obsolete_at_end_count = 0;
+ non_obsolete_sofar = 0;
while (current != dstate->entries + dstate->real_msgid_count)
{
- char u8buf[4096];
- *u8buf = 0;
- if (current->msgid)
- unicode_string_to_u8(u8buf, current->msgid, 4096);
- *u8buf = 0;
- if (current->msgstr && current->msgstr[0])
- unicode_string_to_u8(u8buf, current->msgstr[0], 4096);
- *u8buf = 0;
- if (current->comments && current->comments[0])
- unicode_string_to_u8(u8buf, current->comments[0], 4096);
+ if (!current->obsolete)
+ non_obsolete_sofar++;
+ else if (non_obsolete_sofar == dstate->msgid_count)
+ dstate->obsolete_at_end_count++;
if (!current->obsolete && current->msgid && current->msgstr)
update_warning(current->msgid, *current->msgstr,
¤t->warning);
diff --git a/poe.c b/poe.c
@@ -60,19 +60,23 @@ cancel_callback(struct DrawState* state, struct tb_event* ev)
void
goto_msgid(struct DrawState* state, const size_t msgid_number)
{
- if (msgid_number > state->real_msgid_count + 1)
+ size_t last_non_obsolete
+ = state->real_msgid_count - state->obsolete_at_end_count;
+
+ if (msgid_number > state->real_msgid_count)
return;
+
state->msgid_number = msgid_number;
+
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 = (state->real_msgid_count
- > state->maxy - 2
- ? state->real_msgid_count - (state->maxy - 2)
+ else if (last_non_obsolete < state->msgid_number + state->maxy - 2)
+ state->first_shown_msgid = (last_non_obsolete > state->maxy - 2
+ ? last_non_obsolete - (state->maxy - 2)
: 1);
else
;
@@ -553,16 +557,17 @@ next_msgid(struct DrawState* state, const int delta)
{
size_t ret = state->msgid_number;
size_t start = ret;
+ size_t last_non_obsolete
+ = state->real_msgid_count - state->obsolete_at_end_count;
- while (ret < state->real_msgid_count + 1)
+ while (ret < last_non_obsolete + 1)
{
ret++;
if (!state->entries[ret - 1].obsolete && ret >= start + delta)
break;
}
- return ret == state->real_msgid_count + 1 ? state->real_msgid_count
- : ret;
+ return ret == last_non_obsolete + 1 ? last_non_obsolete : ret;
}
void
@@ -1298,7 +1303,9 @@ move_list_down(struct DrawState* state)
int
move_list_end(struct DrawState* state)
{
- goto_msgid(state, state->real_msgid_count);
+ goto_msgid(state,
+ next_msgid(state,
+ state->real_msgid_count - state->msgid_number));
return 0;
}