pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src ChangeLog Makefile.am ascii.c cmdline....


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src ChangeLog Makefile.am ascii.c cmdline....
Date: Wed, 14 Dec 2005 06:59:06 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Branch:         
Changes by:     Ben Pfaff <address@hidden>      05/12/14 06:59:06

Modified files:
        src            : ChangeLog Makefile.am ascii.c cmdline.c 
                         command.c error.c error.h glob.c glob.h lexer.c 
                         main.c main.h output.c output.h postscript.c 
                         q2c.c set.q settings.c settings.h title.c vfm.c 
                         vfm.h 
        src/expressions: parse.c 
Removed files:
        src            : log.h 

Log message:
        Move global initialization and cleanup code into main.c.
        Remove vestigial log infrastructure.
        Minor related cleanups.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ChangeLog.diff?tr1=1.252&tr2=1.253&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/Makefile.am.diff?tr1=1.59&tr2=1.60&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ascii.c.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/cmdline.c.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/command.c.diff?tr1=1.28&tr2=1.29&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/error.c.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/error.h.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/glob.c.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/glob.h.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/lexer.c.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/main.c.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/main.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/output.c.diff?tr1=1.22&tr2=1.23&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/output.h.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/postscript.c.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/q2c.c.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/set.q.diff?tr1=1.28&tr2=1.29&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/settings.c.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/settings.h.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/title.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/vfm.c.diff?tr1=1.43&tr2=1.44&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/vfm.h.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/expressions/parse.c.diff?tr1=1.14&tr2=1.15&r1=text&r2=text

Patches:
Index: pspp/src/ChangeLog
diff -u pspp/src/ChangeLog:1.252 pspp/src/ChangeLog:1.253
--- pspp/src/ChangeLog:1.252    Sun Dec 11 07:35:50 2005
+++ pspp/src/ChangeLog  Wed Dec 14 06:59:06 2005
@@ -1,3 +1,65 @@
+Tue Dec 13 22:34:42 2005  Ben Pfaff  <address@hidden>
+
+       Move global initialization and cleanup code into main.c.
+       Remove vestigial log infrastructure.
+       Minor related cleanups.
+       
+       * command.c: (shell) When execl() fails, use _exit(), not
+       err_hcf().
+
+       * error.c: (err_hcf) Move into main.c, rename terminate().  All
+       callers updated.
+       (err_done) New function with just the error.c-specific code for
+       err_hcf().  Called by terminate().
+
+       * glob.c: Removed all Borland C, DJGPP cruft.
+       (init_glob) Merged into main().
+       (done_glob) Merged into terminate().
+       (get_date) Removed.
+       (get_start_date) New function.  All users of curdate updated to call
+       this function instead.
+
+       * lexer.c: (lex_init) Moved initialization of tokstr here, from
+       init_glob().
+       (lex_done) Moved destruction of tokstr here, from done_glob().
+
+       * main.c: (global var pgmname) Removed.  Changed all references to
+       program_name, which is defined by gnulib.
+       (global var curdate) Removed.
+       (main) Moved init_glob() code here.  Merged parse_script() in
+       here.
+       (parse_script) Removed.
+       (terminate) Moved err_hcf() here from error.c and renamed
+       terminate().  Merged done_glob() code in here.  Call err_done().
+       All callers updated.
+       (i18n_init) New function.
+       (fpu_init) New function.
+
+       * output.c: (outp_init) Make void.
+       (init_default_drivers) New function.
+       (outp_read_devices) If no drivers are initialized successfully,
+       call init_default_drivers() to initialize a default driver.
+       (outp_done) Make void.
+       (static var prog) Make const.
+       (parse_options) Make parameter const.
+       (colon_tokenize) Make return value const.
+       (configure_driver) Change prototype to take a broken-down driver
+       configuration instead of a line of text.
+       (configure_driver_line) New function that does what
+       configure_driver() did before.
+
+       * q2c.c: (global var pgmname) Rename program_name.
+
+       * settings.c: (settings_init) Renamed from init_settings().
+       (settings_done) Renamed from done_settings().
+
+       * vfm.c: (global var last_vfm_invocation) Make static.
+       (vfm_last_invocation) New function.  All references to
+       last_vfm_invocation update to call this.
+       (procedure) Call update_last_vfm_invocation().
+       (internal_procedure) Ditto.
+       (update_last_vfm_invocation) New function.
+       
 Sat Dec 10 23:30:19 2005  Ben Pfaff  <address@hidden>
 
        Separate random numbers from other settings because of GSL
Index: pspp/src/Makefile.am
diff -u pspp/src/Makefile.am:1.59 pspp/src/Makefile.am:1.60
--- pspp/src/Makefile.am:1.59   Sun Dec 11 07:35:51 2005
+++ pspp/src/Makefile.am        Wed Dec 14 06:59:06 2005
@@ -158,7 +158,6 @@
        levene.h                                \
        linked-list.c                           \
        linked-list.h                           \
-       log.h                                   \
        loop.c                                  \
        magic.c                                 \
        magic.h                                 \
Index: pspp/src/ascii.c
diff -u pspp/src/ascii.c:1.19 pspp/src/ascii.c:1.20
--- pspp/src/ascii.c:1.19       Wed Oct 26 05:06:14 2005
+++ pspp/src/ascii.c    Wed Dec 14 06:59:06 2005
@@ -26,6 +26,7 @@
 #include "alloc.h"
 #include "error.h"
 #include "filename.h"
