diff options
author | Bruno Haible <bruno@clisp.org> | 2023-03-13 20:52:33 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-03-14 02:57:28 +0100 |
commit | c00beb5944c6e447773d5358e237ebfc6f844ca1 (patch) | |
tree | 92bb3752899fc017dadbe02cd5c21e10958be675 | |
parent | 3904fddd401dc6b22bffedcc8668f144fe467494 (diff) | |
download | gettext-c00beb5944c6e447773d5358e237ebfc6f844ca1.tar.gz |
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.
-rw-r--r-- | gettext-tools/src/format-lisp.c | 9 | ||||
-rw-r--r-- | gettext-tools/src/format-scheme.c | 9 | ||||
-rwxr-xr-x | gettext-tools/tests/format-lisp-2 | 3 | ||||
-rwxr-xr-x | gettext-tools/tests/format-scheme-2 | 3 |
4 files changed, 22 insertions, 2 deletions
diff --git a/gettext-tools/src/format-lisp.c b/gettext-tools/src/format-lisp.c index f69c880e4..c3d8136b8 100644 --- a/gettext-tools/src/format-lisp.c +++ b/gettext-tools/src/format-lisp.c @@ -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--; } } diff --git a/gettext-tools/src/format-scheme.c b/gettext-tools/src/format-scheme.c index 184ce5cac..8cbf615e3 100644 --- a/gettext-tools/src/format-scheme.c +++ b/gettext-tools/src/format-scheme.c @@ -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--; } } diff --git a/gettext-tools/tests/format-lisp-2 b/gettext-tools/tests/format-lisp-2 index a3958e989..ac27e8df6 100755 --- a/gettext-tools/tests/format-lisp-2 +++ b/gettext-tools/tests/format-lisp-2 @@ -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" diff --git a/gettext-tools/tests/format-scheme-2 b/gettext-tools/tests/format-scheme-2 index 5dd074511..78cf180db 100755 --- a/gettext-tools/tests/format-scheme-2 +++ b/gettext-tools/tests/format-scheme-2 @@ -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~}" |