~strahinja/poe

113f5f2b87af4330c88424d8c5b18bf644a4608b — Страхиња Радић 9 months ago 48f0e73 v1.4.6
Fix wrapping on save

Signed-off-by: Страхиња Радић <contact@strahinja.org>
3 files changed, 34 insertions(+), 34 deletions(-)

M config.h
M po.c
M po.h
M config.h => config.h +1 -1
@@ 1,6 1,6 @@
/* See the file LICENSE for copyright and license details. */

#define SAVE_WRAP_WIDTH	  0
#define SAVE_WRAP_WIDTH	  70
#define WRAP_FIRST_MSGSTR 0
#define WARN_COUNT_DOTS	  0


M po.c => po.c +31 -33
@@ 603,22 603,21 @@ 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, 1,
			       SAVE_WRAP_WIDTH);
		const uint32_t* pumsgid = current->msgid;
		size_t len		= 0;
		size_t msgid_size = current->msgid_size * UTF8REPMAX;
		size_t num_lines  = u32_lines_in_string(current->msgid, 1,
			 SAVE_WRAP_WIDTH);

		len = u32_next_line(current->msgid, &pumsgid, 1, 0);

		if (num_lines > 1 && SAVE_WRAP_WIDTH > 0
			&& len > SAVE_WRAP_WIDTH)
		if ((num_lines > 1)
			&& (u32_strlen(current->msgid)
				> SAVE_MULTILINE_TRESHOLD))
		{
			const uint32_t* pumsgid = current->msgid;

			fprintf(output, "msgid \"\"\n");

			pumsgid = current->msgid;
			while (*pumsgid)
			{
				size_t len		    = 0;
				char* u8_msgid		    = NULL;
				const uint32_t* old_pumsgid = pumsgid;



@@ 657,19 656,18 @@ save_loop_entries_start:
			= current->msgid_plural_size * UTF8REPMAX;
		size_t num_lines = u32_lines_in_string(current->msgid_plural, 1,
			SAVE_WRAP_WIDTH);
		const uint32_t* pumsgid = current->msgid_plural;
		size_t len		= 0;

		len = u32_next_line(current->msgid_plural, &pumsgid, 1, 0);

		if (num_lines > 1 && SAVE_WRAP_WIDTH > 0
			&& len > SAVE_WRAP_WIDTH)
		if ((num_lines > 1)
			&& (u32_strlen(current->msgid_plural)
				> SAVE_MULTILINE_TRESHOLD))
		{
			const uint32_t* pumsgid = current->msgid_plural;

			fprintf(output, "msgid_plural \"\"\n");

			pumsgid = current->msgid_plural;
			while (*pumsgid)
			{
				size_t len		    = 0;
				char* u8_msgid		    = NULL;
				const uint32_t* old_pumsgid = pumsgid;



@@ 704,27 702,25 @@ save_loop_entries_start:
	{
		size_t num_lines = u32_lines_in_string(*current->msgstr, 1,
			SAVE_WRAP_WIDTH);
		const uint32_t* pumsgstr = *current->msgstr;
		size_t len		 = 0;
		int first_entry = current == entries && !current->msgid;
		int first_entry	 = (current == entries) && !current->msgid;

		len = u32_next_line(*current->msgstr, &pumsgstr, 1, 0);

		if (num_lines > 1 && (first_entry && WRAP_FIRST_MSGSTR)
			|| (!first_entry && SAVE_WRAP_WIDTH > 0
				&& len > SAVE_WRAP_WIDTH))
		if ((num_lines > 1)
			&& (first_entry
				|| (u32_strlen(*current->msgstr)
					> SAVE_MULTILINE_TRESHOLD)))
		{
			int seen_generator = 0;
			const uint32_t* pumsgstr = *current->msgstr;
			int seen_generator	 = 0;
			char now[MAXDATEBUF];
			time_t t	  = time(NULL);
			struct tm* now_tm = localtime(&t);
			strftime(now, MAXDATEBUF, "%F %H:%M%z", now_tm);

			strftime(now, MAXDATEBUF, "%F %H:%M%z", now_tm);
			fprintf(output, "msgstr \"\"\n");

			pumsgstr = *current->msgstr;
			while (*pumsgstr)
			{
				size_t len		     = 0;
				char* u8_msgstr		     = NULL;
				const uint32_t* old_pumsgstr = pumsgstr;



@@ 785,17 781,19 @@ save_loop_entries_start:
		{
			size_t num_lines = u32_lines_in_string(*current->msgstr,
				1, SAVE_WRAP_WIDTH);
			const uint32_t* pumsgstr = *(current->msgstr + m);
			size_t len		 = 0;

			if (num_lines > 1 && SAVE_WRAP_WIDTH > 0
				&& len > SAVE_WRAP_WIDTH)
			if ((num_lines > 1)
				&& (u32_strlen(*(current->msgstr + m))
					> SAVE_MULTILINE_TRESHOLD))
			{
				const uint32_t* pumsgstr
					= *(current->msgstr + m);

				fprintf(output, "msgstr[%ld] \"\"\n", m);

				pumsgstr = *(current->msgstr + m);
				while (*pumsgstr)
				{
					size_t len		     = 0;
					char* u8_msgstr		     = NULL;
					const uint32_t* old_pumsgstr = pumsgstr;


M po.h => po.h +2 -0
@@ 6,6 6,8 @@
#define MSGSTR_MAX	   4096
#define ALLOC_DELTA	   10
#define PO_DETECTION_LINES 24
/* If msgid/msgstr is longer, it will be saved as multiple lines */
#define SAVE_MULTILINE_TRESHOLD 70

#define LOAD_PARSE_ERR(e) (LOAD_ERR_PARSE_PREFIX + (e))