1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
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.
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.
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
28 #include <libpspp/i18n.h>
30 static int viewlength = 24;
31 static int viewwidth = 79;
32 static bool long_view = false;
34 static bool safer_mode = false;
36 static char decimal = '.';
37 static char grouping = ',';
39 static bool echo = false;
40 static bool include = true;
42 static int epoch = -1;
44 static bool errorbreak = false;
46 static bool scompress = true;
48 static bool undefined = true;
49 static double blanks = SYSMIS;
51 static int mxwarns = 100;
52 static int mxerrs = 100;
54 static bool printback = true;
55 static bool mprint = true;
57 static int mxloops = 1;
59 static bool nulline = true;
61 static char endcmd = '.';
63 static size_t workspace = 4L * 1024 * 1024;
65 static struct fmt_spec default_format = {FMT_F, 8, 2};
67 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
68 static struct custom_currency cc[CC_CNT] =
77 static bool testing_mode = false;
79 static int global_algorithm = ENHANCED;
80 static int cmd_algorithm = ENHANCED;
81 static int *algorithm = &global_algorithm;
83 static int syntax = ENHANCED;
85 static void init_viewport (void);
100 /* Screen length in lines. */
102 get_viewlength (void)
107 /* Sets the view length. */
109 set_viewlength (int viewlength_)
111 viewlength = viewlength_;
114 /* Set view width to a very long value, and prevent it from ever
117 force_long_view (void)
130 /* Sets the screen width. */
132 set_viewwidth (int viewwidth_)
134 viewwidth = viewwidth_;
139 get_termcap_viewport (void)
141 char term_buffer[16384];
142 if (getenv ("TERM") == NULL)
144 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
146 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
150 if (tgetnum ("li") > 0)
151 viewlength = tgetnum ("li");
153 if (tgetnum ("co") > 1)
154 viewwidth = tgetnum ("co") - 1;
156 #endif /* HAVE_LIBTERMCAP */
164 viewwidth = viewlength = -1;
167 get_termcap_viewport ();
168 #endif /* HAVE_LIBTERMCAP */
170 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
171 viewwidth = atoi (getenv ("COLUMNS"));
172 if (viewlength < 0 && getenv ("LINES") != NULL)
173 viewlength = atoi (getenv ("LINES"));
181 /* Whether PSPP can erase and overwrite files. */
183 get_safer_mode (void)
188 /* Set safer mode. */
190 set_safer_mode (void)
195 /* The character used for a decimal point: ',' or '.'. Only
196 respected for data input and output. */
203 /* Sets the character used for a decimal point, which must be
204 either ',' or '.'. */
206 set_decimal (char decimal_)
208 assert (decimal_ == '.' || decimal_ == ',');
212 /* The character used for grouping in numbers: '.' or ','; the
213 opposite of set_decimal. Only used in COMMA data input and
221 /* Sets the character used for grouping, which must be either ','
224 set_grouping (char grouping_)
226 assert (grouping_ == '.' || grouping_ == ',');
227 grouping = grouping_;
230 /* Echo commands to the listing file/printer? */
239 set_echo (bool echo_)
244 /* If echo is on, whether commands from include files are echoed. */
251 /* Set include file echo. */
253 set_include (bool include_)
258 /* What year to use as the start of the epoch. */
265 struct tm *tm = localtime (&t);
266 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
272 /* Sets the year that starts the epoch. */
274 set_epoch (int epoch_)
279 /* Does an error stop execution? */
281 get_errorbreak (void)
286 /* Sets whether an error stops execution. */
288 set_errorbreak (bool errorbreak_)
290 errorbreak = errorbreak_;
293 /* Compress system files by default? */
295 get_scompression (void)
300 /* Set system file default compression. */
302 set_scompression (bool scompress_)
304 scompress = scompress_;
307 /* Whether to warn on undefined values in numeric data. */
314 /* Set whether to warn on undefined values. */
316 set_undefined (bool undefined_)
318 undefined = undefined_;
321 /* The value that blank numeric fields are set to when read in. */
328 /* Set the value that blank numeric fields are set to when read
331 set_blanks (double blanks_)
336 /* Maximum number of warnings + errors. */
343 /* Sets maximum number of warnings + errors. */
345 set_mxwarns (int mxwarns_)
350 /* Maximum number of errors. */
357 /* Sets maximum number of errors. */
359 set_mxerrs (int mxerrs_)
364 /* Whether commands are written to the display. */
371 /* Sets whether commands are written to the display. */
373 set_printback (bool printback_)
375 printback = printback_;
378 /* Independent of get_printback, controls whether the commands
379 generated by macro invocations are displayed. */
386 /* Sets whether the commands generated by macro invocations are
389 set_mprint (bool mprint_)
394 /* Implied limit of unbounded loop. */
401 /* Set implied limit of unbounded loop. */
403 set_mxloops (int mxloops_)
408 /* Whether a blank line is a command terminator. */
415 /* Set whether a blank line is a command terminator. */
417 set_nulline (bool nulline_)
422 /* The character used to terminate commands. */
429 /* Set the character used to terminate commands. */
431 set_endcmd (char endcmd_)
436 /* Approximate maximum amount of memory to use for cases, in
444 /* Set approximate maximum amount of memory to use for cases, in
448 set_workspace (size_t workspace_)
450 workspace = workspace_;
453 /* Default format for variables created by transformations and by
454 DATA LIST {FREE,LIST}. */
455 const struct fmt_spec *
458 return &default_format;
461 /* Set default format for variables created by transformations
462 and by DATA LIST {FREE,LIST}. */
464 set_format (const struct fmt_spec *default_format_)
466 default_format = *default_format_;
469 /* Gets the custom currency specification with the given IDX. */
470 const struct custom_currency *
473 assert (idx >= 0 && idx < CC_CNT);
477 /* Gets custom currency specification IDX to CC. */
479 set_cc (int idx, const struct custom_currency *cc_)
481 assert (idx >= 0 && idx < CC_CNT);
485 /* Are we in testing mode? (e.g. --testing-mode command line
488 get_testing_mode (void)
493 /* Set testing mode. */
495 set_testing_mode (bool testing_mode_)
497 testing_mode = testing_mode_;
500 /* Return the current algorithm setting */
507 /* Set the algorithm option globally. */
509 set_algorithm (enum behavior_mode mode)
511 global_algorithm = mode;
514 /* Set the algorithm option for this command only */
516 set_cmd_algorithm (enum behavior_mode mode)
518 cmd_algorithm = mode;
519 algorithm = &cmd_algorithm;
522 /* Unset the algorithm option for this command */
524 unset_cmd_algorithm (void)
526 algorithm = &global_algorithm;
529 /* Get the current syntax setting */
536 /* Set the syntax option */
538 set_syntax (enum behavior_mode mode)