changeset 6913:f779c83d6ccf

[project @ 2007-09-18 18:58:12 by jwe]
author jwe
date Tue, 18 Sep 2007 18:58:13 +0000
parents 66c7da4ee7a1
children 40be41c7d098
files ChangeLog aclocal.m4 configure.in liboctave/ChangeLog liboctave/cmd-edit.cc liboctave/cmd-edit.h liboctave/cmd-hist.cc src/ChangeLog src/input.cc
diffstat 9 files changed, 201 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Sep 18 15:26:08 2007 +0000
+++ b/ChangeLog	Tue Sep 18 18:58:13 2007 +0000
@@ -1,3 +1,8 @@
+2007-07-20  Thomas Treichl  <Thomas.Treichl@gmx.net>
+
+	* aclocal.m4 (OCTAVE_CHECK_STRPTIME): New macro.
+	* configure.in: Use it.
+
 2007-09-06  John W. Eaton  <jwe@octave.org>
 
 	* configure.in: Avoid broken strptime function on Cygwin systems.
--- a/aclocal.m4	Tue Sep 18 15:26:08 2007 +0000
+++ b/aclocal.m4	Tue Sep 18 18:58:13 2007 +0000
@@ -987,6 +987,67 @@
   if test "$octave_cv_hdf5_dll" = yes; then
     AC_DEFINE(_HDF5USEDLL_, 1, [Define if using HDF5 dll (Win32)])
   fi])
