38 #include <sys/types.h>
135 input_event_hook_functions.
clear ();
144 VPS1 =
"octave:\\#> ";
170 if (! input_string.empty ())
174 if (input_string[input_string.length () - 1] !=
'\n')
189 if (! eof && retval.empty ())
195 static inline std::string
198 Vlast_prompt_time.
stamp ();
240 bool history_skip_auto_repeated_debugging_command =
false;
260 && retval.find_first_not_of (
" \t\n\r") != std::string::npos)
272 history_skip_auto_repeated_debugging_command =
true;
277 if (! history_skip_auto_repeated_debugging_command)
285 if (retval[retval.length () - 1] !=
'\n')
356 static std::string dirfns_commands[] = {
"cd",
"ls"};
357 static const size_t dirfns_commands_length = 2;
363 for (
size_t i = 0; i < dirfns_commands_length; i++)
365 int index = line.find (dirfns_commands[i] +
" ");
382 static std::string prefix;
383 static std::string hint;
385 static size_t hint_len = 0;
387 static int list_index = 0;
388 static int name_list_len = 0;
389 static int name_list_total_len = 0;
393 static int matches = 0;
411 name_list_len = name_list.
length ();
415 name_list.
append (file_name_list);
417 name_list_total_len = name_list.
length ();
419 hint_len = hint.length ();
423 for (
int i = 0; i < name_list_len; i++)
424 if (hint == name_list[i].substr (0, hint_len))
428 if (name_list_total_len > 0 && matches > 0)
430 while (list_index < name_list_total_len)
432 std::string name = name_list[list_index];
436 if (hint == name.substr (0, hint_len))
438 if (list_index <= name_list_len && ! prefix.empty ())
439 retval = prefix +
"." + name;
455 (Vcompletion_append_char);
471 return (std::string (
"'") + text);
485 static const char *s =
"\t\n !\"\'*+-/:;<=>(){}[\\]^`~";
519 bool have_file =
false;
526 nm = caller->
name ();
535 std::ostringstream buf;
541 static char ctrl_z =
'Z' & 0x1f;
543 buf << ctrl_z << ctrl_z << nm <<
":" << curr_debug_line;
553 buf <<
"stopped in " << nm;
555 if (curr_debug_line > 0)
556 buf <<
" at line " << curr_debug_line;
566 std::pair<std::string, int> (nm, curr_debug_line));
573 if (! line_buf.empty ())
574 buf <<
"\n" << curr_debug_line <<
": " << line_buf;
583 std::string msg = buf.str ();
586 std::cerr << msg << std::endl;
607 curr_parser.
reset ();
609 int retval = curr_parser.
run ();
615 if (retval == 0 && curr_parser.
stmt_list)
684 int nargin = args.
length ();
686 int read_as_string = 0;
691 std::string prompt = args(0).string_value ();
695 error (
"input: unrecognized argument");
712 size_t len = input_buf.length ();
716 if (input_buf[len - 1] !=
'\n')
725 if (input_buf.length () == 1 && input_buf[0] ==
'\n')
728 retval(0) = input_buf;
732 int parse_status = 0;
734 retval =
eval_string (input_buf,
true, parse_status, nargout);
741 error (
"input: reading user-input failed!");
748 @deftypefn {Built-in Function} {@var{ans} =} input (@var{prompt})\n\
749 @deftypefnx {Built-in Function} {@var{ans} =} input (@var{prompt}, \"s\")\n\
750 Print @var{prompt} and wait for user input.\n\
755 input (\"Pick a number, any number! \")\n\
762 Pick a number, any number!\n\
766 and waits for the user to enter a value. The string entered by the user\n\
767 is evaluated as an expression, so it may be a literal constant, a variable\n\
768 name, or any other valid Octave code.\n\
770 The number of return arguments, their size, and their class depend on the\n\
771 expression entered.\n\
773 If you are only interested in getting a literal string value, you can call\n\
774 @code{input} with the character string @qcode{\"s\"} as the second argument.\n\
775 This tells Octave to return the string entered by the user directly, without\n\
776 evaluating it first.\n\
778 Because there may be output waiting to be displayed by the pager, it is a\n\
779 good idea to always call @code{fflush (stdout)} before calling @code{input}.\n\
780 This will ensure that all pending output is written to the screen before\n\
782 @seealso{yes_or_no, kbhit, pause, menu, listdlg}\n\
787 int nargin = args.
length ();
789 if (nargin == 1 || nargin == 2)
800 std::string prompt_string = prompt +
"(yes or no) ";
808 if (input_buf ==
"yes")
810 else if (input_buf ==
"no")
813 message (0,
"Please answer yes or no.");
817 DEFUN (yes_or_no, args, ,
819 @deftypefn {Built-in Function} {@var{ans} =} yes_or_no (\"@var{prompt}\")\n\
820 Ask the user a yes-or-no question.\n\
822 Return logical true if the answer is yes or false if the answer is no.\n\
824 Takes one argument, @var{prompt}, which is the string to display when asking\n\
825 the question. @var{prompt} should end in a space; @code{yes-or-no} adds the\n\
826 string @samp{(yes or no) } to it. The user must confirm the answer with\n\
827 @key{RET} and can edit it until it has been confirmed.\n\
833 int nargin = args.
length ();
835 if (nargin == 0 || nargin == 1)
841 if (args(0).is_string ())
842 prompt = args(0).string_value ();
845 error (
"yes_or_no: PROMPT must be a string");
863 int nargin = args.
length ();
865 assert (nargin == 0 || nargin == 1);
887 std::string prompt =
"debug> ";
889 prompt = args(0).string_value ();
897 DEFUN (keyboard, args, ,
899 @deftypefn {Built-in Function} {} keyboard ()\n\
900 @deftypefnx {Built-in Function} {} keyboard (\"@var{prompt}\")\n\
901 Stop m-file execution and enter debug mode.\n\
903 When the @code{keyboard} function is executed, Octave prints a prompt and\n\
904 waits for user input. The input strings are then evaluated and the results\n\
905 are printed. This makes it possible to examine the values of variables\n\
906 within a function, and to assign new values if necessary. To leave the\n\
907 prompt and return to normal execution type @samp{return} or @samp{dbcont}.\n\
908 The @code{keyboard} function does not return an exit status.\n\
910 If @code{keyboard} is invoked without arguments, a default prompt of\n\
911 @samp{debug> } is used.\n\
912 @seealso{dbstop, dbcont, dbquit}\n\
917 int nargin = args.
length ();
919 if (nargin == 0 || nargin == 1)
944 @deftypefn {Command} {} echo\n\
945 @deftypefnx {Command} {} echo on\n\
946 @deftypefnx {Command} {} echo off\n\
947 @deftypefnx {Command} {} echo on all\n\
948 @deftypefnx {Command} {} echo off all\n\
949 Control whether commands are displayed as they are executed.\n\
951 Valid options are:\n\
955 Enable echoing of commands as they are executed in script files.\n\
958 Disable echoing of commands as they are executed in script files.\n\
961 Enable echoing of commands as they are executed in script files and\n\
965 Disable echoing of commands as they are executed in script files and\n\
970 With no arguments, @code{echo} toggles the current echo state.\n\
975 int argc = args.
length () + 1;
988 Vecho_executing_commands =
ECHO_OFF;
996 std::string
arg = argv[1];
1000 else if (arg ==
"off")
1001 Vecho_executing_commands =
ECHO_OFF;
1009 std::string
arg = argv[1];
1011 if (arg ==
"on" && argv[2] ==
"all")
1014 Vecho_executing_commands = tmp;
1016 else if (arg ==
"off" && argv[2] ==
"all")
1017 Vecho_executing_commands =
ECHO_OFF;
1031 DEFUN (__echostate__, , ,
1033 @deftypefn {Built-in Function} {@var{state} =} __echostate__ ()\n\
1034 Undocumented internal function\n\
1040 DEFUN (completion_matches, args, nargout,
1042 @deftypefn {Built-in Function} {} completion_matches (@var{hint})\n\
1043 Generate possible completions given @var{hint}.\n\
1045 This function is provided for the benefit of programs like Emacs which\n\
1046 might be controlling Octave and handling user input. The current\n\
1047 command number is not incremented when this function is called. This is\n\
1048 a feature, not a bug.\n\
1053 int nargin = args.
length ();
1057 std::string hint = args(0).string_value ();
1090 if (! list.
empty ())
1101 int len = list.
length ();
1103 for (
int i = 0; i < len; i++)
1116 DEFUN (readline_read_init_file, args, ,
1118 @deftypefn {Built-in Function} {} readline_read_init_file (@var{file})\n\
1119 Read the readline library initialization file @var{file}.\n\
1121 If @var{file} is omitted, read the default initialization file\n\
1122 (normally @file{~/.inputrc}).\n\
1124 @xref{Readline Init File, , , readline, GNU Readline Library},\n\
1126 @seealso{readline_re_read_init_file}\n\
1131 int nargin = args.
length ();
1135 else if (nargin == 1)
1137 std::string file = args(0).string_value ();
1148 DEFUN (readline_re_read_init_file, args, ,
1150 @deftypefn {Built-in Function} {} readline_re_read_init_file ()\n\
1151 Re-read the last readline library initialization file that was read.\n\
1153 @xref{Readline Init File, , , readline, GNU Readline Library},\n\
1155 @seealso{readline_read_init_file}\n\
1160 if (args.length () == 0)
1171 input_event_hook_functions.
run ();
1173 if (input_event_hook_functions.
empty ())
1179 DEFUN (add_input_event_hook, args, ,
1181 @deftypefn {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn})\n\
1182 @deftypefnx {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn}, @var{data})\n\
1183 Add the named function or function handle @var{fcn} to the list of functions\n\
1184 to call periodically when Octave is waiting for input.\n\
1186 The function should have the form\n\
1189 @var{fcn} (@var{data})\n\
1192 If @var{data} is omitted, Octave calls the function without any arguments.\n\
1194 The returned identifier may be used to remove the function handle from the\n\
1195 list of input hook functions.\n\
1196 @seealso{remove_input_event_hook}\n\
1201 int nargin = args.
length ();
1203 if (nargin == 1 || nargin == 2)
1208 user_data = args(1);
1214 if (input_event_hook_functions.
empty ())
1217 input_event_hook_functions.
insert (hook_fcn.
id (), hook_fcn);
1219 retval = hook_fcn.
id ();
1222 error (
"add_input_event_hook: FCN must be a function handle or string");
1230 DEFUN (remove_input_event_hook, args, ,
1232 @deftypefn {Built-in Function} {} remove_input_event_hook (@var{name})\n\
1233 @deftypefnx {Built-in Function} {} remove_input_event_hook (@var{fcn_id})\n\
1234 Remove the named function or function handle with the given identifier\n\
1235 from the list of functions to call periodically when Octave is waiting\n\
1237 @seealso{add_input_event_hook}\n\
1242 int nargin = args.
length ();
1244 if (nargin == 1 || nargin == 2)
1246 std::string hook_fcn_id = args(0).string_value ();
1248 bool warn = (nargin < 2);
1253 = input_event_hook_functions.
find (hook_fcn_id);
1255 if (p != input_event_hook_functions.
end ())
1256 input_event_hook_functions.
erase (p);
1258 warning (
"remove_input_event_hook: %s not found in list",
1259 hook_fcn_id.c_str ());
1261 if (input_event_hook_functions.
empty ())
1265 error (
"remove_input_event_hook: argument not valid as a hook function name or id");
1273 DEFUN (PS1, args, nargout,
1275 @deftypefn {Built-in Function} {@var{val} =} PS1 ()\n\
1276 @deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\
1277 @deftypefnx {Built-in Function} {} PS1 (@var{new_val}, \"local\")\n\
1278 Query or set the primary prompt string.\n\
1280 When executing interactively, Octave displays the primary prompt when it is\n\
1281 ready to read a command.\n\
1283 The default value of the primary prompt string is @qcode{\"octave:\\#> \"}.\n\
1284 To change it, use a command like\n\
1287 PS1 (\"\\\\u@@\\\\H> \")\n\
1291 which will result in the prompt @samp{boris@@kremvax> } for the user\n\
1292 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two\n\
1293 backslashes are required to enter a backslash into a double-quoted\n\
1294 character string. @xref{Strings}.\n\
1296 You can also use ANSI escape sequences if your terminal supports them.\n\
1297 This can be useful for coloring the prompt. For example,\n\
1300 PS1 (\"\\\\[\\\\033[01;31m\\\\]\\\\s:\\\\#> \\\\[\\\\033[0m\\\\]\")\n\
1304 will give the default Octave prompt a red coloring.\n\
1306 When called from inside a function with the @qcode{\"local\"} option, the\n\
1307 variable is changed locally for the function and any subroutines it calls.\n\
1308 The original variable value is restored when exiting the function.\n\
1309 @seealso{PS2, PS4}\n\
1315 DEFUN (PS2, args, nargout,
1317 @deftypefn {Built-in Function} {@var{val} =} PS2 ()\n\
1318 @deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\
1319 @deftypefnx {Built-in Function} {} PS2 (@var{new_val}, \"local\")\n\
1320 Query or set the secondary prompt string.\n\
1322 The secondary prompt is printed when Octave is expecting additional input to\n\
1323 complete a command. For example, if you are typing a @code{for} loop that\n\
1324 spans several lines, Octave will print the secondary prompt at the beginning\n\
1325 of each line after the first. The default value of the secondary prompt\n\
1326 string is @qcode{\"> \"}.\n\
1328 When called from inside a function with the @qcode{\"local\"} option, the\n\
1329 variable is changed locally for the function and any subroutines it calls.\n\
1330 The original variable value is restored when exiting the function.\n\
1331 @seealso{PS1, PS4}\n\
1337 DEFUN (PS4, args, nargout,
1339 @deftypefn {Built-in Function} {@var{val} =} PS4 ()\n\
1340 @deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\
1341 @deftypefnx {Built-in Function} {} PS4 (@var{new_val}, \"local\")\n\
1342 Query or set the character string used to prefix output produced\n\
1343 when echoing commands is enabled.\n\
1345 The default value is @qcode{\"+ \"}.\n\
1346 @xref{Diary and Echo Commands}, for a description of echoing commands.\n\
1348 When called from inside a function with the @qcode{\"local\"} option, the\n\
1349 variable is changed locally for the function and any subroutines it calls.\n\
1350 The original variable value is restored when exiting the function.\n\
1351 @seealso{echo, echo_executing_commands, PS1, PS2}\n\
1357 DEFUN (completion_append_char, args, nargout,
1359 @deftypefn {Built-in Function} {@var{val} =} completion_append_char ()\n\
1360 @deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\
1361 @deftypefnx {Built-in Function} {} completion_append_char (@var{new_val}, \"local\")\n\
1362 Query or set the internal character variable that is appended to\n\
1363 successful command-line completion attempts.\n\
1365 The default value is @qcode{\" \"} (a single space).\n\
1367 When called from inside a function with the @qcode{\"local\"} option, the\n\
1368 variable is changed locally for the function and any subroutines it calls.\n\
1369 The original variable value is restored when exiting the function.\n\
1375 DEFUN (echo_executing_commands, args, nargout,
1377 @deftypefn {Built-in Function} {@var{val} =} echo_executing_commands ()\n\
1378 @deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\
1379 @deftypefnx {Built-in Function} {} echo_executing_commands (@var{new_val}, \"local\")\n\
1380 Query or set the internal variable that controls the echo state.\n\
1382 It may be the sum of the following values:\n\
1386 Echo commands read from script files.\n\
1389 Echo commands from functions.\n\
1392 Echo commands read from command line.\n\
1395 More than one state can be active at once. For example, a value of 3 is\n\
1396 equivalent to the command @kbd{echo on all}.\n\
1398 The value of @code{echo_executing_commands} may be set by the @kbd{echo}\n\
1399 command or the command line option @option{--echo-commands}.\n\
1401 When called from inside a function with the @qcode{\"local\"} option, the\n\
1402 variable is changed locally for the function and any subroutines it calls.\n\
1403 The original variable value is restored when exiting the function.\n\
1409 DEFUN (__request_drawnow__, args, ,
1411 @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\
1412 @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\
1413 Undocumented internal function.\n\
1418 int nargin = args.
length ();
1422 else if (nargin == 1)
1430 DEFUN (__gud_mode__, args, ,
1432 @deftypefn {Built-in Function} {} __gud_mode__ ()\n\
1433 Undocumented internal function.\n\
1438 int nargin = args.
length ();
1442 else if (nargin == 1)
1450 DEFUN (filemarker, args, nargout,
1452 @deftypefn {Built-in Function} {@var{val} =} filemarker ()\n\
1453 @deftypefnx {Built-in Function} {@var{old_val} =} filemarker (@var{new_val})\n\
1454 @deftypefnx {Built-in Function} {} filemarker (@var{new_val}, \"local\")\n\
1455 Query or set the character used to separate the filename from the subfunction\n\
1456 names contained within the file.\n\
1458 By default this is the character @samp{>}.\n\
1459 This can be used in a generic manner to interact with subfunctions.\n\
1463 help ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
1467 returns the help string associated with the subfunction @code{mysubfunc}\n\
1468 located in the file @file{myfunc.m}.\n\
1470 @code{filemarker} is also useful during debugging for placing breakpoints\n\
1471 within subfunctions or nested functions.\n\
1475 dbstop ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
1479 will set a breakpoint at the first line of the subfunction @code{mysubfunc}.\n\
1481 When called from inside a function with the @qcode{\"local\"} option, the\n\
1482 variable is changed locally for the function and any subroutines it calls.\n\
1483 The original variable value is restored when exiting the function.\n\
1490 if (!
error_state && (::isalnum (Vfilemarker) || Vfilemarker ==
'_'))
1493 error (
"filemarker: character can not be a valid character for a function name");
static FILE * get_input_stream(void)
static void enter_debugger_event(const std::string &file, int line)
static void pre_input_event(void)
static bool ignoring_entries(void)
static void restore_frame(size_t n)
static const std::string in_src
virtual bool reading_fcn_file(void) const
static bool erase_empty_line(bool flag)
static uint32_t state[624]
static void exit_debugger_event(void)
std::string octave_fgets(FILE *f)
OCTINTERP_API void print_usage(void)
octave_idx_type length(void) const
void accept(tree_walker &tw)
std::string octave_gets(bool &eof)
static void re_read_init_file(void)
static void set_filename_quote_characters(const std::string &s)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
static void add_event_hook(event_hook_fcn f)
std::string name(void) const
#define SET_INTERNAL_VARIABLE(NM)
octave_value_list feval(const std::string &name, const octave_value_list &args, int nargout)
static string_vector names(const map_type &lst)
static void set_completion_append_character(char c)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
iterator find(const std::string &id)
static void execute_in_debugger_event(const std::string &file, int line)
static bool quiet_breakpoint_flag
static void set_default_prompts(std::string &ps1, std::string &ps2, std::string &ps4)
static void set_name(const std::string &n)
static bool add(const std::string &)
static void set_basic_quote_characters(const std::string &s)
static const std::string in_src
void do_input_echo(const std::string &) const
void insert(const std::string &id, const hook_function &f)
void message(const char *name, const char *fmt,...)
octave_base_lexer * lexer
static int current_line(void)
static octave_user_code * caller_user_code(size_t nskip=0)
void add_fcn(void(*fcn)(void))
static void post_input_event(void)
static size_t current_frame(void)
static string_vector generate_filename_completions(const std::string &text)
static void set_input_stream(FILE *f)
void resize(octave_idx_type n, const std::string &rfv=std::string())
std::string get_input(bool &eof)
static void set_workspace(void)
std::string get_input(bool &eof)
string_vector generate_struct_completions(const std::string &text, std::string &prefix, std::string &hint)
string_vector & append(const std::string &s)
std::string get_input(bool &eof)
static void read_init_file(const std::string &file=std::string())
static bool interrupt(bool=true)
static void set_completion_function(completion_fcn f)
void reset_error_handler(void)
string_vector & sort(bool make_uniq=false)
octave_idx_type length(void) const
tree_evaluator * current_evaluator
static std::string decode_prompt_string(const std::string &s)
int pipe_handler_error_count
virtual bool reading_script_file(void) const
static std::string get_line_buffer(void)
static void remove_event_hook(event_hook_fcn f)
static std::string readline(const std::string &prompt)
static int caller_user_code_line(void)
void warning(const char *fmt,...)
bool looks_like_struct(const std::string &text)
static void set_basic_word_break_characters(const std::string &s)
charNDArray max(char d, const charNDArray &m)
virtual std::string fcn_file_name(void) const
static const std::string in_src
octave_idx_type length(void) const
Number of elements in the array.
virtual bool reading_classdef_file(void) const
static const std::string in_src
octave_value_list ovl(const octave_value &a0)
static size_t current_frame
static void set_quoting_function(quoting_fcn f)
tree_statement_list * stmt_list
string_vector make_name_list(void)
bool reading_classdef_file
static void set_completer_word_break_characters(const std::string &s)
static int input(yyscan_t yyscanner)
std::string get_file_line(const std::string &fname, size_t line)
static void set_completer_quote_characters(const std::string &s)
static bool goto_frame_relative(int n, bool verbose=false)
static void append_history(const std::string &hist_entry)
void run(const octave_value_list &initial_args=octave_value_list())
static void ignore_entries(bool=true)
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
map_type::iterator iterator