Implemented long variable names a la spss V12.
[pspp-builds.git] / src / var-display.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by John Darrington <john@darrington.wattle.id.au>
4
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.
9
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.
14
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
18    02111-1307, USA. */
19
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include "alloc.h"
24 #include "command.h"
25 #include "error.h"
26 #include "lexer.h"
27 #include "str.h"
28 #include "var.h"
29
30 #include "debug-print.h"
31
32 /* Set variables' alignment
33    This is the alignment for GUI display only.
34    It affects nothing but GUIs
35 */
36 int
37 cmd_variable_alignment (void)
38 {
39   do
40     {
41       struct variable **v;
42       int nv;
43
44       int i;
45       enum alignment align;
46
47
48       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
49         return CMD_PART_SUCCESS_MAYBE;
50
51       if ( lex_force_match('(') ) 
52         {
53           if ( lex_match_id("LEFT"))
54             align = ALIGN_LEFT;
55           else if ( lex_match_id("RIGHT"))
56             align = ALIGN_RIGHT;
57           else if ( lex_match_id("CENTER"))
58             align = ALIGN_CENTRE;
59           else
60             return CMD_FAILURE;
61
62           lex_force_match(')');
63         }
64
65       for( i = 0 ; i < nv ; ++i ) 
66         v[i]->alignment = align;
67
68
69       while (token == '/')
70         lex_get ();
71       free (v);
72
73     }
74   while (token != '.');
75   return CMD_SUCCESS;
76 }
77
78 /* Set variables' display width.
79    This is the width for GUI display only.
80    It affects nothing but GUIs
81 */
82 int
83 cmd_variable_width (void)
84 {
85   do
86     {
87       struct variable **v;
88       int nv;
89       int i;
90
91       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
92         return CMD_PART_SUCCESS_MAYBE;
93
94       if ( lex_force_match('(') ) 
95         {
96           if ( lex_force_int()) 
97             lex_get();
98           else
99             return CMD_FAILURE;
100           lex_force_match(')');
101         }
102
103       for( i = 0 ; i < nv ; ++i ) 
104           v[i]->display_width = tokval;
105
106       while (token == '/')
107         lex_get ();
108       free (v);
109
110     }
111   while (token != '.');
112   return CMD_SUCCESS;
113 }
114
115 /* Set variables' measurement level */
116 int
117 cmd_variable_level (void)
118 {
119   do
120     {
121       struct variable **v;
122       int nv;
123       enum measure level;
124       int i;
125
126       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
127         return CMD_PART_SUCCESS_MAYBE;
128
129       if ( lex_force_match('(') ) 
130         {
131           if ( lex_match_id("SCALE"))
132             level = MEASURE_SCALE;
133           else if ( lex_match_id("ORDINAL"))
134             level = MEASURE_ORDINAL;
135           else if ( lex_match_id("NOMINAL"))
136             level = MEASURE_NOMINAL;
137           else
138             return CMD_FAILURE;
139
140           lex_force_match(')');
141         }
142
143       for( i = 0 ; i < nv ; ++i ) 
144         v[i]->measure = level ;
145
146
147       while (token == '/')
148         lex_get ();
149       free (v);
150
151     }
152   while (token != '.');
153   return CMD_SUCCESS;
154 }