26 #if defined (HAVE_CONFIG_H)
44 #if defined (USE_READLINE)
57 #if defined (USE_READLINE)
67 OCTAVE_DISABLE_COPY_MOVE (gnu_history)
69 ~gnu_history () =
default;
71 void do_process_histcontrol (
const std::string&);
73 std::string do_histcontrol ()
const;
75 bool do_add (
const std::string&);
81 int do_where ()
const;
83 int do_length ()
const;
85 int do_max_input_history ()
const;
89 int do_current_number ()
const;
95 int do_is_stifled ()
const;
97 void do_set_mark (
int);
101 void do_read (
const std::string&,
bool);
103 void do_read_range (
const std::string&,
int,
int,
bool);
105 void do_write (
const std::string&)
const;
107 void do_append (
const std::string&);
109 void do_truncate_file (
const std::string&,
int)
const;
113 std::string do_get_entry (
int)
const;
115 void do_replace_entry (
int,
const std::string&);
117 void do_clean_up_and_save (
const std::string&,
int);
125 gnu_history::do_process_histcontrol (
const std::string& control_arg)
127 m_history_control = 0;
129 std::size_t
len = control_arg.length ();
134 if (control_arg[beg] ==
':')
138 std::size_t end = control_arg.find (
':', beg);
140 if (end == std::string::npos)
143 std::string tmp = control_arg.substr (beg, end-beg);
145 if (tmp ==
"erasedups")
147 else if (tmp ==
"ignoreboth")
149 else if (tmp ==
"ignoredups")
151 else if (tmp ==
"ignorespace")
155 (
"Octave:history-control",
156 "unknown histcontrol directive %s", tmp.c_str ());
158 if (end != std::string::npos)
165 gnu_history::do_histcontrol ()
const
173 retval.append (
"ignorespace");
177 if (retval.length () > 0)
180 retval.append (
"ignoredups");
185 if (retval.length () > 0)
188 retval.append (
"erasedups");
195 gnu_history::do_add (
const std::string& s)
197 if (! do_ignoring_entries ())
200 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
204 std::string stmp = s;
205 if (stmp.back () ==
'\n')
209 m_lines_this_session += added;
210 return added > 0 ? true :
false;
216 gnu_history::do_remove (
int n)
222 gnu_history::do_clear ()
228 gnu_history::do_where ()
const
234 gnu_history::do_length ()
const
240 gnu_history::do_max_input_history ()
const
246 gnu_history::do_base ()
const
252 gnu_history::do_current_number ()
const
254 return m_size > 0 ? do_base () + do_where () : -1;
258 gnu_history::do_stifle (
int n)
264 gnu_history::do_unstifle ()
270 gnu_history::do_is_stifled ()
const
276 gnu_history::do_set_mark (
int n)
282 gnu_history::do_goto_mark ()
305 gnu_history::do_read (
const std::string&
f,
bool must_exist)
311 if (status != 0 && must_exist)
313 std::string msg =
"reading file '" +
f +
"'";
319 m_lines_in_file = do_where ();
325 error (
"gnu_history::read: missing filename");
329 gnu_history::do_read_range (
const std::string&
f,
int from,
int to,
333 from = m_lines_in_file;
339 if (status != 0 && must_exist)
341 std::ostringstream buf;
342 buf <<
"reading lines " << from <<
" to " << to
343 <<
" from file '" <<
f <<
"'";
345 error (status, buf.str ());
349 m_lines_in_file = do_where ();
355 error (
"gnu_history::read_range: missing filename");
359 gnu_history::do_write (
const std::string& f_arg)
const
363 std::string
f = f_arg;
372 if (! hist_dir.empty ())
376 (*current_liboctave_error_handler)
377 (
"%s: Could not create directory \"%s\" for history",
378 "gnu_history::do_write", hist_dir.c_str ());
385 std::string msg =
"writing file '" +
f +
"'";
391 error (
"gnu_history::write: missing filename");
396 gnu_history::do_append (
const std::string& f_arg)
400 if (m_lines_this_session)
402 if (m_lines_this_session < do_where ())
406 std::string
f = f_arg;
424 std::string msg =
"appending to file '" + f_arg +
"'";
429 m_lines_in_file += m_lines_this_session;
431 m_lines_this_session = 0;
434 error (
"gnu_history::append: missing filename");
441 gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const
445 std::string
f = f_arg;
453 error (
"gnu_history::truncate_file: missing filename");
458 gnu_history::do_list (
int limit,
bool number_lines)
const
469 gnu_history::do_get_entry (
int n)
const
482 gnu_history::do_replace_entry (
int which,
const std::string&
line)
488 gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
492 std::string
f = f_arg;
504 do_write (
f.c_str ());
507 error (
"gnu_history::clean_up_and_save: missing filename");
514 command_history::instance_ok ()
520 make_command_history ();
527 (*current_liboctave_error_handler)
528 (
"unable to create command history object!");
534 command_history::make_command_history ()
536 #if defined (USE_READLINE)
537 s_instance =
new gnu_history ();
545 const std::string& f_arg,
int sz,
546 const std::string& control_arg)
549 s_instance->
do_initialize (read_history_file, f_arg, sz, control_arg);
574 return instance_ok () ? s_instance->
do_file () :
"";
600 return instance_ok () ? s_instance->
do_size () : 0;
620 return s_instance->
do_add (s);
641 return instance_ok () ? s_instance->
do_where () : 0;
647 return instance_ok () ? s_instance->
do_length () : 0;
659 return instance_ok () ? s_instance->
do_base () : 0;
678 return instance_ok () ? s_instance->
do_unstifle () : 0;
697 return instance_ok () ? s_instance->
do_goto_mark () : 0;
710 s_instance->
do_read (
f, must_exist);
751 return (instance_ok ()
781 const std::string& f_arg,
int sz,
782 const std::string& control_arg)
788 if (read_history_file)
910 error (
"command_history::read: missing filename");
917 error (
"command_history::read_range: missing filename");
925 std::string
f = f_arg;
931 error (
"command_history::write: missing filename");
946 std::string
f = f_arg;
952 error (
"command_history::append: missing filename");
963 std::string
f = f_arg;
969 error (
"command_history::truncate_file: missing filename");
994 std::string
f = f_arg;
1000 error (
"command_history::clean_up_and_save: missing filename");
1008 (*current_liboctave_error_handler) (
"%s", std::strerror (err_num));
1011 std::strerror (err_num));
1017 (*current_liboctave_error_handler) (
"%s", s.c_str ());
1020 OCTAVE_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,...)
std::string dirname(const std::string &path)
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
bool dir_exists(const std::string &dirname)
bool file_exists(const std::string &filename, bool is_dir)
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
std::string tilde_expand(const std::string &name)
int recursive_mkdir(const std::string &name, mode_t mode)
void octave_stifle_history(int)
int octave_unstifle_history(void)
int octave_where_history(void)
void octave_clear_history(void)
char * octave_history_goto_mark(int n)
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)
int octave_max_input_history(void)
int octave_history_length(void)
void octave_replace_history_entry(int, const char *)
char * octave_history_get(int n)
int octave_history_base(void)
int octave_add_history(const char *, int)
int octave_history_truncate_file(const char *, int)
void octave_using_history(void)
int octave_history_is_stifled(void)
void octave_remove_history(int)