1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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, see <http://www.gnu.org/licenses/>. */
22 #include <ui/debugger.h>
23 #include "command-line.h"
26 #include "read-line.h"
28 #include <data/dictionary.h>
29 #include <data/file-handle-def.h>
30 #include <libpspp/getl.h>
31 #include <data/file-name.h>
32 #include <data/format.h>
33 #include <data/procedure.h>
34 #include <data/settings.h>
35 #include <data/variable.h>
36 #include <gsl/gsl_errno.h>
37 #include <language/command.h>
38 #include <language/lexer/lexer.h>
39 #include <language/prompt.h>
40 #include <libpspp/compiler.h>
41 #include <libpspp/message.h>
42 #include <libpspp/version.h>
43 #include <math/random.h>
44 #include <output/output.h>
46 #if HAVE_FPU_CONTROL_H
47 #include <fpu_control.h>
63 #define _(msgid) gettext (msgid)
67 static void i18n_init (void);
68 static void fpu_init (void);
69 static void terminate (bool success) NO_RETURN;
71 /* If a segfault happens, issue a message to that effect and halt */
72 void bug_handler(int sig);
74 /* Handle quit/term/int signals */
75 void interrupt_handler(int sig);
76 static struct dataset * the_dataset = NULL;
78 static struct lexer *the_lexer;
79 static struct source_stream *the_source_stream ;
81 static int view_length = -1;
82 static int view_width = -1;
84 static void get_termcap_viewport (int);
87 /* Program entry point. */
89 main (int argc, char **argv)
91 signal (SIGABRT, bug_handler);
92 signal (SIGSEGV, bug_handler);
93 signal (SIGFPE, bug_handler);
94 signal (SIGINT, interrupt_handler);
95 signal (SIGWINCH, get_termcap_viewport);
97 set_program_name (argv[0]);
101 gsl_set_error_handler_off ();
108 create_source_stream (
109 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
112 readln_initialize ();
113 get_termcap_viewport (0);
114 settings_init (&view_width, &view_length);
117 the_dataset = create_dataset ();
119 if (parse_command_line (argc, argv, the_source_stream))
121 msg_ui_init (the_source_stream);
122 if (!get_testing_mode ())
123 outp_read_devices ();
125 outp_configure_driver_line (
126 ss_cstr ("raw-ascii:ascii:listing:width=9999 length=9999 "
127 "output-file=\"pspp.list\" emphasis=none "
128 "headers=off paginate=off squeeze=on "
129 "top-margin=0 bottom-margin=0"));
130 the_lexer = lex_create (the_source_stream);
134 int result = cmd_parse (the_lexer, the_dataset);
136 if (result == CMD_EOF || result == CMD_FINISH)
138 if (result == CMD_CASCADING_FAILURE &&
139 !getl_is_interactive (the_source_stream))
141 msg (SE, _("Stopping syntax file processing here to avoid "
142 "a cascade of dependent command failures."));
143 getl_abort_noninteractive (the_source_stream);
146 check_msg_count (the_source_stream);
150 terminate (!any_errors ());
158 setlocale (LC_MESSAGES, "");
161 setlocale (LC_PAPER, "");
163 bindtextdomain (PACKAGE, locale_dir);
164 textdomain (PACKAGE);
165 #endif /* ENABLE_NLS */
171 #if HAVE_FEHOLDEXCEPT
174 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
175 __setfpucw (_FPU_IEEE);
181 /* If a segfault happens, issue a message to that effect and halt */
191 request_bug_report_and_abort("Assertion Failure/Abort");
193 request_bug_report_and_abort("Floating Point Exception");
195 request_bug_report_and_abort("Segmentation Violation");
197 request_bug_report_and_abort("Unknown");
202 interrupt_handler(int sig UNUSED)
208 /* Terminate PSPP. SUCCESS should be true to exit successfully,
209 false to exit as a failure. */
211 terminate (bool success)
213 static bool terminating = false;
218 destroy_dataset (the_dataset);
223 lex_destroy (the_lexer);
224 destroy_source_stream (the_source_stream);
226 readln_uninitialize ();
232 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
240 #define _(msgid) gettext (msgid)
243 set_fallback_viewport (void)
245 if (view_width < 0 && getenv ("COLUMNS") != NULL)
246 view_width = atoi (getenv ("COLUMNS"));
248 if (view_length < 0 && getenv ("LINES") != NULL)
249 view_length = atoi (getenv ("LINES"));
258 /* Code that interfaces to ncurses. This must be at the very end
259 of this file because curses.h redefines "bool" on some systems
260 (e.g. OpenBSD), causing declaration mismatches with functions
261 that have parameters or return values of type "bool". */
267 get_termcap_viewport (int sig UNUSED)
269 char term_buffer [16384];
271 if (getenv ("TERM") == NULL)
274 else if (tgetent (term_buffer, getenv ("TERM")) <= 0)
276 error (0,0, _("could not access definition for terminal `%s'"),
281 if (tgetnum ("li") > 0)
282 view_length = tgetnum ("li");
284 if (tgetnum ("co") > 1)
285 view_width = tgetnum ("co") - 1;
288 set_fallback_viewport ();
291 #else /* !HAVE_LIBNCURSES */
294 get_termcap_viewport (int sig UNUSED)
296 set_fallback_viewport ();
299 #endif /* !HAVE_LIBNCURSES */