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
22 #include "command-line.h"
25 #include "procedure.h"
26 #include "read-line.h"
28 #include <data/dictionary.h>
29 #include <data/file-handle-def.h>
30 #include <data/file-name.h>
31 #include <data/settings.h>
32 #include <data/variable.h>
33 #include <gsl/gsl_errno.h>
34 #include <language/command.h>
35 #include <language/lexer/lexer.h>
36 #include <language/line-buffer.h>
37 #include <libpspp/compiler.h>
38 #include <libpspp/message.h>
39 #include <libpspp/version.h>
40 #include <math/random.h>
41 #include <output/output.h>
46 #if HAVE_FPU_CONTROL_H
47 #include <fpu_control.h>
59 #define _(msgid) gettext (msgid)
63 static void i18n_init (void);
64 static void fpu_init (void);
65 static int execute_command (void);
66 static void terminate (bool success) NO_RETURN;
68 /* If a segfault happens, issue a message to that effect and halt */
69 void bug_handler(int sig);
71 /* Handle quit/term/int signals */
72 void interrupt_handler(int sig);
75 /* Program entry point. */
77 main (int argc, char **argv)
79 signal (SIGSEGV, bug_handler);
80 signal (SIGFPE, bug_handler);
81 signal (SIGINT, interrupt_handler);
83 set_program_name ("pspp");
86 gsl_set_error_handler_off ();
97 default_dict = dict_create ();
99 if (parse_command_line (argc, argv))
101 outp_read_devices ();
106 int result = execute_command ();
107 if (result == CMD_EOF || result == CMD_QUIT)
109 if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ())
111 msg (SE, _("Stopping syntax file processing here to avoid "
112 "a cascade of dependent command failures."));
113 getl_abort_noninteractive ();
120 terminate (!any_errors ());
123 /* Parses a command and returns the result. */
125 execute_command (void)
127 /* Read the command's first token.
128 The first token is part of the first line of the command. */
129 getl_set_prompt_style (GETL_PROMPT_FIRST);
134 /* Parse the command.
135 Any lines read after the first token must be continuation
137 getl_set_prompt_style (GETL_PROMPT_LATER);
138 return cmd_parse (vfm_source != NULL ? CMD_STATE_DATA : CMD_STATE_INITIAL);
146 setlocale (LC_MESSAGES, "");
148 setlocale (LC_MONETARY, "");
149 bindtextdomain (PACKAGE, locale_dir);
150 textdomain (PACKAGE);
151 #endif /* ENABLE_NLS */
157 #if HAVE_FEHOLDEXCEPT
160 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
161 __setfpucw (_FPU_IEEE);
165 /* If a segfault happens, issue a message to that effect and halt */
172 request_bug_report_and_abort("Floating Point Exception");
175 request_bug_report_and_abort("Segmentation Violation");
178 request_bug_report_and_abort("");
184 interrupt_handler(int sig UNUSED)
190 /* Terminate PSPP. SUCCESS should be true to exit successfully,
191 false to exit as a failure. */
193 terminate (bool success)
195 static bool terminating = false;
200 cancel_transformations ();
201 dict_destroy (default_dict);
207 getl_uninitialize ();
208 readln_uninitialize ();
213 exit (success ? EXIT_SUCCESS : EXIT_FAILURE);