+#include "glob.h"
 #include "main.h"
 #include "misc.h"
 #include "output.h"
@@ -1579,7 +1580,8 @@
       {
        char temp[40];
 
-       snprintf (temp, 80, _("%s - Page %d"), curdate, x->page_number);
+       snprintf (temp, 80, _("%s - Page %d"), get_start_date (),
+                  x->page_number);
        memcpy (&s[x->w - strlen (temp)], temp, strlen (temp));
       }
 
Index: pspp/src/cmdline.c
diff -u pspp/src/cmdline.c:1.14 pspp/src/cmdline.c:1.15
--- pspp/src/cmdline.c:1.14     Sun Dec 11 02:48:45 2005
+++ pspp/src/cmdline.c  Wed Dec 14 06:59:06 2005
@@ -26,17 +26,18 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include "alloc.h"
+#include "copyleft.h"
 #include "error.h"
 #include "filename.h"
 #include "getl.h"
+#include "glob.h"
 #include "main.h"
 #include "output.h"
+#include "progname.h"
 #include "settings.h"
 #include "str.h"
 #include "var.h"
 #include "version.h"
-#include "copyleft.h"
-#include "glob.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -158,7 +159,7 @@
          break;
        case 'l':
          outp_list_classes ();
-         err_hcf (1);
+         terminate (true);
        case 'n':
          printf (_("%s is not yet implemented."),"-n");
           putchar('\n');
@@ -187,7 +188,7 @@
        case 'V':
          puts (version);
          puts (legal);
-         err_hcf (1);
+         terminate (true);
         case 'T':
           force_long_view ();
           set_testing_mode (true);
@@ -282,9 +283,9 @@
 static void
 usage (void)
 {
-  printf (gettext (pre_syntax_message), pgmname);
+  printf (gettext (pre_syntax_message), program_name);
   outp_list_classes ();
-  printf (gettext (post_syntax_message),PACKAGE_BUGREPORT);
+  printf (gettext (post_syntax_message), PACKAGE_BUGREPORT);
 
-  err_hcf (1);
+  terminate (true);
 }
Index: pspp/src/command.c
diff -u pspp/src/command.c:1.28 pspp/src/command.c:1.29
--- pspp/src/command.c:1.28     Sun Dec 11 02:48:45 2005
+++ pspp/src/command.c  Wed Dec 14 06:59:06 2005
@@ -739,7 +739,7 @@
        
        execl (shell_fn, shell_process, NULL);
 
-       err_hcf (1);
+       _exit (1);
       }
 
     case -1:
Index: pspp/src/error.c
diff -u pspp/src/error.c:1.18 pspp/src/error.c:1.19
--- pspp/src/error.c:1.18       Wed Oct 26 05:06:14 2005
+++ pspp/src/error.c    Wed Dec 14 06:59:06 2005
@@ -30,6 +30,7 @@
 #include "lexer.h"
 #include "main.h"
 #include "output.h"
+#include "progname.h"
 #include "settings.h"
 #include "str.h"
 #include "var.h"
@@ -93,10 +94,10 @@
   fflush (stdout);
   fflush (stderr);
 
-  fprintf (stderr, "%s: %s\n", pgmname,
+  fprintf (stderr, "%s: %s\n", program_name,
           _("Terminating NOW due to a fatal error!"));
 
-  err_hcf (0);
+  terminate (false);
 }
 
 /* Terminate unless we're interactive or will go interactive when the
@@ -193,33 +194,18 @@
 #define EXIT_FAILURE 1
 #endif
 
-static int terminating;
+static void puts_stdout (const char *s);
+static void dump_message (char *errbuf, unsigned indent,
+                         void (*func) (const char *), unsigned width);
 
-/* Halt-catch-fire.  SUCCESS should be nonzero if exiting successfully
-   or zero if not.  Despite the name, this is the usual way to finish,
-   successfully or not. */
 void
-err_hcf (int success)
+err_done (void) 
 {
-  terminating = 1;
-
-  lex_done();
-  getl_uninitialize ();
-
-  free(file_loc);
+  free (file_loc);
   file_loc = NULL;
   nfile_loc = mfile_loc = 0;
-  
-  outp_done ();
-  done_glob();
-
-  exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
-static void puts_stdout (const char *s);
-static void dump_message (char *errbuf, unsigned indent,
-                         void (*func) (const char *), unsigned width);
-
 void
 err_vmsg (const struct error *e, const char *format, va_list args)
 {
@@ -304,8 +290,8 @@
 
   ds_destroy (&msg);
 
-  if (e->class == FE && !terminating)
-    err_hcf (0);
+  if (e->class == FE)
+    terminate (0);
 }
 
 /* Private functions. */
Index: pspp/src/error.h
diff -u pspp/src/error.h:1.6 pspp/src/error.h:1.7
--- pspp/src/error.h:1.6        Fri Apr 29 01:02:14 2005
+++ pspp/src/error.h    Wed Dec 14 06:59:06 2005
@@ -81,9 +81,9 @@
 void err_location (struct file_locator *);
 
 /* Obscure functions. */
+void err_done (void);
 void err_break (void);
 void err_check_count (void);
-void err_hcf (int exit_code) NO_RETURN;
 void err_vmsg (const struct error *, const char *, va_list);
 
 /* Used in panic situations only */
Index: pspp/src/expressions/parse.c
diff -u pspp/src/expressions/parse.c:1.14 pspp/src/expressions/parse.c:1.15
--- pspp/src/expressions/parse.c:1.14   Thu Nov  3 06:21:47 2005
+++ pspp/src/expressions/parse.c        Wed Dec 14 06:59:06 2005
@@ -731,6 +731,7 @@
           "JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
         };
 
