X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvector.c;h=87046ad42b8127853f7a67b75bb2f07dc4583121;hb=9ade26c8349b4434008c46cf09bc7473ec743972;hp=cc4c96f0ab8744538fafb4e4e35d9dd1e99bf832;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp-builds.git
diff --git a/src/data/vector.c b/src/data/vector.c
index cc4c96f0..87046ad4 100644
--- a/src/data/vector.c
+++ b/src/data/vector.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2010, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,19 +15,22 @@
along with this program. If not, see . */
#include
-#include "vector.h"
-#include "dictionary.h"
+#include "data/vector.h"
-#include
-#include
+#include
-#include "xalloc.h"
+#include "data/dictionary.h"
+#include "data/identifier.h"
+#include "libpspp/assertion.h"
+#include "libpspp/str.h"
+
+#include "gl/xalloc.h"
/* Vector of variables. */
struct vector
{
- char name[LONG_NAME_LEN + 1]; /* Name. */
+ char *name; /* Name. */
struct variable **vars; /* Set of variables. */
size_t var_cnt; /* Number of variables. */
};
@@ -44,19 +47,18 @@ check_widths (const struct vector *vector)
assert (width == var_get_width (vector->vars[i]));
}
-/* Creates and returns a new vector with the given NAME
+/* Creates and returns a new vector with the given UTF-8 encoded NAME
that contains the VAR_CNT variables in VARS.
All variables in VARS must have the same type and width. */
struct vector *
-vector_create (const char *name,
- struct variable **vars, size_t var_cnt)
+vector_create (const char *name, struct variable **vars, size_t var_cnt)
{
struct vector *vector = xmalloc (sizeof *vector);
assert (var_cnt > 0);
- assert (var_is_plausible_name (name, false));
- str_copy_trunc (vector->name, sizeof vector->name, name);
+ assert (id_is_plausible (name, false));
+ vector->name = xstrdup (name);
vector->vars = xmemdup (vars, var_cnt * sizeof *vector->vars);
vector->var_cnt = var_cnt;
check_widths (vector);
@@ -77,8 +79,7 @@ vector_clone (const struct vector *old,
struct vector *new = xmalloc (sizeof *new);
size_t i;
- strcpy (new->name, old->name);
-
+ new->name = xstrdup (old->name);
new->vars = xnmalloc (old->var_cnt, sizeof *new->vars);
new->var_cnt = old->var_cnt;
for (i = 0; i < new->var_cnt; i++)
@@ -96,11 +97,12 @@ vector_clone (const struct vector *old,
void
vector_destroy (struct vector *vector)
{
+ free (vector->name);
free (vector->vars);
free (vector);
}
-/* Returns VECTOR's name. */
+/* Returns VECTOR's name, as a UTF-8 encoded string. */
const char *
vector_get_name (const struct vector *vector)
{
@@ -108,7 +110,7 @@ vector_get_name (const struct vector *vector)
}
/* Returns the type of the variables in VECTOR. */
-enum var_type vector_get_type (const struct vector *vector)
+enum val_type vector_get_type (const struct vector *vector)
{
return var_get_type (vector->vars[0]);
}