@@ 481,7 481,6 @@ load_file(struct DrawState* dstate, long* lineno, long* col)
return LOAD_ERR_NONE;
}
-/* TODO: Convert to u32_next_line (currently deletes all strings) */
int
save_file(const struct PoEntry* entries, const size_t real_msgid_count,
const char* filename, const int nplurals)
@@ 592,40 591,66 @@ save_loop_entries_start:
if (current->msgid)
{
- size_t msgid_size = current->msgid_size * UTF8REPMAX;
- size_t num_lines = u32_lines_in_string(current->msgid,
- SAVE_WRAP_WIDTH);
+ size_t msgid_size = current->msgid_size * UTF8REPMAX;
+ size_t num_lines
+ = u32_lines_in_string(current->msgid, SAVE_WRAP_WIDTH);
if (num_lines > 1)
{
- struct BufferLine* msgid_split = split(current->msgid,
- SAVE_WRAP_WIDTH);
- struct BufferLine* pmsgid_split = NULL;
-
- if (!msgid_split)
- return SAVE_ERR_CANT_ALLOC;
+ const uint32_t* pumsgid = current->msgid;
fprintf(output, "msgid \"\"\n");
- for (size_t i = 0; i < num_lines; i++)
+
+ while (*pumsgid)
{
- pmsgid_split = msgid_split + i;
- int last = i == num_lines - 1;
- char* u8_msgid = calloc(current->msgid_size,
- UTF8REPMAX);
+ size_t len = 0;
+ char* u8_msgid = NULL;
+ const uint32_t* old_pumsgid = pumsgid;
+
+ len = u32_next_line(current->msgid, &pumsgid,
+ SAVE_WRAP_WIDTH);
+ if (len == 0)
+ continue;
+
+ u8_msgid = calloc(len + 1, UTF8REPMAX);
if (!u8_msgid)
return SAVE_ERR_CANT_ALLOC;
- size_t len = u32_strlen(pmsgid_split->text);
- unicode_string_to_u8(u8_msgid,
- pmsgid_split->text, msgid_size);
- if (!(last && len == 0))
- fprintf(output, "\"%s\"\n", u8_msgid);
+
+ unicode_string_to_u8(u8_msgid, old_pumsgid, len);
+ fprintf(output, "\"%s\"\n", u8_msgid);
free(u8_msgid);
}
- for (size_t i = 0; i < num_lines; i++)
- {
- pmsgid_split = msgid_split + i;
- free_bufferline(pmsgid_split);
- }
- free(msgid_split);
+
+ /*
+ * struct BufferLine* msgid_split
+ * = split(current->msgid, SAVE_WRAP_WIDTH); struct
+ * BufferLine* pmsgid_split = NULL;
+ *
+ * if (!msgid_split)
+ * return
+ * SAVE_ERR_CANT_ALLOC;
+ *
+ * fprintf(output, "msgid
+ * \"\"\n"); for (size_t i = 0; i < num_lines; i++)
+ * {
+ * pmsgid_split =
+ * msgid_split + i; int last = i == num_lines - 1;
+ * char* u8_msgid =
+ * calloc(current->msgid_size, UTF8REPMAX); if
+ * (!u8_msgid) return SAVE_ERR_CANT_ALLOC; size_t len =
+ * u32_strlen(pmsgid_split->text);
+ * unicode_string_to_u8(u8_msgid,
+ * pmsgid_split->text,
+ * msgid_size); if (!(last && len == 0)) fprintf(output,
+ * "\"%s\"\n", u8_msgid); free(u8_msgid);
+ * }
+ * for (size_t i = 0; i <
+ * num_lines; i++)
+ * {
+ * pmsgid_split =
+ * msgid_split + i; free_bufferline(pmsgid_split);
+ * }
+ * free(msgid_split);
+ */
}
else
{
@@ 646,40 671,68 @@ save_loop_entries_start:
{
size_t msgid_plural_size
= current->msgid_plural_size * UTF8REPMAX;
- size_t num_lines = u32_lines_in_string(current->msgid_plural,
- SAVE_WRAP_WIDTH);
+ size_t num_lines = u32_lines_in_string(current->msgid_plural,
+ SAVE_WRAP_WIDTH);
if (num_lines > 1)
{
- struct BufferLine* msgid_split
- = split(current->msgid_plural, SAVE_WRAP_WIDTH);
- struct BufferLine* pmsgid_split = NULL;
-
- if (!msgid_split)
- return SAVE_ERR_CANT_ALLOC;
+ const uint32_t* pumsgid = current->msgid_plural;
fprintf(output, "msgid_plural \"\"\n");
- for (size_t i = 0; i < num_lines; i++)
+
+ while (*pumsgid)
{
- pmsgid_split = msgid_split + i;
- int last = i == num_lines - 1;
- char* u8_msgid
- = calloc(current->msgid_plural_size,
- UTF8REPMAX);
+ size_t len = 0;
+ char* u8_msgid = NULL;
+ const uint32_t* old_pumsgid = pumsgid;
+
+ len = u32_next_line(current->msgid_plural,
+ &pumsgid, SAVE_WRAP_WIDTH);
+ if (len == 0)
+ continue;
+
+ u8_msgid = calloc(len + 1, UTF8REPMAX);
if (!u8_msgid)
return SAVE_ERR_CANT_ALLOC;
- size_t len = u32_strlen(pmsgid_split->text);
- unicode_string_to_u8(u8_msgid,
- pmsgid_split->text, msgid_plural_size);
- if (!(last && len == 0))
- fprintf(output, "\"%s\"\n", u8_msgid);
+
+ unicode_string_to_u8(u8_msgid, old_pumsgid, len);
+ fprintf(output, "\"%s\"\n", u8_msgid);
free(u8_msgid);
}
- for (size_t i = 0; i < num_lines; i++)
- {
- pmsgid_split = msgid_split + i;
- free_bufferline(pmsgid_split);
- }
- free(msgid_split);
+
+ /*
+ * struct BufferLine* msgid_split
+ * =
+ * split(current->msgid_plural, SAVE_WRAP_WIDTH); struct
+ * BufferLine* pmsgid_split = NULL;
+ *
+ * if (!msgid_split)
+ * return
+ * SAVE_ERR_CANT_ALLOC;
+ *
+ * fprintf(output, "msgid_plural
+ * \"\"\n"); for (size_t i = 0; i < num_lines; i++)
+ * {
+ * pmsgid_split =
+ * msgid_split + i; int last = i == num_lines - 1;
+ * char* u8_msgid
+ * =
+ * calloc(current->msgid_plural_size, UTF8REPMAX); if
+ * (!u8_msgid) return SAVE_ERR_CANT_ALLOC; size_t len =
+ * u32_strlen(pmsgid_split->text);
+ * unicode_string_to_u8(u8_msgid,
+ * pmsgid_split->text,
+ * msgid_plural_size); if (!(last && len == 0))
+ * fprintf(output,
+ * "\"%s\"\n", u8_msgid); free(u8_msgid);
+ * }
+ * for (size_t i = 0; i <
+ * num_lines; i++)
+ * {
+ * pmsgid_split =
+ * msgid_split + i; free_bufferline(pmsgid_split);
+ * }
+ * free(msgid_split);
+ */
}
else
{
@@ 696,8 749,8 @@ save_loop_entries_start:
if (current->msgstr_count == 1)
{
- size_t num_lines = u32_lines_in_string(*current->msgstr,
- SAVE_WRAP_WIDTH);
+ size_t num_lines = u32_lines_in_string(*current->msgstr,
+ SAVE_WRAP_WIDTH);
if (num_lines > 1)
{
int first_entry = current == entries && !current->msgid;
@@ 707,30 760,35 @@ save_loop_entries_start:
struct tm* now_tm = localtime(&t);
strftime(now, MAXDATEBUF, "%F %H:%M%z", now_tm);
- struct BufferLine* msgstr_split
- = split(*current->msgstr, SAVE_WRAP_WIDTH);
- struct BufferLine* pmsgstr_split = NULL;
-
- if (!msgstr_split)
- return SAVE_ERR_CANT_ALLOC;
+ const uint32_t* pumsgstr = *current->msgstr;
fprintf(output, "msgstr \"\"\n");
- for (size_t i = 0; i < num_lines; i++)
+
+ while (*pumsgstr)
{
- pmsgstr_split = msgstr_split + i;
- int last = i == num_lines - 1;
- char u8_msgstr[MAXMSGLINE * UTF8REPMAX];
- size_t len = u32_strlen(pmsgstr_split->text);
- unicode_string_to_u8(u8_msgstr,
- pmsgstr_split->text,
- MAXMSGLINE * UTF8REPMAX);
+ size_t len = 0;
+ char* u8_msgstr = NULL;
+ const uint32_t* old_pumsgstr = pumsgstr;
+ len = u32_next_line(*current->msgstr, &pumsgstr,
+ SAVE_WRAP_WIDTH);
+
+ if (len == 0)
+ continue;
+
+ /* TODO: Fixme */
+ u8_msgstr = calloc(len + 1, UTF8REPMAX);
+ if (!u8_msgstr)
+ return SAVE_ERR_CANT_ALLOC;
+
+ /* TODO: Fixme */
+ unicode_string_to_u8(u8_msgstr, old_pumsgstr,
+ len);
if (first_entry
&& starts_with(u8_msgstr,
"PO-Revision-Date: "))
fprintf(output,
- "\"PO-Revision-Date:"
- " %s\\n\"\n",
+ "\"PO-Revision-Date: %s\\n\"\n",
now);
else if (first_entry
&& starts_with(u8_msgstr,
@@ 738,23 796,71 @@ save_loop_entries_start:
{
seen_generator = 1;
fprintf(output,
- "\"X-Generator:"
- " poe %s"
- "\\n\"\n",
+ "\"X-Generator: poe %s\\n\"\n",
VERSION);
}
- else if (!(last && len == 0))
+ else
fprintf(output, "\"%s\"\n", u8_msgstr);
+ free(u8_msgstr);
}
if (first_entry && !seen_generator)
fprintf(output, "\"X-Generator: poe %s\"\n",
VERSION);
- for (size_t i = 0; i < num_lines; i++)
- {
- pmsgstr_split = msgstr_split + i;
- free_bufferline(pmsgstr_split);
- }
- free(msgstr_split);
+
+ /*
+ * struct BufferLine*
+ * msgstr_split = split(*current->msgstr,
+ * SAVE_WRAP_WIDTH); struct BufferLine* pmsgstr_split =
+ * NULL;
+ *
+ * if (!msgstr_split)
+ * return
+ * SAVE_ERR_CANT_ALLOC;
+ *
+ * fprintf(output, "msgstr
+ * \"\"\n"); for (size_t i = 0; i < num_lines; i++)
+ * {
+ * pmsgstr_split =
+ * msgstr_split + i; int last = i == num_lines - 1;
+ * char
+ * u8_msgstr[MAXMSGLINE * UTF8REPMAX]; size_t len =
+ * u32_strlen(pmsgstr_split->text);
+ * unicode_string_to_u8(u8_msgstr,
+ * pmsgstr_split->text,
+ * MAXMSGLINE *
+ * UTF8REPMAX);
+ *
+ * if (first_entry
+ * &&
+ * starts_with(u8_msgstr, "PO-Revision-Date: "))
+ * fprintf(output,
+ * "\"PO-Revision-Date:"
+ * "
+ * %s\\n\"\n", now); else if (first_entry
+ * &&
+ * starts_with(u8_msgstr, "X-Generator: "))
+ * {
+ * seen_generator
+ * = 1; fprintf(output,
+ * "\"X-Generator:"
+ * " poe
+ * %s"
+ * "\\n\"\n",
+ * VERSION);
+ * }
+ * else if (!(last && len
+ * == 0)) fprintf(output, "\"%s\"\n", u8_msgstr);
+ * }
+ * if (first_entry &&
+ * !seen_generator) fprintf(output, "\"X-Generator: poe
+ * %s\"\n", VERSION); for (size_t i = 0; i < num_lines;
+ * i++)
+ * {
+ * pmsgstr_split =
+ * msgstr_split + i; free_bufferline(pmsgstr_split);
+ * }
+ * free(msgstr_split);
+ */
}
else if (current->msgid_plural
&& (!*current->msgstr || !**current->msgstr))
@@ 776,35 882,69 @@ save_loop_entries_start:
SAVE_WRAP_WIDTH);
if (num_lines > 1)
{
- struct BufferLine* msgstr_split
- = split(*(current->msgstr + m),
- SAVE_WRAP_WIDTH);
- struct BufferLine* pmsgstr_split = NULL;
-
- if (!msgstr_split)
- return SAVE_ERR_CANT_ALLOC;
+ const uint32_t* pumsgstr
+ = *(current->msgstr + m);
fprintf(output, "msgstr[%ld] \"\"\n", m);
- for (size_t i = 0; i < num_lines; i++)
+
+ while (*pumsgstr)
{
- pmsgstr_split = msgstr_split + i;
- int last = i == num_lines - 1;
- char u8_msgstr[MAXMSGLINE * UTF8REPMAX];
- size_t len = u32_strlen(
- pmsgstr_split->text);
+ size_t len = 0;
+ char* u8_msgstr = NULL;
+ const uint32_t* old_pumsgstr = pumsgstr;
+
+ len = u32_next_line(*(current->msgstr
+ + m),
+ &pumsgstr, SAVE_WRAP_WIDTH);
+ if (len == 0)
+ continue;
+
+ u8_msgstr = calloc(len + 1, UTF8REPMAX);
+ if (!u8_msgstr)
+ return SAVE_ERR_CANT_ALLOC;
+
unicode_string_to_u8(u8_msgstr,
- pmsgstr_split->text,
- MAXMSGLINE * UTF8REPMAX);
- if (!(last && len == 0))
- fprintf(output, "\"%s\"\n",
- u8_msgstr);
- }
- for (size_t i = 0; i < num_lines; i++)
- {
- pmsgstr_split = msgstr_split + i;
- free_bufferline(pmsgstr_split);
+ old_pumsgstr, len);
+ fprintf(output, "\"%s\"\n", u8_msgstr);
+ free(u8_msgstr);
}
- free(msgstr_split);
+
+ /*
+ * struct BufferLine*
+ * msgstr_split = split(*(current->msgstr + m),
+ * SAVE_WRAP_WIDTH);
+ * struct BufferLine*
+ * pmsgstr_split = NULL;
+ *
+ * if (!msgstr_split)
+ * return
+ * SAVE_ERR_CANT_ALLOC;
+ *
+ * fprintf(output,
+ * "msgstr[%ld] \"\"\n", m); for (size_t i = 0;
+ * i < num_lines; i++)
+ * {
+ * pmsgstr_split
+ * = msgstr_split + i; int last = i == num_lines
+ * - 1; char u8_msgstr[MAXMSGLINE * UTF8REPMAX];
+ * size_t
+ * len = u32_strlen( pmsgstr_split->text);
+ * unicode_string_to_u8(u8_msgstr,
+ * pmsgstr_split->text,
+ * MAXMSGLINE
+ * * UTF8REPMAX); if (!(last && len == 0))
+ * fprintf(output,
+ * "\"%s\"\n", u8_msgstr);
+ * }
+ * for (size_t i
+ * = 0; i < num_lines; i++)
+ * {
+ * pmsgstr_split
+ * = msgstr_split + i;
+ * free_bufferline(pmsgstr_split);
+ * }
+ * free(msgstr_split);
+ */
}
else
{