1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include <libpspp/i18n.h>
29 static int viewlength = 24;
30 static int viewwidth = 79;
31 static bool long_view = false;
33 static bool safer_mode = false;
35 static bool echo = false;
36 static bool include = true;
38 static int epoch = -1;
40 static bool errorbreak = false;
42 static bool route_errors_to_terminal = true;
43 static bool route_errors_to_listing = true;
45 static bool scompress = true;
47 static bool undefined = true;
48 static double blanks = SYSMIS;
50 static int mxwarns = 100;
51 static int mxerrs = 100;
53 static bool printback = true;
54 static bool mprint = true;
56 static int mxloops = 1;
58 static bool nulline = true;
60 static char endcmd = '.';
62 static size_t workspace = 4L * 1024 * 1024;
64 static struct fmt_spec default_format = {FMT_F, 8, 2};
66 static bool testing_mode = false;
68 static int global_algorithm = ENHANCED;
69 static int cmd_algorithm = ENHANCED;
70 static int *algorithm = &global_algorithm;
72 static int syntax = ENHANCED;
74 static void init_viewport (void);
89 /* Screen length in lines. */
96 /* Sets the view length. */
98 set_viewlength (int viewlength_)
100 viewlength = viewlength_;
103 /* Set view width to a very long value, and prevent it from ever
106 force_long_view (void)
119 /* Sets the screen width. */
121 set_viewwidth (int viewwidth_)
123 viewwidth = viewwidth_;
128 get_termcap_viewport (void)
130 char term_buffer[16384];
131 if (getenv ("TERM") == NULL)
133 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
135 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
139 if (tgetnum ("li") > 0)
140 viewlength = tgetnum ("li");
142 if (tgetnum ("co") > 1)
143 viewwidth = tgetnum ("co") - 1;
145 #endif /* HAVE_LIBTERMCAP */
153 viewwidth = viewlength = -1;
156 get_termcap_viewport ();
157 #endif /* HAVE_LIBTERMCAP */
159 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
160 viewwidth = atoi (getenv ("COLUMNS"));
161 if (viewlength < 0 && getenv ("LINES") != NULL)
162 viewlength = atoi (getenv ("LINES"));
170 /* Whether PSPP can erase and overwrite files. */
172 get_safer_mode (void)
177 /* Set safer mode. */
179 set_safer_mode (void)
184 /* Echo commands to the listing file/printer? */
193 set_echo (bool echo_)
198 /* If echo is on, whether commands from include files are echoed. */
205 /* Set include file echo. */
207 set_include (bool include_)
212 /* What year to use as the start of the epoch. */
219 struct tm *tm = localtime (&t);
220 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
226 /* Sets the year that starts the epoch. */
228 set_epoch (int epoch_)
233 /* Does an error stop execution? */
235 get_errorbreak (void)
240 /* Sets whether an error stops execution. */
242 set_errorbreak (bool errorbreak_)
244 errorbreak = errorbreak_;
247 /* Route error messages to terminal? */
249 get_error_routing_to_terminal (void)
251 return route_errors_to_terminal;
254 /* Sets whether error messages should be routed to the
257 set_error_routing_to_terminal (bool route_to_terminal)
259 route_errors_to_terminal = route_to_terminal;
262 /* Route error messages to listing file? */
264 get_error_routing_to_listing (void)
266 return route_errors_to_listing;
269 /* Sets whether error messages should be routed to the
272 set_error_routing_to_listing (bool route_to_listing)
274 route_errors_to_listing = route_to_listing;
277 /* Compress system files by default? */
279 get_scompression (void)
284 /* Set system file default compression. */
286 set_scompression (bool scompress_)
288 scompress = scompress_;
291 /* Whether to warn on undefined values in numeric data. */
298 /* Set whether to warn on undefined values. */
300 set_undefined (bool undefined_)
302 undefined = undefined_;
305 /* The value that blank numeric fields are set to when read in. */
312 /* Set the value that blank numeric fields are set to when read
315 set_blanks (double blanks_)
320 /* Maximum number of warnings + errors. */
327 /* Sets maximum number of warnings + errors. */
329 set_mxwarns (int mxwarns_)
334 /* Maximum number of errors. */
341 /* Sets maximum number of errors. */
343 set_mxerrs (int mxerrs_)
348 /* Whether commands are written to the display. */
355 /* Sets whether commands are written to the display. */
357 set_printback (bool printback_)
359 printback = printback_;
362 /* Independent of get_printback, controls whether the commands
363 generated by macro invocations are displayed. */
370 /* Sets whether the commands generated by macro invocations are
373 set_mprint (bool mprint_)
378 /* Implied limit of unbounded loop. */
385 /* Set implied limit of unbounded loop. */
387 set_mxloops (int mxloops_)
392 /* Whether a blank line is a command terminator. */
399 /* Set whether a blank line is a command terminator. */
401 set_nulline (bool nulline_)
406 /* The character used to terminate commands. */
413 /* Set the character used to terminate commands. */
415 set_endcmd (char endcmd_)
420 /* Approximate maximum amount of memory to use for cases, in
428 /* Approximate maximum number of cases to allocate in-core, given
429 that each case contains VALUE_CNT values. */
431 get_workspace_cases (size_t value_cnt)
433 size_t case_size = sizeof (union value) * value_cnt + 4 * sizeof (void *);
434 size_t case_cnt = MAX (get_workspace () / case_size, 4);
438 /* Set approximate maximum amount of memory to use for cases, in
442 set_workspace (size_t workspace_)
444 workspace = workspace_;
447 /* Default format for variables created by transformations and by
448 DATA LIST {FREE,LIST}. */
449 const struct fmt_spec *
452 return &default_format;
455 /* Set default format for variables created by transformations
456 and by DATA LIST {FREE,LIST}. */
458 set_format (const struct fmt_spec *default_format_)
460 default_format = *default_format_;
463 /* Are we in testing mode? (e.g. --testing-mode command line
466 get_testing_mode (void)
471 /* Set testing mode. */
473 set_testing_mode (bool testing_mode_)
475 testing_mode = testing_mode_;
478 /* Return the current algorithm setting */
485 /* Set the algorithm option globally. */
487 set_algorithm (enum behavior_mode mode)
489 global_algorithm = mode;
492 /* Set the algorithm option for this command only */
494 set_cmd_algorithm (enum behavior_mode mode)
496 cmd_algorithm = mode;
497 algorithm = &cmd_algorithm;
500 /* Unset the algorithm option for this command */
502 unset_cmd_algorithm (void)
504 algorithm = &global_algorithm;
507 /* Get the current syntax setting */
514 /* Set the syntax option */
516 set_syntax (enum behavior_mode mode)