1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
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.
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.
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/>. */
25 #include <libpspp/i18n.h>
27 static int viewlength = 24;
28 static int viewwidth = 79;
29 static bool long_view = false;
31 static bool safer_mode = false;
33 static bool echo = false;
34 static bool include = true;
36 static int epoch = -1;
38 static bool errorbreak = false;
40 static bool route_errors_to_terminal = true;
41 static bool route_errors_to_listing = true;
43 static bool scompress = true;
45 static bool undefined = true;
46 static double blanks = SYSMIS;
48 static int mxwarns = 100;
49 static int mxerrs = 100;
51 static bool printback = true;
52 static bool mprint = true;
54 static int mxloops = 1;
56 static bool nulline = true;
58 static char endcmd = '.';
60 static size_t workspace = 4L * 1024 * 1024;
62 static struct fmt_spec default_format = {FMT_F, 8, 2};
64 static bool testing_mode = false;
66 static int global_algorithm = ENHANCED;
67 static int cmd_algorithm = ENHANCED;
68 static int *algorithm = &global_algorithm;
70 static int syntax = ENHANCED;
72 static void init_viewport (void);
87 /* Screen length in lines. */
94 /* Sets the view length. */
96 set_viewlength (int viewlength_)
98 viewlength = viewlength_;
101 /* Set view width to a very long value, and prevent it from ever
104 force_long_view (void)
117 /* Sets the screen width. */
119 set_viewwidth (int viewwidth_)
121 viewwidth = viewwidth_;
126 get_termcap_viewport (void)
128 char term_buffer[16384];
129 if (getenv ("TERM") == NULL)
131 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
133 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
137 if (tgetnum ("li") > 0)
138 viewlength = tgetnum ("li");
140 if (tgetnum ("co") > 1)
141 viewwidth = tgetnum ("co") - 1;
143 #endif /* HAVE_LIBTERMCAP */
151 viewwidth = viewlength = -1;
154 get_termcap_viewport ();
155 #endif /* HAVE_LIBTERMCAP */
157 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
158 viewwidth = atoi (getenv ("COLUMNS"));
159 if (viewlength < 0 && getenv ("LINES") != NULL)
160 viewlength = atoi (getenv ("LINES"));
168 /* Whether PSPP can erase and overwrite files. */
170 get_safer_mode (void)
175 /* Set safer mode. */
177 set_safer_mode (void)
182 /* Echo commands to the listing file/printer? */
191 set_echo (bool echo_)
196 /* If echo is on, whether commands from include files are echoed. */
203 /* Set include file echo. */
205 set_include (bool include_)
210 /* What year to use as the start of the epoch. */
217 struct tm *tm = localtime (&t);
218 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
224 /* Sets the year that starts the epoch. */
226 set_epoch (int epoch_)
231 /* Does an error stop execution? */
233 get_errorbreak (void)
238 /* Sets whether an error stops execution. */
240 set_errorbreak (bool errorbreak_)
242 errorbreak = errorbreak_;
245 /* Route error messages to terminal? */
247 get_error_routing_to_terminal (void)
249 return route_errors_to_terminal;
252 /* Sets whether error messages should be routed to the
255 set_error_routing_to_terminal (bool route_to_terminal)
257 route_errors_to_terminal = route_to_terminal;
260 /* Route error messages to listing file? */
262 get_error_routing_to_listing (void)
264 return route_errors_to_listing;
267 /* Sets whether error messages should be routed to the
270 set_error_routing_to_listing (bool route_to_listing)
272 route_errors_to_listing = route_to_listing;
275 /* Compress system files by default? */
277 get_scompression (void)
282 /* Set system file default compression. */
284 set_scompression (bool scompress_)
286 scompress = scompress_;
289 /* Whether to warn on undefined values in numeric data. */
296 /* Set whether to warn on undefined values. */
298 set_undefined (bool undefined_)
300 undefined = undefined_;
303 /* The value that blank numeric fields are set to when read in. */
310 /* Set the value that blank numeric fields are set to when read
313 set_blanks (double blanks_)
318 /* Maximum number of warnings + errors. */
325 /* Sets maximum number of warnings + errors. */
327 set_mxwarns (int mxwarns_)
332 /* Maximum number of errors. */
339 /* Sets maximum number of errors. */
341 set_mxerrs (int mxerrs_)
346 /* Whether commands are written to the display. */
353 /* Sets whether commands are written to the display. */
355 set_printback (bool printback_)
357 printback = printback_;
360 /* Independent of get_printback, controls whether the commands
361 generated by macro invocations are displayed. */
368 /* Sets whether the commands generated by macro invocations are
371 set_mprint (bool mprint_)
376 /* Implied limit of unbounded loop. */
383 /* Set implied limit of unbounded loop. */
385 set_mxloops (int mxloops_)
390 /* Whether a blank line is a command terminator. */
397 /* Set whether a blank line is a command terminator. */
399 set_nulline (bool nulline_)
404 /* The character used to terminate commands. */
411 /* Set the character used to terminate commands. */
413 set_endcmd (char endcmd_)
418 /* Approximate maximum amount of memory to use for cases, in
426 /* Approximate maximum number of cases to allocate in-core, given
427 that each case contains VALUE_CNT values. */
429 get_workspace_cases (size_t value_cnt)
431 size_t case_size = sizeof (union value) * value_cnt + 4 * sizeof (void *);
432 size_t case_cnt = MAX (get_workspace () / case_size, 4);
436 /* Set approximate maximum amount of memory to use for cases, in
440 set_workspace (size_t workspace_)
442 workspace = workspace_;
445 /* Default format for variables created by transformations and by
446 DATA LIST {FREE,LIST}. */
447 const struct fmt_spec *
450 return &default_format;
453 /* Set default format for variables created by transformations
454 and by DATA LIST {FREE,LIST}. */
456 set_format (const struct fmt_spec *default_format_)
458 default_format = *default_format_;
461 /* Are we in testing mode? (e.g. --testing-mode command line
464 get_testing_mode (void)
469 /* Set testing mode. */
471 set_testing_mode (bool testing_mode_)
473 testing_mode = testing_mode_;
476 /* Return the current algorithm setting */
483 /* Set the algorithm option globally. */
485 set_algorithm (enum behavior_mode mode)
487 global_algorithm = mode;
490 /* Set the algorithm option for this command only */
492 set_cmd_algorithm (enum behavior_mode mode)
494 cmd_algorithm = mode;
495 algorithm = &cmd_algorithm;
498 /* Unset the algorithm option for this command */
500 unset_cmd_algorithm (void)
502 algorithm = &global_algorithm;
505 /* Get the current syntax setting */
512 /* Set the syntax option */
514 set_syntax (enum behavior_mode mode)