+      time_t last_vfm_invocation = vfm_last_invocation ();
       struct tm *time;
       char temp_buf[10];
 
@@ -748,21 +749,23 @@
     return expr_allocate_number (e, SYSMIS);
   else if (lex_match_id ("$JDATE"))
     {
-      struct tm *time = localtime (&last_vfm_invocation);
-      return expr_allocate_number (e, expr_ymd_to_ofs (time->tm_year + 1900,
-                                                       time->tm_mon + 1,
-                                                       time->tm_mday));
+      time_t time = vfm_last_invocation ();
+      struct tm *tm = localtime (&time);
+      return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900,
+                                                       tm->tm_mon + 1,
+                                                       tm->tm_mday));
     }
   else if (lex_match_id ("$TIME"))
     {
-      struct tm *time = localtime (&last_vfm_invocation);
+      time_t time = vfm_last_invocation ();
+      struct tm *tm = localtime (&time);
       return expr_allocate_number (e,
-                                   expr_ymd_to_date (time->tm_year + 1900,
-                                                     time->tm_mon + 1,
-                                                     time->tm_mday)
-                                   + time->tm_hour * 60 * 60.
-                                   + time->tm_min * 60.
-                                   + time->tm_sec);
+                                   expr_ymd_to_date (tm->tm_year + 1900,
+                                                     tm->tm_mon + 1,
+                                                     tm->tm_mday)
+                                   + tm->tm_hour * 60 * 60.
+                                   + tm->tm_min * 60.
+                                   + tm->tm_sec);
     }
   else if (lex_match_id ("$LENGTH"))
     return expr_allocate_number (e, get_viewlength ());
Index: pspp/src/glob.c
diff -u pspp/src/glob.c:1.32 pspp/src/glob.c:1.33
--- pspp/src/glob.c:1.32        Sun Dec 11 07:35:51 2005
+++ pspp/src/glob.c     Wed Dec 14 06:59:06 2005
@@ -19,66 +19,9 @@
 
 #include <config.h>
 #include "glob.h"
-#include "error.h"
-#include "progname.h"
-#include <stdlib.h>
-#include <stdio.h>
 #include <time.h>
-
-#if HAVE_LIBHISTORY
-#if HAVE_READLINE_HISTORY_H
-#include <readline/history.h>
-#else /* no readline/history.h */
-extern void using_history ();
-extern int read_history ();
-extern void stifle_history ();
-#endif /* no readline/history.h */
-#endif /* -lhistory */
-
-#if HAVE_FPU_CONTROL_H
-#include <fpu_control.h>
-#elif __BORLANDC__
-#include <float.h>
-#include <math.h>
-#endif
-
-#if __DJGPP__
-#include <conio.h>
-#elif defined (__WIN32__) && defined (__BORLANDC__)
-#undef gettext
-#include <conio.h>
-#define gettext(STRING)                                \
-       STRING
-#endif
-
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
-#if HAVE_FENV_H
-#include <fenv.h>
-#endif
-
-#include "alloc.h"
-#include "calendar.h"
-#include "command.h"
-#include "dictionary.h"
-#include "error.h"
-#include "file-handle.h"
-#include "filename.h"
-#include "getl.h"
-#include "hash.h"
-#include "lexer.h"
-#include "magic.h"
-#include "main.h"
-#include "random.h"
-#include "settings.h"
 #include "str.h"
-#include "var.h"
-#include "version.h"
-#include "vfm.h"
-
-#include "gettext.h"
+#include "strftime.h"
 
 /* var.h */
 struct dictionary *default_dict;
@@ -90,128 +33,32 @@
 int FILTER_before_TEMPORARY;
 
 struct file_handle *default_handle;
-
-/* log.h */
-char *logfn;
-FILE *logfile;
-int logging;
 
 /* Functions. */
 
