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);
163 ok = sscanf (tmp.c_str (),
"%d", &val) == 1;
175 bool insert_curr,
const char *warn_for)
179 int hist_count = hlist.
numel () - 1;
194 int hist_beg = hist_count;
195 int hist_end = hist_count;
197 bool reverse =
false;
201 int nargin = args.
length ();
207 error (
"%s: arguments must be integers", warn_for);
210 hist_beg += (hist_count + 1);
214 hist_end += (hist_count + 1);
218 else if (nargin == 1)
221 error (
"%s: argument must be an integer", warn_for);
224 hist_beg += (hist_count + 1);
231 if (hist_beg > hist_count || hist_end > hist_count)
232 error (
"%s: history specification out of range", warn_for);
234 if (hist_end < hist_beg)
236 std::swap (hist_end, hist_beg);
245 error (
"%s: couldn't open temporary file '%s'", warn_for,
250 for (
int i = hist_end; i >= hist_beg; i--)
251 file << hlist[i] <<
"\n";
255 for (
int i = hist_beg; i <= hist_end; i++)
256 file << hlist[i] <<
"\n";
271 : m_interpreter (interp), m_input_from_tmp_file (false),
272 m_timestamp_format_string (default_timestamp_format ())
292 if (! timestamp.empty ())
308 "input_from_tmp_file");
316 "timestamp_format_string");
328 bool numbered_output = nargout == 0;
336 int nargin = args.
length ();
361 if (option ==
"-r" || option ==
"-w" || option ==
"-a"
367 = args(++i).xstring_value (
"history: filename must be a string for %s option",
379 else if (option ==
"-w")
383 else if (option ==
"-r")
390 else if (option ==
"-n")
402 else if (option ==
"-c")
407 else if (option ==
"-q")
408 numbered_output =
false;
409 else if (option ==
"--")
420 if (sscanf (option.c_str (),
"%d", &tmp) == 1)
430 if (option.length () > 0 && option[0] ==
'-')
431 error (
"history: unrecognized option '%s'", option.c_str ());
433 error (
"history: bad non-numeric arg '%s'", option.c_str ());
461 std::string cmd = env.
editor ();
462 cmd.append (R
"( ")" + name + '"');
470 int status = system (cmd.c_str ());
476 if (status != EXIT_SUCCESS)
477 error (
"edit_history: text editor command failed");
544 if (! env_file.empty ())
560 if (! env_size.empty ())
564 if (sscanf (env_size.c_str (),
"%d", &val) == 1)
565 size = (val > 0 ? val : 0);
619 if (args.length () > 2)
629 DEFMETHOD (history, interp, args, nargout,
679 return nargout > 0 ?
ovl (
Cell (hlist)) :
ovl ();
738 if (args.length () > 2)
746 DEFUN (history_control, args, nargout,
774 std::string tmp = old_history_control;
778 if (tmp != old_history_control)
784 DEFUN (history_size, args, nargout,
800 int tmp = old_history_size;
806 if (tmp != old_history_size)
812 DEFUN (history_file, args, nargout,
852 std::string tmp = old_history_file;
856 if (tmp != old_history_file)
862 DEFMETHOD (history_timestamp_format_string, interp, args, nargout,
897 DEFUN (history_save, args, nargout,
915 bool tmp = old_history_save;
919 if (tmp != old_history_save)
charNDArray max(char d, const charNDArray &m)
void add_fcn(void(*fcn)(Params...), Args &&... args)
static void process_histcontrol(const std::string &)
static std::string histcontrol(void)
static void read_range(int=-1, int=-1, bool=true)
static void ignore_entries(bool=true)
static void set_file(const std::string &)
static std::string file(void)
static bool ignoring_entries(void)
static void initialize(bool, const std::string &, int, const std::string &)
static void append(const std::string &="")
static bool add(const std::string &)
static void set_size(int)
static void read(bool=true)
static void write(const std::string &="")
static string_vector list(int=-1, bool=false)
octave_value editor(const octave_value_list &args, int nargout)
Provides threadsafe access to octave.
void set_history(const string_vector &hist)
void append_history(const std::string &hist_entry)
interpreter & m_interpreter
void write_timestamp(void)
std::string m_timestamp_format_string
void do_edit_history(const octave_value_list &args=octave_value_list())
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
void do_run_history(const octave_value_list &args=octave_value_list())
void initialize(bool read_history_file=false)
static int default_size(void)
bool m_input_from_tmp_file
static std::string default_timestamp_format(void)
bool input_from_tmp_file(void) const
std::string timestamp_format_string(void) const
history_system(interpreter &interp)
string_vector do_history(const octave_value_list &args=octave_value_list(), int nargout=0)
static std::string default_file(void)
environment & get_environment(void)
event_manager & get_event_manager(void)
std::string strftime(const std::string &fmt) const
static std::string get_host_name(void)
static std::string getenv(const std::string &name)
static std::string get_home_directory(void)
static std::string get_user_name(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
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)
std::string concat(const std::string &dir, const std::string &file)
std::string tempnam(const std::string &dir, const std::string &pfx)
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 void edit_history_add_hist(const std::string &line)
static void unlink_cleanup(const char *file)
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
static bool get_int_arg(const octave_value &arg, int &val)
interrupt_handler ignore_interrupts(void)
event_manager & __get_event_manager__(const std::string &who)
static char * edit_history_readline(std::fstream &stream)
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)
static std::string mk_tmp_hist_file(const octave_value_list &args, bool insert_curr, const char *warn_for)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
int octave_unlink_wrapper(const char *nm)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)