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 (
"unknown histcontrol directive %s", tmp.c_str ());
151 if (end != std::string::npos)
158 gnu_history::do_histcontrol (
void)
const
166 retval.append (
"ignorespace");
170 if (retval.length () > 0)
173 retval.append (
"ignoredups");
178 if (retval.length () > 0)
181 retval.append (
"erasedups");
188 gnu_history::do_add (
const std::string& s)
190 if (! do_ignoring_entries ())
193 || (s.length () == 1 && (s[0] ==
'\r' || s[0] ==
'\n')))
197 std::string stmp = s;
198 int stmp_len = stmp.length ();
199 if (stmp[stmp_len - 1] ==
'\n')
200 stmp.resize (stmp_len - 1);
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)
307 std::string msg =
"reading file '" + f +
"'";
313 lines_in_file = do_where ();
319 error (
"gnu_history::read: missing file name");
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 file name");
353 gnu_history::do_write (
const std::string& f_arg)
const
357 std::string f = f_arg;
368 std::string msg =
"writing file '" + f +
"'";
374 error (
"gnu_history::write: missing file name");
379 gnu_history::do_append (
const std::string& f_arg)
383 if (lines_this_session)
385 if (lines_this_session < do_where ())
389 std::string f = f_arg;
402 tem = gnulib::open (f.c_str (), O_CREAT, 0666);
411 std::string msg =
"appending to file '" + f_arg +
"'";
416 lines_in_file += lines_this_session;
418 lines_this_session = 0;
421 error (
"gnu_history::append: missing file name");
428 gnu_history::do_truncate_file (
const std::string& f_arg,
int n)
const
432 std::string f = f_arg;
440 error (
"gnu_history::truncate_file: missing file name");
445 gnu_history::do_list (
int limit,
bool number_lines)
const
456 gnu_history::do_get_entry (
int n)
const
469 gnu_history::do_replace_entry (
int which,
const std::string& line)
475 gnu_history::do_clean_up_and_save (
const std::string& f_arg,
int n)
479 std::string f = f_arg;
491 do_write (f.c_str ());
494 error (
"gnu_history::clean_up_and_save: missing file name");
515 (*current_liboctave_error_handler)
516 (
"unable to create command history object!");
527 #if defined (USE_READLINE)
536 const std::string& f_arg,
int sz,
537 const std::string & control_arg)
782 (*current_liboctave_warning_handler)
783 (
"readline is not linked, so history control is not available");
788 const std::string& f_arg,
int sz,
789 const std::string & control_arg)
795 if (read_history_file)
921 error (
"command_history::read: missing file name");
928 error (
"command_history::read_range: missing file name");
936 std::string f = f_arg;
942 error (
"command_history::write: missing file name");
957 std::string f = f_arg;
963 error (
"command_history::append: missing file name");
974 std::string f = f_arg;
980 error (
"command_history::truncate_file: missing file name");
993 return std::string ();
1006 std::string f = f_arg;
1012 error (
"command_history::clean_up_and_save: missing file name");
1023 gnulib::strerror (err_num));
1029 (*current_liboctave_error_handler) (
"%s", s.c_str ());