-static void get_date (void);
-
-
-void
-init_glob (int argc UNUSED, char **argv)
-{
-  set_program_name (argv[0]);
-
-  /* FIXME: Allow i18n of other locale items (besides LC_MESSAGES). */
-#if ENABLE_NLS
-#if HAVE_LC_MESSAGES
-  setlocale (LC_MESSAGES, "");
-#endif
-  setlocale (LC_MONETARY, "");
-  bindtextdomain (PACKAGE, locale_dir);
-  textdomain (PACKAGE);
-#endif /* ENABLE_NLS */
-
-  fn_init ();
-  fh_init ();
-  getl_initialize ();
-
-  /* PORTME: If your system/OS has the nasty tendency to halt with a
-     SIGFPE whenever there's a floating-point overflow (or other
-     exception), be sure to mask off those bits in the FPU here.
-     PSPP wants a guarantee that, no matter what boneheaded
-     floating-point operation it performs, the process will not halt.  */
-#if HAVE_FEHOLDEXCEPT
-  {
-    fenv_t foo;
-
-    feholdexcept (&foo);
-  }
-#elif HAVE___SETFPUCW && defined(_FPU_IEEE)
-  __setfpucw (_FPU_IEEE);
-#elif __BORLANDC__
-  _control87 (0xffff, 0x137f);
-#endif
-
-  /* var.h */
-  default_dict = dict_create ();
-
-  last_vfm_invocation = time (NULL);
-
-  /* lexer.h */
-  ds_init (&tokstr, 64);
-
-  /* common.h */
-  {
-    char *cp;
-    
-    pgmname = argv[0];
-    for (;;)
-      {
-       cp = strchr (pgmname, DIR_SEPARATOR);
-       if (!cp)
-         break;
-       pgmname = &cp[1];
-      }
-    cur_proc = NULL;
-  }
-
-
-  init_settings ();
-  random_init ();
-
-  /* log.h */
-  logging = 1;
-  logfn = xstrdup ("pspp.log");
-  logfile = NULL;
-
-  get_date ();
-}
-
-void
-done_glob(void)
-{
-  cancel_transformations ();
-  dict_destroy (default_dict);
-  free (logfn);
-  random_done ();
-  done_settings ();
-  ds_destroy (&tokstr);
-
-  fh_done();
-}
-
 static void
-get_date (void)
+get_cur_date (char cur_date[12])
 {
+  time_t now = time (NULL);
 
-  time_t t;
-  struct tm *tmp;
-
-  if ((time_t) -1 == time (&t))
+  if (now != (time_t) -1) 
     {
-      strcpy (curdate, "?? ??? 2???");
-      return;
+      struct tm *tm = localtime (&now);
+      if (tm != NULL) 
+        {
+          strftime (cur_date, 12, "%d %b %Y", tm);
+          return;
+        }
     }
-  tmp = localtime (&t);
-
-  strftime (curdate, 12, "%d %b %Y",tmp);
+  strcpy (cur_date, "?? ??? 2???");
 }
 
-#if __BORLANDC__
-int
-_RTLENTRY _EXPFUNC _matherr (struct exception _FAR *__e)
+const char *
+get_start_date (void)
 {
-  return 1;
-}
+  static char start_date[12];
 
-int
-_RTLENTRY _EXPFUNC _matherrl (struct _exceptionl _FAR *__e)
-{
-  return 1;
+  if (start_date[0] == '\0')
+    get_cur_date (start_date);
+  return start_date; 
 }
-#endif
Index: pspp/src/glob.h
diff -u pspp/src/glob.h:1.6 pspp/src/glob.h:1.7
--- pspp/src/glob.h:1.6 Sun Dec 11 02:48:45 2005
+++ pspp/src/glob.h     Wed Dec 14 06:59:06 2005
@@ -17,10 +17,9 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA. */
 
-#if !INCLUDED_GLOB_H
-#define INCLUDED_GLOB_H 1
+#if !GLOB_H
+#define GLOB_H 1
 
-void init_glob (int argc UNUSED, char **argv);
-void done_glob (void);
+const char *get_start_date (void);
 
 #endif /* glob.h */
