Rewrite and improve formatted output routines.
[pspp-builds.git] / src / language / dictionary / vector.c
index 90f245c85f4b84b9ca54490667fa7fd751aeadd9..1216d9dd338d5586fb34e63956c5492887b67bd8 100644 (file)
 
 #include <stdlib.h>
 
-#include <procedure.h>
+#include <data/procedure.h>
 #include <data/dictionary.h>
 #include <data/variable.h>
 #include <language/command.h>
 #include <language/lexer/lexer.h>
+#include <language/lexer/variable-parser.h>
 #include <libpspp/alloc.h>
+#include <libpspp/assertion.h>
 #include <libpspp/message.h>
 #include <libpspp/misc.h>
 #include <libpspp/str.h>
@@ -35,7 +37,7 @@
 #define _(msgid) gettext (msgid)
 
 int
-cmd_vector (void)
+cmd_vector (struct dataset *ds)
 {
   /* Just to be different, points to a set of null terminated strings
      containing the names of the vectors to be created.  The list
@@ -49,6 +51,8 @@ cmd_vector (void)
   /* Maximum allocated position for vecnames, plus one position. */
   char *endp = NULL;
 
+  struct dictionary *dict = dataset_dict (ds);
+
   cp = vecnames = xmalloc (256);
   endp = &vecnames[256];
   do
@@ -73,7 +77,7 @@ cmd_vector (void)
                goto fail;
              }
 
-         if (dict_lookup_vector (default_dict, tokid))
+         if (dict_lookup_vector (dict, tokid))
            {
              msg (SE, _("There is already a vector with name %s."), tokid);
              goto fail;
@@ -102,11 +106,11 @@ cmd_vector (void)
              goto fail;
            }
 
-         if (!parse_variables (default_dict, &v, &nv,
+         if (!parse_variables (dict, &v, &nv,
                                 PV_SAME_TYPE | PV_DUPLICATE))
            goto fail;
 
-          dict_create_vector (default_dict, vecnames, v, nv);
+          dict_create_vector (dict, vecnames, v, nv);
           free (v);
        }
       else if (lex_match ('('))
@@ -156,7 +160,7 @@ cmd_vector (void)
              for (i = 0; i < nv; i++)
                {
                  sprintf (name, "%s%d", cp, i + 1);
-                 if (dict_lookup_var (default_dict, name))
+                 if (dict_lookup_var (dict, name))
                    {
                      msg (SE, _("There is already a variable named %s."),
                            name);
@@ -173,10 +177,10 @@ cmd_vector (void)
              for (i = 0; i < nv; i++)
                {
                  sprintf (name, "%s%d", cp, i + 1);
-                 v[i] = dict_create_var_assert (default_dict, name, 0);
+                 v[i] = dict_create_var_assert (dict, name, 0);
                }
-              if (!dict_create_vector (default_dict, cp, v, nv))
-                assert (0);
+              if (!dict_create_vector (dict, cp, v, nv))
+                NOT_REACHED ();
              cp += strlen (cp) + 1;
            }
           free (v);