37 #if defined (HAVE_CONFIG_H)
85 char *line =
new char [line_len];
90 if (lindex + 2 >= line_len)
92 char *tmp_line =
new char [line_len += 128];
93 strcpy (tmp_line, line);
100 line[lindex++] =
'\n';
101 line[lindex++] =
'\0';
114 if (lindex + 2 >= line_len)
116 char *tmp_line =
new char [lindex+3];
117 strcpy (tmp_line, line);
124 line[lindex++] =
'\n';
125 line[lindex++] =
'\0';
134 std::string tmp = line;
136 int len = tmp.length ();
138 if (
len > 0 && tmp[
len-1] ==
'\n')
139 tmp.resize (
len - 1);
162 ok = sscanf (tmp.c_str (),
"%d", &val) == 1;
174 bool insert_curr,
const char *warn_for)
178 int hist_count = hlist.
numel () - 1;
193 int hist_beg = hist_count;
194 int hist_end = hist_count;
196 bool reverse =
false;
200 int nargin = args.
length ();
206 error (
"%s: arguments must be integers", warn_for);
209 hist_beg += (hist_count + 1);
213 hist_end += (hist_count + 1);
217 else if (nargin == 1)
220 error (
"%s: argument must be an integer", warn_for);
223 hist_beg += (hist_count + 1);
230 if (hist_beg > hist_count || hist_end > hist_count)
231 error (
"%s: history specification out of range", warn_for);
233 if (hist_end < hist_beg)
235 std::swap (hist_end, hist_beg);
244 error (
"%s: couldn't open temporary file '%s'", warn_for,
249 for (
int i = hist_end; i >= hist_beg; i--)
250 file << hlist[i] <<
"\n";
254 for (
int i = hist_beg; i <= hist_end; i++)
255 file << hlist[i] <<
"\n";
264 : m_interpreter (interp), m_input_from_tmp_file (false),
265 m_timestamp_format_string (default_timestamp_format ())
272 sys::env::getenv (
"OCTAVE_HISTCONTROL"));
285 if (! timestamp.empty ())
301 "input_from_tmp_file");
309 "timestamp_format_string");
321 bool numbered_output = nargout == 0;
324 ([] (
const std::string& old_filename)
331 int nargin = args.
length ();
356 if (option ==
"-r" || option ==
"-w" || option ==
"-a"
362 = args(++i).xstring_value (
"history: filename must be a string for %s option",
374 else if (option ==
"-w")
378 else if (option ==
"-r")
385 else if (option ==
"-n")
397 else if (option ==
"-c")
402 else if (option ==
"-q")
403 numbered_output =
false;
404 else if (option ==
"--")
415 if (sscanf (option.c_str (),
"%d", &tmp) == 1)
425 if (option.length () > 0 && option[0] ==
'-')
426 error (
"history: unrecognized option '%s'", option.c_str ());
428 error (
"history: bad non-numeric arg '%s'", option.c_str ());
435 int len = hlist.numel ();
456 std::string cmd =
env.editor ();
457 cmd.append (R
"( ")" + name + '"');
471 if (status != EXIT_SUCCESS)
472 error (
"edit_history: text editor command failed");
498 int(*unlink_fptr)(
const std::string&) =
sys::unlink;
516 int(*unlink_fptr)(
const std::string&) =
sys::unlink;
531 std::string env_file = sys::env::getenv (
"OCTAVE_HISTFILE");
533 if (! env_file.empty ())
541 std::string user_data_dir = sys::env::get_user_data_directory ();
557 std::string env_size = sys::env::getenv (
"OCTAVE_HISTSIZE");
559 if (! env_size.empty ())
563 if (sscanf (env_size.c_str (),
"%d", &val) == 1)
564 size = (val > 0 ? val : 0);
574 + sys::env::get_user_name ()
576 + sys::env::get_host_name ()
616 if (args.length () > 2)
626 DEFMETHOD (history, interp, args, nargout,
676 return nargout > 0 ?
ovl (
Cell (hlist)) :
ovl ();
735 if (args.length () > 2)
743 DEFUN (history_control, args, nargout,
772 std::string tmp = old_history_control;
776 if (tmp != old_history_control)
782 DEFUN (history_size, args, nargout,
798 int tmp = old_history_size;
804 if (tmp != old_history_size)
810 DEFUN (history_file, args, nargout,
854 std::string tmp = old_history_file;
858 if (tmp != old_history_file)
864 DEFMETHOD (history_timestamp_format_string, interp, args, nargout,
899 DEFUN (history_save, args, nargout,
918 bool tmp = old_history_save;
922 if (tmp != old_history_save)
charNDArray max(char d, const charNDArray &m)
static void read(bool=true)
static void initialize(bool, const std::string &, int, const std::string &)
static void append(const std::string &="")
static void set_file(const std::string &)
static bool add(const std::string &)
static void set_size(int)
static bool ignoring_entries(void)
static void ignore_entries(bool=true)
static void process_histcontrol(const std::string &)
static std::string file(void)
static std::string histcontrol(void)
static void read_range(int=-1, int=-1, bool=true)
static string_vector list(int=-1, bool=false)
static void write(const std::string &="")
Provides threadsafe access to octave.
void append_history(const std::string &hist_entry)
OCTINTERP_API void set_history(void)
void do_edit_history(const octave_value_list &args=octave_value_list())
bool input_from_tmp_file(void) const
history_system(interpreter &interp)
void do_run_history(const octave_value_list &args=octave_value_list())
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
void initialize(bool read_history_file=false)
bool m_input_from_tmp_file
static std::string default_timestamp_format(void)
std::string timestamp_format_string(void) const
interpreter & m_interpreter
std::string m_timestamp_format_string
static int default_size(void)
static std::string default_file(void)
string_vector do_history(const octave_value_list &args=octave_value_list(), int nargout=0)
void write_timestamp(void)
event_manager & get_event_manager(void)
environment & get_environment(void)
octave_idx_type length(void) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
bool isnumeric(void) const
bool is_string(void) const
std::string string_value(bool force=false) const
octave_idx_type numel(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
int unlink(const std::string &name)
std::string tempnam(const std::string &dir, const std::string &pfx)
std::string dir_sep_str(void)
event_manager & __get_event_manager__(void)
int system(const std::string &cmd_str)
std::fstream fstream(const std::string &filename, const std::ios::openmode mode)
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
static char * edit_history_readline(std::fstream &stream)
static void edit_history_add_hist(const std::string &line)
static std::string mk_tmp_hist_file(const octave_value_list &args, bool insert_curr, const char *warn_for)
static bool get_int_arg(const octave_value &arg, int &val)
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
interrupt_handler ignore_interrupts(void)
static string_vector make_absolute(const string_vector &sv)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)