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};
71 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
72 static struct custom_currency cc[CC_CNT] =
81 static bool testing_mode = false;
83 static int global_algorithm = ENHANCED;
84 static int cmd_algorithm = ENHANCED;
85 static int *algorithm = &global_algorithm;
87 static int syntax = ENHANCED;
89 static void init_viewport (void);
105 /* Screen length in lines. */
107 get_viewlength (void)
112 /* Sets the view length. */
114 set_viewlength (int viewlength_)
116 viewlength = viewlength_;
119 /* Set view width to a very long value, and prevent it from ever
122 force_long_view (void)
135 /* Sets the screen width. */
137 set_viewwidth (int viewwidth_)
139 viewwidth = viewwidth_;
144 get_termcap_viewport (void)
146 char term_buffer[16384];
147 if (getenv ("TERM") == NULL)
149 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
151 msg (IE, _("Could not access definition for terminal `%s'."), termtype);
155 if (tgetnum ("li") > 0)
156 viewlength = tgetnum ("li");
158 if (tgetnum ("co") > 1)
159 viewwidth = tgetnum ("co") - 1;
161 #endif /* HAVE_LIBTERMCAP */
169 viewwidth = viewlength = -1;
172 get_termcap_viewport ();
173 #endif /* HAVE_LIBTERMCAP */
175 if (viewwidth < 0 && getenv ("COLUMNS") != NULL)
176 viewwidth = atoi (getenv ("COLUMNS"));
177 if (viewlength < 0 && getenv ("LINES") != NULL)
178 viewlength = atoi (getenv ("LINES"));
186 /* Whether PSPP can erase and overwrite files. */
188 get_safer_mode (void)
193 /* Set safer mode. */
195 set_safer_mode (void)
200 /* The character used for a decimal point: ',' or '.'. Only
201 respected for data input and output. */
208 /* Sets the character used for a decimal point, which must be
209 either ',' or '.'. */
211 set_decimal (char decimal_)
213 assert (decimal_ == '.' || decimal_ == ',');
217 /* The character used for grouping in numbers: '.' or ','; the
218 opposite of set_decimal. Only used in COMMA data input and
226 /* Sets the character used for grouping, which must be either ','
229 set_grouping (char grouping_)
231 assert (grouping_ == '.' || grouping_ == ',');
232 grouping = grouping_;
235 /* Gets the normal command prompt. */
239 return prompt != NULL ? prompt : "PSPP> ";
242 /* Sets the normal command prompt. */
244 set_prompt (const char *prompt_)
247 prompt = xstrdup (prompt_);
250 /* Gets the prompt used for data (after BEGIN DATA and before END
255 return dprompt != NULL ? dprompt : "data> ";
258 /* Sets the prompt used for data (after BEGIN DATA and before END
261 set_dprompt (const char *dprompt_)
264 dprompt = xstrdup (dprompt_);
267 /* Gets the continuation prompt used for second and subsequent
268 lines of commands. */
272 return cprompt != NULL ? cprompt : " > ";
275 /* Sets the continuation prompt used for second and subsequent
276 lines of commands. */
278 set_cprompt (const char *cprompt_)
281 cprompt = xstrdup (cprompt_);
284 /* Echo commands to the listing file/printer? */
293 set_echo (bool echo_)
298 /* If echo is on, whether commands from include files are echoed. */
305 /* Set include file echo. */
307 set_include (bool include_)
312 /* What year to use as the start of the epoch. */
319 struct tm *tm = localtime (&t);
320 epoch = (tm != NULL ? tm->tm_year + 1900 : 2000) - 69;
326 /* Sets the year that starts the epoch. */
328 set_epoch (int epoch_)
333 /* Does an error stop execution? */
335 get_errorbreak (void)
340 /* Sets whether an error stops execution. */
342 set_errorbreak (bool errorbreak_)
344 errorbreak = errorbreak_;
347 /* Compress system files by default? */
349 get_scompression (void)
354 /* Set system file default compression. */
356 set_scompression (bool scompress_)
358 scompress = scompress_;
361 /* Whether to warn on undefined values in numeric data. */
368 /* Set whether to warn on undefined values. */
370 set_undefined (bool undefined_)
372 undefined = undefined_;
375 /* The value that blank numeric fields are set to when read in. */
382 /* Set the value that blank numeric fields are set to when read
385 set_blanks (double blanks_)
390 /* Maximum number of warnings + errors. */
397 /* Sets maximum number of warnings + errors. */
399 set_mxwarns (int mxwarns_)
404 /* Maximum number of errors. */
411 /* Sets maximum number of errors. */
413 set_mxerrs (int mxerrs_)
418 /* Whether commands are written to the display. */
425 /* Sets whether commands are written to the display. */
427 set_printback (bool printback_)
429 printback = printback_;
432 /* Independent of get_printback, controls whether the commands
433 generated by macro invocations are displayed. */
440 /* Sets whether the commands generated by macro invocations are
443 set_mprint (bool mprint_)
448 /* Implied limit of unbounded loop. */
455 /* Set implied limit of unbounded loop. */
457 set_mxloops (int mxloops_)
462 /* Whether a blank line is a command terminator. */
469 /* Set whether a blank line is a command terminator. */
471 set_nulline (bool nulline_)
476 /* The character used to terminate commands. */
483 /* Set the character used to terminate commands. */
485 set_endcmd (char endcmd_)
490 /* Approximate maximum amount of memory to use for cases, in
498 /* Set approximate maximum amount of memory to use for cases, in
502 set_workspace (size_t workspace_)
504 workspace = workspace_;
507 /* Default format for variables created by transformations and by
508 DATA LIST {FREE,LIST}. */
509 const struct fmt_spec *
512 return &default_format;
515 /* Set default format for variables created by transformations
516 and by DATA LIST {FREE,LIST}. */
518 set_format (const struct fmt_spec *default_format_)
520 default_format = *default_format_;
523 /* Gets the custom currency specification with the given IDX. */
524 const struct custom_currency *
527 assert (idx >= 0 && idx < CC_CNT);
531 /* Gets custom currency specification IDX to CC. */
533 set_cc (int idx, const struct custom_currency *cc_)
535 assert (idx >= 0 && idx < CC_CNT);
539 /* Are we in testing mode? (e.g. --testing-mode command line
542 get_testing_mode (void)
547 /* Set testing mode. */
549 set_testing_mode (bool testing_mode_)
551 testing_mode = testing_mode_;
554 /* Return the current algorithm setting */
561 /* Set the algorithm option globally. */
563 set_algorithm (enum behavior_mode mode)
565 global_algorithm = mode;
568 /* Set the algorithm option for this command only */
570 set_cmd_algorithm (enum behavior_mode mode)
572 cmd_algorithm = mode;
573 algorithm = &cmd_algorithm;
576 /* Unset the algorithm option for this command */
578 unset_cmd_algorithm (void)
580 algorithm = &global_algorithm;
583 /* Get the current syntax setting */
590 /* Set the syntax option */
592 set_syntax (enum behavior_mode mode)