42 #if defined (USE_READLINE)
46 #include <sys/types.h>
63 ~gnu_history (
void) { }
65 void do_process_histcontrol (
const std::string&);
67 std::string do_histcontrol (
void)
const;
69 bool do_add (
const std::string&);
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);
95 void do_read (
const std::string&,
bool);
97 void do_read_range (
const std::string&,
int,
int,
bool);
99 void do_write (
const std::string&)
const;
101 void do_append (
const std::string&);
103 void do_truncate_file (
const std::string&,
int)
const;
107 std::string do_get_entry (
int)
const;
109 void do_replace_entry (
int,
const std::string&);
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)
137 std::string tmp = control_arg.substr (beg, end-beg);
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");
171 if (retval.length () > 0)
174 retval.append (
"ignoredups");
179 if (retval.length () > 0)
182 retval.append (
"erasedups");
189 gnu_history::do_add (
const std::string& s)
191 if (! do_ignoring_entries ())
194 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
198 std::string stmp = s;
199 int stmp_len = stmp.length ();
200 if (stmp[stmp_len - 1] ==
'\n')
201 stmp.resize (stmp_len - 1);
204 lines_this_session += added;
205 return (added > 0) ?
true :
false;
211 gnu_history::do_remove (
int n)
217 gnu_history::do_clear (
void)
223 gnu_history::do_where (
void)
const
229 gnu_history::do_length (
void)
const
235 gnu_history::do_max_input_history (
void)
const
241 gnu_history::do_base (
void)
const
247 gnu_history::do_current_number (
void)
const
249 return (xsize > 0) ? do_base () + do_where () : -1;
253 gnu_history::do_stifle (
int n)
259 gnu_history::do_unstifle (
void)
265 gnu_history::do_is_stifled (
void)
const
271 gnu_history::do_set_mark (
int n)
277 gnu_history::do_goto_mark (
void)
300 gnu_history::do_read (
const std::string&
f,
bool must_exist)
306 if (status != 0 && must_exist)
308 std::string msg =
"reading file '" + f +
"'";
314 lines_in_file = do_where ();
320 error (
"gnu_history::read: missing file name");
324 gnu_history::do_read_range (
const std::string& f,
int from,
int to,
328 from = lines_in_file;
334 if (status != 0 && must_exist)
336 std::ostringstream buf;
337 buf <<
"reading lines " << from <<
" to " << to
338 <<
" from file '" << f <<
"'";
340 error (status, buf.str ());
344 lines_in_file = do_where ();
350 error (
"gnu_history::read_range: missing file name");
354 gnu_history::do_write (
const std::string& f_arg)
const
358 std::string f = f_arg;
369 std::string msg =
"writing file '" + f +
"'";
375 error (
"gnu_history::write: missing file name");
380 gnu_history::do_append (
const std::string& f_arg)
384 if (lines_this_session)
386 if (lines_this_session < do_where ())
390 std::string f = f_arg;
403 tem = gnulib::open (f.c_str (), O_CREAT, 0666);
412 std::string msg =
"appending to file '" + f_arg +
"'";
417 lines_in_file += lines_this_session;
419 lines_this_session = 0;
422 error (
"gnu_history::append: missing file name");
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 file name");
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 file name");
516 (*current_liboctave_error_handler)
517 (
"unable to create command history object!");
528 #if defined (USE_READLINE)
537 const std::string& f_arg,
int sz,
538 const std::string & control_arg)
783 (*current_liboctave_warning_with_id_handler)
784 (
"Octave:history-control",
785 "readline is not linked, so history control is not available");
790 const std::string& f_arg,
int sz,
791 const std::string & control_arg)
797 if (read_history_file)
923 error (
"command_history::read: missing file name");
930 error (
"command_history::read_range: missing file name");
938 std::string f = f_arg;
944 error (
"command_history::write: missing file name");
959 std::string f = f_arg;
965 error (
"command_history::append: missing file name");
976 std::string f = f_arg;
982 error (
"command_history::truncate_file: missing file name");
995 return std::string ();
1008 std::string f = f_arg;
1014 error (
"command_history::clean_up_and_save: missing file name");
1025 gnulib::strerror (err_num));
1031 (*current_liboctave_error_handler) (
"%s", s.c_str ());
static bool ignoring_entries(void)
virtual void do_read(const std::string &, bool)
void octave_replace_history_entry(int, const char *)
virtual bool do_ignoring_entries(void) const
void octave_stifle_history(int)
static void clear_undo_list(void)
char * octave_history_get(int n)
int octave_history_is_stifled(void)
virtual void do_set_mark(int)
virtual string_vector do_list(int, bool) const
virtual bool do_is_initialized(void) const
virtual void do_clear(void)
static std::string file(void)
int octave_add_history(const char *, int)
void error(const char *fmt,...)
int octave_history_truncate_file(const char *, int)
virtual std::string do_get_entry(int) const
int octave_max_input_history(void)
virtual void do_set_file(const std::string &)
int octave_append_history(int, const char *)
virtual void do_read_range(const std::string &, int, int, bool)
static int max_input_history(void)
virtual int do_base(void) const
static void append(const std::string &=std::string())
void octave_remove_history(int)
static void cleanup_instance(void)
static void read(bool=true)
virtual int do_size(void) const
static void set_file(const std::string &)
void error(int, const std::string &msg="") const
static string_vector list(int=-1, bool=false)
liboctave_warning_with_id_handler current_liboctave_warning_with_id_handler
static void set_mark(int n)
virtual int do_current_number(void) const
static bool add(const std::string &)
static std::string tilde_expand(const std::string &)
static void insert_text(const std::string &text)
static void remove_startup_hook(startup_hook_fcn f)
char * octave_history_goto_mark(int n)
static void make_command_history(void)
static void clean_up_and_save(const std::string &=std::string(), int=-1)
static void truncate_file(const std::string &=std::string(), int=-1)
virtual void do_ignore_entries(bool)
virtual int do_goto_mark(void)
virtual void do_append(const std::string &)
int octave_history_length(void)
liboctave_error_handler current_liboctave_error_handler
static int unstifle(void)
static int is_stifled(void)
virtual void do_set_size(int)
F77_RET_T const double const double * f
virtual int do_where(void) const
virtual std::string do_histcontrol(void) const
virtual int do_length(void) const
static command_history * instance
int octave_history_base(void)
static bool instance_ok(void)
virtual void do_initialize(bool, const std::string &, int, const std::string &)
static int current_number(void)
static std::string get_entry(int)
int octave_read_history(const char *)
static bool is_initialized(void)
int octave_where_history(void)
virtual void do_replace_entry(int, const std::string &)
virtual void do_process_histcontrol(const std::string &)
char ** octave_history_list(int, int)
static void write(const std::string &=std::string())
virtual void do_remove(int)
virtual void do_clean_up_and_save(const std::string &, int)
void octave_using_history(void)
int octave_read_history_range(const char *, int, int)
static std::string histcontrol(void)
virtual int do_max_input_history(void) const
static void initialize(bool, const std::string &, int, const std::string &)
static void replace_entry(int, const std::string &)
virtual void do_write(const std::string &) const
virtual bool do_add(const std::string &)
virtual std::string do_file(void)
static int goto_mark(void)
virtual void do_stifle(int)
static void set_size(int)
int octave_write_history(const char *)
virtual void do_truncate_file(const std::string &, int) const
virtual int do_unstifle(void)
void octave_clear_history(void)
static void process_histcontrol(const std::string &)
static void ignore_entries(bool=true)
int octave_unstifle_history(void)
static void read_range(int=-1, int=-1, bool=true)
static bool read_history_file
virtual int do_is_stifled(void) const