26#if defined (HAVE_CONFIG_H)
44#if defined (USE_READLINE)
57#if defined (USE_READLINE)
66 OCTAVE_DISABLE_COPY_MOVE (gnu_history)
68 ~gnu_history () =
default;
74 bool do_add (
const std::string&);
100 void do_read (
const std::string&,
bool);
104 void do_write (
const std::string&)
const;
124gnu_history::do_process_histcontrol (
const std::string& control_arg)
126 m_history_control = 0;
128 std::size_t
len = control_arg.length ();
133 if (control_arg[beg] ==
':')
137 std::size_t end = control_arg.find (
':', beg);
139 if (end == std::string::npos)
142 std::string tmp = control_arg.substr (beg, end-beg);
144 if (tmp ==
"erasedups")
146 else if (tmp ==
"ignoreboth")
148 else if (tmp ==
"ignoredups")
150 else if (tmp ==
"ignorespace")
154 (
"Octave:history-control",
155 "unknown histcontrol directive %s", tmp.c_str ());
157 if (end != std::string::npos)
164gnu_history::do_histcontrol ()
const
172 retval.append (
"ignorespace");
176 if (retval.length () > 0)
179 retval.append (
"ignoredups");
184 if (retval.length () > 0)
187 retval.append (
"erasedups");
194gnu_history::do_add (
const std::string& s)
196 if (! do_ignoring_entries ())
199 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
203 std::string stmp = s;
204 if (stmp.back () ==
'\n')
208 m_lines_this_session += added;
209 return added > 0 ? true :
false;
215gnu_history::do_remove (
int n)
221gnu_history::do_clear ()
227gnu_history::do_where ()
const
229 return ::octave_where_history ();
233gnu_history::do_length ()
const
235 return ::octave_history_length ();
239gnu_history::do_max_input_history ()
const
241 return ::octave_max_input_history ();
245gnu_history::do_base ()
const
247 return ::octave_history_base ();
251gnu_history::do_current_number ()
const
253 return m_size > 0 ? do_base () + do_where () : -1;
257gnu_history::do_stifle (
int n)
263gnu_history::do_unstifle ()
265 return ::octave_unstifle_history ();
269gnu_history::do_is_stifled ()
const
271 return ::octave_history_is_stifled ();
275gnu_history::do_set_mark (
int n)
281gnu_history::do_goto_mark ()
304gnu_history::do_read (
const std::string&
f,
bool must_exist)
310 if (status != 0 && must_exist)
312 std::string msg =
"reading file '" +
f +
"'";
318 m_lines_in_file = do_where ();
324 error (
"gnu_history::read: missing filename");
328gnu_history::do_read_range (
const std::string&
f,
int from,
int to,
332 from = m_lines_in_file;
338 if (status != 0 && must_exist)
340 std::ostringstream buf;
341 buf <<
"reading lines " << from <<
" to " << to
342 <<
" from file '" <<
f <<
"'";
344 error (status, buf.str ());
348 m_lines_in_file = do_where ();
354 error (
"gnu_history::read_range: missing filename");
358gnu_history::do_write (
const std::string& f_arg)
const
362 std::string
f = f_arg;
370 std::string hist_dir = sys::file_ops::dirname (
f);
371 if (! hist_dir.empty ())
373 if (! sys::dir_exists (hist_dir)
374 && (sys::recursive_mkdir (hist_dir, 0777) < 0))
375 (*current_liboctave_error_handler)
376 (
"%s: Could not create directory \"%s\" for history",
377 "gnu_history::do_write", hist_dir.c_str ());
384 std::string msg =
"writing file '" +
f +
"'";
390 error (
"gnu_history::write: missing filename");
395gnu_history::do_append (
const std::string& f_arg)
399 if (m_lines_this_session)
401 if (m_lines_this_session < do_where ())
405 std::string
f = f_arg;
412 if (! sys::file_exists (
f))
414 std::ofstream tmp = sys::ofstream (
f, std::ios::out);
423 std::string msg =
"appending to file '" + f_arg +
"'";
428 m_lines_in_file += m_lines_this_session;
430 m_lines_this_session = 0;
433 error (
"gnu_history::append: missing filename");
440gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const
444 std::string
f = f_arg;
452 error (
"gnu_history::truncate_file: missing filename");
457gnu_history::do_list (
int limit,
bool number_lines)
const
468gnu_history::do_get_entry (
int n)
const
481gnu_history::do_replace_entry (
int which,
const std::string& line)
487gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
491 std::string
f = f_arg;
503 do_write (
f.c_str ());
506 error (
"gnu_history::clean_up_and_save: missing filename");
513command_history::instance_ok ()
519 make_command_history ();
526 (*current_liboctave_error_handler)
527 (
"unable to create command history object!");
533command_history::make_command_history ()
535#if defined (USE_READLINE)
536 s_instance =
new gnu_history ();
544 const std::string& f_arg,
int sz,
545 const std::string& control_arg)
548 s_instance->
do_initialize (read_history_file, f_arg, sz, control_arg);
564 std::string
f = sys::file_ops::tilde_expand (f_arg);
573 return instance_ok () ? s_instance->
do_file () :
"";
599 return instance_ok () ? s_instance->
do_size () : 0;
619 return s_instance->
do_add (s);
640 return instance_ok () ? s_instance->
do_where () : 0;
646 return instance_ok () ? s_instance->
do_length () : 0;
658 return instance_ok () ? s_instance->
do_base () : 0;
677 return instance_ok () ? s_instance->
do_unstifle () : 0;
696 return instance_ok () ? s_instance->
do_goto_mark () : 0;
709 s_instance->
do_read (
f, must_exist);
750 return (instance_ok ()
757 return instance_ok () ? s_instance->
do_get_entry (n) :
"";
780 const std::string& f_arg,
int sz,
781 const std::string& control_arg)
787 if (read_history_file)
909 error (
"command_history::read: missing filename");
916 error (
"command_history::read_range: missing filename");
924 std::string
f = f_arg;
930 error (
"command_history::write: missing filename");
945 std::string
f = f_arg;
951 error (
"command_history::append: missing filename");
962 std::string
f = f_arg;
968 error (
"command_history::truncate_file: missing filename");
993 std::string
f = f_arg;
999 error (
"command_history::clean_up_and_save: missing filename");
1007 (*current_liboctave_error_handler) (
"%s", std::strerror (err_num));
1010 std::strerror (err_num));
1016 (*current_liboctave_error_handler) (
"%s", s.c_str ());
1019OCTAVE_END_NAMESPACE(octave)
static void remove_startup_hook(startup_hook_fcn f)
static void clear_undo_list()
static void insert_text(const std::string &text)
static void truncate_file(const std::string &="", int=-1)
virtual std::string do_get_entry(int) const
bool m_ignoring_additions
virtual int do_goto_mark()
static bool ignoring_entries()
static int current_number()
static void read(bool=true)
static bool is_initialized()
virtual void do_stifle(int)
virtual void do_replace_entry(int, const std::string &)
virtual int do_is_stifled() const
virtual void do_read(const std::string &, bool)
virtual bool do_add(const std::string &)
static void initialize(bool, const std::string &, int, const std::string &)
static void append(const std::string &="")
static std::string file()
virtual string_vector do_list(int, bool) const
virtual bool do_ignoring_entries() const
static void set_file(const std::string &)
virtual int do_size() const
static std::string histcontrol()
virtual bool do_is_initialized() const
static bool add(const std::string &)
static void set_size(int)
virtual void do_set_size(int)
virtual int do_base() const
virtual void do_set_mark(int)
virtual int do_length() const
static void clean_up_and_save(const std::string &="", int=-1)
void error(int, const std::string &msg="") const
virtual std::string do_histcontrol() const
virtual int do_where() const
virtual void do_clean_up_and_save(const std::string &, int)
virtual void do_read_range(const std::string &, int, int, bool)
virtual void do_truncate_file(const std::string &, int) const
static void ignore_entries(bool=true)
virtual void do_remove(int)
virtual int do_current_number() const
static void process_histcontrol(const std::string &)
virtual std::string do_file()
virtual void do_write(const std::string &) const
static void replace_entry(int, const std::string &)
static void read_range(int=-1, int=-1, bool=true)
virtual int do_unstifle()
virtual void do_initialize(bool, const std::string &, int, const std::string &)
static void set_mark(int n)
virtual void do_process_histcontrol(const std::string &)
static string_vector list(int=-1, bool=false)
static std::string get_entry(int)
static int max_input_history()
static void write(const std::string &="")
virtual void do_ignore_entries(bool)
virtual void do_set_file(const std::string &)
virtual int do_max_input_history() const
virtual void do_append(const std::string &)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler
F77_RET_T const F77_DBLE const F77_DBLE * f
void octave_stifle_history(int)
char * octave_history_goto_mark(int n)
void octave_clear_history(void)
int octave_read_history_range(const char *, int, int)
int octave_write_history(const char *)
int octave_append_history(int, const char *)
int octave_read_history(const char *)
char ** octave_history_list(int, int)
void octave_replace_history_entry(int, const char *)
char * octave_history_get(int n)
int octave_add_history(const char *, int)
int octave_history_truncate_file(const char *, int)
void octave_using_history(void)
void octave_remove_history(int)