38 #include <sys/types.h>
134 input_event_hook_functions.
clear ();
143 VPS1 =
"octave:\\#> ";
169 if (! input_string.empty ())
173 if (input_string[input_string.length () - 1] !=
'\n')
188 if (! eof && retval.empty ())
194 static inline std::string
197 Vlast_prompt_time.
stamp ();
239 bool history_skip_auto_repeated_debugging_command =
false;
259 && retval.find_first_not_of (
" \t\n\r") != std::string::npos)
271 history_skip_auto_repeated_debugging_command =
true;
276 if (! history_skip_auto_repeated_debugging_command)
284 if (retval[retval.length () - 1] !=
'\n')
355 static std::string dirfns_commands[] = {
"cd",
"ls"};
356 static const size_t dirfns_commands_length = 2;
362 for (
size_t i = 0; i < dirfns_commands_length; i++)
364 int index = line.find (dirfns_commands[i] +
" ");
381 static std::string prefix;
382 static std::string hint;
384 static size_t hint_len = 0;
386 static int list_index = 0;
387 static int name_list_len = 0;
388 static int name_list_total_len = 0;
392 static int matches = 0;
410 name_list_len = name_list.
length ();
414 name_list.
append (file_name_list);
416 name_list_total_len = name_list.
length ();
418 hint_len = hint.length ();
422 for (
int i = 0; i < name_list_len; i++)
423 if (hint == name_list[i].substr (0, hint_len))
427 if (name_list_total_len > 0 && matches > 0)
429 while (list_index < name_list_total_len)
431 std::string name = name_list[list_index];
435 if (hint == name.substr (0, hint_len))
437 if (list_index <= name_list_len && ! prefix.empty ())
438 retval = prefix +
"." + name;
454 (Vcompletion_append_char);
470 return (std::string (
"'") + text);
484 static const char *s =
"\t\n !\"\'*+-/:;<=>(){}[\\]^`~";
516 bool have_file =
false;
523 nm = caller->
name ();
528 curr_debug_line = -1;
530 std::ostringstream buf;
536 static char ctrl_z =
'Z' & 0x1f;
538 buf << ctrl_z << ctrl_z << nm <<
":" << curr_debug_line;
546 buf <<
"stopped in " << nm;
548 if (curr_debug_line > 0)
549 buf <<
" at line " << curr_debug_line;
558 std::pair<std::string, int> (nm, curr_debug_line));
563 if (! line_buf.empty ())
564 buf <<
"\n" << curr_debug_line <<
": " << line_buf;
569 std::string msg = buf.str ();
572 std::cerr << msg << std::endl;
591 curr_parser.
reset ();
593 int retval = curr_parser.
run ();
599 if (retval == 0 && curr_parser.
stmt_list)
668 int nargin = args.
length ();
670 int read_as_string = 0;
675 std::string prompt = args(0).string_value ();
679 error (
"input: unrecognized argument");
696 size_t len = input_buf.length ();
700 if (input_buf[len - 1] !=
'\n')
709 if (input_buf.length () == 1 && input_buf[0] ==
'\n')
712 retval(0) = input_buf;
716 int parse_status = 0;
718 retval =
eval_string (input_buf,
true, parse_status, nargout);
725 error (
"input: reading user-input failed!");
732 @deftypefn {Built-in Function} {@var{ans} =} input (@var{prompt})\n\
733 @deftypefnx {Built-in Function} {@var{ans} =} input (@var{prompt}, \"s\")\n\
734 Print a prompt and wait for user input. For example,\n\
737 input (\"Pick a number, any number! \")\n\
744 Pick a number, any number!\n\
748 and waits for the user to enter a value. The string entered by the user\n\
749 is evaluated as an expression, so it may be a literal constant, a\n\
750 variable name, or any other valid expression.\n\
752 Currently, @code{input} only returns one value, regardless of the number\n\
753 of values produced by the evaluation of the expression.\n\
755 If you are only interested in getting a literal string value, you can\n\
756 call @code{input} with the character string @qcode{\"s\"} as the second\n\
757 argument. This tells Octave to return the string entered by the user\n\
758 directly, without evaluating it first.\n\
760 Because there may be output waiting to be displayed by the pager, it is\n\
761 a good idea to always call @code{fflush (stdout)} before calling\n\
762 @code{input}. This will ensure that all pending output is written to\n\
763 the screen before your prompt.\n\
764 @seealso{yes_or_no, kbhit}\n\
769 int nargin = args.
length ();
771 if (nargin == 1 || nargin == 2)
782 std::string prompt_string = prompt +
"(yes or no) ";
790 if (input_buf ==
"yes")
792 else if (input_buf ==
"no")
795 message (0,
"Please answer yes or no.");
799 DEFUN (yes_or_no, args, ,
801 @deftypefn {Built-in Function} {@var{ans} =} yes_or_no (\"@var{prompt}\")\n\
802 Ask the user a yes-or-no question. Return logical true if the answer is yes\n\
803 or false if the answer is no. Takes one argument, @var{prompt}, which is\n\
804 the string to display when asking the question. @var{prompt} should end in\n\
805 a space; @code{yes-or-no} adds the string @samp{(yes or no) } to it. The\n\
806 user must confirm the answer with @key{RET} and can edit it until it has\n\
813 int nargin = args.
length ();
815 if (nargin == 0 || nargin == 1)
821 prompt = args(0).string_value ();
825 error (
"yes_or_no: PROMPT must be a character string");
843 int nargin = args.
length ();
845 assert (nargin == 0 || nargin == 1);
867 std::string prompt =
"debug> ";
869 prompt = args(0).string_value ();
877 DEFUN (keyboard, args, ,
879 @deftypefn {Built-in Function} {} keyboard ()\n\
880 @deftypefnx {Built-in Function} {} keyboard (\"@var{prompt}\")\n\
881 This function is normally used for simple debugging. When the\n\
882 @code{keyboard} function is executed, Octave prints a prompt and waits\n\
883 for user input. The input strings are then evaluated and the results\n\
884 are printed. This makes it possible to examine the values of variables\n\
885 within a function, and to assign new values if necessary. To leave the\n\
886 prompt and return to normal execution type @samp{return} or @samp{dbcont}.\n\
887 The @code{keyboard} function does not return an exit status.\n\
889 If @code{keyboard} is invoked without arguments, a default prompt of\n\
890 @samp{debug> } is used.\n\
891 @seealso{dbcont, dbquit}\n\
896 int nargin = args.
length ();
898 if (nargin == 0 || nargin == 1)
922 @deftypefn {Command} {} echo options\n\
923 Control whether commands are displayed as they are executed. Valid\n\
928 Enable echoing of commands as they are executed in script files.\n\
931 Disable echoing of commands as they are executed in script files.\n\
934 Enable echoing of commands as they are executed in script files and\n\
938 Disable echoing of commands as they are executed in script files and\n\
943 With no arguments, @code{echo} toggles the current echo state.\n\
948 int argc = args.
length () + 1;
961 Vecho_executing_commands =
ECHO_OFF;
969 std::string
arg = argv[1];
973 else if (arg ==
"off")
974 Vecho_executing_commands =
ECHO_OFF;
982 std::string
arg = argv[1];
984 if (arg ==
"on" && argv[2] ==
"all")
987 Vecho_executing_commands = tmp;
989 else if (arg ==
"off" && argv[2] ==
"all")
990 Vecho_executing_commands =
ECHO_OFF;
1004 DEFUN (completion_matches, args, nargout,
1006 @deftypefn {Built-in Function} {} completion_matches (@var{hint})\n\
1007 Generate possible completions given @var{hint}.\n\
1009 This function is provided for the benefit of programs like Emacs which\n\
1010 might be controlling Octave and handling user input. The current\n\
1011 command number is not incremented when this function is called. This is\n\
1012 a feature, not a bug.\n\
1017 int nargin = args.
length ();
1021 std::string hint = args(0).string_value ();
1054 if (! list.
empty ())
1065 int len = list.
length ();
1067 for (
int i = 0; i < len; i++)
1080 DEFUN (readline_read_init_file, args, ,
1082 @deftypefn {Built-in Function} {} readline_read_init_file (@var{file})\n\
1083 Read the readline library initialization file @var{file}. If\n\
1084 @var{file} is omitted, read the default initialization file (normally\n\
1085 @file{~/.inputrc}).\n\
1087 @xref{Readline Init File, , , readline, GNU Readline Library},\n\
1089 @seealso{readline_re_read_init_file}\n\
1094 int nargin = args.
length ();
1098 else if (nargin == 1)
1100 std::string file = args(0).string_value ();
1111 DEFUN (readline_re_read_init_file, args, ,
1113 @deftypefn {Built-in Function} {} readline_re_read_init_file ()\n\
1114 Re-read the last readline library initialization file that was read.\n\
1115 @xref{Readline Init File, , , readline, GNU Readline Library},\n\
1117 @seealso{readline_read_init_file}\n\
1122 if (args.length () == 0)
1133 input_event_hook_functions.
run ();
1135 if (input_event_hook_functions.
empty ())
1141 DEFUN (add_input_event_hook, args, ,
1143 @deftypefn {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn})\n\
1144 @deftypefnx {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn}, @var{data})\n\
1145 Add the named function or function handle @var{fcn} to the list of functions\n\
1146 to call periodically when Octave is waiting for input. The function should\n\
1150 @var{fcn} (@var{data})\n\
1153 If @var{data} is omitted, Octave calls the function without any\n\
1156 The returned identifier may be used to remove the function handle from\n\
1157 the list of input hook functions.\n\
1158 @seealso{remove_input_event_hook}\n\
1163 int nargin = args.
length ();
1165 if (nargin == 1 || nargin == 2)
1170 user_data = args(1);
1176 if (input_event_hook_functions.
empty ())
1179 input_event_hook_functions.
insert (hook_fcn.
id (), hook_fcn);
1181 retval = hook_fcn.
id ();
1184 error (
"add_input_event_hook: expecting function handle or character string as first argument");
1192 DEFUN (remove_input_event_hook, args, ,
1194 @deftypefn {Built-in Function} {} remove_input_event_hook (@var{name})\n\
1195 @deftypefnx {Built-in Function} {} remove_input_event_hook (@var{fcn_id})\n\
1196 Remove the named function or function handle with the given identifier\n\
1197 from the list of functions to call periodically when Octave is waiting\n\
1199 @seealso{add_input_event_hook}\n\
1204 int nargin = args.
length ();
1206 if (nargin == 1 || nargin == 2)
1208 std::string hook_fcn_id = args(0).string_value ();
1210 bool warn = (nargin < 2);
1215 = input_event_hook_functions.
find (hook_fcn_id);
1217 if (p != input_event_hook_functions.
end ())
1218 input_event_hook_functions.
erase (p);
1220 warning (
"remove_input_event_hook: %s not found in list",
1221 hook_fcn_id.c_str ());
1223 if (input_event_hook_functions.
empty ())
1227 error (
"remove_input_event_hook: argument not valid as a hook function name or id");
1235 DEFUN (PS1, args, nargout,
1237 @deftypefn {Built-in Function} {@var{val} =} PS1 ()\n\
1238 @deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\
1239 @deftypefnx {Built-in Function} {} PS1 (@var{new_val}, \"local\")\n\
1240 Query or set the primary prompt string. When executing interactively,\n\
1241 Octave displays the primary prompt when it is ready to read a command.\n\
1243 The default value of the primary prompt string is @qcode{\"octave:\\#> \"}.\n\
1244 To change it, use a command like\n\
1247 PS1 (\"\\\\u@@\\\\H> \")\n\
1251 which will result in the prompt @samp{boris@@kremvax> } for the user\n\
1252 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two\n\
1253 backslashes are required to enter a backslash into a double-quoted\n\
1254 character string. @xref{Strings}.\n\
1256 You can also use ANSI escape sequences if your terminal supports them.\n\
1257 This can be useful for coloring the prompt. For example,\n\
1260 PS1 (\"\\\\[\\\\033[01;31m\\\\]\\\\s:\\\\#> \\\\[\\\\033[0m\\\\]\")\n\
1264 will give the default Octave prompt a red coloring.\n\
1266 When called from inside a function with the @qcode{\"local\"} option, the\n\
1267 variable is changed locally for the function and any subroutines it calls. \n\
1268 The original variable value is restored when exiting the function.\n\
1269 @seealso{PS2, PS4}\n\
1275 DEFUN (PS2, args, nargout,
1277 @deftypefn {Built-in Function} {@var{val} =} PS2 ()\n\
1278 @deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\
1279 @deftypefnx {Built-in Function} {} PS2 (@var{new_val}, \"local\")\n\
1280 Query or set the secondary prompt string. The secondary prompt is\n\
1281 printed when Octave is expecting additional input to complete a\n\
1282 command. For example, if you are typing a @code{for} loop that spans several\n\
1283 lines, Octave will print the secondary prompt at the beginning of\n\
1284 each line after the first. The default value of the secondary prompt\n\
1285 string is @qcode{\"> \"}.\n\
1287 When called from inside a function with the @qcode{\"local\"} option, the\n\
1288 variable is changed locally for the function and any subroutines it calls. \n\
1289 The original variable value is restored when exiting the function.\n\
1290 @seealso{PS1, PS4}\n\
1296 DEFUN (PS4, args, nargout,
1298 @deftypefn {Built-in Function} {@var{val} =} PS4 ()\n\
1299 @deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\
1300 @deftypefnx {Built-in Function} {} PS4 (@var{new_val}, \"local\")\n\
1301 Query or set the character string used to prefix output produced\n\
1302 when echoing commands is enabled.\n\
1303 The default value is @qcode{\"+ \"}.\n\
1304 @xref{Diary and Echo Commands}, for a description of echoing commands.\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{echo, echo_executing_commands, PS1, PS2}\n\
1315 DEFUN (completion_append_char, args, nargout,
1317 @deftypefn {Built-in Function} {@var{val} =} completion_append_char ()\n\
1318 @deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\
1319 @deftypefnx {Built-in Function} {} completion_append_char (@var{new_val}, \"local\")\n\
1320 Query or set the internal character variable that is appended to\n\
1321 successful command-line completion attempts. The default\n\
1322 value is @qcode{\" \"} (a single space).\n\
1324 When called from inside a function with the @qcode{\"local\"} option, the\n\
1325 variable is changed locally for the function and any subroutines it calls. \n\
1326 The original variable value is restored when exiting the function.\n\
1332 DEFUN (echo_executing_commands, args, nargout,
1334 @deftypefn {Built-in Function} {@var{val} =} echo_executing_commands ()\n\
1335 @deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\
1336 @deftypefnx {Built-in Function} {} echo_executing_commands (@var{new_val}, \"local\")\n\
1337 Query or set the internal variable that controls the echo state.\n\
1338 It may be the sum of the following values:\n\
1342 Echo commands read from script files.\n\
1345 Echo commands from functions.\n\
1348 Echo commands read from command line.\n\
1351 More than one state can be active at once. For example, a value of 3 is\n\
1352 equivalent to the command @kbd{echo on all}.\n\
1354 The value of @code{echo_executing_commands} may be set by the @kbd{echo}\n\
1355 command or the command line option @option{--echo-commands}.\n\
1357 When called from inside a function with the @qcode{\"local\"} option, the\n\
1358 variable is changed locally for the function and any subroutines it calls. \n\
1359 The original variable value is restored when exiting the function.\n\
1365 DEFUN (__request_drawnow__, args, ,
1367 @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\
1368 @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\
1369 Undocumented internal function.\n\
1374 int nargin = args.
length ();
1378 else if (nargin == 1)
1386 DEFUN (__gud_mode__, args, ,
1388 @deftypefn {Built-in Function} {} __gud_mode__ ()\n\
1389 Undocumented internal function.\n\
1394 int nargin = args.
length ();
1398 else if (nargin == 1)
1406 DEFUN (filemarker, args, nargout,
1408 @deftypefn {Built-in Function} {@var{val} =} filemarker ()\n\
1409 @deftypefnx {Built-in Function} {} filemarker (@var{new_val})\n\
1410 @deftypefnx {Built-in Function} {} filemarker (@var{new_val}, \"local\")\n\
1411 Query or set the character used to separate filename from the\n\
1412 the subfunction names contained within the file. This can be used in\n\
1413 a generic manner to interact with subfunctions. For example,\n\
1416 help ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
1420 returns the help string associated with the subfunction @code{mysubfunc}\n\
1421 of the function @code{myfunc}. Another use of @code{filemarker} is when\n\
1422 debugging it allows easier placement of breakpoints within subfunctions.\n\
1426 dbstop ([\"myfunc\", filemarker, \"mysubfunc\"])\n\
1430 will set a breakpoint at the first line of the subfunction @code{mysubfunc}.\n\
1432 When called from inside a function with the @qcode{\"local\"} option, the\n\
1433 variable is changed locally for the function and any subroutines it calls. \n\
1434 The original variable value is restored when exiting the function.\n\
1441 if (!
error_state && (::isalnum (Vfilemarker) || Vfilemarker ==
'_'))
1444 error (
"filemarker: character can not be a valid character for a function name");