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