Fix bug #15766 (/KEEP subcommand on SAVE doesn't fully support ALL)
[pspp-builds.git] / src / language / lexer / variable-parser.c
index 937e51ca697a25740817540368305ff9a68a8e8c..904ebe755f43104b92c9267fd49a13ac7c6395a6 100644 (file)
    02110-1301, USA. */
 
 #include <config.h>
-#include "variable.h"
+
+#include <language/lexer/variable-parser.h>
+
 #include <ctype.h>
 #include <stdbool.h>
 #include <stdlib.h>
-#include "alloc.h"
-#include "bit-vector.h"
-#include "dictionary.h"
-#include "message.h"
-#include "hash.h"
+
 #include "lexer.h"
-#include "misc.h"
-#include "pool.h"
-#include "size_max.h"
-#include "str.h"
+#include <data/dictionary.h>
+#include <data/procedure.h>
+#include <data/variable.h>
+#include <libpspp/alloc.h>
+#include <libpspp/bit-vector.h>
+#include <libpspp/hash.h>
+#include <libpspp/message.h>
+#include <libpspp/misc.h>
+#include <libpspp/pool.h>
+#include <libpspp/str.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -160,20 +164,16 @@ add_variable (struct variable ***v, size_t *nv, size_t *mv,
          (*v)[0]->name, add->name, add->name);
   else if ((pv_opts & PV_NO_DUPLICATE) && included[idx]) 
     msg (SE, _("Variable %s appears twice in variable list."), add->name);
-  else 
+  else if ((pv_opts & PV_DUPLICATE) || !included[idx])
     {
       if (*nv >= *mv)
         {
           *mv = 2 * (*nv + 1);
           *v = xnrealloc (*v, *mv, sizeof **v);
         }
-
-      if ((pv_opts & PV_DUPLICATE) || !included[idx])
-        {
-          (*v)[(*nv)++] = add;
-          if (!(pv_opts & PV_DUPLICATE))
-            included[idx] = 1;
-        }
+      (*v)[(*nv)++] = add;
+      if (included != NULL)
+        included[idx] = 1;
     }
 }
 
@@ -239,16 +239,16 @@ parse_var_set_vars (const struct var_set *vs,
   else
     included = NULL;
 
-  if (lex_match (T_ALL))
-    add_variables (v, nv, &mv, included, pv_opts,
-                   vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY);
-  else 
+  do
     {
-      do
+      if (lex_match (T_ALL))
+        add_variables (v, nv, &mv, included, pv_opts,
+                       vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY);
+      else 
         {
           enum dict_class class;
           size_t first_idx;
-          
+
           if (!parse_var_idx_class (vs, &first_idx, &class))
             goto fail;
 
@@ -289,13 +289,15 @@ parse_var_set_vars (const struct var_set *vs,
 
               add_variables (v, nv, &mv, included, pv_opts,
                              vs, first_idx, last_idx, class);
-            }
-          if (pv_opts & PV_SINGLE)
-            break;
-          lex_match (',');
+            } 
         }
-      while (token == T_ID && var_set_lookup_var (vs, tokid) != NULL);
+
+      if (pv_opts & PV_SINGLE)
+        break;
+      lex_match (',');
     }
+  while (token == T_ALL
+         || (token == T_ID && var_set_lookup_var (vs, tokid) != NULL));
   
   if (*nv == 0)
     goto fail;