Index: pspp/src/lexer.c
diff -u pspp/src/lexer.c:1.24 pspp/src/lexer.c:1.25
--- pspp/src/lexer.c:1.24       Sun Dec 11 02:48:45 2005
+++ pspp/src/lexer.c    Wed Dec 14 06:59:06 2005
@@ -92,6 +92,7 @@
 void
 lex_init (void)
 {
+  ds_init (&tokstr, 64);
   ds_init (&put_tokstr, 64);
   if (!lex_get_line ())
     unexpected_eof ();
@@ -100,7 +101,8 @@
 void
 lex_done (void)
 {
-  ds_destroy(&put_tokstr);
+  ds_destroy (&put_tokstr);
+  ds_destroy (&tokstr);
 }
 
 
Index: pspp/src/main.c
diff -u pspp/src/main.c:1.18 pspp/src/main.c:1.19
--- pspp/src/main.c:1.18        Sun Jul 31 21:42:46 2005
+++ pspp/src/main.c     Wed Dec 14 06:59:06 2005
@@ -18,20 +18,37 @@
    02110-1301, USA. */
 
 #include <config.h>
-#include <stdio.h>
-#include <gsl/gsl_errno.h>
 #include "main.h"
+#include <gsl/gsl_errno.h>
+#include <signal.h>
+#include <stdio.h>
 #include "cmdline.h"
 #include "command.h"
 #include "dictionary.h"
 #include "error.h"
+#include "file-handle.h"
+#include "filename.h"
 #include "getl.h"
 #include "glob.h"
 #include "lexer.h"
 #include "output.h"
+#include "progname.h"
+#include "random.h"
 #include "settings.h"
 #include "var.h"
-#include <signal.h>
+#include "version.h"
+
+#if HAVE_FPU_CONTROL_H
+#include <fpu_control.h>
+#endif
+
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#if HAVE_FENV_H
+#include <fenv.h>
+#endif
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -40,20 +57,14 @@
 
 #include "debug-print.h"
 
-static void parse_script (void) NO_RETURN;
+static void i18n_init (void);
+static void fpu_init (void);
 static void handle_error (int code);
 static int execute_command (void);
 
-/* argv[0] with stripped leading directories. */
-char *pgmname;
-
 /* Whether FINISH. has been executed. */
 int finished;
 
-/* The current date in the form DD MMM YYYY. */
-char curdate[12];
-
-
 /* If a segfault happens, issue a message to that effect and halt */
 void bug_handler(int sig);
 
@@ -64,50 +75,66 @@
    we hit end-of-file unexpectedly (or whatever). */
 int start_interactive;
 
-
-
-
-
-
 /* Program entry point. */
 int
 main (int argc, char **argv)
 {
-
   signal (SIGSEGV, bug_handler);
-  signal (SIGFPE,  bug_handler);
-  signal (SIGINT,  interrupt_handler);
+  signal (SIGFPE, bug_handler);
+  signal (SIGINT, interrupt_handler);
 
-  gsl_set_error_handler_off();
+  set_program_name ("pspp");
+  i18n_init ();
+  fpu_init ();
+  gsl_set_error_handler_off ();
+
+  outp_init ();
+  fn_init ();
+  fh_init ();
+  getl_initialize ();
+  settings_init ();
+  random_init ();
+
+  default_dict = dict_create ();
 
-  /* Initialization. */
-  if (!outp_init ())
-    err_hcf (0);
-  init_glob (argc, argv);
   parse_command_line (argc, argv);
-  if (!outp_read_devices ())
-    msg (FE, _("Error initializing output drivers."));
+  outp_read_devices ();
 
   lex_init ();
 
-  /* Execution. */
-  parse_script ();
-
-  /* Should never be reached */
-  return (-1);
-}
-
-/* Parses the entire script. */
-static void
-parse_script (void)
-{
   while (!finished)
     {
       err_check_count ();
       handle_error (execute_command ());
     }
 
-  err_hcf (err_error_count==0);
+  terminate (err_error_count == 0);
+  abort ();
+}
+
+/* Terminate PSPP.  SUCCESS should be true to exit successfully,
+   false to exit as a failure.  */
+void
+terminate (bool success)
+{
+  static bool terminating = false;
+  if (terminating)
+    return;
+  terminating = true;
+
+  err_done ();
+  outp_done ();
+
+  cancel_transformations ();
+  dict_destroy (default_dict);
+
+  random_done ();
+  settings_done ();
+  fh_done ();
+  lex_done ();
+  getl_uninitialize ();
+
+  exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
 }
 
 /* Parse and execute a command, returning its return code. */
@@ -129,7 +156,7 @@
        break;
 
       if (!getl_perform_delayed_reset ())
-       err_hcf (err_error_count==0);
+       terminate (err_error_count == 0);
     }
 
   /* Parse the command. */
@@ -191,12 +218,34 @@
       lex_discard_line (); 
     }
 }
+
+static void
+i18n_init (void) 
+{
+#if ENABLE_NLS
+#if HAVE_LC_MESSAGES
+  setlocale (LC_MESSAGES, "");
+#endif
+  setlocale (LC_MONETARY, "");
+  bindtextdomain (PACKAGE, locale_dir);
+  textdomain (PACKAGE);
+#endif /* ENABLE_NLS */
+}
 
-
+static void
+fpu_init (void) 
+{
+#if HAVE_FEHOLDEXCEPT
+  fenv_t foo;
+  feholdexcept (&foo);
+#elif HAVE___SETFPUCW && defined(_FPU_IEEE)
+  __setfpucw (_FPU_IEEE);
+#endif
+}
 
 /* If a segfault happens, issue a message to that effect and halt */
 void 
-bug_handler(int sig UNUSED)
+bug_handler(int sig)
 {
   switch (sig) 
     {
@@ -216,5 +265,5 @@
 void 
 interrupt_handler(int sig UNUSED)
 {
-  err_hcf(0);
+  terminate (false);
 }
Index: pspp/src/main.h
diff -u pspp/src/main.h:1.2 pspp/src/main.h:1.3
--- pspp/src/main.h:1.2 Fri Apr 29 01:02:15 2005
+++ pspp/src/main.h     Wed Dec 14 06:59:06 2005
@@ -17,12 +17,14 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA. */
 
-#if !main_h
-#define main_h 1
+#if !MAIN_H
+#define MAIN_H 1
+
+#include <stdbool.h>
 
-extern char *pgmname;
-extern char curdate[];
 extern int start_interactive;
 extern int finished;
 
+void terminate (bool success);
+
 #endif /* main.h */
Index: pspp/src/output.c
diff -u pspp/src/output.c:1.22 pspp/src/output.c:1.23
--- pspp/src/output.c:1.22      Sun Dec 11 02:48:45 2005
+++ pspp/src/output.c   Wed Dec 14 06:59:06 2005
@@ -79,7 +79,9 @@
 static int disabled_devices;
 
 static void destroy_driver (struct outp_driver *);
-static void configure_driver (char *);
+static void configure_driver_line (char *);
+static void configure_driver (const char *, const char *,
+                              const char *, const char *);
 
 #if GLOBAL_DEBUGGING
 /* This mechanism attempts to catch reentrant use of outp_driver_list. */
@@ -221,7 +223,7 @@
 }
 
 /* Initializes global variables. */
-int
+void
 outp_init (void)
 {
   extern struct outp_class ascii_class;
@@ -229,7 +231,9 @@
   extern struct outp_class postscript_class;
   extern struct outp_class epsf_class;
 #endif
+#if !NO_HTML
   extern struct outp_class html_class;
+#endif
 
   char def[] = "default";
 
@@ -243,8 +247,6 @@
   add_class (&ascii_class);
 
   add_name (def, &def[strlen (def)], OUTP_S_INIT_FILE);
-
-  return 1;
 }
 
 /* Deletes all the output macros. */
@@ -262,8 +264,19 @@
     }
 }
 
