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 static int viewlength = 24;
29 static int viewwidth = 79;
30 static bool long_view = false;
32 static bool safer_mode = false;
34 static char decimal = '.';
35 static char grouping = ',';
37 static char *prompt = NULL;
38 static char *cprompt = NULL;
39 static char *dprompt = NULL;
41 static bool echo = false;
42 static bool include = true;
44 static int epoch = -1;
46 static bool errorbreak = false;
48 static bool scompress = false;
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};
70 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
71 static struct custom_currency cc[CC_CNT] =
82 static bool testing_mode = false;
84 static int global_algorithm = ENHANCED;
85 static int cmd_algorithm = ENHANCED;
86 static int *algorithm = &global_algorithm;
88 static int syntax = ENHANCED;
90 static void init_viewport (void);
109 /* Screen length in lines. */
111 get_viewlength (void)
116 /* Sets the view length. */
118 set_viewlength (int viewlength_)
120 viewlength = viewlength_;
123 /* Set view width to a very long value, and prevent it from ever
126 force_long_view (void)
139 /* Sets the screen width. */
141 set_viewwidth (int viewwidth_)
143 viewwidth = viewwidth_;
148 get_termcap_viewport (void)
150 char term_buffer[16384];
151 if (getenv ("TERM") == NULL)
153 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
155 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
159 if (tgetnum ("li") > 0)
160 viewlength = tgetnum ("li");
162 if (tgetnum ("co") > 1)
163 viewwidth = tgetnum ("co") - 1;
165 #endif /* HAVE_LIBTERMCAP */
173 viewwidth = viewlength = -1;
176 get_termcap_viewport ();
177 #endif /* HAVE_LIBTERMCAP */
179 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
180 viewwidth = atoi (getenv ("COLUMNS"));
181 if (viewlength < 0 && getenv ("LINES") != NULL)
182 viewlength = atoi (getenv ("LINES"));
190 /* Whether PSPP can erase and overwrite files. */
192 get_safer_mode (void)
197 /* Set safer mode. */
199 set_safer_mode (void)
204 /* The character used for a decimal point: ',' or '.'. Only
205 respected for data input and output. */
212 /* Sets the character used for a decimal point, which must be
213 either ',' or '.'. */
215 set_decimal (char decimal_)
217 assert (decimal_ == '.' || decimal_ == ',');
221 /* The character used for grouping in numbers: '.' or ','; the
222 opposite of set_decimal. Only used in COMMA data input and
230 /* Sets the character used for grouping, which must be either ','
233 set_grouping (char grouping_)
235 assert (grouping_ == '.' || grouping_ == ',');
236 grouping = grouping_;
239 /* Gets the normal command prompt. */
243 return prompt != NULL ? prompt : "PSPP> ";
246 /* Sets the normal command prompt. */
248 set_prompt (const char *prompt_)
251 prompt = xstrdup (prompt_);
254 /* Gets the prompt used for data (after BEGIN DATA and before END
259 return dprompt != NULL ? dprompt : "data> ";
262 /* Sets the prompt used for data (after BEGIN DATA and before END
265 set_dprompt (const char *dprompt_)
268 dprompt = xstrdup (dprompt_);
271 /* Gets the continuation prompt used for second and subsequent
272 lines of commands. */
276 return cprompt != NULL ? cprompt : " > ";
279 /* Sets the continuation prompt used for second and subsequent
280 lines of commands. */
282 set_cprompt (const char *cprompt_)
285 cprompt = xstrdup (cprompt_);
288 /* Echo commands to the listing file/printer? */
297 set_echo (bool echo_)
302 /* If echo is on, whether commands from include files are echoed. */
309 /* Set include file echo. */
311 set_include (bool include_)
316 /* What year to use as the start of the epoch. */
323 struct tm *tm = localtime (&t);
324 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
330 /* Sets the year that starts the epoch. */
332 set_epoch (int epoch_)
337 /* Does an error stop execution? */
339 get_errorbreak (void)
344 /* Sets whether an error stops execution. */
346 set_errorbreak (bool errorbreak_)
348 errorbreak = errorbreak_;
351 /* Compress system files by default? */
353 get_scompression (void)
358 /* Set system file default compression. */
360 set_scompression (bool scompress_)
362 scompress = scompress_;
365 /* Whether to warn on undefined values in numeric data. */
372 /* Set whether to warn on undefined values. */
374 set_undefined (bool undefined_)
376 undefined = undefined_;
379 /* The value that blank numeric fields are set to when read in. */
386 /* Set the value that blank numeric fields are set to when read
389 set_blanks (double blanks_)
394 /* Maximum number of warnings + errors. */
401 /* Sets maximum number of warnings + errors. */
403 set_mxwarns (int mxwarns_)
408 /* Maximum number of errors. */
415 /* Sets maximum number of errors. */
417 set_mxerrs (int mxerrs_)
422 /* Whether commands are written to the display. */
429 /* Sets whether commands are written to the display. */
431 set_printback (bool printback_)
433 printback = printback_;
436 /* Independent of get_printback, controls whether the commands
437 generated by macro invocations are displayed. */
444 /* Sets whether the commands generated by macro invocations are
447 set_mprint (bool mprint_)
452 /* Implied limit of unbounded loop. */
459 /* Set implied limit of unbounded loop. */
461 set_mxloops (int mxloops_)
466 /* Whether a blank line is a command terminator. */
473 /* Set whether a blank line is a command terminator. */
475 set_nulline (bool nulline_)
480 /* The character used to terminate commands. */
487 /* Set the character used to terminate commands. */
489 set_endcmd (char endcmd_)
494 /* Approximate maximum amount of memory to use for cases, in
502 /* Set approximate maximum amount of memory to use for cases, in
506 set_workspace (size_t workspace_)
508 workspace = workspace_;
511 /* Default format for variables created by transformations and by
512 DATA LIST {FREE,LIST}. */
513 const struct fmt_spec *
516 return &default_format;
519 /* Set default format for variables created by transformations
520 and by DATA LIST {FREE,LIST}. */
522 set_format (const struct fmt_spec *default_format_)
524 default_format = *default_format_;
527 /* Gets the custom currency specification with the given IDX. */
528 const struct custom_currency *
531 assert (idx >= 0 && idx < CC_CNT);
535 /* Gets custom currency specification IDX to CC. */
537 set_cc (int idx, const struct custom_currency *cc_)
539 assert (idx >= 0 && idx < CC_CNT);
543 /* Returns the current random number generator. */
552 /* Initializes or reinitializes the random number generator with
555 set_rng (unsigned long seed)
557 rng = gsl_rng_alloc (gsl_rng_mt19937);
560 gsl_rng_set (rng, seed);
563 /* Are we in testing mode? (e.g. --testing-mode command line
566 get_testing_mode (void)
571 /* Set testing mode. */
573 set_testing_mode (bool testing_mode_)
575 testing_mode = testing_mode_;
578 /* Return the current algorithm setting */
585 /* Set the algorithm option globally. */
587 set_algorithm (enum behavior_mode mode)
589 global_algorithm = mode;
592 /* Set the algorithm option for this command only */
594 set_cmd_algorithm (enum behavior_mode mode)
596 cmd_algorithm = mode;
597 algorithm = &cmd_algorithm;
600 /* Unset the algorithm option for this command */
602 unset_cmd_algorithm (void)
604 algorithm = &global_algorithm;
607 /* Get the current syntax setting */
614 /* Set the syntax option */
616 set_syntax (enum behavior_mode mode)