1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2007 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>
29 #ifdef HAVE_LIBNCURSES
35 #define _(msgid) gettext (msgid)
37 static int viewlength = 24;
38 static int viewwidth = 79;
39 static bool long_view = false;
41 static bool safer_mode = false;
43 static bool do_echo = false;
44 static bool include = true;
46 static int epoch = -1;
48 static bool errorbreak = false;
50 static bool route_errors_to_terminal = true;
51 static bool route_errors_to_listing = true;
53 static bool scompress = true;
55 static bool undefined = true;
56 static double blanks = SYSMIS;
58 static int mxwarns = 100;
59 static int mxerrs = 100;
61 static bool printback = true;
62 static bool mprint = true;
64 static int mxloops = 1;
66 static bool nulline = true;
68 static char endcmd = '.';
70 static size_t workspace = 4L * 1024 * 1024;
72 static struct fmt_spec default_format = {FMT_F, 8, 2};
74 static bool testing_mode = false;
76 static int global_algorithm = ENHANCED;
77 static int cmd_algorithm = ENHANCED;
78 static int *algorithm = &global_algorithm;
80 static int syntax = ENHANCED;
82 static void init_viewport (void);
97 /* Screen length in lines. */
104 /* Sets the view length. */
106 set_viewlength (int viewlength_)
108 viewlength = viewlength_;
111 /* Set view width to a very long value, and prevent it from ever
114 force_long_view (void)
127 /* Sets the screen width. */
129 set_viewwidth (int viewwidth_)
131 viewwidth = viewwidth_;
136 get_termcap_viewport (void)
138 char term_buffer[16384];
139 if (getenv ("TERM") == NULL)
141 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
143 error (0,0, _("could not access definition for terminal `%s'"),
148 if (tgetnum ("li") > 0)
149 viewlength = tgetnum ("li");
151 if (tgetnum ("co") > 1)
152 viewwidth = tgetnum ("co") - 1;
154 #endif /* HAVE_LIBNCURSES */
162 viewwidth = viewlength = -1;
165 get_termcap_viewport ();
166 #endif /* HAVE_LIBNCURSES */
168 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
169 viewwidth = atoi (getenv ("COLUMNS"));
170 if (viewlength < 0 && getenv ("LINES") != NULL)
171 viewlength = atoi (getenv ("LINES"));
179 /* Whether PSPP can erase and overwrite files. */
181 get_safer_mode (void)
186 /* Set safer mode. */
188 set_safer_mode (void)
193 /* Echo commands to the listing file/printer? */
202 set_echo (bool echo_)
207 /* If echo is on, whether commands from include files are echoed. */
214 /* Set include file echo. */
216 set_include (bool include_)
221 /* What year to use as the start of the epoch. */
228 struct tm *tm = localtime (&t);
229 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
235 /* Sets the year that starts the epoch. */
237 set_epoch (int epoch_)
242 /* Does an error stop execution? */
244 get_errorbreak (void)
249 /* Sets whether an error stops execution. */
251 set_errorbreak (bool errorbreak_)
253 errorbreak = errorbreak_;
256 /* Route error messages to terminal? */
258 get_error_routing_to_terminal (void)
260 return route_errors_to_terminal;
263 /* Sets whether error messages should be routed to the
266 set_error_routing_to_terminal (bool route_to_terminal)
268 route_errors_to_terminal = route_to_terminal;
271 /* Route error messages to listing file? */
273 get_error_routing_to_listing (void)
275 return route_errors_to_listing;
278 /* Sets whether error messages should be routed to the
281 set_error_routing_to_listing (bool route_to_listing)
283 route_errors_to_listing = route_to_listing;
286 /* Compress system files by default? */
288 get_scompression (void)
293 /* Set system file default compression. */
295 set_scompression (bool scompress_)
297 scompress = scompress_;
300 /* Whether to warn on undefined values in numeric data. */
307 /* Set whether to warn on undefined values. */
309 set_undefined (bool undefined_)
311 undefined = undefined_;
314 /* The value that blank numeric fields are set to when read in. */
321 /* Set the value that blank numeric fields are set to when read
324 set_blanks (double blanks_)
329 /* Maximum number of warnings + errors. */
336 /* Sets maximum number of warnings + errors. */
338 set_mxwarns (int mxwarns_)
343 /* Maximum number of errors. */
350 /* Sets maximum number of errors. */
352 set_mxerrs (int mxerrs_)
357 /* Whether commands are written to the display. */
364 /* Sets whether commands are written to the display. */
366 set_printback (bool printback_)
368 printback = printback_;
371 /* Independent of get_printback, controls whether the commands
372 generated by macro invocations are displayed. */
379 /* Sets whether the commands generated by macro invocations are
382 set_mprint (bool mprint_)
387 /* Implied limit of unbounded loop. */
394 /* Set implied limit of unbounded loop. */
396 set_mxloops (int mxloops_)
401 /* Whether a blank line is a command terminator. */
408 /* Set whether a blank line is a command terminator. */
410 set_nulline (bool nulline_)
415 /* The character used to terminate commands. */
422 /* Set the character used to terminate commands. */
424 set_endcmd (char endcmd_)
429 /* Approximate maximum amount of memory to use for cases, in
437 /* Approximate maximum number of cases to allocate in-core, given
438 that each case contains VALUE_CNT values. */
440 get_workspace_cases (size_t value_cnt)
442 size_t case_size = sizeof (union value) * value_cnt + 4 * sizeof (void *);
443 size_t case_cnt = MAX (get_workspace () / case_size, 4);
447 /* Set approximate maximum amount of memory to use for cases, in
451 set_workspace (size_t workspace_)
453 workspace = workspace_;
456 /* Default format for variables created by transformations and by
457 DATA LIST {FREE,LIST}. */
458 const struct fmt_spec *
461 return &default_format;
464 /* Set default format for variables created by transformations
465 and by DATA LIST {FREE,LIST}. */
467 set_format (const struct fmt_spec *default_format_)
469 default_format = *default_format_;
472 /* Are we in testing mode? (e.g. --testing-mode command line
475 get_testing_mode (void)
480 /* Set testing mode. */
482 set_testing_mode (bool testing_mode_)
484 testing_mode = testing_mode_;
487 /* Return the current algorithm setting */
494 /* Set the algorithm option globally. */
496 set_algorithm (enum behavior_mode mode)
498 global_algorithm = mode;
501 /* Set the algorithm option for this command only */
503 set_cmd_algorithm (enum behavior_mode mode)
505 cmd_algorithm = mode;
506 algorithm = &cmd_algorithm;
509 /* Unset the algorithm option for this command */
511 unset_cmd_algorithm (void)
513 algorithm = &global_algorithm;
516 /* Get the current syntax setting */
523 /* Set the syntax option */
525 set_syntax (enum behavior_mode mode)