You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
#include <config.h>
-#include <assert.h>
+#include "error.h"
#include <stdlib.h>
#include "alloc.h"
-#include "cases.h"
#include "command.h"
+#include "dictionary.h"
#include "error.h"
#include "lexer.h"
#include "misc.h"
#include "str.h"
#include "var.h"
-#include "vector.h"
-
-/* Vectors created on VECTOR. */
-struct vector *vec;
-
-/* Number of vectors in vec. */
-int nvec;
int
cmd_vector (void)
/* Maximum allocated position for vecnames, plus one position. */
char *endp = NULL;
- /* Variables on list (long form only). */
- struct variable **v = NULL;
- int nv;
-
- lex_match_id ("VECTOR");
-
cp = vecnames = xmalloc (256);
endp = &vecnames[256];
do
goto fail;
}
- if (find_vector (tokid))
+ if (dict_lookup_vector (default_dict, tokid))
{
msg (SE, _("There is already a vector with name %s."), tokid);
goto fail;
if (lex_match ('='))
{
/* Long form. */
+ struct variable **v;
+ int nv;
if (strchr (vecnames, '\0')[1])
{
goto fail;
}
- if (!parse_variables (NULL, &v, &nv, PV_SAME_TYPE | PV_DUPLICATE))
+ if (!parse_variables (default_dict, &v, &nv,
+ PV_SAME_TYPE | PV_DUPLICATE))
goto fail;
- vec = xrealloc (vec, sizeof *vec * (nvec + 1));
- vec[nvec].index = nvec;
- strcpy (vec[nvec].name, vecnames);
- vec[nvec].v = v;
- vec[nvec].nv = nv;
- nvec++;
- v = NULL; /* prevent block from being freed on error */
+ dict_create_vector (default_dict, vecnames, v, nv);
+ free (v);
}
else if (lex_match ('('))
{
int ndig;
/* Name of an individual variable to be created. */
- char name[9];
+ char name[SHORT_NAME_LEN + 1];
+
+ /* Vector variables. */
+ struct variable **v;
+ int nv;
if (!lex_force_int ())
return CMD_FAILURE;
if (!lex_force_match (')'))
goto fail;
- /* First check that all the generated variable names are 8
+ /* First check that all the generated variable names are SHORT_NAME_LEN
characters or shorter. */
ndig = intlog10 (nv);
for (cp = vecnames; *cp;)
{
int len = strlen (cp);
- if (len + ndig > 8)
+ if (len + ndig > SHORT_NAME_LEN)
{
msg (SE, _("%s%d is too long for a variable name."), cp, nv);
goto fail;
for (i = 0; i < nv; i++)
{
sprintf (name, "%s%d", cp, i + 1);
- if (is_varname (name))
+ if (dict_lookup_var (default_dict, name))
{
msg (SE, _("There is already a variable named %s."), name);
goto fail;
}
/* Finally create the variables and vectors. */
- vec = xrealloc (vec, sizeof *vec * (nvec + nv));
+ v = xmalloc (nv * sizeof *v);
for (cp = vecnames; *cp;)
{
- vec[nvec].index = nvec;
- strcpy (vec[nvec].name, cp);
- vec[nvec].v = xmalloc (sizeof *vec[nvec].v * nv);
- vec[nvec].nv = nv;
for (i = 0; i < nv; i++)
{
sprintf (name, "%s%d", cp, i + 1);
- vec[nvec].v[i] = force_create_variable (&default_dict, name,
- NUMERIC, 0);
- envector (vec[nvec].v[i]);
+ v[i] = dict_create_var_assert (default_dict, name, 0);
}
- nvec++;
+ if (!dict_create_vector (default_dict, cp, v, nv))
+ assert (0);
cp += strlen (cp) + 1;
}
+ free (v);
}
else
{
fail:
free (vecnames);
- free (v);
return CMD_PART_SUCCESS_MAYBE;
}
-
-/* Returns a pointer to the vector with name NAME, or NULL on
- failure. */
-struct vector *
-find_vector (const char *name)
-{
- int i;
-
- for (i = 0; i < nvec; i++)
- if (!strcmp (vec[i].name, name))
- return &vec[i];
- return NULL;
-}