26 #if defined (HAVE_CONFIG_H)
44 #if defined (USE_READLINE)
56 #if defined (USE_READLINE)
59 gnu_history :
public command_history
64 : command_history (), mark (0) { }
66 ~gnu_history (
void) =
default;
68 void do_process_histcontrol (
const std::string&);
70 std::string do_histcontrol (
void)
const;
72 bool do_add (
const std::string&);
78 int do_where (
void)
const;
80 int do_length (
void)
const;
82 int do_max_input_history (
void)
const;
84 int do_base (
void)
const;
86 int do_current_number (
void)
const;
90 int do_unstifle (
void);
92 int do_is_stifled (
void)
const;
94 void do_set_mark (
int);
96 int do_goto_mark (
void);
98 void do_read (
const std::string&,
bool);
100 void do_read_range (
const std::string&,
int,
int,
bool);
102 void do_write (
const std::string&)
const;
104 void do_append (
const std::string&);
106 void do_truncate_file (
const std::string&,
int)
const;
110 std::string do_get_entry (
int)
const;
112 void do_replace_entry (
int,
const std::string&);
114 void do_clean_up_and_save (
const std::string&,
int);
122 gnu_history::do_process_histcontrol (
const std::string& control_arg)
124 m_history_control = 0;
126 size_t len = control_arg.length ();
131 if (control_arg[beg] ==
':')
135 size_t end = control_arg.find (
':', beg);
137 if (end == std::string::npos)
140 std::string tmp = control_arg.substr (beg, end-beg);
142 if (tmp ==
"erasedups")
144 else if (tmp ==
"ignoreboth")
146 else if (tmp ==
"ignoredups")
148 else if (tmp ==
"ignorespace")
152 (
"Octave:history-control",
153 "unknown histcontrol directive %s", tmp.c_str ());
155 if (end != std::string::npos)
162 gnu_history::do_histcontrol (
void)
const
170 retval.append (
"ignorespace");
177 retval.append (
"ignoredups");
185 retval.append (
"erasedups");
192 gnu_history::do_add (
const std::string& s)
194 if (! do_ignoring_entries ())
197 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
201 std::string stmp = s;
202 if (stmp.back () ==
'\n')
206 m_lines_this_session += added;
207 return added > 0 ? true :
false;
213 gnu_history::do_remove (
int n)
219 gnu_history::do_clear (
void)
225 gnu_history::do_where (
void)
const
231 gnu_history::do_length (
void)
const
237 gnu_history::do_max_input_history (
void)
const
243 gnu_history::do_base (
void)
const
249 gnu_history::do_current_number (
void)
const
251 return m_size > 0 ? do_base () + do_where () : -1;
255 gnu_history::do_stifle (
int n)
261 gnu_history::do_unstifle (
void)
267 gnu_history::do_is_stifled (
void)
const
273 gnu_history::do_set_mark (
int n)
279 gnu_history::do_goto_mark (
void)
302 gnu_history::do_read (
const std::string&
f,
bool must_exist)
308 if (status != 0 && must_exist)
310 std::string msg =
"reading file '" +
f +
"'";
316 m_lines_in_file = do_where ();
322 error (
"gnu_history::read: missing filename");
326 gnu_history::do_read_range (
const std::string&
f,
int from,
int to,
330 from = m_lines_in_file;
336 if (status != 0 && must_exist)
338 std::ostringstream buf;
339 buf <<
"reading lines " << from <<
" to " << to
340 <<
" from file '" <<
f <<
"'";
342 error (status, buf.str ());
346 m_lines_in_file = do_where ();
352 error (
"gnu_history::read_range: missing filename");
356 gnu_history::do_write (
const std::string& f_arg)
const
360 std::string
f = f_arg;
371 std::string msg =
"writing file '" +
f +
"'";
377 error (
"gnu_history::write: missing filename");
382 gnu_history::do_append (
const std::string& f_arg)
386 if (m_lines_this_session)
388 if (m_lines_this_session < do_where ())
392 std::string
f = f_arg;
399 sys::file_stat fs (
f);
412 std::string msg =
"appending to file '" + f_arg +
"'";
417 m_lines_in_file += m_lines_this_session;
419 m_lines_this_session = 0;
422 error (
"gnu_history::append: missing filename");
429 gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const
433 std::string
f = f_arg;
441 error (
"gnu_history::truncate_file: missing filename");
446 gnu_history::do_list (
int limit,
bool number_lines)
const
457 gnu_history::do_get_entry (
int n)
const
470 gnu_history::do_replace_entry (
int which,
const std::string&
line)
476 gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
480 std::string
f = f_arg;
492 do_write (
f.c_str ());
495 error (
"gnu_history::clean_up_and_save: missing filename");
515 (*current_liboctave_error_handler)
516 (
"unable to create command history object!");
524 #if defined (USE_READLINE)
533 const std::string& f_arg,
int sz,
534 const std::string & control_arg)
769 const std::string& f_arg,
int sz,
770 const std::string & control_arg)
776 if (read_history_file)
898 error (
"command_history::read: missing filename");
905 error (
"command_history::read_range: missing filename");
913 std::string
f = f_arg;
919 error (
"command_history::write: missing filename");
934 std::string
f = f_arg;
940 error (
"command_history::append: missing filename");
951 std::string
f = f_arg;
957 error (
"command_history::truncate_file: missing filename");
982 std::string
f = f_arg;
988 error (
"command_history::clean_up_and_save: missing filename");
996 (*current_liboctave_error_handler) (
"%s", std::strerror (err_num));
999 std::strerror (err_num));
1005 (*current_liboctave_error_handler) (
"%s", s.c_str ());
static void clear_undo_list(void)
static void remove_startup_hook(startup_hook_fcn f)
static void insert_text(const std::string &text)
static std::string get_entry(int)
virtual std::string do_get_entry(int) const
static void make_command_history(void)
static void process_histcontrol(const std::string &)
virtual void do_process_histcontrol(const std::string &)
static std::string histcontrol(void)
static void read_range(int=-1, int=-1, bool=true)
virtual std::string do_histcontrol(void) const
virtual void do_truncate_file(const std::string &, int) const
static void ignore_entries(bool=true)
virtual int do_goto_mark(void)
virtual void do_read(const std::string &, bool)
static bool instance_ok(void)
static bool is_initialized(void)
static void set_file(const std::string &)
virtual int do_where(void) const
virtual void do_clear(void)
virtual void do_read_range(const std::string &, int, int, bool)
static std::string file(void)
virtual void do_append(const std::string &)
virtual bool do_add(const std::string &)
virtual int do_length(void) const
static int max_input_history(void)
static void truncate_file(const std::string &="", int=-1)
virtual void do_ignore_entries(bool)
virtual int do_unstifle(void)
void error(int, const std::string &msg="") const
static int is_stifled(void)
virtual void do_initialize(bool, const std::string &, int, const std::string &)
static void set_mark(int n)
virtual void do_clean_up_and_save(const std::string &, int)
virtual int do_max_input_history(void) const
bool m_ignoring_additions
virtual void do_set_mark(int)
static bool ignoring_entries(void)
virtual void do_remove(int)
static int current_number(void)
static void initialize(bool, const std::string &, int, const std::string &)
virtual bool do_ignoring_entries(void) const
static void append(const std::string &="")
static int goto_mark(void)
virtual void do_stifle(int)
static void clean_up_and_save(const std::string &="", int=-1)
virtual void do_set_size(int)
virtual void do_set_file(const std::string &)
virtual void do_write(const std::string &) const
static bool add(const std::string &)
static command_history * s_instance
virtual std::string do_file(void)
static int unstifle(void)
virtual int do_size(void) const
virtual int do_base(void) const
virtual int do_current_number(void) const
static void cleanup_instance(void)
virtual string_vector do_list(int, bool) const
static void set_size(int)
virtual int do_is_stifled(void) const
static void read(bool=true)
virtual void do_replace_entry(int, const std::string &)
static void replace_entry(int, const std::string &)
static void write(const std::string &="")
virtual bool do_is_initialized(void) const
static string_vector list(int=-1, bool=false)
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
std::string tilde_expand(const std::string &name)
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
static double f(double k, double l_nu, double c_pm)
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)
octave_value::octave_value(const Array< char > &chm, char type) return retval