From 00fcd2a1b8462ef2ed26d32382f95e494cce088b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 14 Aug 2016 09:28:23 -0700 Subject: [PATCH] VECTOR: Support creating string variables also. Bug #48763. --- NEWS | 6 ++++-- doc/variables.texi | 22 ++++++++++++---------- src/language/dictionary/vector.c | 8 ++++---- tests/language/dictionary/vector.at | 6 +++++- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 883590541..8959f7ec5 100644 --- a/NEWS +++ b/NEWS @@ -6,9 +6,11 @@ Please send PSPP bug reports to bug-gnu-pspp@gnu.org. Changes from 0.10.2 to 0.10.4: - * Gtk+3.14.5 or later must now be used when building. + * Gtk+3.14.5 or later must now be used when building. - * The AUTORECODE command now accepts an optional / before INTO. + * The AUTORECODE command now accepts an optional / before INTO. + + * The short form of the VECTOR command can now create string variables. Changes from 0.10.1 to 0.10.2: diff --git a/doc/variables.texi b/doc/variables.texi index 6a6a77b7f..cc13e784d 100644 --- a/doc/variables.texi +++ b/doc/variables.texi @@ -782,18 +782,20 @@ were consecutive members of an array with a vector(index) notation. To make a vector out of a set of existing variables, specify a name for the vector followed by an equals sign (@samp{=}) and the variables -to put in the vector. All the variables in the vector must be the same -type. String variables in a vector must all have the same width. +to put in the vector. The variables must be all numeric or all +string, and string variables must have the same width. To make a vector and create variables at the same time, specify one or -more vector names followed by a count in parentheses. This will cause -variables named @code{@var{vec}1} through @code{@var{vec}@var{count}} -to be created as numeric variables. By default, the new variables -have print and write format F8.2, but an alternate format may be -specified inside the parentheses before or after the count and -separated from it by white space or a comma. Variable names including -numeric suffixes may not exceed 64 characters in length, and none of -the variables may exist prior to @cmd{VECTOR}. +more vector names followed by a count in parentheses. This will +create variables named @code{@var{vec}1} through +@code{@var{vec}@var{count}}. By default, the new variables are +numeric with format F8.2, but an alternate format may be specified +inside the parentheses before or after the count and separated from it +by white space or a comma. With a string format such as A8, the +variables will be string variables; with a numeric format, they will +be numeric. Variable names including the suffixes may not exceed 64 +characters in length, and none of the variables may exist prior to +@cmd{VECTOR}. Vectors created with @cmd{VECTOR} disappear after any procedure or procedure-like command is executed. The variables contained in the diff --git a/src/language/dictionary/vector.c b/src/language/dictionary/vector.c index 512ec3c2b..6560288c4 100644 --- a/src/language/dictionary/vector.c +++ b/src/language/dictionary/vector.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2010, 2011, 2012, 2016 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 @@ -136,8 +136,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) { seen_format = true; if (!parse_format_specifier (lexer, &format) - || !fmt_check_output (&format) - || !fmt_check_type_compat (&format, VAL_NUMERIC)) + || !fmt_check_output (&format)) goto fail; } else @@ -184,7 +183,8 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) for (j = 0; j < var_cnt; j++) { char *name = xasprintf ("%s%d", vectors[i], j + 1); - vars[j] = dict_create_var_assert (dict, name, 0); + vars[j] = dict_create_var_assert (dict, name, + fmt_var_width (&format)); var_set_both_formats (vars[j], &format); free (name); } diff --git a/tests/language/dictionary/vector.at b/tests/language/dictionary/vector.at index e7a2cdd10..36aed7a6c 100644 --- a/tests/language/dictionary/vector.at +++ b/tests/language/dictionary/vector.at @@ -19,7 +19,8 @@ AT_CLEANUP AT_SETUP([VECTOR short form with format specification]) AT_DATA([vector.sps], [dnl data list notable/x 1. -vector #vec(4, comma10.2). +vector #vec(4, comma10.2) + /#svec(3, a8). display vector. ]) AT_CHECK([pspp -o pspp.csv vector.sps]) @@ -29,6 +30,9 @@ Vector,Position,Variable,Print Format ,2,#vec2,COMMA10.2 ,3,#vec3,COMMA10.2 ,4,#vec4,COMMA10.2 +#svec,1,#svec1,A8 +,2,#svec2,A8 +,3,#svec3,A8 ]) AT_CLEANUP -- 2.11.4.GIT