Mercurial > hg > octave-nkf
changeset 5305:539428e4606a
[project @ 2005-04-26 02:59:08 by jwe]
author | jwe |
---|---|
date | Tue, 26 Apr 2005 02:59:08 +0000 |
parents | 7b6edb02f8c9 |
children | 63cf9851f55c |
files | src/ChangeLog src/oct-hist.cc src/oct-hist.h src/octave.cc src/toplev.cc |
diffstat | 5 files changed, 101 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2005-04-25 John W. Eaton <jwe@octave.org> + + * oct-hist.cc (default_history_file, default_history_size): Now static. + * oct-hist.h: Delete decls. + + * oct-hist.cc (default_history_timestamp_format, + default_history_timestamp_format): New functions. + (Vdefault_history_timestamp_format): New variable. + (symbols_of_oct_hist): DEFVAR it. + (octave_history_write_timestamp): New function. + * oct-hist.h (octave_history_write_timestamp): Provide decl. + * toplev.cc (): call octave_history_write_timestamp here. + * octave.cc (maximum_braindamage): + Bind history_timestamp_format_string here. + 2005-04-22 John W. Eaton <jwe@octave.org> * version.h (OCTAVE_VERSION): Now 2.9.2.
--- a/src/oct-hist.cc +++ b/src/oct-hist.cc @@ -53,6 +53,7 @@ #include "file-ops.h" #include "lo-mappers.h" #include "oct-env.h" +#include "oct-time.h" #include "str-vec.h" #include <defaults.h> @@ -80,31 +81,17 @@ // The number of lines to keep in the history file. static int Vhistory_size; +// The format of the timestamp marker written to the history file when +// Octave exits. +static std::string Vhistory_timestamp_format_string; + // TRUE if we are saving history. bool Vsaving_history = true; // Get some default values, possibly reading them from the // environment. -int -default_history_size (void) -{ - int size = 1024; - - std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); - - if (! env_size.empty ()) - { - int val; - - if (sscanf (env_size.c_str (), "%d", &val) == 1) - size = val > 0 ? val : 0; - } - - return size; -} - -std::string +static std::string default_history_file (void) { std::string file; @@ -138,6 +125,35 @@ return file; } +static int +default_history_size (void) +{ + int size = 1024; + + std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); + + if (! env_size.empty ()) + { + int val; + + if (sscanf (env_size.c_str (), "%d", &val) == 1) + size = val > 0 ? val : 0; + } + + return size; +} + +static std::string +default_history_timestamp_format (void) +{ + return + std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") + + octave_env::get_user_name () + + std::string ("@") + + octave_env::get_host_name () + + std::string (">"); +} + // Display, save, or load history. Stolen and modified from bash. // // Arg of -w FILENAME means write file, arg of -r FILENAME @@ -533,6 +549,17 @@ unlink (name.c_str ()); } +void +octave_history_write_timestamp (void) +{ + octave_localtime now; + + std::string timestamp = now.strftime (Vhistory_timestamp_format_string); + + if (! timestamp.empty ()) + command_history::add (timestamp); +} + DEFCMD (edit_history, args, , "-*- texinfo -*-\n\ @deffn {Command} edit_history options\n\ @@ -688,6 +715,24 @@ } static int +history_timestamp_format_string (void) +{ + int status = 0; + + octave_value v = builtin_any_variable ("history_timestamp_format_string"); + + if (v.is_string ()) + Vhistory_timestamp_format_string = v.string_value (); + else + { + gripe_invalid_value_specified ("history_timestamp_format_string"); + status = -1; + } + + return status; +} + +static int saving_history (void) { Vsaving_history = check_preference ("saving_history"); @@ -718,6 +763,21 @@ environment variable @code{OCTAVE_HISTSIZE}.\n\ @end defvr"); + DEFVAR (history_timestamp_format_string, + default_history_timestamp_format (), + history_timestamp_format_string, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} history_timestamp_format_string\n\ +This variable specifies the the format string for the comment line\n\ +that is written to the history file when Octave exits. The format\n\ +string is passed to @code{strftime}. The default value is\n\ +\n\ +@example\n\ +\"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ +@end example\n\ +@seealso{strftime}\n\ +@end defvr"); + DEFVAR (saving_history, true, saving_history, "-*- texinfo -*-\n\ @defvr {Built-in Variable} saving_history\n\
--- a/src/oct-hist.h +++ b/src/oct-hist.h @@ -27,8 +27,8 @@ #include "cmd-hist.h" -extern int default_history_size (void); -extern std::string default_history_file (void); +// Write timestamp to history file. +extern void octave_history_write_timestamp (void); // TRUE means input is coming from temporary history file. extern bool input_from_tmp_history_file;
--- a/src/octave.cc +++ b/src/octave.cc @@ -433,6 +433,8 @@ bind_builtin_variable ("crash_dumps_octave_core", false); bind_builtin_variable ("default_save_options", "-mat-binary"); bind_builtin_variable ("fixed_point_format", true); + bind_builtin_variable ("history_timestamp_format_string", + "%%-- %D %I:%M %p --%%"); bind_builtin_variable ("page_screen_output", false); bind_builtin_variable ("print_empty_dimensions", false); bind_builtin_variable ("warn_function_name_clash", false);
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -545,6 +545,8 @@ // XXX FIXME XXX -- is this needed? Can it cause any trouble? raw_mode (0); + octave_history_write_timestamp (); + command_history::clean_up_and_save (); close_files (); @@ -553,7 +555,7 @@ flush_octave_stdout (); - if (!quitting_gracefully && (interactive || forced_interactive)) + if (! quitting_gracefully && (interactive || forced_interactive)) std::cout << "\n"; } }