Applying patch #5562
[pspp-builds.git] / src / ui / terminal / main.c
index 2ad53d36d4e4e3da16dea2580ed41c1c439933a7..5b4ad2d3ac54d6002dbb81c51678375298406d36 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
    Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
 #include <signal.h>
 #include <stdio.h>
 
+#include <ui/debugger.h>
 #include "command-line.h"
 #include "msg-ui.h"
 #include "progname.h"
 #include "read-line.h"
 
+
 #include <data/dictionary.h>
 #include <data/file-handle-def.h>
+#include <libpspp/getl.h>
 #include <data/file-name.h>
+#include <data/format.h>
 #include <data/procedure.h>
 #include <data/settings.h>
 #include <data/variable.h>
 #include <gsl/gsl_errno.h>
 #include <language/command.h>
 #include <language/lexer/lexer.h>
-#include <language/line-buffer.h>
+#include <language/prompt.h>
 #include <libpspp/compiler.h>
 #include <libpspp/message.h>
 #include <libpspp/version.h>
@@ -69,12 +73,15 @@ void bug_handler(int sig);
 
 /* Handle quit/term/int signals */
 void interrupt_handler(int sig);
+static struct dataset * the_dataset = NULL;
 
+static struct lexer *the_lexer;
 
 /* Program entry point. */
 int
 main (int argc, char **argv)
 {
+  signal (SIGABRT, bug_handler);
   signal (SIGSEGV, bug_handler);
   signal (SIGFPE, bug_handler);
   signal (SIGINT, interrupt_handler);
@@ -84,25 +91,28 @@ main (int argc, char **argv)
   fpu_init ();
   gsl_set_error_handler_off ();
 
+  fmt_init ();
   outp_init ();
-  msg_ui_init ();
   fn_init ();
   fh_init ();
   getl_initialize ();
+  prompt_init ();
   readln_initialize ();
   settings_init ();
   random_init ();
-  proc_init ();
+  the_dataset = create_dataset ();
 
   if (parse_command_line (argc, argv)) 
     {
+      msg_ui_init ();
       outp_read_devices ();
-      lex_init ();
+      the_lexer = lex_create (do_read_line);
 
       for (;;)
         {
-          int result = cmd_parse (proc_has_source ()
-                                  ? CMD_STATE_DATA : CMD_STATE_INITIAL);
+          int result = cmd_parse (the_lexer, the_dataset, 
+                                 proc_has_source (the_dataset)
+                                 ? CMD_STATE_DATA : CMD_STATE_INITIAL);
           if (result == CMD_EOF || result == CMD_FINISH)
             break;
           if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ())
@@ -147,17 +157,19 @@ fpu_init (void)
 void 
 bug_handler(int sig)
 {
+#if DEBUGGING
+  connect_debugger ();
+#endif
   switch (sig) 
     {
+    case SIGABRT:
+      request_bug_report_and_abort("Assertion Failure/Abort");
     case SIGFPE:
       request_bug_report_and_abort("Floating Point Exception");
-      break;
     case SIGSEGV:
       request_bug_report_and_abort("Segmentation Violation");
-      break;
     default:
-      request_bug_report_and_abort("");
-      break;
+      request_bug_report_and_abort("Unknown");
     }
 }
 
@@ -178,17 +190,19 @@ terminate (bool success)
     {
       terminating = true;
 
-      proc_done ();
+      destroy_dataset (the_dataset);
 
       random_done ();
       settings_done ();
       fh_done ();
-      lex_done ();
+      lex_destroy (the_lexer);
       getl_uninitialize ();
+      prompt_done ();
       readln_uninitialize ();
 
       outp_done ();
       msg_ui_done ();
+      fmt_done ();
     }
   exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
 }