DO REPEAT: Order PRINT output correctly.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 2 Mar 2023 22:16:25 +0000 (14:16 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 2 Mar 2023 22:17:37 +0000 (14:17 -0800)
This was printed in reverse order, although the commands were executed in
the correct order.

src/language/commands/repeat.c
tests/language/commands/do-repeat.at

index f71409147cd5f167deb680a523f75b6ae7d811d7..2efce93e2bca0609499b0412f958d5ddcc023fee 100644 (file)
@@ -275,17 +275,22 @@ parse_commands (struct lexer *lexer, struct hmap *dummies)
   bool print = ok && lex_match_id (lexer, "PRINT");
   lex_discard_rest_of_command (lexer);
 
-  for (size_t i = 0; i < n_values; i++)
+  if (print)
     {
-      struct string *output = &outputs[n_values - i - 1];
-      if (print)
+      for (size_t i = 0; i < n_values; i++)
         {
+          struct string *output = &outputs[i];
           struct substring s = output->ss;
           ss_chomp_byte (&s, '\n');
           char *label = xasprintf (_("Expansion %zu of %zu"), i + 1, n_values);
           output_item_submit (
             text_item_create_nocopy (TEXT_ITEM_LOG, ss_xstrdup (s), label));
         }
+    }
+
+  for (size_t i = 0; i < n_values; i++)
+    {
+      struct string *output = &outputs[n_values - i - 1];
       const char *encoding = lex_get_encoding (lexer);
       struct lex_reader *reader = lex_reader_for_substring_nocopy (ds_ss (output), encoding);
       lex_reader_set_file_name (reader, file_name);
index ad2fa978b56b922d31f12e5f7c1ef95028c0bbd2..81bc952bc8ac3d9cab991ab1cc773d8bbf4e0c4f 100644 (file)
@@ -32,9 +32,9 @@ LIST.
 ])
 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
 AT_CHECK([cat pspp.csv], [0], [dnl
-COMPUTE x=3.
-COMPUTE y='c'.
-COMPUTE c=3.
+COMPUTE x=1.
+COMPUTE y='a'.
+COMPUTE a=1.
 END CASE.
 
 COMPUTE x=2.
@@ -42,9 +42,9 @@ COMPUTE y='b'.
 COMPUTE b=2.
 END CASE.
 
-COMPUTE x=1.
-COMPUTE y='a'.
-COMPUTE a=1.
+COMPUTE x=3.
+COMPUTE y='c'.
+COMPUTE c=3.
 END CASE.
 
 Table: Data List