1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 /* Just to be different, points to a set of null terminated strings
36 containing the names of the vectors to be created. The list
37 itself is terminated by a empty string. So a list of three
38 elements, A B C, would look like this: "A\0B\0C\0\0". */
41 /* vecnames iterators. */
44 /* Maximum allocated position for vecnames, plus one position. */
47 lex_match_id ("VECTOR");
49 cp = vecnames = xmalloc (256);
50 endp = &vecnames[256];
53 /* Get the name(s) of the new vector(s). */
60 char *old_vecnames = vecnames;
61 vecnames = xrealloc (vecnames, endp - vecnames + 256);
62 cp = (cp - old_vecnames) + vecnames;
63 endp = (endp - old_vecnames) + vecnames + 256;
66 for (cp2 = cp; cp2 < cp; cp2 += strlen (cp))
67 if (!strcmp (cp2, tokid))
69 msg (SE, _("Vector name %s is given twice."), tokid);
73 if (dict_lookup_vector (default_dict, tokid))
75 msg (SE, _("There is already a vector with name %s."), tokid);
79 cp = stpcpy (cp, tokid) + 1;
85 /* Now that we have the names it's time to check for the short
93 if (strchr (vecnames, '\0')[1])
95 /* There's more than one vector name. */
96 msg (SE, _("A slash must be used to separate each vector "
97 "specification when using the long form. Commands "
98 "such as VECTOR A,B=Q1 TO Q20 are not supported."));
102 if (!parse_variables (default_dict, &v, &nv,
103 PV_SAME_TYPE | PV_DUPLICATE))
106 dict_create_vector (default_dict, vecnames, v, nv);
109 else if (lex_match ('('))
113 /* Maximum number of digits in a number to add to the base
117 /* Name of an individual variable to be created. */
120 /* Vector variables. */
124 if (!lex_force_int ())
130 msg (SE, _("Vectors must have at least one element."));
133 if (!lex_force_match (')'))
136 /* First check that all the generated variable names are 8
137 characters or shorter. */
138 ndig = intlog10 (nv);
139 for (cp = vecnames; *cp;)
141 int len = strlen (cp);
144 msg (SE, _("%s%d is too long for a variable name."), cp, nv);
150 /* Next check that none of the variables exist. */
151 for (cp = vecnames; *cp;)
153 for (i = 0; i < nv; i++)
155 sprintf (name, "%s%d", cp, i + 1);
156 if (dict_lookup_var (default_dict, name))
158 msg (SE, _("There is already a variable named %s."), name);
162 cp += strlen (cp) + 1;
165 /* Finally create the variables and vectors. */
166 v = xmalloc (nv * sizeof *v);
167 for (cp = vecnames; *cp;)
169 for (i = 0; i < nv; i++)
171 sprintf (name, "%s%d", cp, i + 1);
172 v[i] = dict_create_var (default_dict, name, 0);
173 assert (v[i] != NULL);
176 if (!dict_create_vector (default_dict, cp, v, nv))
178 cp += strlen (cp) + 1;
184 msg (SE, _("The syntax for this command does not match "
185 "the expected syntax for either the long form "
186 "or the short form of VECTOR."));
193 while (lex_match ('/'));
197 lex_error (_("expecting end of command"));
204 return CMD_PART_SUCCESS_MAYBE;