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>
30 #define _(msgid) gettext (msgid)
32 static int viewlength = 24;
33 static int viewwidth = 79;
34 static bool long_view = false;
36 static bool safer_mode = false;
38 static bool do_echo = false;
39 static bool include = true;
41 static int epoch = -1;
43 static bool errorbreak = false;
45 static bool route_errors_to_terminal = true;
46 static bool route_errors_to_listing = true;
48 static bool scompress = true;
50 static bool undefined = true;
51 static double blanks = SYSMIS;
53 static int mxwarns = 100;
54 static int mxerrs = 100;
56 static bool printback = true;
57 static bool mprint = true;
59 static int mxloops = 1;
61 static bool nulline = true;
63 static char endcmd = '.';
65 static size_t workspace = 4L * 1024 * 1024;
67 static struct fmt_spec default_format = {FMT_F, 8, 2};
69 static bool testing_mode = false;
71 static int global_algorithm = ENHANCED;
72 static int cmd_algorithm = ENHANCED;
73 static int *algorithm = &global_algorithm;
75 static int syntax = ENHANCED;
77 static void init_viewport (void);
78 static void get_termcap_viewport (void);
93 /* Screen length in lines. */
100 /* Sets the view length. */
102 set_viewlength (int viewlength_)
104 viewlength = viewlength_;
107 /* Set view width to a very long value, and prevent it from ever
110 force_long_view (void)
123 /* Sets the screen width. */
125 set_viewwidth (int viewwidth_)
127 viewwidth = viewwidth_;
136 viewwidth = viewlength = -1;
138 get_termcap_viewport ();
140 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
141 viewwidth = atoi (getenv ("COLUMNS"));
142 if (viewlength < 0 && getenv ("LINES") != NULL)
143 viewlength = atoi (getenv ("LINES"));
151 /* Whether PSPP can erase and overwrite files. */
153 get_safer_mode (void)
158 /* Set safer mode. */
160 set_safer_mode (void)
165 /* Echo commands to the listing file/printer? */
174 set_echo (bool echo_)
179 /* If echo is on, whether commands from include files are echoed. */
186 /* Set include file echo. */
188 set_include (bool include_)
193 /* What year to use as the start of the epoch. */
200 struct tm *tm = localtime (&t);
201 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
207 /* Sets the year that starts the epoch. */
209 set_epoch (int epoch_)
214 /* Does an error stop execution? */
216 get_errorbreak (void)
221 /* Sets whether an error stops execution. */
223 set_errorbreak (bool errorbreak_)
225 errorbreak = errorbreak_;
228 /* Route error messages to terminal? */
230 get_error_routing_to_terminal (void)
232 return route_errors_to_terminal;
235 /* Sets whether error messages should be routed to the
238 set_error_routing_to_terminal (bool route_to_terminal)
240 route_errors_to_terminal = route_to_terminal;
243 /* Route error messages to listing file? */
245 get_error_routing_to_listing (void)
247 return route_errors_to_listing;
250 /* Sets whether error messages should be routed to the
253 set_error_routing_to_listing (bool route_to_listing)
255 route_errors_to_listing = route_to_listing;
258 /* Compress system files by default? */
260 get_scompression (void)
265 /* Set system file default compression. */
267 set_scompression (bool scompress_)
269 scompress = scompress_;
272 /* Whether to warn on undefined values in numeric data. */
279 /* Set whether to warn on undefined values. */
281 set_undefined (bool undefined_)
283 undefined = undefined_;
286 /* The value that blank numeric fields are set to when read in. */
293 /* Set the value that blank numeric fields are set to when read
296 set_blanks (double blanks_)
301 /* Maximum number of warnings + errors. */
308 /* Sets maximum number of warnings + errors. */
310 set_mxwarns (int mxwarns_)
315 /* Maximum number of errors. */
322 /* Sets maximum number of errors. */
324 set_mxerrs (int mxerrs_)
329 /* Whether commands are written to the display. */
336 /* Sets whether commands are written to the display. */
338 set_printback (bool printback_)
340 printback = printback_;
343 /* Independent of get_printback, controls whether the commands
344 generated by macro invocations are displayed. */
351 /* Sets whether the commands generated by macro invocations are
354 set_mprint (bool mprint_)
359 /* Implied limit of unbounded loop. */
366 /* Set implied limit of unbounded loop. */
368 set_mxloops (int mxloops_)
373 /* Whether a blank line is a command terminator. */
380 /* Set whether a blank line is a command terminator. */
382 set_nulline (bool nulline_)
387 /* The character used to terminate commands. */
394 /* Set the character used to terminate commands. */
396 set_endcmd (char endcmd_)
401 /* Approximate maximum amount of memory to use for cases, in
409 /* Approximate maximum number of cases to allocate in-core, given
410 that each case contains VALUE_CNT values. */
412 get_workspace_cases (size_t value_cnt)
414 size_t case_size = sizeof (union value) * value_cnt + 4 * sizeof (void *);
415 size_t case_cnt = MAX (get_workspace () / case_size, 4);
419 /* Set approximate maximum amount of memory to use for cases, in
423 set_workspace (size_t workspace_)
425 workspace = workspace_;
428 /* Default format for variables created by transformations and by
429 DATA LIST {FREE,LIST}. */
430 const struct fmt_spec *
433 return &default_format;
436 /* Set default format for variables created by transformations
437 and by DATA LIST {FREE,LIST}. */
439 set_format (const struct fmt_spec *default_format_)
441 default_format = *default_format_;
444 /* Are we in testing mode? (e.g. --testing-mode command line
447 get_testing_mode (void)
452 /* Set testing mode. */
454 set_testing_mode (bool testing_mode_)
456 testing_mode = testing_mode_;
459 /* Return the current algorithm setting */
466 /* Set the algorithm option globally. */
468 set_algorithm (enum behavior_mode mode)
470 global_algorithm = mode;
473 /* Set the algorithm option for this command only */
475 set_cmd_algorithm (enum behavior_mode mode)
477 cmd_algorithm = mode;
478 algorithm = &cmd_algorithm;
481 /* Unset the algorithm option for this command */
483 unset_cmd_algorithm (void)
485 algorithm = &global_algorithm;
488 /* Get the current syntax setting */
495 /* Set the syntax option */
497 set_syntax (enum behavior_mode mode)
502 /* Code that interfaces to ncurses. This must be at the very end
503 of this file because curses.h redefines "bool" on some systems
504 (e.g. OpenBSD), causing declaration mismatches with functions
505 that have parameters or return values of type "bool". */
511 get_termcap_viewport (void)
513 char term_buffer[16384];
514 if (getenv ("TERM") == NULL)
516 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
518 error (0,0, _("could not access definition for terminal `%s'"),
523 if (tgetnum ("li") > 0)
524 viewlength = tgetnum ("li");
526 if (tgetnum ("co") > 1)
527 viewwidth = tgetnum ("co") - 1;
529 #else /* !HAVE_LIBNCURSES */
531 get_termcap_viewport (void)
535 #endif /* !HAVE_LIBNCURSES */