X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvector.c;h=fc7a2dd317f6b4d04a1a4153351246228f76bb91;hb=9987b8c21548797582808e6cf8c2551876c3e5a1;hp=acaa07870a5c8bd96e7818a03f72c8f39ad4c132;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/vector.c b/src/vector.c index acaa07870a..fc7a2dd317 100644 --- a/src/vector.c +++ b/src/vector.c @@ -14,27 +14,23 @@ 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 -#include +#include "error.h" #include #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; +#include "gettext.h" +#define _(msgid) gettext (msgid) int cmd_vector (void) @@ -51,12 +47,6 @@ 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 @@ -75,13 +65,13 @@ cmd_vector (void) } for (cp2 = cp; cp2 < cp; cp2 += strlen (cp)) - if (!strcmp (cp2, tokid)) + if (!strcasecmp (cp2, tokid)) { msg (SE, _("Vector name %s is given twice."), tokid); 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; @@ -98,26 +88,24 @@ cmd_vector (void) if (lex_match ('=')) { /* Long form. */ + struct variable **v; + size_t nv; if (strchr (vecnames, '\0')[1]) { /* There's more than one vector name. */ msg (SE, _("A slash must be used to separate each vector " - "specification when using the long form. Commands " - "such as VECTOR A,B=Q1 TO Q20 are not supported.")); + "specification when using the long form. Commands " + "such as VECTOR A,B=Q1 TO Q20 are not supported.")); 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 ('(')) { @@ -128,7 +116,11 @@ cmd_vector (void) 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; @@ -142,13 +134,13 @@ cmd_vector (void) if (!lex_force_match (')')) goto fail; - /* First check that all the generated variable names are 8 - characters or shorter. */ + /* First check that all the generated variable names + are LONG_NAME_LEN characters or shorter. */ ndig = intlog10 (nv); for (cp = vecnames; *cp;) { int len = strlen (cp); - if (len + ndig > 8) + if (len + ndig > LONG_NAME_LEN) { msg (SE, _("%s%d is too long for a variable name."), cp, nv); goto fail; @@ -162,9 +154,10 @@ cmd_vector (void) 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); + msg (SE, _("There is already a variable named %s."), + name); goto fail; } } @@ -172,23 +165,19 @@ cmd_vector (void) } /* 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 { @@ -212,19 +201,5 @@ cmd_vector (void) 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; -}