2632ce9e8975a5d5798c53f20a33b390831271e6
[pspp-builds.git] / src / language / dictionary / variable-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., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <libpspp/alloc.h>
24 #include <language/command.h>
25 #include <libpspp/message.h>
26 #include <language/lexer/lexer.h>
27 #include <libpspp/str.h>
28 #include <data/variable.h>
29
30 /* Set variables' alignment
31    This is the alignment for GUI display only.
32    It affects nothing but GUIs
33 */
34 int
35 cmd_variable_alignment (void)
36 {
37   do
38     {
39       struct variable **v;
40       size_t nv;
41
42       size_t i;
43       enum alignment align;
44
45
46       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
47         return CMD_FAILURE;
48
49       if ( lex_force_match('(') ) 
50         {
51           if ( lex_match_id("LEFT"))
52             align = ALIGN_LEFT;
53           else if ( lex_match_id("RIGHT"))
54             align = ALIGN_RIGHT;
55           else if ( lex_match_id("CENTER"))
56             align = ALIGN_CENTRE;
57           else 
58             {
59               free (v);
60               return CMD_FAILURE; 
61             }
62
63           lex_force_match(')');
64         }
65       else 
66         {
67           free (v);
68           return CMD_FAILURE; 
69         }
70
71       for( i = 0 ; i < nv ; ++i ) 
72         v[i]->alignment = align;
73
74
75       while (token == '/')
76         lex_get ();
77       free (v);
78
79     }
80   while (token != '.');
81   return CMD_SUCCESS;
82 }
83
84 /* Set variables' display width.
85    This is the width for GUI display only.
86    It affects nothing but GUIs
87 */
88 int
89 cmd_variable_width (void)
90 {
91   do
92     {
93       struct variable **v;
94       size_t nv;
95       size_t i;
96
97       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
98         return CMD_FAILURE;
99
100       if ( lex_force_match('(') ) 
101         {
102           if ( lex_force_int()) 
103             lex_get();
104           else
105             return CMD_FAILURE;
106           lex_force_match(')');
107         }
108
109       for( i = 0 ; i < nv ; ++i ) 
110           v[i]->display_width = tokval;
111
112       while (token == '/')
113         lex_get ();
114       free (v);
115
116     }
117   while (token != '.');
118   return CMD_SUCCESS;
119 }
120
121 /* Set variables' measurement level */
122 int
123 cmd_variable_level (void)
124 {
125   do
126     {
127       struct variable **v;
128       size_t nv;
129       enum measure level;
130       size_t i;
131
132       if (!parse_variables (default_dict, &v, &nv, PV_NONE))
133         return CMD_FAILURE;
134
135       if ( lex_force_match('(') ) 
136         {
137           if ( lex_match_id("SCALE"))
138             level = MEASURE_SCALE;
139           else if ( lex_match_id("ORDINAL"))
140             level = MEASURE_ORDINAL;
141           else if ( lex_match_id("NOMINAL"))
142             level = MEASURE_NOMINAL;
143           else 
144             {
145               free (v);
146               return CMD_FAILURE; 
147             }
148
149           lex_force_match(')');
150         }
151       else
152         {
153           free (v);
154           return CMD_FAILURE; 
155         }
156       
157       for( i = 0 ; i < nv ; ++i ) 
158         v[i]->measure = level ;
159
160
161       while (token == '/')
162         lex_get ();
163       free (v);
164
165     }
166   while (token != '.');
167   return CMD_SUCCESS;
168 }