#include "xalloc.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
/* Set variables' alignment
This is the alignment for GUI display only.
It affects nothing but GUIs
do
{
struct variable **v;
+ long int width;
size_t nv;
size_t i;
if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_FAILURE;
- if ( lex_force_match (lexer, '(') )
- {
- if ( lex_force_int (lexer))
- lex_get (lexer);
- else
- return CMD_FAILURE;
- lex_force_match (lexer, ')');
- }
+ if (!lex_force_match (lexer, '(') || !lex_force_int (lexer))
+ {
+ free (v);
+ return CMD_FAILURE;
+ }
+ width = lex_integer (lexer);
+ lex_get (lexer);
+ if (!lex_force_match (lexer, ')'))
+ {
+ free (v);
+ return CMD_FAILURE;
+ }
+
+ if (width < 0)
+ {
+ msg (SE, _("Variable display width must be a positive integer."));
+ free (v);
+ return CMD_FAILURE;
+ }
+ width = MIN (width, 2 * MAX_STRING);
for( i = 0 ; i < nv ; ++i )
- var_set_display_width (v[i], lex_integer (lexer));
+ var_set_display_width (v[i], width);
while (lex_token (lexer) == '/')
lex_get (lexer);
--- /dev/null
+#!/bin/sh
+
+# This program tests variable display attribute commands: VARIABLE
+# ALIGNMENT, VARIABLE WIDTH, VARIABLE LEVEL.
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+# ensure that top_builddir are absolute
+if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
+if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
+top_builddir=`cd $top_builddir; pwd`
+PSPP=$top_builddir/src/ui/terminal/pspp
+
+# ensure that top_srcdir is absolute
+top_srcdir=`cd $top_srcdir; pwd`
+
+STAT_CONFIG_PATH=$top_srcdir/config
+export STAT_CONFIG_PATH
+
+
+cleanup()
+{
+ cd /
+ rm -rf $TEMPDIR
+}
+
+
+fail()
+{
+ echo $activity
+ echo FAILED
+ cleanup;
+ exit 1;
+}
+
+
+no_result()
+{
+ echo $activity
+ echo NO RESULT;
+ cleanup;
+ exit 2;
+}
+
+pass()
+{
+ cleanup;
+ exit 0;
+}
+
+mkdir -p $TEMPDIR
+
+cd $TEMPDIR
+
+# Create command file.
+activity="create program"
+cat > $TESTFILE << EOF
+data list free /x y z.
+variable alignment x (left)/y (right)/z (center).
+variable width x (10)/y (12)/z (14).
+variable level x (scale)/y (ordinal)/z (nominal).
+display dictionary.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$SUPERVISOR $PSPP --testing-mode $TESTFILE
+if [ $? -ne 0 ] ; then fail ; fi
+
+activity="compare output"
+perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
+diff -b $TEMPDIR/pspp.list - << EOF
+1.1 DISPLAY.
++--------+-------------------------------------------+--------+
+|Variable|Description |Position|
+#========#===========================================#========#
+|x |Format: F8.2 | 1|
+| |Measure: Scale | |
+| |Display Alignment: Left | |
+| |Display Width: 10 | |
++--------+-------------------------------------------+--------+
+|y |Format: F8.2 | 2|
+| |Measure: Ordinal | |
+| |Display Alignment: Right | |
+| |Display Width: 12 | |
++--------+-------------------------------------------+--------+
+|z |Format: F8.2 | 3|
+| |Measure: Nominal | |
+| |Display Alignment: Center | |
+| |Display Width: 14 | |
++--------+-------------------------------------------+--------+
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;