Changed the default value od SCOMPRESS to true.
[pspp] / src / data / settings.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
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 "settings.h"
22 #include <assert.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include "format.h"
26 #include "value.h"
27 #include "xalloc.h"
28
29 static int viewlength = 24;
30 static int viewwidth = 79;
31 static bool long_view = false;
32
33 static bool safer_mode = false;
34
35 static char decimal = '.';
36 static char grouping = ',';
37
38 static bool echo = false;
39 static bool include = true;
40
41 static int epoch = -1;
42
43 static bool errorbreak = false;
44
45 static bool scompress = true;
46
47 static bool undefined = true;
48 static double blanks = SYSMIS;
49
50 static int mxwarns = 100;
51 static int mxerrs = 100;
52
53 static bool printback = true;
54 static bool mprint = true;
55
56 static int mxloops = 1;
57
58 static bool nulline = true;
59
60 static char endcmd = '.';
61
62 static size_t workspace = 4L * 1024 * 1024;
63
64 static struct fmt_spec default_format = {FMT_F, 8, 2};
65
66 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
67 static struct custom_currency cc[CC_CNT] = 
68   {
69     CC_INITIALIZER,
70     CC_INITIALIZER,
71     CC_INITIALIZER,
72     CC_INITIALIZER,
73     CC_INITIALIZER,
74   };
75
76 static bool testing_mode = false;
77
78 static int global_algorithm = ENHANCED;
79 static int cmd_algorithm = ENHANCED;
80 static int *algorithm = &global_algorithm;
81
82 static int syntax = ENHANCED;
83
84 static void init_viewport (void);
85
86 void
87 settings_init (void)
88 {
89   init_viewport ();
90 }
91
92 void
93 settings_done (void)
94 {
95 }
96
97 /* Screen length in lines. */
98 int
99 get_viewlength (void)
100 {
101   return viewlength;
102 }
103
104 /* Sets the view length. */
105 void
106 set_viewlength (int viewlength_) 
107 {
108   viewlength = viewlength_;
109 }
110
111 /* Set view width to a very long value, and prevent it from ever
112    changing. */
113 void
114 force_long_view (void)
115 {
116   long_view = true;
117   viewwidth = 9999;
118 }
119
120 /* Screen width. */
121 int
122 get_viewwidth(void)
123 {
124   return viewwidth;
125 }
126
127 /* Sets the screen width. */
128 void
129 set_viewwidth (int viewwidth_) 
130 {
131   viewwidth = viewwidth_;
132 }
133
134 #if HAVE_LIBTERMCAP
135 static void
136 get_termcap_viewport (void)
137 {
138   char term_buffer[16384];
139   if (getenv ("TERM") == NULL)
140     return;
141   else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
142     {
143       msg (IE, _("Could not access definition for terminal `%s'."), termtype);
144       return;
145     }
146
147   if (tgetnum ("li") > 0)
148     viewlength = tgetnum ("li");
149
150   if (tgetnum ("co") > 1)
151     viewwidth = tgetnum ("co") - 1;
152 }
153 #endif /* HAVE_LIBTERMCAP */
154
155 static void 
156 init_viewport (void)
157 {
158   if (long_view)
159     return;
160   
161   viewwidth = viewlength = -1;
162
163 #if HAVE_LIBTERMCAP
164   get_termcap_viewport ();
165 #endif /* HAVE_LIBTERMCAP */
166
167   if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
168     viewwidth = atoi (getenv ("COLUMNS"));
169   if (viewlength < 0 && getenv ("LINES") != NULL)
170     viewlength = atoi (getenv ("LINES"));
171
172   if (viewwidth < 0)
173     viewwidth = 79;
174   if (viewlength < 0)
175     viewlength = 24;
176 }
177
178 /* Whether PSPP can erase and overwrite files. */
179 bool
180 get_safer_mode (void)
181 {
182   return safer_mode;
183 }
184
185 /* Set safer mode. */
186 void
187 set_safer_mode (void)
188 {
189   safer_mode = true;
190 }
191
192 /* The character used for a decimal point: ',' or '.'.  Only
193    respected for data input and output. */
194 char 
195 get_decimal (void)
196 {
197   return decimal;
198 }
199
200 /* Sets the character used for a decimal point, which must be
201    either ',' or '.'. */
202 void
203 set_decimal (char decimal_) 
204 {
205   assert (decimal_ == '.' || decimal_ == ',');
206   decimal = decimal_;
207 }
208
209 /* The character used for grouping in numbers: '.' or ','; the
210    opposite of set_decimal.  Only used in COMMA data input and
211    output. */
212 char
213 get_grouping (void)
214 {
215   return grouping;
216 }
217
218 /* Sets the character used for grouping, which must be either ','
219    or '.'. */
220 void
221 set_grouping (char grouping_) 
222 {
223   assert (grouping_ == '.' || grouping_ == ',');
224   grouping = grouping_;
225 }
226  
227 /* Echo commands to the listing file/printer? */
228 bool
229 get_echo (void)
230 {
231   return echo;
232 }
233
234 /* Set echo. */
235 void
236 set_echo (bool echo_) 
237 {
238   echo = echo_;
239 }
240
241 /* If echo is on, whether commands from include files are echoed. */
242 bool
243 get_include (void)
244 {
245   return include;
246 }
247
248 /* Set include file echo. */
249 void
250 set_include (bool include_) 
251 {
252   include = include_;
253 }
254
255 /* What year to use as the start of the epoch. */
256 int
257 get_epoch (void) 
258 {
259   if (epoch < 0) 
260     {
261       time_t t = time (0);
262       struct tm *tm = localtime (&t);
263       epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
264     }
265
266   return epoch;
267 }
268
269 /* Sets the year that starts the epoch. */
270 void
271 set_epoch (int epoch_) 
272 {
273   epoch = epoch_;
274 }
275
276 /* Does an error stop execution? */
277 bool
278 get_errorbreak (void)
279 {
280   return errorbreak;
281 }
282
283 /* Sets whether an error stops execution. */
284 void
285 set_errorbreak (bool errorbreak_) 
286 {
287   errorbreak = errorbreak_;
288 }
289
290 /* Compress system files by default? */
291 bool 
292 get_scompression (void)
293 {
294   return scompress;
295 }
296
297 /* Set system file default compression. */
298 void
299 set_scompression (bool scompress_) 
300 {
301   scompress = scompress_;
302 }
303
304 /* Whether to warn on undefined values in numeric data. */
305 bool
306 get_undefined (void)
307 {
308   return undefined;
309 }
310
311 /* Set whether to warn on undefined values. */
312 void
313 set_undefined (bool undefined_) 
314 {
315   undefined = undefined_;
316 }
317
318 /* The value that blank numeric fields are set to when read in. */
319 double
320 get_blanks (void)
321 {
322   return blanks;
323 }
324
325 /* Set the value that blank numeric fields are set to when read
326    in. */
327 void
328 set_blanks (double blanks_) 
329 {
330   blanks = blanks_;
331 }
332
333 /* Maximum number of warnings + errors. */
334 int
335 get_mxwarns (void)
336 {  
337   return mxwarns;
338 }
339
340 /* Sets maximum number of warnings + errors. */
341 void
342 set_mxwarns (int mxwarns_) 
343 {
344   mxwarns = mxwarns_;
345 }
346
347 /* Maximum number of errors. */
348 int
349 get_mxerrs (void)
350 {
351   return mxerrs;
352 }
353
354 /* Sets maximum number of errors. */
355 void
356 set_mxerrs (int mxerrs_) 
357 {
358   mxerrs = mxerrs_;
359 }
360
361 /* Whether commands are written to the display. */
362 bool
363 get_printback (void)
364 {
365   return printback;
366 }
367
368 /* Sets whether commands are written to the display. */
369 void
370 set_printback (bool printback_) 
371 {
372   printback = printback_;
373 }
374
375 /* Independent of get_printback, controls whether the commands
376    generated by macro invocations are displayed. */
377 bool
378 get_mprint (void)
379 {
380   return mprint;
381 }
382
383 /* Sets whether the commands generated by macro invocations are
384    displayed. */
385 void
386 set_mprint (bool mprint_) 
387 {
388   mprint = mprint_;
389 }
390
391 /* Implied limit of unbounded loop. */
392 int
393 get_mxloops (void)
394 {
395   return mxloops;
396 }
397
398 /* Set implied limit of unbounded loop. */
399 void
400 set_mxloops (int mxloops_) 
401 {
402   mxloops = mxloops_;
403 }
404
405 /* Whether a blank line is a command terminator. */
406 bool
407 get_nulline (void)
408 {
409   return nulline;
410 }
411
412 /* Set whether a blank line is a command terminator. */
413 void
414 set_nulline (bool nulline_)
415 {
416   nulline = nulline_;
417 }
418
419 /* The character used to terminate commands. */
420 char
421 get_endcmd (void)
422 {
423   return endcmd;
424 }
425
426 /* Set the character used to terminate commands. */
427 void
428 set_endcmd (char endcmd_) 
429 {
430   endcmd = endcmd_;
431 }
432
433 /* Approximate maximum amount of memory to use for cases, in
434    bytes. */
435 size_t
436 get_workspace (void)
437 {
438   return workspace;
439 }
440
441 /* Set approximate maximum amount of memory to use for cases, in
442    bytes. */
443
444 void
445 set_workspace (size_t workspace_) 
446 {
447   workspace = workspace_;
448 }
449
450 /* Default format for variables created by transformations and by
451    DATA LIST {FREE,LIST}. */
452 const struct fmt_spec *
453 get_format (void)
454
455   return &default_format;
456 }
457
458 /* Set default format for variables created by transformations
459    and by DATA LIST {FREE,LIST}. */
460 void
461 set_format (const struct fmt_spec *default_format_) 
462 {
463   default_format = *default_format_;
464 }
465
466 /* Gets the custom currency specification with the given IDX. */
467 const struct custom_currency *
468 get_cc (int idx)
469 {
470   assert (idx >= 0 && idx < CC_CNT);
471   return &cc[idx];
472 }
473
474 /* Gets custom currency specification IDX to CC. */
475 void
476 set_cc (int idx, const struct custom_currency *cc_) 
477 {
478   assert (idx >= 0 && idx < CC_CNT);
479   cc[idx] = *cc_;
480 }
481
482 /* Are we in testing mode?  (e.g. --testing-mode command line
483    option) */
484 bool
485 get_testing_mode (void) 
486 {
487   return testing_mode;
488 }
489
490 /* Set testing mode. */
491 void
492 set_testing_mode (bool testing_mode_) 
493 {
494   testing_mode = testing_mode_;
495 }
496
497 /* Return the current algorithm setting */
498 enum behavior_mode
499 get_algorithm (void)
500 {
501   return *algorithm;
502 }
503
504 /* Set the algorithm option globally. */
505 void 
506 set_algorithm (enum behavior_mode mode)
507 {
508   global_algorithm = mode;
509 }
510
511 /* Set the algorithm option for this command only */
512 void 
513 set_cmd_algorithm (enum behavior_mode mode)
514 {
515   cmd_algorithm = mode; 
516   algorithm = &cmd_algorithm;
517 }
518
519 /* Unset the algorithm option for this command */
520 void
521 unset_cmd_algorithm (void)
522 {
523   algorithm = &global_algorithm;
524 }
525
526 /* Get the current syntax setting */
527 enum behavior_mode
528 get_syntax (void)
529 {
530   return syntax;
531 }
532
533 /* Set the syntax option */
534 void 
535 set_syntax (enum behavior_mode mode)
536 {
537   syntax = mode;
538 }