Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / language / dictionary / variable-display.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <data/procedure.h>
23 #include <data/variable.h>
24 #include <language/command.h>
25 #include <language/lexer/lexer.h>
26 #include <language/lexer/variable-parser.h>
27 #include <libpspp/alloc.h>
28 #include <libpspp/message.h>
29 #include <libpspp/str.h>
30
31 /* Set variables' alignment
32    This is the alignment for GUI display only.
33    It affects nothing but GUIs
34 */
35 int
36 cmd_variable_alignment (struct lexer *lexer, struct dataset *ds)
37 {
38   do
39     {
40       struct variable **v;
41       size_t nv;
42
43       size_t i;
44       enum alignment align;
45
46       if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
47         return CMD_FAILURE;
48
49       if ( lex_force_match (lexer, '(') )
50         {
51           if ( lex_match_id (lexer, "LEFT"))
52             align = ALIGN_LEFT;
53           else if ( lex_match_id (lexer, "RIGHT"))
54             align = ALIGN_RIGHT;
55           else if ( lex_match_id (lexer, "CENTER"))
56             align = ALIGN_CENTRE;
57           else
58             {
59               free (v);
60               return CMD_FAILURE;
61             }
62
63           lex_force_match (lexer, ')');
64         }
65       else
66         {
67           free (v);
68           return CMD_FAILURE;
69         }
70
71       for( i = 0 ; i < nv ; ++i )
72         var_set_alignment (v[i], align);
73
74       while (lex_token (lexer) == '/')
75         lex_get (lexer);
76       free (v);
77
78     }
79   while (lex_token (lexer) != '.');
80   return CMD_SUCCESS;
81 }
82
83 /* Set variables' display width.
84    This is the width for GUI display only.
85    It affects nothing but GUIs
86 */
87 int
88 cmd_variable_width (struct lexer *lexer, struct dataset *ds)
89 {
90   do
91     {
92       struct variable **v;
93       size_t nv;
94       size_t i;
95
96       if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
97         return CMD_FAILURE;
98
99       if ( lex_force_match (lexer, '(') )
100         {
101           if ( lex_force_int (lexer))
102             lex_get (lexer);
103           else
104             return CMD_FAILURE;
105           lex_force_match (lexer, ')');
106         }
107
108       for( i = 0 ; i < nv ; ++i )
109         var_set_display_width (v[i], lex_integer (lexer));
110
111       while (lex_token (lexer) == '/')
112         lex_get (lexer);
113       free (v);
114
115     }
116   while (lex_token (lexer) != '.');
117   return CMD_SUCCESS;
118 }
119
120 /* Set variables' measurement level */
121 int
122 cmd_variable_level (struct lexer *lexer, struct dataset *ds)
123 {
124   do
125     {
126       struct variable **v;
127       size_t nv;
128       enum measure level;
129       size_t i;
130
131       if (!parse_variables (lexer, dataset_dict (ds), &v, &nv, PV_NONE))
132         return CMD_FAILURE;
133
134       if ( lex_force_match (lexer, '(') )
135         {
136           if ( lex_match_id (lexer, "SCALE"))
137             level = MEASURE_SCALE;
138           else if ( lex_match_id (lexer, "ORDINAL"))
139             level = MEASURE_ORDINAL;
140           else if ( lex_match_id (lexer, "NOMINAL"))
141             level = MEASURE_NOMINAL;
142           else
143             {
144               free (v);
145               return CMD_FAILURE;
146             }
147
148           lex_force_match (lexer, ')');
149         }
150       else
151         {
152           free (v);
153           return CMD_FAILURE;
154         }
155
156       for( i = 0 ; i < nv ; ++i )
157         var_set_measure (v[i], level);
158
159
160       while (lex_token (lexer) == '/')
161         lex_get (lexer);
162       free (v);
163
164     }
165   while (lex_token (lexer) != '.');
166   return CMD_SUCCESS;
167 }