poe

Уређивач .po фајлова
git clone https://git.sr.ht/~strahinja/poe
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 091d7ac0421db6716f3dd94df4c2cdf5b679c2d1
родитељ 09698640c4fdb81ec849489492b689f8027adf45
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Tue,  2 Jun 2026 21:41:53 +0000

Update untranslated count on msgstr_save; bugfix: unwanted input_buffer == NULL

Diffstat:
MTODO | 7+++++--
Mdraw.h | 2+-
Mpo.c | 5++---
Mpoe.c | 45++++++++++++++++++++++++++++++---------------
измењених датотека: 4, додавања: 38(+), брисања: 21(-)

diff --git a/TODO b/TODO @@ -1,9 +1,12 @@ TODO ==== -[ ] Investigate: testcase-001.po +[~] Investigate: testcase-001.po + [x] Cases where state->input_buffer == NULL when it shouldn't be + [ ] scan-build + [ ] Additional tests -[ ] Investigate: statistics not updated when editing entries? +[x] Investigate: statistics not updated when editing entries? [ ] Support Yudit's nonstandard PO format (no empty lines between individual entries) diff --git a/draw.h b/draw.h @@ -126,7 +126,7 @@ struct DrawState { int edit_dirty; /* tracking changes in the edit box */ ssize_t fuzzy_before_edit; int in_prompt; - int reshow_edit; + int reshow_edit; /* edit box shown again after save/cancel? */ int show_edit; int show_help; int edit_info_focused; diff --git a/po.c b/po.c @@ -1335,7 +1335,7 @@ set_nplurals(struct DrawState* state, struct PoEntry* entry) static uint32_t* unplurals = NULL; uint32_t* ppf; uint32_t* temp; - char* ptoken = token; + char* ptoken = token; int errornum; int read_number = 0; int nplurals_len = 0; @@ -1378,8 +1378,7 @@ set_nplurals(struct DrawState* state, struct PoEntry* entry) } if (*ptoken) { - state->nplurals - = strtonumber(ptoken, 0, INT_MAX, &errornum); + state->nplurals = strtonumber(ptoken, 0, INT_MAX, &errornum); if (errornum != STN_NONE) { state->error = ERR_BAD_NPLURALS; diff --git a/poe.c b/poe.c @@ -59,7 +59,6 @@ cancel_callback(struct DrawState* state, struct tb_event* ev) state->edit_dirty = 0; cancel_msgstr(state); } - state->prompt_callback = NULL; return 0; } @@ -99,6 +98,7 @@ cancel_msgstr(struct DrawState* state) } state->show_edit = 0; + state->reshow_edit = 0; state->edit_info_focused = 0; for (i = 0; i < state->input_rows_count; i++) @@ -339,7 +339,7 @@ edit_page_down(struct DrawState* state) } move_list_down(state); state->msgstr_index = 0; - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; return show_edit(state); } @@ -349,10 +349,11 @@ edit_page_down_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return edit_page_down(state); } @@ -387,10 +388,11 @@ edit_page_up_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return edit_page_up(state); } @@ -724,7 +726,10 @@ handle_key_event(struct tb_event* ev, struct DrawState* state) if (ev->ch && strchr("YyNn", ev->ch)) { if (state->prompt_callback) + { state->prompt_callback(state, ev); + state->prompt_callback = NULL; + } state->in_prompt = 0; *state->prompt = 0; } @@ -1772,10 +1777,11 @@ next_fuzzy_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return next_fuzzy(state); } @@ -1838,10 +1844,11 @@ next_plural_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return next_plural(state); } @@ -1888,10 +1895,11 @@ next_untranslated_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return next_untranslated(state); } @@ -1953,6 +1961,7 @@ paste_paste_buffer_to_input(struct DrawState* state) return 1; } + assert(state->input_buffer != NULL); if (!state->in_prompt && *state->input_buffer->text) { state->in_prompt = 1; @@ -2041,7 +2050,7 @@ position_to(struct DrawState* state, const int row, const int column) { ssize_t dlen; - assert(state != NULL); + assert((state != NULL) && (state->input_buffer != NULL)); if (row != state->coord.row) { state->coord.row = row; @@ -2213,10 +2222,11 @@ prev_plural_callback(struct DrawState* state, struct tb_event* ev) assert((state != NULL) && (ev != NULL)); if (strchr("Yy", ev->ch)) { - state->reshow_edit = state->show_edit; + state->reshow_edit = 1; save_msgstr(state); } - state->edit_dirty = 0; + else + state->edit_dirty = 0; return prev_plural(state); } @@ -2338,6 +2348,11 @@ save_msgstr(struct DrawState* state) to_save_size * sizeof(uint32_t)) < 0) goto save_msgstr_error; + if (*current->msgstr[state->msgstr_index] && !*to_save) + state->untranslated_count++; + else if (!*current->msgstr[state->msgstr_index] && *to_save) + state->untranslated_count--; + u32_set_msgstr(state, current, to_save, state->msgstr_index, 0); update_warning(current->msgid, to_save, &current->warning); state->input_changed_fuzzy = UNCHANGED;