Fix lisp-format, scheme-format: Add a loop normalization.

* gettext-tools/src/format-lisp.c (normalize_outmost_list): Algorithmic fixes.
* gettext-tools/src/format-scheme.c (normalize_outmost_list): Likewise.
* gettext-tools/tests/format-lisp-2: Add another test.
* gettext-tools/tests/format-scheme-2: Likewise.
This commit is contained in:
Bruno Haible 2023-03-13 20:52:33 +01:00
parent 3904fddd40
commit c00beb5944
4 changed files with 22 additions and 2 deletions

View File

@ -462,7 +462,7 @@ normalize_outermost_list (struct format_arg_list *list)
}
/* Proceed as if the loop period were n, with
list->repeated.element[0].repcount incremented by repcount0_extra. */
for (m = 2; m <= n / 2; n++)
for (m = 2; m <= n / 2; m++)
if ((n % m) == 0)
{
/* m is a divisor of n. Try to reduce the loop period to n. */
@ -489,6 +489,12 @@ normalize_outermost_list (struct format_arg_list *list)
break;
}
}
if (list->repeated.count == 1)
{
/* The loop has period 1. Normalize the repcount. */
list->repeated.element[0].repcount = 1;
list->repeated.length = 1;
}
/* Step 3: Roll as much as possible of the initial segment's tail
into the loop. */
@ -503,6 +509,7 @@ normalize_outermost_list (struct format_arg_list *list)
certainly different and doesn't need to be considered. */
list->initial.length -=
list->initial.element[list->initial.count-1].repcount;
free_element (&list->initial.element[list->initial.count-1]);
list->initial.count--;
}
}

View File

@ -465,7 +465,7 @@ normalize_outermost_list (struct format_arg_list *list)
}
/* Proceed as if the loop period were n, with
list->repeated.element[0].repcount incremented by repcount0_extra. */
for (m = 2; m <= n / 2; n++)
for (m = 2; m <= n / 2; m++)
if ((n % m) == 0)
{
/* m is a divisor of n. Try to reduce the loop period to n. */
@ -492,6 +492,12 @@ normalize_outermost_list (struct format_arg_list *list)
break;
}
}
if (list->repeated.count == 1)
{
/* The loop has period 1. Normalize the repcount. */
list->repeated.element[0].repcount = 1;
list->repeated.length = 1;
}
/* Step 3: Roll as much as possible of the initial segment's tail
into the loop. */
@ -506,6 +512,7 @@ normalize_outermost_list (struct format_arg_list *list)
certainly different and doesn't need to be considered. */
list->initial.length -=
list->initial.element[list->initial.count-1].repcount;
free_element (&list->initial.element[list->initial.count-1]);
list->initial.count--;
}
}

View File

@ -154,6 +154,9 @@ msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
# Invalid: ~^ inside iteration depends on position
msgid "abc~{~D ~^~C~}"
msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
# Valid: ( | . i . i) normalizes to ( | . i)
msgid "abc~@{~D~^~D~}"
msgstr "xyz~@{~D~}"
# Valid: justification is optional
msgid "abc~<~D~;~C~>"
msgstr "xyz~D~C"

View File

@ -178,6 +178,9 @@ msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
# Invalid: ~^ inside iteration depends on position
msgid "abc~{~D ~^~C~}"
msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
# Valid: ( | . i . i) normalizes to ( | . i)
msgid "abc~@{~D~^~D~}"
msgstr "xyz~@{~D~}"
# Invalid: type compatibility with non-strict checking
msgid "abc~{~c~c~}"
msgid_plural "abc~{~c~c~}"