-/* Reads the initialization file; initializes outp_driver_list. */
-int
+static void
+init_default_drivers (void) 
+{
+  msg (MM, _("Using default output driver configuration."));
+  configure_driver ("list-ascii", "ascii", "listing",
+                    "length=66 width=79 char-set=ascii "
+                    "output-file=\"pspp.list\" "
+                    "bold-on=\"\" italic-on=\"\" bold-italic-on=\"\"");
+}
+
+/* Reads the initialization file; initializes
+   outp_driver_list. */
+void
 outp_read_devices (void)
 {
   int result = 0;
@@ -329,7 +342,7 @@
              struct outp_names *n = search_names (cp, ep);
              if (n)
                {
-                 configure_driver (cp);
+                 configure_driver_line (cp);
                  delete_name (n);
                }
            }
@@ -348,14 +361,18 @@
   free (init_fn);
   ds_destroy (&line);
   delete_macros ();
-  if (outp_driver_list == NULL)
-    msg (MW, _("No output drivers are active."));
 
-  if (result)
-    msg (VM (2), _("Device definition file read successfully."));
+  if (result) 
+    {
+      msg (VM (2), _("Device definition file read successfully."));
+      if (outp_driver_list == NULL) 
+        msg (MW, _("No output drivers are active.")); 
+    }
   else
     msg (VM (1), _("Error reading device definition file."));
-  return result;
+
+  if (!result || outp_driver_list == NULL)
+    init_default_drivers ();
 }
 
 /* Clear the list of drivers to configure. */
@@ -439,7 +456,7 @@
 }
 
 /* Closes all the output drivers. */
-int
+void
 outp_done (void)
 {
   struct outp_driver_class_list *n = outp_class_list ; 
@@ -462,8 +479,6 @@
   
   free (outp_subtitle);
   outp_subtitle = NULL;
-
-  return 1;
 }
 
 /* Display on stdout a list of all registered driver classes. */
@@ -491,7 +506,7 @@
 
 static int op_token;           /* `=', 'a', 0. */
 static struct string op_tokstr;
-static char *prog;
+static const char *prog;
 
 /* Parses a token from prog into op_token, op_tokstr.  Sets op_token
    to '=' on an equals sign, to 'a' on a string or identifier token,
@@ -622,7 +637,7 @@
 /* Applies the user-specified options in string S to output driver D
    (at configuration time). */
 static void
