poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 7bbfce79fd34691bee6991cc8a87f3d97c56f571
родитељ 14bfb577f9b5aadeb894f0b61de9268125cbb5b3
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Thu, 23 Sep 2021 14:29:52 +0200

Fix: sometimes lines in long msgids were skipped; fix: dirname wasn't applied to tmp_filename when the filename variable didn't include directories, resulting in "write error"

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 2+-
Mpo.c | 25+++++++------------------
измењених датотека: 2, додавања: 8(+), брисања: 19(-)

diff --git a/TODO b/TODO @@ -3,7 +3,7 @@ [x] Fix: very long msgids/msgstrs get truncated (lftp) - [ ] Investigate \" in msgid (makes the line ignored?) + [x] Investigate \" in msgid (makes the line ignored?) < > Sort by flag/column? diff --git a/po.c b/po.c @@ -161,18 +161,16 @@ u32_set_msgid(struct PoEntry* entry, const uint32_t* msgid, size_t msgid_size, entry->msgid_size = MSGDELTA; entry->msgid_len = 0; entry->msgid = calloc(entry->msgid_size, sizeof(uint32_t)); - if (!entry->msgid) - return NULL; } else if (entry->msgid_len + msgid_len >= entry->msgid_size) { entry->msgid_size += MSGDELTA; entry->msgid = realloc(entry->msgid, entry->msgid_size * sizeof(uint32_t)); - if (!entry->msgid_plural) - return NULL; } entry->msgid_len += msgid_len; + if (!entry->msgid) + return NULL; if (append) u32_strncat(entry->msgid, msgid, entry->msgid_size); else @@ -195,8 +193,6 @@ u32_set_msgid_plural(struct PoEntry* entry, const uint32_t* msgid_plural, entry->msgid_plural_len = 0; entry->msgid_plural = calloc(entry->msgid_plural_size, sizeof(uint32_t)); - if (!entry->msgid_plural) - return NULL; } else if (entry->msgid_plural_size + msgid_plural_len >= entry->msgid_plural_size) @@ -204,10 +200,10 @@ u32_set_msgid_plural(struct PoEntry* entry, const uint32_t* msgid_plural, entry->msgid_plural_size += MSGDELTA; entry->msgid_plural = realloc(entry->msgid_plural, entry->msgid_plural_size * sizeof(uint32_t)); - if (!entry->msgid_plural) - return NULL; } entry->msgid_plural_len += msgid_plural_len; + if (!entry->msgid_plural) + return NULL; if (append) u32_strncat(entry->msgid_plural, msgid_plural, entry->msgid_plural_size); @@ -486,7 +482,7 @@ save_file(const struct PoEntry* entries, const size_t real_msgid_count, char* backup_filename = calloc(len + 2, 1); char tmp_filename[MAXPATH]; strcpy(tmp_filename, filename); - dirname(tmp_filename); + strcpy(tmp_filename, dirname(tmp_filename)); strncat(tmp_filename, "/poe.tmp", MAXPATH - 1); if (!(output = fopen(tmp_filename, "wt"))) @@ -504,7 +500,8 @@ save_loop_entries_start: for (size_t c = 0; c < current->comment_lines; c++) { unicode_string_to_u8(u8_comment, - *(current->comments + c), MAXCOMMENTLINE * UTF8REPMAX); + *(current->comments + c), + MAXCOMMENTLINE * UTF8REPMAX); fprintf(output, "#%s%s\n", current->obsolete ? "~" : "", u8_comment); } @@ -567,10 +564,6 @@ save_loop_entries_start: if (current->msgid) { size_t msgid_size = current->msgid_size * UTF8REPMAX; - /*char* msgid = calloc(current->msgid_size, UTF8REPMAX);*/ - /*if (!msgid)*/ - /*return SAVE_ERR_CANT_ALLOC;*/ - /*unicode_string_to_u8(msgid, current->msgid, msgid_size);*/ size_t actual_lines = 0; size_t num_lines = u32_lines_in_string(current->msgid, &actual_lines); @@ -617,7 +610,6 @@ save_loop_entries_start: fprintf(output, "msgid \"%s\"\n", u8_msgid); free(u8_msgid); } - /*free(msgid);*/ } else fprintf(output, "msgid \"\"\n"); @@ -626,9 +618,6 @@ save_loop_entries_start: { size_t msgid_plural_size = current->msgid_plural_size * UTF8REPMAX; - /*char msgid_plural[MAXMSG];*/ - /*unicode_string_to_u8(msgid_plural, current->msgid_plural,*/ - /*MAXMSG);*/ size_t actual_lines = 0; size_t num_lines = u32_lines_in_string(current->msgid_plural, &actual_lines);