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
29 static int viewlength = 24;
30 static int viewwidth = 79;
31 static bool long_view = false;
33 static bool safer_mode = false;
35 static char decimal = '.';
36 static char grouping = ',';
38 static char *prompt = NULL;
39 static char *cprompt = NULL;
40 static char *dprompt = NULL;
42 static bool echo = false;
43 static bool include = true;
45 static int epoch = -1;
47 static bool errorbreak = false;
49 static bool scompress = false;
51 static bool undefined = true;
52 static double blanks = SYSMIS;
54 static int mxwarns = 100;
55 static int mxerrs = 100;
57 static bool printback = true;
58 static bool mprint = true;
60 static int mxloops = 1;
62 static bool nulline = true;
64 static char endcmd = '.';
66 static size_t workspace = 4L * 1024 * 1024;
68 static struct fmt_spec default_format = {FMT_F, 8, 2};
70 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
71 static struct custom_currency cc[CC_CNT] =
80 static bool testing_mode = false;
82 static int global_algorithm = ENHANCED;
83 static int cmd_algorithm = ENHANCED;
84 static int *algorithm = &global_algorithm;
86 static int syntax = ENHANCED;
88 static void init_viewport (void);
104 /* Screen length in lines. */
106 get_viewlength (void)
111 /* Sets the view length. */
113 set_viewlength (int viewlength_)
115 viewlength = viewlength_;
118 /* Set view width to a very long value, and prevent it from ever
121 force_long_view (void)
134 /* Sets the screen width. */
136 set_viewwidth (int viewwidth_)
138 viewwidth = viewwidth_;
143 get_termcap_viewport (void)
145 char term_buffer[16384];
146 if (getenv ("TERM") == NULL)
148 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
150 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
154 if (tgetnum ("li") > 0)
155 viewlength = tgetnum ("li");
157 if (tgetnum ("co") > 1)
158 viewwidth = tgetnum ("co") - 1;
160 #endif /* HAVE_LIBTERMCAP */
168 viewwidth = viewlength = -1;
171 get_termcap_viewport ();
172 #endif /* HAVE_LIBTERMCAP */
174 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
175 viewwidth = atoi (getenv ("COLUMNS"));
176 if (viewlength < 0 && getenv ("LINES") != NULL)
177 viewlength = atoi (getenv ("LINES"));
185 /* Whether PSPP can erase and overwrite files. */
187 get_safer_mode (void)
192 /* Set safer mode. */
194 set_safer_mode (void)
199 /* The character used for a decimal point: ',' or '.'. Only
200 respected for data input and output. */
207 /* Sets the character used for a decimal point, which must be
208 either ',' or '.'. */
210 set_decimal (char decimal_)
212 assert (decimal_ == '.' || decimal_ == ',');
216 /* The character used for grouping in numbers: '.' or ','; the
217 opposite of set_decimal. Only used in COMMA data input and
225 /* Sets the character used for grouping, which must be either ','
228 set_grouping (char grouping_)
230 assert (grouping_ == '.' || grouping_ == ',');
231 grouping = grouping_;
234 /* Gets the normal command prompt. */
238 return prompt != NULL ? prompt : "PSPP> ";
241 /* Sets the normal command prompt. */
243 set_prompt (const char *prompt_)
246 prompt = xstrdup (prompt_);
249 /* Gets the prompt used for data (after BEGIN DATA and before END
254 return dprompt != NULL ? dprompt : "data> ";
257 /* Sets the prompt used for data (after BEGIN DATA and before END
260 set_dprompt (const char *dprompt_)
263 dprompt = xstrdup (dprompt_);
266 /* Gets the continuation prompt used for second and subsequent
267 lines of commands. */
271 return cprompt != NULL ? cprompt : " > ";
274 /* Sets the continuation prompt used for second and subsequent
275 lines of commands. */
277 set_cprompt (const char *cprompt_)
280 cprompt = xstrdup (cprompt_);
283 /* Echo commands to the listing file/printer? */
292 set_echo (bool echo_)
297 /* If echo is on, whether commands from include files are echoed. */
304 /* Set include file echo. */
306 set_include (bool include_)
311 /* What year to use as the start of the epoch. */
318 struct tm *tm = localtime (&t);
319 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
325 /* Sets the year that starts the epoch. */
327 set_epoch (int epoch_)
332 /* Does an error stop execution? */
334 get_errorbreak (void)
339 /* Sets whether an error stops execution. */
341 set_errorbreak (bool errorbreak_)
343 errorbreak = errorbreak_;
346 /* Compress system files by default? */
348 get_scompression (void)
353 /* Set system file default compression. */
355 set_scompression (bool scompress_)
357 scompress = scompress_;
360 /* Whether to warn on undefined values in numeric data. */
367 /* Set whether to warn on undefined values. */
369 set_undefined (bool undefined_)
371 undefined = undefined_;
374 /* The value that blank numeric fields are set to when read in. */
381 /* Set the value that blank numeric fields are set to when read
384 set_blanks (double blanks_)
389 /* Maximum number of warnings + errors. */
396 /* Sets maximum number of warnings + errors. */
398 set_mxwarns (int mxwarns_)
403 /* Maximum number of errors. */
410 /* Sets maximum number of errors. */
412 set_mxerrs (int mxerrs_)
417 /* Whether commands are written to the display. */
424 /* Sets whether commands are written to the display. */
426 set_printback (bool printback_)
428 printback = printback_;
431 /* Independent of get_printback, controls whether the commands
432 generated by macro invocations are displayed. */
439 /* Sets whether the commands generated by macro invocations are
442 set_mprint (bool mprint_)
447 /* Implied limit of unbounded loop. */
454 /* Set implied limit of unbounded loop. */
456 set_mxloops (int mxloops_)
461 /* Whether a blank line is a command terminator. */
468 /* Set whether a blank line is a command terminator. */
470 set_nulline (bool nulline_)
475 /* The character used to terminate commands. */
482 /* Set the character used to terminate commands. */
484 set_endcmd (char endcmd_)
489 /* Approximate maximum amount of memory to use for cases, in
497 /* Set approximate maximum amount of memory to use for cases, in
501 set_workspace (size_t workspace_)
503 workspace = workspace_;
506 /* Default format for variables created by transformations and by
507 DATA LIST {FREE,LIST}. */
508 const struct fmt_spec *
511 return &default_format;
514 /* Set default format for variables created by transformations
515 and by DATA LIST {FREE,LIST}. */
517 set_format (const struct fmt_spec *default_format_)
519 default_format = *default_format_;
522 /* Gets the custom currency specification with the given IDX. */
523 const struct custom_currency *
526 assert (idx >= 0 && idx < CC_CNT);
530 /* Gets custom currency specification IDX to CC. */
532 set_cc (int idx, const struct custom_currency *cc_)
534 assert (idx >= 0 && idx < CC_CNT);
538 /* Are we in testing mode? (e.g. --testing-mode command line
541 get_testing_mode (void)
546 /* Set testing mode. */
548 set_testing_mode (bool testing_mode_)
550 testing_mode = testing_mode_;
553 /* Return the current algorithm setting */
560 /* Set the algorithm option globally. */
562 set_algorithm (enum behavior_mode mode)
564 global_algorithm = mode;
567 /* Set the algorithm option for this command only */
569 set_cmd_algorithm (enum behavior_mode mode)
571 cmd_algorithm = mode;
572 algorithm = &cmd_algorithm;
575 /* Unset the algorithm option for this command */
577 unset_cmd_algorithm (void)
579 algorithm = &global_algorithm;
582 /* Get the current syntax setting */
589 /* Set the syntax option */
591 set_syntax (enum behavior_mode mode)