changeset 1646:23ff3d50ab76

[project @ 1995-12-14 09:44:52 by jwe]
author jwe
date Thu, 14 Dec 1995 09:46:42 +0000
parents 44ed237bdc1e
children 68c5b639e6e6
files src/oct-hist.cc src/oct-hist.h src/user-prefs.cc src/user-prefs.h src/variables.cc
diffstat 5 files changed, 87 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/oct-hist.cc	Thu Dec 14 08:33:32 1995 +0000
+++ b/src/oct-hist.cc	Thu Dec 14 09:46:42 1995 +0000
@@ -47,6 +47,7 @@
 #include <fcntl.h>
 
 #include <readline/history.h>
+#include <readline/tilde.h>
 
 #include "defun.h"
 #include "error.h"
@@ -64,12 +65,6 @@
 // Nonzero means input is coming from temporary history file.
 int input_from_tmp_history_file = 0;
 
-// The number of lines to save in the history file.
-static int octave_hist_size = 1024;
-
-// The name of the history file.
-static char *octave_hist_file;
-
 // The number of hisory lines we read from the history file.
 static int history_lines_in_file = 0;
 
@@ -79,7 +74,7 @@
 // Get some default values, possibly reading them from the
 // environment.
 
-static int
+int
 default_history_size (void)
 {
   int size = 1024;
@@ -93,7 +88,7 @@
   return size;
 }
 
-static char *
+char *
 default_history_file (void)
 {
   char *file = 0;
@@ -120,19 +115,34 @@
 void
 initialize_history (void)
 {
-  octave_hist_file = default_history_file ();
-  octave_hist_size = default_history_size ();
+  static char *file = 0;
+
+  if (file)
+    free (file);
 
-  read_history (octave_hist_file);
+  file = tilde_expand (user_pref.history_file);
+
+  read_history (file);
+
   using_history ();
+
   history_lines_in_file = where_history ();
 }
 
 void
 clean_up_history (void)
 {
-  stifle_history (octave_hist_size);
-  write_history (octave_hist_file);
+  static char *file = 0;
+
+  if (file)
+    free (file);
+
+  stifle_history (user_pref.history_size);
+
+  file = tilde_expand (user_pref.history_file);
+
+  if (user_pref.saving_history)
+    write_history (file);
 }
 
 void
@@ -166,13 +176,16 @@
 	  && ((*argv)[1] == 'r' || (*argv)[1] == 'w'
 	      || (*argv)[1] == 'a' || (*argv)[1] == 'n'))
 	{
-	  char *file;
+	  static char *file = 0;
 	  int result = 0;
 
+	  if (file)
+	    free (file);
+
 	  if (argc > 1)
-	    file = *(argv+1);
+	    file = tilde_expand (*(argv+1));
 	  else
-	    file = octave_hist_file;
+	    file = tilde_expand (user_pref.history_file);
 
 	  switch ((*argv)[1])
 	    {
@@ -626,7 +639,7 @@
 {
   using_history ();
 
-  if (octave_hist_size > 0)
+  if (user_pref.history_size > 0)
     return history_base + where_history ();
   else
     return -1;
--- a/src/oct-hist.h	Thu Dec 14 08:33:32 1995 +0000
+++ b/src/oct-hist.h	Thu Dec 14 09:46:42 1995 +0000
@@ -24,6 +24,8 @@
 #if !defined (octave_octave_hist_h)
 #define octave_octave_hist_h 1
 
+extern int default_history_size (void);
+extern char *default_history_file (void);
 extern void initialize_history (void);
 extern void clean_up_history (void);
 extern void maybe_save_history (const char*);
--- a/src/user-prefs.cc	Thu Dec 14 08:33:32 1995 +0000
+++ b/src/user-prefs.cc	Thu Dec 14 09:46:42 1995 +0000
@@ -52,6 +52,7 @@
   user_pref.do_fortran_indexing = 0;
   user_pref.empty_list_elements_ok = 0;
   user_pref.gnuplot_has_multiplot = 0;
+  user_pref.history_size = 0;
   user_pref.ignore_function_time_stamp = 0;
   user_pref.implicit_str_to_num_ok = 0;
   user_pref.ok_to_lose_imaginary_part = 0;
@@ -85,6 +86,7 @@
   user_pref.editor = 0;
   user_pref.exec_path = 0;
   user_pref.gnuplot_binary = 0;
+  user_pref.history_file = 0;
   user_pref.imagepath = 0;
   user_pref.info_file = 0;
   user_pref.info_prog = 0;
@@ -233,6 +235,27 @@
 }
 
 
+// How many lines of command history should we save?
+
+int
+history_size (void)
+{
+  double val;
+  if (builtin_real_scalar_variable ("history_size", val)
+      && ! xisnan (val))
+    {
+      int ival = NINT (val);
+      if (ival >= 0 && (double) ival == val)
+	{
+	  user_pref.history_size = ival;
+	  return 0;
+	}
+    }
+  gripe_invalid_value_specified ("history_size");
+  return -1;
+}
+
+
 // Should Octave always check to see if function files have changed
 // since they were last compiled?
 
@@ -836,6 +859,26 @@
 }
 
 int
+sv_history_file (void)
+{
+  int status = 0;
+
+  char *s = builtin_string_variable ("history_file");
+  if (s)
+    {
+      delete [] user_pref.history_file;
+      user_pref.history_file = s;
+    }
+  else
+    {
+      gripe_invalid_value_specified ("history_file");
+      status = -1;
+    }
+
+  return status;
+}
+
+int
 sv_imagepath (void)
 {
   int status = 0;
--- a/src/user-prefs.h	Thu Dec 14 08:33:32 1995 +0000
+++ b/src/user-prefs.h	Thu Dec 14 09:46:42 1995 +0000
@@ -33,6 +33,7 @@
   int echo_executing_commands;
   int empty_list_elements_ok;
   int gnuplot_has_multiplot;
+  int history_size;
   int ignore_function_time_stamp;
   int implicit_str_to_num_ok;
   int ok_to_lose_imaginary_part;
@@ -67,6 +68,7 @@
   char *editor;
   char *exec_path;
   char *gnuplot_binary;
+  char *history_file;
   char *imagepath;
   char *info_file;
   char *info_prog;
@@ -89,6 +91,7 @@
 extern int echo_executing_commands (void);
 extern int empty_list_elements_ok (void);
 extern int gnuplot_has_multiplot (void);
+extern int history_size (void);
 extern int ignore_function_time_stamp (void);
 extern int implicit_str_to_num_ok (void);
 extern int ok_to_lose_imaginary_part (void);
@@ -124,6 +127,7 @@
 extern int sv_editor (void);
 extern int sv_exec_path (void);
 extern int sv_gnuplot_binary (void);
+extern int sv_history_file (void);
 extern int sv_imagepath (void);
 extern int sv_info_file (void);
 extern int sv_info_prog (void);
--- a/src/variables.cc	Thu Dec 14 08:33:32 1995 +0000
+++ b/src/variables.cc	Thu Dec 14 09:46:42 1995 +0000
@@ -1738,6 +1738,14 @@
 	  with_multiplot, 0, gnuplot_has_multiplot,
     "true if gnuplot supports multiplot, false otherwise");
 
+  DEFVAR ("history_file", SBV_history_file,
+	  default_history_file (), 0, sv_history_file,
+    "name of command history file");
+
+  DEFVAR ("history_size", SBV_history_size,
+	  default_history_size (), 0, history_size,
+    "number of commands to save in the history list");
+
   DEFCONST ("i", SBV_i, Complex (0.0, 1.0), 1, 0,
     "sqrt (-1)");