26 #if defined (HAVE_CONFIG_H)
44 #if defined (USE_READLINE)
57 #if defined (USE_READLINE)
67 ~gnu_history (
void) =
default;
69 void do_process_histcontrol (
const std::string&);
71 std::string do_histcontrol (
void)
const;
73 bool do_add (
const std::string&);
79 int do_where (
void)
const;
81 int do_length (
void)
const;
83 int do_max_input_history (
void)
const;
85 int do_base (
void)
const;
87 int do_current_number (
void)
const;
91 int do_unstifle (
void);
93 int do_is_stifled (
void)
const;
95 void do_set_mark (
int);
97 int do_goto_mark (
void);
99 void do_read (
const std::string&,
bool);
101 void do_read_range (
const std::string&,
int,
int,
bool);
103 void do_write (
const std::string&)
const;
105 void do_append (
const std::string&);
107 void do_truncate_file (
const std::string&,
int)
const;
111 std::string do_get_entry (
int)
const;
113 void do_replace_entry (
int,
const std::string&);
115 void do_clean_up_and_save (
const std::string&,
int);
123 gnu_history::do_process_histcontrol (
const std::string& control_arg)
125 m_history_control = 0;
127 std::size_t
len = control_arg.length ();
132 if (control_arg[beg] ==
':')
136 std::size_t end = control_arg.find (
':', beg);
138 if (end == std::string::npos)
141 std::string tmp = control_arg.substr (beg, end-beg);
143 if (tmp ==
"erasedups")
145 else if (tmp ==
"ignoreboth")
147 else if (tmp ==
"ignoredups")
149 else if (tmp ==
"ignorespace")
153 (
"Octave:history-control",
154 "unknown histcontrol directive %s", tmp.c_str ());
156 if (end != std::string::npos)
163 gnu_history::do_histcontrol (
void)
const
171 retval.append (
"ignorespace");
175 if (retval.length () > 0)
178 retval.append (
"ignoredups");
183 if (retval.length () > 0)
186 retval.append (
"erasedups");
193 gnu_history::do_add (
const std::string& s)
195 if (! do_ignoring_entries ())
198 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
202 std::string stmp = s;
203 if (stmp.back () ==
'\n')
207 m_lines_this_session += added;
208 return added > 0 ? true :
false;
214 gnu_history::do_remove (
int n)
220 gnu_history::do_clear (
void)
226 gnu_history::do_where (
void)
const
232 gnu_history::do_length (
void)
const
238 gnu_history::do_max_input_history (
void)
const
244 gnu_history::do_base (
void)
const
250 gnu_history::do_current_number (
void)
const
252 return m_size > 0 ? do_base () + do_where () : -1;
256 gnu_history::do_stifle (
int n)
262 gnu_history::do_unstifle (
void)
268 gnu_history::do_is_stifled (
void)
const
274 gnu_history::do_set_mark (
int n)
280 gnu_history::do_goto_mark (
void)
303 gnu_history::do_read (
const std::string&
f,
bool must_exist)
309 if (status != 0 && must_exist)
311 std::string msg =
"reading file '" +
f +
"'";
317 m_lines_in_file = do_where ();
323 error (
"gnu_history::read: missing filename");
327 gnu_history::do_read_range (
const std::string&
f,
int from,
int to,
331 from = m_lines_in_file;
337 if (status != 0 && must_exist)
339 std::ostringstream buf;
340 buf <<
"reading lines " << from <<
" to " << to
341 <<
" from file '" <<
f <<
"'";
343 error (status, buf.str ());
347 m_lines_in_file = do_where ();
353 error (
"gnu_history::read_range: missing filename");
357 gnu_history::do_write (
const std::string& f_arg)
const
361 std::string
f = f_arg;
370 if (! hist_dir.empty ())
372 sys::file_stat fs (hist_dir);
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");
395 gnu_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 sys::file_stat fs (
f);
425 std::string msg =
"appending to file '" + f_arg +
"'";
430 m_lines_in_file += m_lines_this_session;
432 m_lines_this_session = 0;
435 error (
"gnu_history::append: missing filename");
442 gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const
446 std::string
f = f_arg;
454 error (
"gnu_history::truncate_file: missing filename");
459 gnu_history::do_list (
int limit,
bool number_lines)
const
470 gnu_history::do_get_entry (
int n)
const
483 gnu_history::do_replace_entry (
int which,
const std::string& line)
489 gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
493 std::string
f = f_arg;
505 do_write (
f.c_str ());
508 error (
"gnu_history::clean_up_and_save: missing filename");
528 (*current_liboctave_error_handler)
529 (
"unable to create command history object!");
537 #if defined (USE_READLINE)
546 const std::string& f_arg,
int sz,
547 const std::string& control_arg)
782 const std::string& f_arg,
int sz,
783 const std::string& control_arg)
789 if (read_history_file)
911 error (
"command_history::read: missing filename");
918 error (
"command_history::read_range: missing filename");
926 std::string
f = f_arg;
932 error (
"command_history::write: missing filename");
947 std::string
f = f_arg;
953 error (
"command_history::append: missing filename");
964 std::string
f = f_arg;
970 error (
"command_history::truncate_file: missing filename");
995 std::string
f = f_arg;
1001 error (
"command_history::clean_up_and_save: missing filename");
1009 (*current_liboctave_error_handler) (
"%s", std::strerror (err_num));
1012 std::strerror (err_num));
1018 (*current_liboctave_error_handler) (
"%s", s.c_str ());
static void remove_startup_hook(startup_hook_fcn f)
static void insert_text(const std::string &text)
static void clear_undo_list(void)
static void truncate_file(const std::string &="", int=-1)
virtual std::string do_get_entry(int) const
bool m_ignoring_additions
virtual std::string do_file(void)
static command_history * s_instance
static int current_number(void)
static void read(bool=true)
virtual void do_stifle(int)
virtual void do_replace_entry(int, const std::string &)
virtual int do_base(void) const
virtual int do_goto_mark(void)
virtual int do_size(void) const
static void cleanup_instance(void)
virtual void do_read(const std::string &, bool)
virtual bool do_add(const std::string &)
virtual int do_current_number(void) const
virtual int do_max_input_history(void) const
static void initialize(bool, const std::string &, int, const std::string &)
static void append(const std::string &="")
virtual string_vector do_list(int, bool) const
static void set_file(const std::string &)
virtual int do_is_stifled(void) const
static bool add(const std::string &)
static void set_size(int)
virtual std::string do_histcontrol(void) const
virtual bool do_is_initialized(void) const
virtual void do_set_size(int)
static int goto_mark(void)
static bool ignoring_entries(void)
virtual void do_set_mark(int)
static void clean_up_and_save(const std::string &="", int=-1)
void error(int, const std::string &msg="") const
virtual int do_length(void) 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 make_command_history(void)
static void ignore_entries(bool=true)
virtual void do_remove(int)
static int is_stifled(void)
static int unstifle(void)
static void process_histcontrol(const std::string &)
static std::string file(void)
virtual void do_write(const std::string &) const
static std::string histcontrol(void)
static void replace_entry(int, const std::string &)
virtual void do_clear(void)
static void read_range(int=-1, int=-1, bool=true)
virtual int do_unstifle(void)
virtual void do_initialize(bool, const std::string &, int, const std::string &)
static int max_input_history(void)
static void set_mark(int n)
virtual void do_process_histcontrol(const std::string &)
static string_vector list(int=-1, bool=false)
static bool instance_ok(void)
virtual bool do_ignoring_entries(void) const
static std::string get_entry(int)
static void write(const std::string &="")
virtual void do_ignore_entries(bool)
virtual void do_set_file(const std::string &)
virtual int do_where(void) const
static bool is_initialized(void)
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)
int recursive_mkdir(const std::string &name, mode_t mode)
std::string tilde_expand(const std::string &name)
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
std::ofstream ofstream(const std::string &filename, const std::ios::openmode 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)