-parse_options (char *s, struct outp_driver * d)
+parse_options (const char *s, struct outp_driver * d)
 {
   prog = s;
   op_token = -1;
@@ -683,7 +698,7 @@
    after all fields have been used up.
 
    FIXME: Should ignore colons inside double quotes. */
-static char *
+static const char *
 colon_tokenize (char *s, char **cp)
 {
   char *token;
@@ -711,49 +726,27 @@
    Adds a driver to outp_driver_list pursuant to the specification
    provided.  */
 static void
-configure_driver (char *s)
+configure_driver (const char *driver_name, const char *class_name,
+                  const char *device_type, const char *options)
 {
-  char *token, *cp;
   struct outp_driver *d = NULL, *iter;
   struct outp_driver_class_list *c = NULL;
 
-  s = fn_interp_vars (s, find_defn_value);
-
-  /* Driver name. */
-  token = colon_tokenize (s, &cp);
-  if (!token)
-    {
-      msg (IS, _("Driver name expected."));
-      goto error;
-    }
-
   d = xmalloc (sizeof *d);
-
   d->class = NULL;
-  d->name = xstrdup (token);
+  d->name = xstrdup (driver_name);
   d->driver_open = 0;
   d->page_open = 0;
-
   d->next = d->prev = NULL;
-
   d->device = OUTP_DEV_NONE;
-  
   d->ext = NULL;
 
-  /* Class name. */
-  token = colon_tokenize (NULL, &cp);
-  if (!token)
-    {
-      msg (IS, _("Class name expected."));
-      goto error;
-    }
-
   for (c = outp_class_list; c; c = c->next)
-    if (!strcmp (c->class->name, token))
+    if (!strcmp (c->class->name, class_name))
       break;
   if (!c)
     {
-      msg (IS, _("Unknown output driver class `%s'."), token);
+      msg (IS, _("Unknown output driver class `%s'."), class_name);
       goto error;
     }
   
@@ -773,12 +766,12 @@
     }
 
   /* Device types. */
-  token = colon_tokenize (NULL, &cp);
-  if (token)
+  if (device_type != NULL)
     {
+      char *copy = xstrdup (device_type);
       char *sp, *type;
 
-      for (type = strtok_r (token, " \t\r\v", &sp); type;
+      for (type = strtok_r (copy, " \t\r\v", &sp); type;
           type = strtok_r (NULL, " \t\r\v", &sp))
        {
          if (!strcmp (type, "listing"))
@@ -790,15 +783,16 @@
          else
            {
              msg (IS, _("Unknown device type `%s'."), type);
+              free (copy);
              goto error;
            }
        }
+      free (copy);
     }
   
   /* Options. */
-  token = colon_tokenize (NULL, &cp);
-  if (token)
-    parse_options (token, d);
+  if (options != NULL)
+    parse_options (options, d);
   if (!d->class->postopen_driver (d))
     {
       msg (IS, _("Can't complete initialization of output driver `%s' of "
@@ -817,13 +811,39 @@
   if (outp_driver_list)
     outp_driver_list->prev = d;
   outp_driver_list = d;
-  goto exit;
+  return;
 
 error:
   if (d)
     destroy_driver (d);
-exit:
-  free (s);
+  return;
+}
+
+/* String S is in format:
+   DRIVERNAME:CLASSNAME:DEVICETYPE:OPTIONS
+   Adds a driver to outp_driver_list pursuant to the specification
+   provided.  */
+static void
+configure_driver_line (char *s)
+{
+  char *cp;
+  const char *driver_name, *class_name, *device_type, *options;
+
+  s = fn_interp_vars (s, find_defn_value);
+
+  /* Driver name. */
+  driver_name = colon_tokenize (s, &cp);
+  class_name = colon_tokenize (NULL, &cp);
+  device_type = colon_tokenize (NULL, &cp);
+  options = colon_tokenize (NULL, &cp);
+  if (driver_name == NULL || class_name == NULL)
+    {
+      msg (IS, _("Driver definition line contains fewer fields "
+                 "than expected"));
+      return;
+    }
+
+  configure_driver (driver_name, class_name, device_type, options);
 }
 
 /* Destroys output driver D. */
Index: pspp/src/output.h
diff -u pspp/src/output.h:1.8 pspp/src/output.h:1.9
--- pspp/src/output.h:1.8       Mon Jun 13 06:51:13 2005
+++ pspp/src/output.h   Wed Dec 14 06:59:06 2005
@@ -242,9 +242,9 @@
 extern char *outp_title;
 extern char *outp_subtitle;
 
-int outp_init (void);
-int outp_read_devices (void);
-int outp_done (void);
+void outp_init (void);
+void outp_read_devices (void);
+void outp_done (void);
 
 void outp_configure_clear (void);
 void outp_configure_add (char *);
Index: pspp/src/postscript.c
diff -u pspp/src/postscript.c:1.23 pspp/src/postscript.c:1.24
--- pspp/src/postscript.c:1.23  Wed Oct 26 05:06:14 2005
+++ pspp/src/postscript.c       Wed Dec 14 06:59:06 2005
@@ -40,10 +40,10 @@
 #include "font.h"
 #include "getl.h"
 #include "getline.h"
+#include "glob.h"
 #include "hash.h"
 #include "main.h"
 #include "misc.h"
-#include "misc.h"
 #include "output.h"
 #include "som.h"
 #include "version.h"
@@ -2105,7 +2105,7 @@
     int rh_width;
     char buf[128];
 
-    sprintf (buf, _("%s - Page %d"), curdate, ext->page_number);
+    sprintf (buf, _("%s - Page %d"), get_start_date (), ext->page_number);
     rh_width = text_width (this, buf);
 
     out_text_plain (this, buf, this->width - this->prop_em_width - rh_width,
Index: pspp/src/q2c.c
diff -u pspp/src/q2c.c:1.27 pspp/src/q2c.c:1.28
--- pspp/src/q2c.c:1.27 Sun Dec 11 02:48:45 2005
+++ pspp/src/q2c.c      Wed Dec 14 06:59:06 2005
@@ -53,7 +53,7 @@
 #define MAX_TOK_LEN 1024
 
 /* argv[0]. */
-char *pgmname;
+char *program_name;
 
 /* Have the input and output files been opened yet? */
 int is_open;
@@ -97,7 +97,7 @@
   fclose (in);
   fclose (out);
   if (remove (ofn) == -1)
-    fprintf (stderr, "%s: %s: remove: %s\n", pgmname, ofn, strerror (errno));
+    fprintf (stderr, "%s: %s: remove: %s\n", program_name, ofn, strerror 
(errno));
 }
 
 void hcf (void) NO_RETURN;
@@ -120,7 +120,7 @@
   va_list args;
 
   va_start (args, format);
-  fprintf (stderr, "%s: ", pgmname);
+  fprintf (stderr, "%s: ", program_name);
   vfprintf (stderr, format, args);
   fprintf (stderr, "\n");
   va_end (args);
@@ -1992,7 +1992,7 @@
 int
 main (int argc, char *argv[])
 {
-  pgmname = argv[0];
+  program_name = argv[0];
   if (argc != 3)
     fail ("Syntax: q2c input.q output.c");
 
Index: pspp/src/set.q
diff -u pspp/src/set.q:1.28 pspp/src/set.q:1.29
--- pspp/src/set.q:1.28 Sun Dec 11 07:35:51 2005
+++ pspp/src/set.q      Wed Dec 14 06:59:06 2005
@@ -30,7 +30,6 @@
 #include "lexer.h"
 #include "error.h"
 #include "magic.h"
-#include "log.h"
 #include "output.h"
 #include "random.h"
 #include "var.h"
Index: pspp/src/settings.c
diff -u pspp/src/settings.c:1.2 pspp/src/settings.c:1.3
--- pspp/src/settings.c:1.2     Sun Dec 11 07:35:51 2005
+++ pspp/src/settings.c Wed Dec 14 06:59:06 2005
@@ -89,17 +89,17 @@
 static void init_viewport (void);
 
 void
-done_settings (void)
+settings_init (void)
 {
-  free (prompt);
-  free (cprompt);
-  free (dprompt);
+  init_viewport ();
 }
 
 void
-init_settings (void)
+settings_done (void)
 {
-  init_viewport ();
+  free (prompt);
+  free (cprompt);
+  free (dprompt);
 }
 
 /* Screen length in lines. */
Index: pspp/src/settings.h
diff -u pspp/src/settings.h:1.11 pspp/src/settings.h:1.12
--- pspp/src/settings.h:1.11    Sun Dec 11 07:35:51 2005
+++ pspp/src/settings.h Wed Dec 14 06:59:06 2005
@@ -32,8 +32,8 @@
     SET_ROUTE_DISABLE = 010    /* Disable output--overrides all other bits. */
   };
 
-void init_settings (void);
-void done_settings (void);
+void settings_init (void);
+void settings_done (void);
 
 void force_long_view (void);
 int get_viewlength (void);
Index: pspp/src/title.c
diff -u pspp/src/title.c:1.10 pspp/src/title.c:1.11
--- pspp/src/title.c:1.10       Sun Jul 31 21:42:46 2005
+++ pspp/src/title.c    Wed Dec 14 06:59:06 2005
@@ -24,6 +24,7 @@
 #include "command.h"
 #include "dictionary.h"
 #include "error.h"
+#include "glob.h"
 #include "lexer.h"
 #include "main.h"
 #include "output.h"
@@ -135,14 +136,11 @@
   /* Add a few header lines for reference. */
   {
     char buf[256];
-    struct tm *tmp = localtime (&last_vfm_invocation);
 
     if (dict_get_documents (default_dict) != NULL)
       add_document_line ("", 0);
 
-    sprintf (buf, _("Document entered %s %02d:%02d:%02d by %s (%s):"),
-            curdate, tmp->tm_hour, tmp->tm_min, tmp->tm_sec, version,
-            host_system);
+    sprintf (buf, _("Document entered %s by %s:"), get_start_date (), version);
     add_document_line (buf, 1);
   }
 
Index: pspp/src/vfm.c
diff -u pspp/src/vfm.c:1.43 pspp/src/vfm.c:1.44
--- pspp/src/vfm.c:1.43 Thu Nov  3 06:21:47 2005
+++ pspp/src/vfm.c      Wed Dec 14 06:59:06 2005
@@ -80,7 +80,7 @@
 static int compaction_necessary;
 
 /* Time at which vfm was last invoked. */
-time_t last_vfm_invocation;
+static time_t last_vfm_invocation;
 
 /* Lag queue. */
 int n_lag;                     /* Number of cases to lag. */
@@ -90,6 +90,7 @@
 
 static void internal_procedure (int (*proc_func) (struct ccase *, void *),
                                 void *aux);
+static void update_last_vfm_invocation (void);
 static void create_trns_case (struct ccase *, struct dictionary *);
 static void open_active_file (void);
 static int write_case (struct write_case_data *wc_data);
@@ -104,6 +105,15 @@
 
 /* Public functions. */
 
+/* Returns the last time the data was read. */
+time_t
+vfm_last_invocation (void) 
+{
+  if (last_vfm_invocation == 0)
+    update_last_vfm_invocation ();
+  return last_vfm_invocation;
+}
+
 /* Reads the data from the input program and writes it to a new
    active file.  For each case we read from the input program, we
    do the following
@@ -136,6 +146,7 @@
       && n_trns == 0)
     {
       /* Nothing to do. */
+      update_last_vfm_invocation ();
       return;
     }
 
@@ -162,7 +173,7 @@
   case_create (&wc_data.sink_case, dict_get_next_value_idx (default_dict));
   wc_data.cases_written = 0;
 
-  last_vfm_invocation = time (NULL);
+  update_last_vfm_invocation ();
 
   if (vfm_source != NULL) 
     vfm_source->class->read (vfm_source,
@@ -175,6 +186,13 @@
   assert (--recursive_call == 0);
 }
 
+/* Updates last_vfm_invocation. */
+static void
+update_last_vfm_invocation (void) 
+{
+  last_vfm_invocation = time (NULL);
+}
+
 /* Creates and returns a case, initializing it from the vectors
    that say which `value's need to be initialized just once, and
    which ones need to be re-initialized before every case. */
Index: pspp/src/vfm.h
diff -u pspp/src/vfm.h:1.11 pspp/src/vfm.h:1.12
--- pspp/src/vfm.h:1.11 Fri Apr 29 01:02:16 2005
+++ pspp/src/vfm.h      Wed Dec 14 06:59:06 2005
@@ -22,9 +22,6 @@
 
 #include <time.h>
 
-/* This is the time at which vfm was last invoked. */
-extern time_t last_vfm_invocation;
-
 struct ccase;
 typedef struct write_case_data *write_case_data;
 typedef int write_case_func (write_case_data);
@@ -134,5 +131,7 @@
 void multipass_procedure_with_splits (void (*) (const struct casefile *,
                                                 void *),
                                       void *aux);
+
+time_t vfm_last_invocation (void);
 
 #endif /* !vfm_h */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]