23 #if defined (HAVE_CONFIG_H) 41 #if defined (USE_READLINE) 53 #if defined (USE_READLINE) 56 gnu_history :
public command_history
61 : command_history (), mark (0) { }
63 ~gnu_history (
void) =
default;
75 int do_where (
void)
const;
77 int do_length (
void)
const;
79 int do_max_input_history (
void)
const;
81 int do_base (
void)
const;
83 int do_current_number (
void)
const;
87 int do_unstifle (
void);
89 int do_is_stifled (
void)
const;
91 void do_set_mark (
int);
93 int do_goto_mark (
void);
97 void do_read_range (
const std::string&,
int,
int,
bool);
103 void do_truncate_file (
const std::string&,
int)
const;
111 void do_clean_up_and_save (
const std::string&,
int);
119 gnu_history::do_process_histcontrol (
const std::string& control_arg)
123 size_t len = control_arg.length ();
128 if (control_arg[beg] ==
':')
132 size_t end = control_arg.find (
':', beg);
134 if (end == std::string::npos)
139 if (
tmp ==
"erasedups")
141 else if (
tmp ==
"ignoreboth")
143 else if (
tmp ==
"ignoredups")
145 else if (
tmp ==
"ignorespace")
149 (
"Octave:history-control",
150 "unknown histcontrol directive %s",
tmp.c_str ());
152 if (end != std::string::npos)
159 gnu_history::do_histcontrol (
void)
const 167 retval.append (
"ignorespace");
174 retval.append (
"ignoredups");
182 retval.append (
"erasedups");
191 if (! do_ignoring_entries ())
194 || (
s.length () == 1 && (
s[0] ==
'\r' ||
s[0] ==
'\n')))
199 if (stmp.back () ==
'\n')
203 lines_this_session += added;
204 return (added > 0) ? true :
false;
210 gnu_history::do_remove (
int n)
216 gnu_history::do_clear (
void)
222 gnu_history::do_where (
void)
const 228 gnu_history::do_length (
void)
const 234 gnu_history::do_max_input_history (
void)
const 240 gnu_history::do_base (
void)
const 246 gnu_history::do_current_number (
void)
const 248 return (xsize > 0) ? do_base () + do_where () : -1;
252 gnu_history::do_stifle (
int n)
258 gnu_history::do_unstifle (
void)
264 gnu_history::do_is_stifled (
void)
const 270 gnu_history::do_set_mark (
int n)
276 gnu_history::do_goto_mark (
void)
299 gnu_history::do_read (
const std::string&
f,
bool must_exist)
305 if (status != 0 && must_exist)
313 lines_in_file = do_where ();
319 error (
"gnu_history::read: missing filename");
323 gnu_history::do_read_range (
const std::string&
f,
int from,
int to,
327 from = lines_in_file;
333 if (status != 0 && must_exist)
335 std::ostringstream buf;
336 buf <<
"reading lines " << from <<
" to " << to
337 <<
" from file '" <<
f <<
"'";
339 error (status, buf.str ());
343 lines_in_file = do_where ();
349 error (
"gnu_history::read_range: missing filename");
353 gnu_history::do_write (
const std::string& f_arg)
const 374 error (
"gnu_history::write: missing filename");
383 if (lines_this_session)
385 if (lines_this_session < do_where ())
396 sys::file_stat
fs (
f);
400 std::fstream
tmp (
f, std::ios::out);
409 std::string msg =
"appending to file '" + f_arg +
"'";
414 lines_in_file += lines_this_session;
416 lines_this_session = 0;
419 error (
"gnu_history::append: missing filename");
426 gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const 438 error (
"gnu_history::truncate_file: missing filename");
443 gnu_history::do_list (
int limit,
bool number_lines)
const 454 gnu_history::do_get_entry (
int n)
const 473 gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
489 do_write (
f.c_str ());
492 error (
"gnu_history::clean_up_and_save: missing filename");
512 (*current_liboctave_error_handler)
513 (
"unable to create command history object!");
521 #if defined (USE_READLINE) 786 if (read_history_file)
908 error (
"command_history::read: missing filename");
915 error (
"command_history::read_range: missing filename");
929 error (
"command_history::write: missing filename");
950 error (
"command_history::append: missing filename");
967 error (
"command_history::truncate_file: missing filename");
998 error (
"command_history::clean_up_and_save: missing filename");
1009 std::strerror (err_num));
1015 (*current_liboctave_error_handler) (
"%s",
s.c_str ());
static void write(const std::string &="")
static std::string histcontrol(void)
virtual bool do_is_initialized(void) const
static void cleanup_instance(void)
virtual void do_clear(void)
virtual int do_current_number(void) const
void octave_replace_history_entry(int, const char *)
virtual std::string do_get_entry(int) const
static void read(bool=true)
virtual int do_unstifle(void)
static int current_number(void)
static int is_stifled(void)
virtual void do_append(const std::string &)
void octave_stifle_history(int)
static int goto_mark(void)
virtual int do_goto_mark(void)
char * octave_history_get(int n)
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
virtual int do_size(void) const
int octave_history_is_stifled(void)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
virtual void do_read_range(const std::string &, int, int, bool)
std::string tilde_expand(const std::string &name)
virtual int do_max_input_history(void) const
static void set_size(int)
int octave_add_history(const char *, int)
void error(const char *fmt,...)
int octave_history_truncate_file(const char *, int)
static std::string get_entry(int)
int octave_max_input_history(void)
virtual string_vector do_list(int, bool) const
static void ignore_entries(bool=true)
int octave_append_history(int, const char *)
static bool add(const std::string &)
void octave_remove_history(int)
static command_history * instance
static bool is_initialized(void)
static void clean_up_and_save(const std::string &="", int=-1)
static int max_input_history(void)
liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler
static void make_command_history(void)
virtual int do_is_stifled(void) const
char * octave_history_goto_mark(int n)
virtual int do_base(void) const
virtual void do_replace_entry(int, const std::string &)
void error(int, const std::string &msg="") const
int octave_history_length(void)
virtual std::string do_histcontrol(void) const
static void truncate_file(const std::string &="", int=-1)
static void insert_text(const std::string &text)
static string_vector list(int=-1, bool=false)
virtual std::string do_file(void)
int octave_history_base(void)
static int unstifle(void)
static void remove_startup_hook(startup_hook_fcn f)
static void clear_undo_list(void)
virtual void do_truncate_file(const std::string &, int) const
virtual void do_set_mark(int)
virtual void do_remove(int)
virtual bool do_add(const std::string &)
virtual void do_write(const std::string &) const
virtual void do_process_histcontrol(const std::string &)
static void read_range(int=-1, int=-1, bool=true)
virtual void do_stifle(int)
int octave_read_history(const char *)
int octave_where_history(void)
static void initialize(bool, const std::string &, int, const std::string &)
static void set_mark(int n)
char ** octave_history_list(int, int)
virtual int do_length(void) const
void octave_using_history(void)
virtual void do_ignore_entries(bool)
int octave_read_history_range(const char *, int, int)
static void set_file(const std::string &)
virtual int do_where(void) const
virtual void do_set_file(const std::string &)
static bool ignoring_entries(void)
octave::sys::file_stat fs(filename)
static bool instance_ok(void)
int octave_write_history(const char *)
octave_idx_type length(void) const
virtual void do_clean_up_and_save(const std::string &, int)
void octave_clear_history(void)
static void append(const std::string &="")
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
virtual void do_read(const std::string &, bool)
virtual bool do_ignoring_entries(void) const
virtual void do_set_size(int)
static std::string file(void)
virtual void do_initialize(bool, const std::string &, int, const std::string &)
int octave_unstifle_history(void)
static void replace_entry(int, const std::string &)
static void process_histcontrol(const std::string &)