]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix lisp-format, scheme-format: Add a loop normalization.
authorBruno Haible <bruno@clisp.org>
Mon, 13 Mar 2023 19:52:33 +0000 (20:52 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 14 Mar 2023 01:57:28 +0000 (02:57 +0100)
* 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.

gettext-tools/src/format-lisp.c
gettext-tools/src/format-scheme.c
gettext-tools/tests/format-lisp-2
gettext-tools/tests/format-scheme-2

index f69c880e432640a4a54aa7529e5a29b018c4cfe3..c3d8136b84083334d1d43e7bf62823708d068cb0 100644 (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--;
             }
         }
index 184ce5cac05fb914d5fc76fcc61f1ef54dddb5b4..8cbf615e3688bdf57f50e075d159fe59695ca5f5 100644 (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--;
             }
         }
index a3958e9895bef4c84fba54b962755bda9d297c9b..ac27e8df61cbd1678da309cf891a993f89d13d3f 100755 (executable)
@@ -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"
index 5dd07451129fc28274a18023f09b1cb8463f89dc..78cf180db5209e5e6cf0adf965a19c5da7d17bf7 100755 (executable)
@@ -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~}"