чување ab74dec9c20884e8561821224d7a8ed3936a2f81
родитељ bdd98bcdf8ff66c16b009fde7fa5f3234815bc33
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 11 Jul 2021 21:47:34 +0200
Fix: new function, update_statistics (called on load end)
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | po.c | | | 50 | ++++++++++++++++++++++++++++++++++++++------------ |
| M | po.h | | | 2 | ++ |
измењених датотека: 2, додавања: 40(+), брисања: 12(-)
diff --git a/po.c b/po.c
@@ -378,16 +378,21 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
{
if (entry->msgid)
dstate->msgid_count++;
- else if (entry->obsolete)
- dstate->obsolete_count++;
+ /*
+ *else if (entry->obsolete)
+ * dstate->obsolete_count++;
+ */
}
- else
- dstate->untranslated_count--;
+ /*
+ *if (entry->msgid || entry->obsolete)
+ * dstate->untranslated_count--;
+ */
/* file has < PO_DETECTION_LINES */
if (msgid_counter > 0)
return LOAD_ERR_NOT_PO_FILE;
+ update_statistics(dstate->entries, dstate, entry);
dstate->real_msgid_count = dstate->msgid_count + dstate->obsolete_count;
return LOAD_ERR_NONE;
@@ -933,15 +938,9 @@ parse_po_line(const char* line, struct DrawState* dstate,
if (*pstate == PS_NONE)
{
struct PoEntry* newchunk = NULL;
- if ((*current_entry)->obsolete)
- dstate->obsolete_count++;
- else
- {
- /* don't count obsolete towards the msgid count or
- * untranslated count */
- dstate->untranslated_count++;
+
+ if (!(*current_entry)->obsolete)
dstate->msgid_count++;
- }
(*current_entry)++;
if (*current_entry == dstate->entries + dstate->msgid_size)
@@ -1062,3 +1061,30 @@ parse_po_line(const char* line, struct DrawState* dstate,
return PARSE_ERR_NONE;
}
+void
+update_statistics(const struct PoEntry* entries, struct DrawState* state,
+ struct PoEntry* entry)
+{
+ const struct PoEntry* current = NULL;
+
+ state->fuzzy_count = 0;
+ state->obsolete_count = 0;
+ state->untranslated_count = 0;
+
+ current = entries;
+ while (current && current != entry)
+ {
+ if (current->obsolete)
+ state->obsolete_count++;
+ else
+ {
+ if (!current->msgstr || !*current->msgstr ||
+ !**current->msgstr)
+ state->untranslated_count++;
+ if (current->flags & FL_FUZZY)
+ state->fuzzy_count++;
+ }
+ current++;
+ }
+}
+
diff --git a/po.h b/po.h
@@ -113,4 +113,6 @@ int save_file(const struct PoEntry* entries, const size_t real_msgid_count,
int parse_po_line(const char* line, struct DrawState* dstate,
struct PoEntry** current_entry, ParseState* pstate, long* col,
int* msgstr_index);
+void update_statistics(const struct PoEntry* entries, struct DrawState* state,
+ struct PoEntry* entry);