+dnl 
+dnl Check to see if the function 'strptime' fills all fields of the tm
+dnl structure correctly or if some systems maybe forget about the tm_wday
+dnl and tm_yday fields (see inline comments below)
+dnl
+AC_DEFUN([OCTAVE_CHECK_STRPTIME],[
+  AC_CHECK_FUNC(strptime)
+  if test "$ac_cv_func_strptime" == yes; then
+    AC_MSG_CHECKING([whether strptime works])
+    AC_CACHE_VAL([octave_cv_strptime],[
+      AC_TRY_RUN([#include <stdio.h>
+      #include <time.h>
+
+      int main (int argc, char *argv[]) {
+
+        struct tm tm;
+        time_t t;
+
+        /* Checks for a handle error if return value == NULL, if so then
+           return an error number immediately */
+        if (strptime("17-09-2007 12:10:20", "%d-%m-%Y %H:%M:%S", &tm) == NULL) {
+          /* printf ("strptime: An handle error occured\n"); */
+          return (1);
+        }
+        /* printf("year: %d; month: %d; day: %d;\n", 
+             tm.tm_year, tm.tm_mon, tm.tm_mday);
+           printf("hour: %d; minute: %d; second: %d\n", 
+             tm.tm_hour, tm.tm_min, tm.tm_sec);
+           printf("strptime: week day: %d, year day: %d\n",
+             tm.tm_wday, tm.tm_yday); */
+
+        /* The hard coded date from above is a 'Monday' and the day
+           number '259' of the year 2007, so tm_wday == 1 and
+           tm_yday == 259, if these values are not set then return 
+           the error number 1 */
+        if (tm.tm_year != 107) return (1);
+        if (tm.tm_mon  != 8)   return (1);
+        if (tm.tm_mday != 17)  return (1);
+        if (tm.tm_hour != 12)  return (1);
+        if (tm.tm_min  != 10)  return (1);
+        if (tm.tm_sec  != 20)  return (1);
+        /* On some system eg. MacOSX and Cygwin the following two fields
+           may be zero, ie. the function does not work as expected */
+        if (tm.tm_wday != 1)   return (1);
+        if (tm.tm_yday != 259) return (1);
+
+        /* If not already returned from this test program then function
+           seems to work correctly */
+        return (0);
+      }],[octave_cv_strptime=yes],[octave_cv_strptime=no],[octave_cv_strptime=no]
+      ) # end of TRY_RUN
+    ])  # end of CACHE_VAL
+
+    AC_MSG_RESULT([$octave_cv_strptime])
+    if test x$octave_cv_strptime = xyes
+    then
+      AC_DEFINE(HAVE_STRPTIME, 1,
+         [Define to 1 if you have a working `strptime' function.])
+    fi
+  fi # if test "$ac_cv_func_strptime" == yes; then
+]) # end of AC_DEFUN of OCTAVE_CHECK_STRPTIME
 dnl
 dnl Check for the QHull version.
 dnl
--- a/configure.in	Tue Sep 18 15:26:08 2007 +0000
+++ b/configure.in	Tue Sep 18 18:58:13 2007 +0000
@@ -29,7 +29,7 @@
 EXTERN_CXXFLAGS="$CXXFLAGS"
 
 AC_INIT
-AC_REVISION($Revision: 1.574 $)
+AC_REVISION($Revision: 1.575 $)
 AC_PREREQ(2.57)
 AC_CONFIG_SRCDIR([src/octave.cc])
 AC_CONFIG_HEADER(config.h)
@@ -1452,17 +1452,7 @@
   ;;
 esac
 
-case "$canonical_host_type" in
-  *-apple-darwin* | *-*-cygwin*)
-    ## The weekday function, which uses strptime, is broken because
-    ## strptime is apparently not setting wday correctly for formats
-    ## like "%d-%m-%Y", so use our version.  We could use an actual
-    ## configure test for this.
-  ;;
-  *)
-    AC_CHECK_FUNCS(strptime)
-  ;;
-esac
+OCTAVE_CHECK_STRPTIME
 
 OCTAVE_SMART_PUTENV
 
--- a/liboctave/ChangeLog	Tue Sep 18 15:26:08 2007 +0000
+++ b/liboctave/ChangeLog	Tue Sep 18 18:58:13 2007 +0000
@@ -1,3 +1,24 @@
+2007-09-18  John W. Eaton  <jwe@octave.org>
+
+	* cmd-edit.h, cmd-edit.cc (command_editor::startup_hook_set,
+	command_editor::event_hook_set): New static data.
+	(default_command_editor::set_startup_hook,
+	gnu_readline::set_startup_hook,
+	default_command_editor::restore_startup_hook,
+	gnu_readline_restore_event_hook):
+	Rename from do_set_startup_hook and do_set_event_hook.
+	(gnu_readline::operate_and_get_next): Call
+	command_editor::add_startup_hook, not
+	command_editor::set_startup_hook.
+	(command_editor::startup_handler, command_editor::event_handler):
+	New functions.
+	(command_editor::add_startup_hook, command_editor::add_event_hook,
+	command_editor::remove_startup_hook,
+	command_editor::remove_event_hook): Rename from set_startup_hook
+	and restore_startup_hook.  Handle hook sets here.
+	* cmd-edit.cc (gnu_history::do_goto_mark):
+	Call remove_startup_hook instead of restore_startup_hook.
+
 2007-09-17  John W. Eaton  <jwe@octave.org>
 
 	* lo-utils.cc (octave_read_complex, octave_read_double): Skip
--- a/liboctave/cmd-edit.cc	Tue Sep 18 15:26:08 2007 +0000
+++ b/liboctave/cmd-edit.cc	Tue Sep 18 18:58:13 2007 +0000
@@ -49,6 +49,10 @@
 
 command_editor *command_editor::instance = 0;
 
+std::set<command_editor::startup_hook_fcn> command_editor::startup_hook_set;
+
+std::set<command_editor::event_hook_fcn> command_editor::event_hook_set;
+
 #if defined (USE_READLINE)
 
 #include <cstdio>
@@ -63,7 +67,7 @@
 
   typedef command_editor::startup_hook_fcn startup_hook_fcn;
 
-  typedef command_editor::event_hook_fcn event_hook_hook_fcn;
+  typedef command_editor::event_hook_fcn event_hook_fcn;
 
   typedef command_editor::completion_fcn completion_fcn;
 
@@ -118,11 +122,13 @@
 
   void do_clear_undo_list (void);
 
-  void do_set_startup_hook (startup_hook_fcn f);
+  void set_startup_hook (startup_hook_fcn f);
+
+  void restore_startup_hook (void);
 
-  void do_restore_startup_hook (void);
+  void set_event_hook (event_hook_fcn f);
 
-  void do_set_event_hook (event_hook_fcn f);
+  void restore_event_hook (void);
 
   void do_restore_event_hook (void);
 
@@ -393,7 +399,7 @@
 }
 
 void
-gnu_readline::do_set_startup_hook (startup_hook_fcn f)
+gnu_readline::set_startup_hook (startup_hook_fcn f)
 {
   previous_startup_hook = ::octave_rl_get_startup_hook ();
 
@@ -401,13 +407,13 @@
 }
 
 void
-gnu_readline::do_restore_startup_hook (void)
+gnu_readline::restore_startup_hook (void)
 {
   ::octave_rl_set_startup_hook (previous_startup_hook);
 }
 
 void
-gnu_readline::do_set_event_hook (event_hook_fcn f)
+gnu_readline::set_event_hook (event_hook_fcn f)
 {
   previous_event_hook = octave_rl_get_event_hook ();
 
@@ -415,7 +421,7 @@
 }
 
 void
-gnu_readline::do_restore_event_hook (void)
+gnu_readline::restore_event_hook (void)
 {
   ::octave_rl_set_event_hook (previous_event_hook);
 }
@@ -452,7 +458,7 @@
   else
     command_history::set_mark (x_where + 1);
 
-  command_editor::set_startup_hook (command_history::goto_mark);
+  command_editor::add_startup_hook (command_history::goto_mark);
 
   return 0;
 }
@@ -615,6 +621,36 @@
 #endif
 }
 
+int
+command_editor::startup_handler (void)
+{
+  for (startup_hook_set_iterator p = startup_hook_set.begin ();
+       p != startup_hook_set.end (); p++)
+    {
+      startup_hook_fcn f = *p;
+
+      if (f)
+	f ();
+    }
+
+  return 0;
+}
+
+int
+command_editor::event_handler (void)
+{
+  for (event_hook_set_iterator p = event_hook_set.begin ();
+       p != event_hook_set.end (); p++)
+    {
+      event_hook_fcn f = *p;
+
+      if (f)
+	f ();
+    }
+
+  return 0;
+}
+
 void
 command_editor::set_name (const std::string& n)
 {
@@ -806,31 +842,55 @@
 }
 
 void
-command_editor::set_startup_hook (startup_hook_fcn f)
+command_editor::add_startup_hook (startup_hook_fcn f)
 {
   if (instance_ok ())
-    instance->do_set_startup_hook (f);
+    {
+      startup_hook_set.insert (f);
+
+      instance->set_startup_hook (startup_handler);
+    }
 }
 
 void
-command_editor::restore_startup_hook (void)
+command_editor::remove_startup_hook (startup_hook_fcn f)
 {
   if (instance_ok ())
-    instance->do_restore_startup_hook ();
+    {
+      startup_hook_set_iterator p = startup_hook_set.find (f);
+
+      if (p != startup_hook_set.end ())
+	event_hook_set.erase (p);
+
+      if (startup_hook_set.empty ())
+	instance->restore_startup_hook ();
+    }
 }
 
 void
-command_editor::set_event_hook (event_hook_fcn f)
+command_editor::add_event_hook (event_hook_fcn f)
 {
   if (instance_ok ())
-    instance->do_set_event_hook (f);
+    {
+      event_hook_set.insert (f);
+
+      instance->set_event_hook (event_handler);
+    }
 }
 
 void
-command_editor::restore_event_hook (void)
+command_editor::remove_event_hook (event_hook_fcn f)
 {
   if (instance_ok ())
-    instance->do_restore_event_hook ();
+    {
+      event_hook_set_iterator p = event_hook_set.find (f);
+
+      if (p != event_hook_set.end ())
+	event_hook_set.erase (p);
+
+      if (event_hook_set.empty ())
+	instance->restore_event_hook ();
+    }
 }
 
 void
--- a/liboctave/cmd-edit.h	Tue Sep 18 15:26:08 2007 +0000
+++ b/liboctave/cmd-edit.h	Tue Sep 18 18:58:13 2007 +0000
@@ -26,6 +26,7 @@
 
 #include <cstdio>
 
+#include <set>
 #include <string>
 
 #include "str-vec.h"
@@ -97,13 +98,13 @@
 
   static void clear_undo_list (void);
 
-  static void set_startup_hook (startup_hook_fcn f);
+  static void add_startup_hook (startup_hook_fcn f);
 
-  static void restore_startup_hook (void);
+  static void remove_startup_hook (startup_hook_fcn f);
 
-  static void set_event_hook (event_hook_fcn f);
+  static void add_event_hook (event_hook_fcn f);
 
-  static void restore_event_hook (void);
+  static void remove_event_hook (event_hook_fcn f);
 
   static void read_init_file (const std::string& file = std::string ());
 
@@ -127,6 +128,20 @@
 
   static void make_command_editor (void);
 
+  static int startup_handler (void);
+
+  static int event_handler (void);
+
+  static std::set<startup_hook_fcn> startup_hook_set;
+
+  static std::set<event_hook_fcn> event_hook_set;
+
+  typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator;
+  typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator;
+
+  typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator;
+  typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator;
+
   // The real thing.
   static command_editor *instance;
 
@@ -191,13 +206,13 @@
 
   virtual void do_clear_undo_list (void) { }
 
-  virtual void do_set_startup_hook (startup_hook_fcn) { }
+  virtual void set_startup_hook (startup_hook_fcn) { }
 
-  virtual void do_restore_startup_hook (void) { }
+  virtual void restore_startup_hook (void) { }
 
-  virtual void do_set_event_hook (event_hook_fcn) { }
+  virtual void set_event_hook (startup_hook_fcn) { }
 
-  virtual void do_restore_event_hook (void) { }
+  virtual void restore_event_hook (void) { }
 
   virtual void do_read_init_file (const std::string&) { }
 
--- a/liboctave/cmd-hist.cc	Tue Sep 18 15:26:08 2007 +0000
+++ b/liboctave/cmd-hist.cc	Tue Sep 18 18:58:13 2007 +0000
@@ -207,7 +207,7 @@
   mark = 0;
 
   // FIXME -- for operate_and_get_next.
-  command_editor::restore_startup_hook ();
+  command_editor::remove_startup_hook (command_history::goto_mark);
 
   return 0;
 }
--- a/src/ChangeLog	Tue Sep 18 15:26:08 2007 +0000
+++ b/src/ChangeLog	Tue Sep 18 18:58:13 2007 +0000
@@ -1,3 +1,11 @@
+2007-09-18  John W. Eaton  <jwe@octave.org>
+
+	* input.cc (input_event_hook, Finput_event_hook): Call
+	command_editor::add_event_hook and
+	command_editor::remove_event_hook intstead of
+	command_editor::set_event_hook and
+	command_editor::restore_event_hook.
+
 2007-09-17  John W. Eaton  <jwe@octave.org>
 
 	* version.h (OCTAVE_VERSION): Now 2.9.14+.
--- a/src/input.cc	Tue Sep 18 15:26:08 2007 +0000
+++ b/src/input.cc	Tue Sep 18 18:58:13 2007 +0000
@@ -1101,7 +1101,7 @@
       hook_fcn = std::string ();
       user_data = octave_value ();
 
-      command_editor::set_event_hook (0);
+      command_editor::remove_event_hook (input_event_hook);
     }
 
   return 0;
@@ -1148,11 +1148,11 @@
 	      return retval;
 	    }
 
-	  command_editor::set_event_hook (input_event_hook);
+	  command_editor::add_event_hook (input_event_hook);
 	}
 
       if (nargin == 0)
-	command_editor::set_event_hook (0);
+	command_editor::remove_event_hook (input_event_hook);
 
       retval(1) = user_data;
       retval(0) = hook_fcn;