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