28 #if defined (HAVE_CONFIG_H)
53 #include "builtin-defun-decls.h"
113 int pos = line.length () - text.length ();
119 while (pos >= 0 && (line[pos] ==
')' || line[pos] ==
'}'))
121 if (line[pos] ==
')')
126 while (curly_count + paren_count > 0 && --pos >= 0)
128 if (line[pos] ==
')')
130 else if (line[pos] ==
'(')
132 else if (line[pos] ==
'}')
134 else if (line[pos] ==
'{')
138 while (--pos >= 0 && line[pos] ==
' ')
142 while (pos >= 0 && (isalnum (line[pos]) || line[pos] ==
'_'))
146 return (line.substr (pos, last + 1 - pos));
148 return std::string ();
153 std::string& prefix, std::string& hint)
157 std::size_t pos = text.rfind (
'.');
160 if (pos != std::string::npos)
162 if (pos == text.length ())
165 hint = text.substr (pos+1);
167 prefix = text.substr (0, pos);
175 std::string base_name = prefix;
177 pos = base_name.find_first_of (
"{(. ");
179 if (pos != std::string::npos)
180 base_name = base_name.substr (0, pos);
227 bool retval = (! text.empty ()
228 && (text !=
"." || prev_char ==
')' || prev_char ==
'}')
230 && text.find (
"..") == std::string::npos
231 && text.rfind (
'.') != std::string::npos);
240 std::string& hint,
bool& deemed_struct)
264 static std::string dirfns_commands[] = {
"cd",
"isfile",
"isfolder",
"ls"};
265 static const std::size_t dirfns_commands_length = 4;
271 for (std::size_t i = 0; i < dirfns_commands_length; i++)
273 int index = line.find (dirfns_commands[i] +
' ');
290 static std::string prefix;
291 static std::string hint;
293 static std::size_t hint_len = 0;
295 static int list_index = 0;
296 static int name_list_len = 0;
297 static int name_list_total_len = 0;
301 static int matches = 0;
314 bool deemed_struct =
false;
322 name_list_len = name_list.
numel ();
331 name_list.
append (file_name_list);
335 name_list_total_len = name_list.
numel ();
337 hint_len = hint.length ();
341 for (
int i = 0; i < name_list_len; i++)
342 if (hint == name_list[i].substr (0, hint_len))
346 if (name_list_total_len > 0 && matches > 0)
348 while (list_index < name_list_total_len)
350 std::string name = name_list[list_index];
354 if (hint == name.substr (0, hint_len))
358 if (list_index <= name_list_len && ! prefix.empty ())
359 retval = (prefix ==
"." ?
"" : prefix) +
'.' + name;
405 : m_interpreter (interp), m_PS1 (R
"(octave:\#> )"), m_PS2 ("> "),
406 m_completion_append_char (
' '), m_gud_mode (false),
407 m_mfile_encoding (
"utf-8"), m_auto_repeat_debug_command (true),
408 m_last_debugging_command (
"\n"), m_input_event_hook_functions (),
409 m_initialized (false)
432 static const char *s =
"\t\n !\"\'*+-/:;<=>(){}[\\]^`~";
470 "completion_append_char");
492 "__mfile_encoding__");
515 if (codec ==
reinterpret_cast<void *
> (-1))
519 error (
"__mfile_encoding__: conversion from encoding '%s' "
520 "not supported", encoding.c_str ());
522 error (
"__mfile_encoding__: error %d opening encoding '%s'",
523 errno, encoding.c_str ());
532 feval (
"__event_manager_gui_preference__",
539 static std::string load_path_dir (
const std::string& dir)
541 std::string lp_dir = dir;
545 if (ipos != std::string::npos)
546 lp_dir = lp_dir.erase (ipos+1);
550 if (ipos != std::string::npos
551 && lp_dir.substr (ipos+1).compare (
"private") == 0)
553 lp_dir = lp_dir.erase (ipos);
558 if (ipos != std::string::npos && lp_dir[ipos+1] ==
'@')
560 lp_dir = lp_dir.erase (ipos);
565 while (ipos != std::string::npos && lp_dir[ipos+1] ==
'+')
567 lp_dir = lp_dir.erase (ipos);
582 enc = enc_it->second;
591 std::transform (enc.begin (), enc.end (), enc.begin (), ::tolower);
593 if (enc.compare (
"delete") == 0)
599 else if (enc.compare (
"utf-8"))
608 if (codec ==
reinterpret_cast<void *
> (-1))
611 error (
"dir_encoding: conversion from encoding '%s' "
612 "not supported", enc.c_str ());
614 error (
"dir_encoding: error %d opening encoding '%s'.",
615 errno, enc.c_str ());
631 "auto_repeat_debug_command");
636 std::string prompt_string = prompt +
"(yes or no) ";
644 if (input_buf ==
"yes")
646 else if (input_buf ==
"no")
649 message (
nullptr,
"Please answer yes or no.");
693 std::string prompt = args(0).xstring_value (
"input: unrecognized argument");
695 bool read_as_string =
false;
699 = args(1).xstring_value (
"input: second argument must be 's'.");
700 if (literal.length () != 1 || literal[0] !=
's')
701 error (
"input: second argument must be 's'.");
703 read_as_string =
true;
716 if (input_buf.empty ())
717 error (
"input: reading user-input failed!");
719 std::size_t
len = input_buf.length ();
723 if (input_buf[
len - 1] !=
'\n')
729 if (input_buf.length () == 1 && input_buf[0] ==
'\n')
732 retval(0) = input_buf;
736 int parse_status = 0;
791 if (! eof && retval.empty ())
822 bool history_skip_auto_repeated_debugging_command =
false;
839 && retval.find_first_not_of (
" \t\n\r") != std::string::npos)
853 history_skip_auto_repeated_debugging_command =
true;
858 if (! history_skip_auto_repeated_debugging_command)
866 if (! retval.empty () && retval.back () !=
'\n')
887 :
base_reader (interp), m_eof (false), m_input_queue ()
890 std::string get_input (
const std::string& prompt,
bool& eof);
892 std::string input_source (
void)
const {
return s_in_src; }
894 bool input_from_terminal (
void)
const {
return true; }
899 std::queue<std::string> m_input_queue;
901 static const std::string s_in_src;
916 file_reader (
interpreter& interp, FILE *f_arg,
const std::string& enc)
917 :
base_reader (interp), m_file (f_arg), m_encoding (enc) { }
919 std::string get_input (
const std::string& prompt,
bool& eof);
921 std::string input_source (
void)
const {
return s_in_src; }
923 bool input_from_file (
void)
const {
return true; }
929 std::string m_encoding;
931 static const std::string s_in_src;
939 eval_string_reader (
interpreter& interp,
const std::string& str)
943 std::string get_input (
const std::string& prompt,
bool& eof);
945 std::string input_source (
void)
const {
return s_in_src; }
947 bool input_from_eval_string (
void)
const {
return true; }
951 std::string m_eval_string;
953 static const std::string s_in_src;
957 : m_rep (new terminal_reader (interp))
961 : m_rep (new file_reader (interp, file))
965 const std::string& enc)
966 : m_rep (new file_reader (interp, file, enc))
970 : m_rep (new eval_string_reader (interp, str))
975 const std::string terminal_reader::s_in_src (
"terminal");
985 terminal_reader::get_input (
const std::string& prompt,
bool& eof)
991 if (m_input_queue.empty ())
993 std::string
input = octave_gets (prompt, m_eof);
1014 std::size_t beg = 0;
1017 std::size_t end =
input.find (
'\n', beg);
1019 if (end == std::string::npos)
1021 m_input_queue.push (
input.substr (beg));
1026 m_input_queue.push (
input.substr (beg, end-beg+1));
1032 std::string retval = m_input_queue.front ();
1033 m_input_queue.pop ();
1035 if (m_input_queue.empty ())
1041 const std::string file_reader::s_in_src (
"file");
1044 file_reader::get_input (
const std::string& ,
bool& eof)
1050 std::string src_str =
fgets (m_file, eof);
1052 std::string mfile_encoding;
1054 if (m_encoding.empty ())
1056 input_system& input_sys = m_interpreter.get_input_system ();
1060 mfile_encoding = m_encoding;
1062 std::string encoding;
1063 if (mfile_encoding.compare (
"system") == 0)
1067 std::transform (encoding.begin (), encoding.end (), encoding.begin (),
1071 encoding = mfile_encoding;
1073 if (encoding.compare (
"utf-8") == 0)
1076 if (src_str.compare (0, 3,
"\xef\xbb\xbf") == 0)
1077 src_str.erase (0, 3);
1083 "Invalid UTF-8 byte sequences have been replaced.");
1088 const char *src = src_str.c_str ();
1089 std::size_t srclen = src_str.length ();
1098 error (
"file_reader::get_input: "
1099 "converting from codepage '%s' to UTF-8: %s",
1100 encoding.c_str (), std::strerror (errno));
1104 src_str = std::string (
reinterpret_cast<char *
> (utf8_str), length);
1110 const std::string eval_string_reader::s_in_src (
"eval_string");
1113 eval_string_reader::get_input (
const std::string& ,
bool& eof)
1121 retval = m_eval_string;
1127 if (retval.empty ())
1172 int nargin = args.
length ();
1174 if (nargin < 1 || nargin > 2)
1196 int nargin = args.
length ();
1206 prompt = args(0).xstring_value (
"yes_or_no: PROMPT must be a string");
1229 int nargin = args.
length ();
1239 = args(0).xstring_value (
"keyboard: PROMPT must be a string");
1249 DEFUN (completion_matches, args, nargout,
1276 std::string hint = args(0).string_value ();
1307 if (! list.empty ())
1318 int len = list.numel ();
1320 for (
int i = 0; i <
len; i++)
1344 DEFUN (readline_read_init_file, args, ,
1358 int nargin = args.
length ();
1367 std::string file = args(0).string_value ();
1375 DEFUN (readline_re_read_init_file, args, ,
1393 DEFMETHOD (add_input_event_hook, interp, args, ,
1413 int nargin = args.
length ();
1415 if (nargin < 1 || nargin > 2)
1421 user_data = args(1);
1429 return ovl (hook_fcn.
id ());
1432 DEFMETHOD (remove_input_event_hook, interp, args, ,
1442 int nargin = args.
length ();
1444 if (nargin < 1 || nargin > 2)
1447 std::string hook_fcn_id = args(
1448 0).xstring_value (
"remove_input_event_hook: argument not valid as a hook function name or id");
1450 bool warn = (nargin < 2);
1455 warning (
"remove_input_event_hook: %s not found in list",
1456 hook_fcn_id.c_str ());
1502 return input_sys.
PS1 (args, nargout);
1526 return input_sys.
PS2 (args, nargout);
1529 DEFMETHOD (completion_append_char, interp, args, nargout,
1549 DEFMETHOD (__request_drawnow__,, args, ,
1556 int nargin = args.
length ();
1569 DEFMETHOD (__gud_mode__, interp, args, nargout,
1577 return input_sys.
gud_mode (args, nargout);
1580 DEFMETHOD (__mfile_encoding__, interp, args, nargout,
1595 DEFMETHOD (dir_encoding, interp, args, nargout,
1635 int nargin = args.
length ();
1637 if (nargin < 1 || nargin > 2)
1641 = args(0).xstring_value (
"dir_encoding: DIR must be a string");
1652 std::string encoding
1653 = args(1).xstring_value (
"dir_encoding: ENCODING must be a string");
1658 return ovl (retval);
1662 DEFMETHOD (auto_repeat_debug_command, interp, args, nargout,
charNDArray max(char d, const charNDArray &m)
void add(F &&fcn, Args &&... args)
OCTAVE_API void run(std::size_t num)
std::string octave_gets(const std::string &prompt, bool &eof)
static const std::string s_in_src
interpreter & m_interpreter
static void set_quoting_function(quoting_fcn f)
static void set_completer_quote_characters(const std::string &s)
static string_vector generate_filename_completions(const std::string &text)
static char get_prev_char(int)
static void set_filename_quote_characters(const std::string &s)
static std::string readline(const std::string &prompt)
static void set_name(const std::string &n)
static void set_completer_word_break_characters(const std::string &s)
static std::string get_line_buffer(void)
static void set_basic_word_break_characters(const std::string &s)
static void force_default_editor(void)
static void set_completion_function(completion_fcn f)
static void set_completion_append_character(char c)
static void re_read_init_file(void)
static void add_event_hook(event_hook_fcn f)
static void set_basic_quote_characters(const std::string &s)
static void read_init_file(const std::string &file="")
static bool add(const std::string &)
void set_discard_warning_messages(bool flag)
OCTINTERP_API octave_value discard_warning_messages(const octave_value_list &args, int nargout)
Provides threadsafe access to octave.
void append_history(const std::string &hist_entry)
OCTINTERP_API void set_workspace(void)
void post_input_event(void)
void exit_debugger_event(void)
void pre_input_event(void)
map_type::iterator iterator
void run(const octave_value_list &initial_args=octave_value_list())
iterator find(const std::string &id)
void insert(const std::string &id, const hook_function &f)
std::string id(void) const
output_system & get_output_system(void)
event_manager & get_event_manager(void)
error_system & get_error_system(void)
tree_evaluator & get_evaluator(void)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
void handle_exception(const execution_exception &ee)
bool is_variable(const std::string &name) const
bool interactive(void) const
void recover_from_exception(void)
input_system & get_input_system(void)
load_path & get_load_path(void)
octave_idx_type length(void) const
bool is_classdef_object(void) const
bool is_defined(void) const
bool isstruct(void) const
string_vector map_keys(void) const
string_vector & append(const std::string &s)
string_vector & sort(bool make_uniq=false)
octave_idx_type numel(void) const
void keyboard(const std::string &prompt="keyboard> ")
bool in_debug_repl(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 warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
void message(const char *name, const char *fmt,...)
std::string canonicalize_file_name(const std::string &name)
OCTAVE_EXPORT octave_value_list Fdrawnow(octave::interpreter &interp, const octave_value_list &args, int)
ColumnVector transform(const Matrix &m, double x, double y, double z)
string_vector make_name_list(void)
int octave_iconv_close_wrapper(void *cd)
void * octave_iconv_open_wrapper(const char *tocode, const char *fromcode)
input_system & __get_input_system__(void)
interpreter & __get_interpreter__(void)
std::string fgets(FILE *f)
const char * octave_locale_charset_wrapper(void)
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
OCTAVE_API unsigned int u8_validate(const std::string &who, std::string &in_string, const u8_fallback_type type=U8_REPLACEMENT_CHAR)
static int input(yyscan_t yyscanner)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
static OCTAVE_NORETURN void eval_error(const char *msg, const dim_vector &x, const dim_vector &y)
static uint32_t state[624]
static std::string dir_sep_chars
int pipe_handler_error_count
uint8_t * octave_u8_conv_from_encoding(const char *fromcode, const char *src, size_t srclen, size_t *lengthp)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)