1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <ui/debugger.h>
25 #include "command-line.h"
28 #include "read-line.h"
30 #include <data/fastfile-factory.h>
31 #include <data/dictionary.h>
32 #include <data/file-handle-def.h>
33 #include <libpspp/getl.h>
34 #include <data/file-name.h>
35 #include <data/format.h>
36 #include <data/procedure.h>
37 #include <data/settings.h>
38 #include <data/variable.h>
39 #include <gsl/gsl_errno.h>
40 #include <language/command.h>
41 #include <language/lexer/lexer.h>
42 #include <language/prompt.h>
43 #include <libpspp/compiler.h>
44 #include <libpspp/message.h>
45 #include <libpspp/version.h>
46 #include <math/random.h>
47 #include <output/output.h>
49 #if HAVE_FPU_CONTROL_H
50 #include <fpu_control.h>
62 #define _(msgid) gettext (msgid)
66 static void i18n_init (void);
67 static void fpu_init (void);
68 static void terminate (bool success) NO_RETURN;
70 /* If a segfault happens, issue a message to that effect and halt */
71 void bug_handler(int sig);
73 /* Handle quit/term/int signals */
74 void interrupt_handler(int sig);
75 static struct dataset * the_dataset = NULL;
77 static struct lexer *the_lexer;
78 static struct source_stream *the_source_stream ;
81 /* Program entry point. */
83 main (int argc, char **argv)
85 struct casefile_factory *factory;
86 signal (SIGABRT, bug_handler);
87 signal (SIGSEGV, bug_handler);
88 signal (SIGFPE, bug_handler);
89 signal (SIGINT, interrupt_handler);
91 set_program_name ("pspp");
94 gsl_set_error_handler_off ();
101 create_source_stream (
102 fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
105 readln_initialize ();
109 factory = fastfile_factory_create ();
111 the_dataset = create_dataset (factory, NULL, NULL);
113 if (parse_command_line (argc, argv, the_source_stream))
115 msg_ui_init (the_source_stream);
116 outp_read_devices ();
117 the_lexer = lex_create (the_source_stream);
121 int result = cmd_parse (the_lexer, the_dataset);
123 if (result == CMD_EOF || result == CMD_FINISH)
125 if (result == CMD_CASCADING_FAILURE &&
126 !getl_is_interactive (the_source_stream))
128 msg (SE, _("Stopping syntax file processing here to avoid "
129 "a cascade of dependent command failures."));
130 getl_abort_noninteractive (the_source_stream);
133 check_msg_count (the_source_stream);
137 terminate (!any_errors ());
145 setlocale (LC_MESSAGES, "");
147 setlocale (LC_MONETARY, "");
148 bindtextdomain (PACKAGE, locale_dir);
149 textdomain (PACKAGE);
150 #endif /* ENABLE_NLS */
156 #if HAVE_FEHOLDEXCEPT
159 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
160 __setfpucw (_FPU_IEEE);
164 /* If a segfault happens, issue a message to that effect and halt */
174 request_bug_report_and_abort("Assertion Failure/Abort");
176 request_bug_report_and_abort("Floating Point Exception");
178 request_bug_report_and_abort("Segmentation Violation");
180 request_bug_report_and_abort("Unknown");
185 interrupt_handler(int sig UNUSED)
191 /* Terminate PSPP. SUCCESS should be true to exit successfully,
192 false to exit as a failure. */
194 terminate (bool success)
196 static bool terminating = false;
201 destroy_dataset (the_dataset);
206 lex_destroy (the_lexer);
207 destroy_source_stream (the_source_stream);
209 readln_uninitialize ();
215 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);