Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / terminal / main.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2007 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include <locale.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #if HAVE_FPU_CONTROL_H
24 #include <fpu_control.h>
25 #endif
26 #if HAVE_FENV_H
27 #include <fenv.h>
28 #endif
29 #if HAVE_IEEEFP_H
30 #include <ieeefp.h>
31 #endif
32
33 #include <data/dictionary.h>
34 #include <data/file-handle-def.h>
35 #include <libpspp/getl.h>
36 #include <data/file-name.h>
37 #include <data/procedure.h>
38 #include <data/settings.h>
39 #include <data/variable.h>
40 #include <gsl/gsl_errno.h>
41 #include <language/command.h>
42 #include <language/lexer/lexer.h>
43 #include <language/prompt.h>
44 #include <libpspp/compiler.h>
45 #include <libpspp/message.h>
46 #include <libpspp/version.h>
47 #include <math/random.h>
48 #include <output/output.h>
49 #include <ui/debugger.h>
50 #include <ui/terminal/command-line.h>
51 #include <ui/terminal/msg-ui.h>
52 #include <ui/terminal/read-line.h>
53 #include <ui/terminal/terminal.h>
54
55 #include "fatal-signal.h"
56 #include "progname.h"
57
58 #include "gettext.h"
59 #define _(msgid) gettext (msgid)
60
61
62 static void i18n_init (void);
63 static void fpu_init (void);
64 static void clean_up (void);
65
66 /* If a segfault happens, issue a message to that effect and halt */
67 void bug_handler(int sig);
68
69 /* Handle quit/term/int signals */
70 void interrupt_handler(int sig);
71 static struct dataset * the_dataset = NULL;
72
73 static struct lexer *the_lexer;
74 static struct source_stream *the_source_stream ;
75
76 /* Program entry point. */
77 int
78 main (int argc, char **argv)
79 {
80   int *view_width_p, *view_length_p;
81
82   set_program_name (argv[0]);
83
84   signal (SIGABRT, bug_handler);
85   signal (SIGSEGV, bug_handler);
86   signal (SIGFPE, bug_handler);
87   at_fatal_signal (clean_up);
88
89   i18n_init ();
90   fpu_init ();
91   gsl_set_error_handler_off ();
92
93   outp_init ();
94   fn_init ();
95   fh_init ();
96   the_source_stream =
97     create_source_stream (
98                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
99                           );
100   prompt_init ();
101   readln_initialize ();
102   terminal_init (&view_width_p, &view_length_p);
103   settings_init (view_width_p, view_length_p);
104   random_init ();
105
106   the_dataset = create_dataset ();
107
108   if (parse_command_line (argc, argv, the_source_stream))
109     {
110       msg_ui_init (the_source_stream);
111       if (!settings_get_testing_mode ())
112         outp_read_devices ();
113       else
114         outp_configure_driver_line (
115           ss_cstr ("raw-ascii:ascii:listing:width=9999 length=9999 "
116                    "output-file=\"pspp.list\" emphasis=none "
117                    "headers=off paginate=off squeeze=on "
118                    "top-margin=0 bottom-margin=0"));
119       the_lexer = lex_create (the_source_stream);
120
121       for (;;)
122         {
123           int result = cmd_parse (the_lexer, the_dataset);
124
125           if (result == CMD_EOF || result == CMD_FINISH)
126             break;
127           if (result == CMD_CASCADING_FAILURE &&
128               !getl_is_interactive (the_source_stream))
129             {
130               msg (SE, _("Stopping syntax file processing here to avoid "
131                          "a cascade of dependent command failures."));
132               getl_abort_noninteractive (the_source_stream);
133             }
134           else
135             check_msg_count (the_source_stream);
136         }
137     }
138
139   clean_up ();
140   return any_errors ();
141 }
142 \f
143 static void
144 i18n_init (void)
145 {
146 #if ENABLE_NLS
147 #if HAVE_LC_MESSAGES
148   setlocale (LC_MESSAGES, "");
149 #endif
150 #if HAVE_LC_PAPER
151   setlocale (LC_PAPER, "");
152 #endif
153   bindtextdomain (PACKAGE, locale_dir);
154   textdomain (PACKAGE);
155 #endif /* ENABLE_NLS */
156 }
157
158 static void
159 fpu_init (void)
160 {
161 #if HAVE_FEHOLDEXCEPT
162   fenv_t foo;
163   feholdexcept (&foo);
164 #elif HAVE___SETFPUCW && defined(_FPU_IEEE)
165   __setfpucw (_FPU_IEEE);
166 #elif HAVE_FPSETMASK
167   fpsetmask (0);
168 #endif
169 }
170
171 /* If a segfault happens, issue a message to that effect and halt */
172 void
173 bug_handler(int sig)
174 {
175 #if DEBUGGING
176   connect_debugger ();
177 #endif
178   switch (sig)
179     {
180     case SIGABRT:
181       request_bug_report_and_abort("Assertion Failure/Abort");
182     case SIGFPE:
183       request_bug_report_and_abort("Floating Point Exception");
184     case SIGSEGV:
185       request_bug_report_and_abort("Segmentation Violation");
186     default:
187       request_bug_report_and_abort("Unknown");
188     }
189 }
190
191 /* Clean up PSPP in preparation for termination.  */
192 static void
193 clean_up (void)
194 {
195   static bool terminating = false;
196   if (!terminating)
197     {
198       terminating = true;
199
200       destroy_dataset (the_dataset);
201
202       random_done ();
203       settings_done ();
204       fh_done ();
205       lex_destroy (the_lexer);
206       destroy_source_stream (the_source_stream);
207       prompt_done ();
208       readln_uninitialize ();
209       outp_done ();
210       msg_ui_done ();
211     }
212 }