чување bd46137434a1e7f2e5596b20f8ece8355af68ff8
родитељ da8bfeee3ada652b60199749797dbdd98498706d
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sat, 3 Jul 2021 18:40:04 +0200
Completed handling of msgstr[]; added 'P' flag when msgstr_count>1 in list view
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 4, додавања: 31(+), брисања: 16(-)
diff --git a/draw.c b/draw.c
@@ -274,12 +274,22 @@ draw_editbox(const struct DrawState* state)
state->input_first_shown_row);
char sbuf[MAXBUFLINE];
- sprintf(sbuf, "%d[%d]:%d[%d]/%d",
- state->input_display_column,
- state->input_first_shown_column,
- state->input_row,
- state->input_first_shown_row,
- state->input_rows_count);
+ if (entry->msgstr_count > 1)
+ sprintf(sbuf, "%d[%d]:%d[%d]/%d (plural: %d/%d)",
+ state->input_display_column,
+ state->input_first_shown_column,
+ state->input_row,
+ state->input_first_shown_row,
+ state->input_rows_count,
+ state->msgstr_index + 1,
+ entry->msgstr_count);
+ else
+ sprintf(sbuf, "%d[%d]:%d[%d]/%d",
+ state->input_display_column,
+ state->input_first_shown_column,
+ state->input_row,
+ state->input_first_shown_row,
+ state->input_rows_count);
draw_string(startx+1, endy-2, DLG_FG, DLG_BG,
sbuf, w-2, strlen(sbuf)+2, 1, 1, LEFT);
if (entry->flags != FL_NONE)
@@ -370,6 +380,9 @@ draw_list_visible(const struct DrawState* state)
state->maxx/2-MAXFLAGSBUF+1-2,
state->maxx/2-MAXFLAGSBUF+1-2, 2, 0,
LEFT);
+ /* don't use msgstr_index as then the entire list will shift
+ * when changing currently displayed plural form msgstr in an
+ * edit box */
if (current->msgstr && current->msgstr_count > 0 &&
current->msgstr + state->msgstr_index)
u32_draw_string(state->maxx/2, cy,
@@ -377,8 +390,8 @@ draw_list_visible(const struct DrawState* state)
: LIST_MSGSTR_FG,
sel ? LIST_MSGSTR_SEL_BG
: LIST_MSGSTR_BG,
- *(current->msgstr +
- state->msgstr_index),
+ *(current->msgstr /*+
+ state->msgstr_index*/),
state->maxx/2, state->maxx/2, 2, 2,
LEFT);
current++;
diff --git a/po.c b/po.c
@@ -7,9 +7,10 @@
char*
format_flags(char* buffer, const size_t max, const struct PoEntry* entry)
{
- snprintf(buffer, max, "%c%c",
+ snprintf(buffer, max, "%c%c%c",
entry->flags & FL_C_FORMAT ? 'C' : ' ',
- entry->flags & FL_FUZZY ? 'F' : ' ');
+ entry->flags & FL_FUZZY ? 'F' : ' ',
+ entry->msgstr_count > 1 ? 'P' : ' ');
return buffer;
}
@@ -104,7 +105,7 @@ u32_set_msgstr(struct PoEntry* entry, const uint32_t* msgstr, int msgstr_index,
{
if (!entry)
return NULL;
- if (!entry->msgstr_count || msgstr_index + 1 > entry->msgstr_count)
+ if (entry->msgstr_count == 0 || msgstr_index + 1 > entry->msgstr_count)
{
uint32_t** newmsgstr = NULL;
entry->msgstr_count = msgstr_index + 1;
@@ -115,6 +116,7 @@ u32_set_msgstr(struct PoEntry* entry, const uint32_t* msgstr, int msgstr_index,
entry->msgstr_count * sizeof(uint32_t*));
if (!newmsgstr)
return NULL;
+ *(newmsgstr + msgstr_index) = NULL;
entry->msgstr = newmsgstr;
}
if (!*(entry->msgstr + msgstr_index))
@@ -285,7 +287,7 @@ parse_po_line(const char* line, struct PoEntry** entries, size_t* entries_size,
if (starts_with(pline, "] "))
{
pline += 2;
- col += 2;
+ (*col) += 2;
}
else
return PARSE_ERR_SYNTAX;
@@ -377,9 +379,7 @@ parse_po_line(const char* line, struct PoEntry** entries, size_t* entries_size,
set_msgstr(*current_entry, token, 0, 1);
else if (*state & PS_MSGSTR_ARRAY)
set_msgstr(*current_entry, token,
- (*current_entry)->msgstr_count ?
- (*current_entry)->msgstr_count -1 : 0,
- 1);
+ (*current_entry)->msgstr_count, 1);
else if (*state & PS_COMMENT_DESC)
{
uint32_t u32_token[MAXCOMMENTLINE];
diff --git a/poe.1.in b/poe.1.in
@@ -91,6 +91,8 @@ _
\fCC-S\fR@Update entry and close dialog
\fCC-B\fP or \fCPgUp\fP@Update entry and edit previous entry
\fCC-F\fP or \fCPgDn\fP@Update entry and edit next entry
+\fCC-P\fP@Show previous plural form of msgstr
+\fCC-N\fP@Show next plural form of msgstr
\fCEscape\fP@Cancel changes and close dialog
\fCC-Z\fP@Toggle fuzzy flag
\fCC-A\fP or \fCHome\fP@Go to start of line
diff --git a/util.h b/util.h
@@ -16,7 +16,7 @@ enum {
#define MAXBUFLINE 1024
#define MAXMSG 1024
#define MAXPATH 1024
-#define MAXFLAGSBUF 2+1
+#define MAXFLAGSBUF 3+1
size_t u8_string_to_unicode(uint32_t* us, const char* s);
char* unicode_string_to_u8(char* s, const uint32_t* us);