GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
input.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26// Get command input interactively or from files.
27
28#if defined (HAVE_CONFIG_H)
29# include "config.h"
30#endif
31
32#include <cstdio>
33#include <cstdlib>
34#include <cstring>
35
36#include <algorithm>
37#include <iostream>
38#include <queue>
39#include <sstream>
40#include <string>
41
42#include "cmd-edit.h"
43#include "file-ops.h"
44#include "iconv-wrappers.h"
46#include "oct-env.h"
47#include "oct-string.h"
48#include "quit.h"
49#include "str-vec.h"
50#include "uniconv-wrappers.h"
51
52#include "builtin-defun-decls.h"
53#include "defun.h"
54#include "error.h"
55#include "errwarn.h"
56#include "event-manager.h"
57#include "help.h"
58#include "hook-fcn.h"
59#include "input.h"
60#include "interpreter-private.h"
61#include "interpreter.h"
62#include "load-path.h"
63#include "octave.h"
64#include "oct-map.h"
65#include "oct-hist.h"
66#include "interpreter.h"
67#include "event-manager.h"
68#include "ovl.h"
69#include "ov-fcn-handle.h"
70#include "ov-usr-fcn.h"
71#include "pager.h"
72#include "pt-eval.h"
73#include "pt-stmt.h"
74#include "sighandlers.h"
75#include "sysdep.h"
76#include "interpreter.h"
77#include "unwind-prot.h"
78#include "utils.h"
79#include "variables.h"
80
81// The time we last printed a prompt.
82octave::sys::time Vlast_prompt_time = 0.0;
83
84// TRUE after a call to completion_matches.
86
87// TRUE if the plotting system has requested a call to drawnow at
88// the next user prompt.
89bool Vdrawnow_requested = false;
90
92
93static std::string
94quoting_filename (const std::string& text, int, char quote)
95{
96 if (quote)
97 return text;
98 else
99 return ("'" + text);
100}
101
102// Try to parse a partial command line in reverse, excluding trailing TEXT.
103// If it appears a variable has been indexed by () or {},
104// return that expression,
105// to allow autocomplete of field names of arrays of structures.
106static std::string
107find_indexed_expression (const std::string& text)
108{
109 std::string line = command_editor::get_line_buffer ();
110
111 int pos = line.length () - text.length ();
112 int curly_count = 0;
113 int paren_count = 0;
114
115 int last = --pos;
116
117 while (pos >= 0 && (line[pos] == ')' || line[pos] == '}'))
118 {
119 if (line[pos] == ')')
120 paren_count++;
121 else
122 curly_count++;
123
124 while (curly_count + paren_count > 0 && --pos >= 0)
125 {
126 if (line[pos] == ')')
127 paren_count++;
128 else if (line[pos] == '(')
129 paren_count--;
130 else if (line[pos] == '}')
131 curly_count++;
132 else if (line[pos] == '{')
133 curly_count--;
134 }
135
136 while (--pos >= 0 && line[pos] == ' ')
137 ;
138 }
139
140 while (pos >= 0 && (isalnum (line[pos]) || line[pos] == '_'))
141 pos--;
142
143 if (++pos >= 0)
144 return (line.substr (pos, last + 1 - pos));
145 else
146 return std::string ();
147}
148
149static string_vector
150generate_struct_completions (const std::string& text,
151 std::string& prefix, std::string& hint)
152{
153 string_vector names;
154
155 std::size_t pos = text.rfind ('.');
156 bool array = false;
157
158 if (pos != std::string::npos)
159 {
160 if (pos == text.length ())
161 hint = "";
162 else
163 hint = text.substr (pos+1);
164
165 prefix = text.substr (0, pos);
166
167 if (prefix == "")
168 {
169 array = true;
170 prefix = find_indexed_expression (text);
171 }
172
173 std::string base_name = prefix;
174
175 pos = base_name.find_first_of ("{(. ");
176
177 if (pos != std::string::npos)
178 base_name = base_name.substr (0, pos);
179
180 interpreter& interp = __get_interpreter__ ();
181
182 if (interp.is_variable (base_name))
183 {
184 int parse_status;
185
186 error_system& es = interp.get_error_system ();
187
188 unwind_protect frame;
189
192
193 es.discard_warning_messages (true);
194
195 try
196 {
197 octave_value tmp
198 = interp.eval_string (prefix, true, parse_status);
199
200 frame.run ();
201
202 if (tmp.is_defined ()
203 && (tmp.isstruct () || tmp.isjava () || tmp.is_classdef_object ()))
204 names = tmp.map_keys ();
205 }
206 catch (const execution_exception&)
207 {
208 interp.recover_from_exception ();
209 }
210 }
211 }
212
213 // Undo look-back that found the array expression,
214 // but insert an extra "." to distinguish from the non-struct case.
215 if (array)
216 prefix = ".";
217
218 return names;
219}
220
221// FIXME: this will have to be much smarter to work "correctly".
222static bool
223looks_like_struct (const std::string& text, char prev_char)
224{
225 bool retval = (! text.empty ()
226 && (text != "." || prev_char == ')' || prev_char == '}')
227 && text.find_first_of (sys::file_ops::dir_sep_chars ()) == std::string::npos
228 && text.find ("..") == std::string::npos
229 && text.rfind ('.') != std::string::npos);
230
231 return retval;
232}
233
234// FIXME: make this generate filenames when appropriate.
235
236static string_vector
237generate_possible_completions (const std::string& text, std::string& prefix,
238 std::string& hint, bool& deemed_struct)
239{
240 string_vector names;
241
242 prefix = "";
243
244 char prev_char = command_editor::get_prev_char (text.length ());
245 deemed_struct = looks_like_struct (text, prev_char);
246
247 if (deemed_struct)
248 names = generate_struct_completions (text, prefix, hint);
249 else
250 names = make_name_list ();
251
252 // Sort and remove duplicates.
253
254 names.sort (true);
255
256 return names;
257}
258
259static bool
260is_completing_dirfns ()
261{
262 static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"};
263 static const std::size_t DIRFNS_COMMANDS_LENGTH = 4;
264
265 bool retval = false;
266
267 std::string line = command_editor::get_line_buffer ();
268
269 for (std::size_t i = 0; i < DIRFNS_COMMANDS_LENGTH; i++)
270 {
271 int index = line.find (dirfns_commands[i] + ' ');
272
273 if (index == 0)
274 {
275 retval = true;
276 break;
277 }
278 }
279
280 return retval;
281}
282
283static std::string
284generate_completion (const std::string& text, int state)
285{
286 std::string retval;
287
288 static std::string prefix;
289 static std::string hint;
290
291 static std::size_t hint_len = 0;
292
293 static int list_index = 0;
294 static int name_list_len = 0;
295 static int name_list_total_len = 0;
296 static string_vector name_list;
297 static string_vector file_name_list;
298
299 static int matches = 0;
300
301 if (state == 0)
302 {
303 list_index = 0;
304
305 prefix = "";
306
307 hint = text;
308
309 // No reason to display symbols while completing a
310 // file/directory operation.
311
312 bool deemed_struct = false;
313
314 if (is_completing_dirfns ())
315 name_list = string_vector ();
316 else
317 name_list = generate_possible_completions (text, prefix, hint,
318 deemed_struct);
319
320 name_list_len = name_list.numel ();
321
322 // If the line was something like "a{1}." then text = "." but
323 // we don't want to expand all the . files.
324 if (! deemed_struct)
325 {
326
327 file_name_list = command_editor::generate_filename_completions (text);
328
329 name_list.append (file_name_list);
330
331 }
332
333 name_list_total_len = name_list.numel ();
334
335 hint_len = hint.length ();
336
337 matches = 0;
338
339 for (int i = 0; i < name_list_len; i++)
340 if (hint == name_list[i].substr (0, hint_len))
341 matches++;
342 }
343
344 if (name_list_total_len > 0 && matches > 0)
345 {
346 while (list_index < name_list_total_len)
347 {
348 std::string name = name_list[list_index];
349
350 list_index++;
351
352 if (hint == name.substr (0, hint_len))
353 {
354 // Special case: array reference forces prefix="."
355 // in generate_struct_completions ()
356 if (list_index <= name_list_len && ! prefix.empty ())
357 retval = (prefix == "." ? "" : prefix) + '.' + name;
358 else
359 retval = name;
360
361 char prev_char =
362 command_editor::get_prev_char (text.length ());
363
364 if (matches == 1 && looks_like_struct (retval, prev_char))
365 {
366 // Don't append anything, since we don't know
367 // whether it should be '(' or '.'.
368
370 }
371 else
372 {
373 input_system& input_sys = __get_input_system__ ();
374
376 (input_sys.completion_append_char ());
377 }
378
379 break;
380 }
381 }
382 }
383
384 return retval;
385}
386
387static int
388internal_input_event_hook_fcn ()
389{
390 octave_quit ();
391
392 input_system& input_sys = __get_input_system__ ();
393
394 input_sys.run_input_event_hooks ();
395
396 return 0;
397}
398
399// Use literal "octave" in default setting for PS1 instead of
400// "\\s" to avoid setting the prompt to "octave.exe" or
401// "octave-gui", etc.
402
404 : m_interpreter (interp), m_PS1 (R"(octave:\#> )"), m_PS2 ("> "),
405 m_completion_append_char (' '), m_gud_mode (false),
406 m_mfile_encoding ("utf-8"), m_auto_repeat_debug_command (true),
407 m_last_debugging_command ("\n"), m_input_event_hook_functions (),
408 m_initialized (false)
409{ }
410
411void
412input_system::initialize (bool line_editing)
413{
414 if (m_initialized)
415 return;
416
417 // Force default line editor if we don't want readline editing.
418 if (! line_editing)
419 {
421 return;
422 }
423
424 // If we are using readline, this allows conditional parsing of the
425 // .inputrc file.
426
427 command_editor::set_name ("Octave");
428
429 // FIXME: this needs to include a comma too, but that
430 // causes trouble for the new struct element completion code.
431
432 static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~";
433
435
437
439
440 command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{");
441
443
444 command_editor::set_completion_function (generate_completion);
445
446 command_editor::set_quoting_function (quoting_filename);
447
448 command_editor::add_event_hook (internal_input_event_hook_fcn);
449
450 m_initialized = true;
451}
452
454input_system::PS1 (const octave_value_list& args, int nargout)
455{
456 return set_internal_variable (m_PS1, args, nargout, "PS1");
457}
458
460input_system::PS2 (const octave_value_list& args, int nargout)
461{
462 return set_internal_variable (m_PS2, args, nargout, "PS2");
463}
464
467 int nargout)
468{
469 return set_internal_variable (m_completion_append_char, args, nargout,
470 "completion_append_char");
471}
472
474input_system::gud_mode (const octave_value_list& args, int nargout)
475{
476 return set_internal_variable (m_gud_mode, args, nargout, "__gud_mode__");
477}
478
480input_system::mfile_encoding (const octave_value_list& args, int nargout)
481{
482 // Save current value in case there is an error in the additional
483 // validation below.
484
485 std::string saved_encoding = m_mfile_encoding;
486
487 // We must pass the actual variable to change here for temporary
488 // "local" settings to work properly.
489
490 octave_value retval
491 = set_internal_variable (m_mfile_encoding, args, nargout,
492 "mfile_encoding");
493
494 // Additional validation if the encoding has changed.
495
496 if (m_mfile_encoding != saved_encoding)
497 {
498 if (m_mfile_encoding.empty ())
499 {
500 m_mfile_encoding = "system";
501 }
502 else
503 {
504 std::transform (m_mfile_encoding.begin (),
505 m_mfile_encoding.end (),
506 m_mfile_encoding.begin (), ::tolower);
507
508 std::string encoding = (m_mfile_encoding.compare ("system") == 0)
509 ? octave_locale_charset_wrapper () : m_mfile_encoding;
510
511 // Check for valid encoding name.
512 void *codec
513 = octave_iconv_open_wrapper (encoding.c_str (), "utf-8");
514
515 if (codec == reinterpret_cast<void *> (-1))
516 {
517 m_mfile_encoding = saved_encoding;
518 if (errno == EINVAL)
519 error ("mfile_encoding: conversion from encoding '%s' "
520 "not supported", encoding.c_str ());
521 else
522 error ("mfile_encoding: error %d opening encoding '%s'",
523 errno, encoding.c_str ());
524 }
525 else
527 }
528
529 }
530
531 // Synchronize the related gui preference for editor encoding
532 F__event_manager_gui_preference__ (m_interpreter, ovl ("editor/default_encoding", m_mfile_encoding));
533
534 return retval;
535}
536
537// Get part of the directory that would be added to the load path
538static std::string
539load_path_dir (const std::string& dir)
540{
541 std::string lp_dir = dir;
542
543 // strip trailing filesep
544 std::size_t ipos = lp_dir.find_last_not_of (sys::file_ops::dir_sep_chars ());
545 if (ipos != std::string::npos)
546 lp_dir = lp_dir.erase (ipos+1);
547
548 // strip trailing private folder
549 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ());
550 if (ipos != std::string::npos
551 && lp_dir.substr (ipos+1).compare ("private") == 0)
552 {
553 lp_dir = lp_dir.erase (ipos);
554 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ());
555 }
556
557 // strip trailing @class folder
558 if (ipos != std::string::npos && lp_dir[ipos+1] == '@')
559 {
560 lp_dir = lp_dir.erase (ipos);
561 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ());
562 }
563
564 // strip (nested) +namespace folders
565 while (ipos != std::string::npos && lp_dir[ipos+1] == '+')
566 {
567 lp_dir = lp_dir.erase (ipos);
568 ipos = lp_dir.find_last_of (sys::file_ops::dir_sep_chars ());
569 }
570
571 return lp_dir;
572}
573
574std::string
575input_system::dir_encoding (const std::string& dir)
576{
577 std::string enc = m_mfile_encoding;
578 // use canonicalized path as key
579 const std::string key = sys::canonicalize_file_name (dir);
580
581 auto enc_it = m_dir_encoding.find (key);
582 if (enc_it != m_dir_encoding.end ())
583 enc = enc_it->second;
584
585 return enc;
586}
587
588void
589input_system::set_dir_encoding (const std::string& dir,
590 std::string& enc)
591{
592 // use lower case
593 std::transform (enc.begin (), enc.end (), enc.begin (), ::tolower);
594
595 if (enc.compare ("delete") == 0)
596 {
597 // Remove path from map
598 m_dir_encoding.erase (load_path_dir (dir));
599 return;
600 }
601 else if (enc.compare ("utf-8"))
602 {
603 // Check for valid encoding name.
604 // FIXME: This will probably not happen very often and opening the
605 // encoder doesn't take long.
606 // Should we cache working encoding identifiers anyway?
607 void *codec
608 = octave_iconv_open_wrapper (enc.c_str (), "utf-8");
609
610 if (codec == reinterpret_cast<void *> (-1))
611 {
612 if (errno == EINVAL)
613 error ("dir_encoding: conversion from encoding '%s' "
614 "not supported", enc.c_str ());
615 else
616 error ("dir_encoding: error %d opening encoding '%s'.",
617 errno, enc.c_str ());
618 }
619 else
621 }
622
623 m_dir_encoding[load_path_dir (dir)] = enc;
624
625 return;
626}
627
630 int nargout)
631{
632 return set_internal_variable (m_auto_repeat_debug_command, args, nargout,
633 "auto_repeat_debug_command");
634}
635
636bool
637input_system::yes_or_no (const std::string& prompt)
638{
639 std::string prompt_string = prompt + "(yes or no) ";
640
641 while (1)
642 {
643 bool eof = false;
644
645 std::string input_buf = interactive_input (prompt_string, eof);
646
647 if (input_buf == "yes")
648 return true;
649 else if (input_buf == "no")
650 return false;
651 else
652 message (nullptr, "Please answer yes or no.");
653 }
654}
655
656std::string
657input_system::interactive_input (const std::string& s, bool& eof)
658{
659 Vlast_prompt_time.stamp ();
660
661 if (Vdrawnow_requested && m_interpreter.interactive ())
662 {
663 bool eval_error = false;
664
665 try
666 {
667 Fdrawnow (m_interpreter);
668 }
669 catch (const execution_exception& ee)
670 {
671 eval_error = true;
672
673 m_interpreter.handle_exception (ee);
674 }
675
676 flush_stdout ();
677
678 // We set Vdrawnow_requested to false even if there is an error in
679 // drawnow so that the error doesn't reappear at every prompt.
680
681 Vdrawnow_requested = false;
682
683 if (eval_error)
684 return "\n";
685 }
686
687 return gnu_readline (s, eof);
688}
689
690// If the user simply hits return, this will produce an empty matrix.
691
693input_system::get_user_input (const octave_value_list& args, int nargout)
694{
695 octave_value_list retval;
696
697 std::string prompt = args(0).xstring_value ("input: unrecognized argument");
698
699 bool read_as_string = false;
700 if (args.length () == 2) // `input (..., "s")`?
701 {
702 std::string literal
703 = args(1).xstring_value ("input: second argument must be 's'.");
704 if (literal.length () != 1 || literal[0] != 's')
705 error ("input: second argument must be 's'.");
706
707 read_as_string = true;
708 }
709
710 output_system& output_sys = m_interpreter.get_output_system ();
711
712 output_sys.reset ();
713
714 octave_diary << prompt;
715
716 bool eof = false;
717
718 std::string input_buf = interactive_input (prompt.c_str (), eof);
719
720 if (input_buf.empty ())
721 error ("input: reading user-input failed!");
722
723 std::size_t len = input_buf.length ();
724
725 octave_diary << input_buf;
726
727 if (input_buf[len - 1] != '\n')
728 octave_diary << "\n";
729
730 if (read_as_string)
731 {
732 // FIXME: fix gnu_readline and octave_gets instead!
733 if (input_buf.length () == 1 && input_buf[0] == '\n')
734 retval(0) = "";
735 else
736 retval(0) = input_buf;
737 }
738 else
739 {
740 int parse_status = 0;
741
742 retval
743 = m_interpreter.eval_string (input_buf, true, parse_status, nargout);
744
745 tree_evaluator& tw = m_interpreter.get_evaluator ();
746
747 if (! tw.in_debug_repl () && retval.empty ())
748 retval(0) = Matrix ();
749 }
750
751 return retval;
752}
753
754bool
756{
757 return ! m_input_event_hook_functions.empty ();
758}
759
760void
762{
763 m_input_event_hook_functions.insert (hook_fcn.id (), hook_fcn);
764}
765
766bool
767input_system::remove_input_event_hook (const std::string& hook_fcn_id)
768{
770 = m_input_event_hook_functions.find (hook_fcn_id);
771
772 if (p == m_input_event_hook_functions.end ())
773 return false;
774
775 m_input_event_hook_functions.erase (p);
776 return true;
777}
778
779void
781{
782 m_input_event_hook_functions.clear ();
783}
784
785void
787{
788 m_input_event_hook_functions.run ();
789}
790
791std::string
792input_system::gnu_readline (const std::string& s, bool& eof) const
793{
794 octave_quit ();
795
796 eof = false;
797
798 std::string retval = command_editor::readline (s, eof);
799
800 if (! eof && retval.empty ())
801 retval = "\n";
802
803 return retval;
804}
805
806std::string
807base_reader::octave_gets (const std::string& prompt, bool& eof)
808{
809 octave_quit ();
810
811 eof = false;
812
813 std::string retval;
814
815 // Process pre input event hook function prior to flushing output and
816 // printing the prompt.
817
819
821
823 {
824 if (! tw.in_debug_repl ())
825 evmgr.exit_debugger_event ();
826
827 evmgr.pre_input_event ();
828
829 evmgr.set_workspace ();
830 }
831
832 bool history_skip_auto_repeated_debugging_command = false;
833
835
837
839
840 output_sys.reset ();
841
842 octave_diary << prompt;
843
844 retval = input_sys.interactive_input (prompt, eof);
845
846 // There is no need to update the load_path cache if there is no
847 // user input.
848 if (retval != "\n"
849 && retval.find_first_not_of (" \t\n\r") != std::string::npos)
850 {
852
853 lp.update ();
854
855 if (tw.in_debug_repl ())
856 input_sys.last_debugging_command (retval);
857 else
858 input_sys.last_debugging_command ("\n");
859 }
860 else if (tw.in_debug_repl () && input_sys.auto_repeat_debug_command ())
861 {
862 retval = input_sys.last_debugging_command ();
863 history_skip_auto_repeated_debugging_command = true;
864 }
865
866 if (retval != "\n")
867 {
868 if (! history_skip_auto_repeated_debugging_command)
869 {
870 if (command_history::add (retval))
871 evmgr.append_history (retval);
872 }
873
874 octave_diary << retval;
875
876 if (! retval.empty () && retval.back () != '\n')
877 octave_diary << "\n";
878 }
879 else
880 octave_diary << "\n";
881
882 // Process post input event hook function after the internal history
883 // list has been updated.
884
886 evmgr.post_input_event ();
887
888 return retval;
889}
890
891class terminal_reader : public base_reader
892{
893public:
894
895 terminal_reader (interpreter& interp)
896 : base_reader (interp), m_eof (false), m_input_queue ()
897 { }
898
899 std::string get_input (const std::string& prompt, bool& eof);
900
901 std::string input_source () const { return s_in_src; }
902
903 bool input_from_terminal () const { return true; }
904
905private:
906
907 bool m_eof;
908 std::queue<std::string> m_input_queue;
909
910 static const std::string s_in_src;
911};
912
913class file_reader : public base_reader
914{
915public:
916
917 file_reader (interpreter& interp, FILE *f_arg)
918 : base_reader (interp), m_file (f_arg)
919 {
920 input_system& input_sys = interp.get_input_system ();
921 m_encoding = input_sys.mfile_encoding ();
922 }
923
924 file_reader (interpreter& interp, FILE *f_arg, const std::string& enc)
925 : base_reader (interp), m_file (f_arg), m_encoding (enc) { }
926
927 std::string get_input (const std::string& prompt, bool& eof);
928
929 std::string input_source () const { return s_in_src; }
930
931 bool input_from_file () const { return true; }
932
933private:
934
935 FILE *m_file;
936
937 std::string m_encoding;
938
939 static const std::string s_in_src;
940};
941
942class eval_string_reader : public base_reader
943{
944public:
945
946 eval_string_reader (interpreter& interp, const std::string& str)
947 : base_reader (interp), m_eval_string (str)
948 { }
949
950 std::string get_input (const std::string& prompt, bool& eof);
951
952 std::string input_source () const { return s_in_src; }
953
954 bool input_from_eval_string () const { return true; }
955
956private:
957
958 std::string m_eval_string;
959
960 static const std::string s_in_src;
961};
962
964 : m_rep (new terminal_reader (interp))
965{ }
966
967input_reader::input_reader (interpreter& interp, FILE *file)
968 : m_rep (new file_reader (interp, file))
969{ }
970
971input_reader::input_reader (interpreter& interp, FILE *file,
972 const std::string& enc)
973 : m_rep (new file_reader (interp, file, enc))
974{ }
975
976input_reader::input_reader (interpreter& interp, const std::string& str)
977 : m_rep (new eval_string_reader (interp, str))
978{ }
979
980const std::string base_reader::s_in_src ("invalid");
981
982const std::string terminal_reader::s_in_src ("terminal");
983
984// If octave_gets returns multiple lines, we cache the input and
985// return it one line at a time. Multiple input lines may happen when
986// using readline and bracketed paste mode is enabled, for example.
987// Instead of queueing lines here, it might be better to modify the
988// grammar in the parser to handle multiple lines when working
989// interactively. See also bug #59938.
990
991std::string
992terminal_reader::get_input (const std::string& prompt, bool& eof)
993{
994 octave_quit ();
995
996 eof = false;
997
998 if (m_input_queue.empty ())
999 {
1000 std::string input = octave_gets (prompt, m_eof);
1001
1002 std::size_t len = input.size ();
1003
1004 if (len == 0)
1005 {
1006 if (m_eof)
1007 {
1008 eof = m_eof;
1009 return input;
1010 }
1011 else
1012 {
1013 // Can this happen, or will the string returned from
1014 // octave_gets always end in a newline character?
1015
1016 input = "\n";
1017 len = 1;
1018 }
1019 }
1020
1021 std::size_t beg = 0;
1022 while (beg < len)
1023 {
1024 std::size_t end = input.find ('\n', beg);
1025
1026 if (end == std::string::npos)
1027 {
1028 m_input_queue.push (input.substr (beg));
1029 break;
1030 }
1031 else
1032 {
1033 m_input_queue.push (input.substr (beg, end-beg+1));
1034 beg = end + 1;
1035 }
1036 }
1037 }
1038
1039 std::string retval = m_input_queue.front ();
1040 m_input_queue.pop ();
1041
1042 if (m_input_queue.empty ())
1043 eof = m_eof;
1044
1045 return retval;
1046}
1047
1048const std::string file_reader::s_in_src ("file");
1049
1050std::string
1051file_reader::get_input (const std::string& /*prompt*/, bool& eof)
1052{
1053 octave_quit ();
1054
1055 eof = false;
1056
1057 std::string src_str = fgets (m_file, eof);
1058
1059 std::string mfile_encoding;
1060
1061 if (m_encoding.empty ())
1062 {
1063 input_system& input_sys = m_interpreter.get_input_system ();
1064 mfile_encoding = input_sys.mfile_encoding ();
1065 }
1066 else
1067 mfile_encoding = m_encoding;
1068
1069 std::string encoding;
1070 if (mfile_encoding.compare ("system") == 0)
1071 {
1072 encoding = octave_locale_charset_wrapper ();
1073 // encoding identifiers should consist of ASCII only characters
1074 std::transform (encoding.begin (), encoding.end (), encoding.begin (),
1075 ::tolower);
1076 }
1077 else
1078 encoding = mfile_encoding;
1079
1080 if (encoding.compare ("utf-8") == 0)
1081 {
1082 // Check for BOM and strip it
1083 if (src_str.compare (0, 3, "\xef\xbb\xbf") == 0)
1084 src_str.erase (0, 3);
1085
1086 // replace invalid portions of the string
1087 // FIXME: Include file name that corresponds to m_file.
1088 if (string::u8_validate ("get_input", src_str) > 0)
1089 warning_with_id ("octave:get_input:invalid_utf8",
1090 "Invalid UTF-8 byte sequences have been replaced.");
1091 }
1092 else
1093 {
1094 // convert encoding to UTF-8 before returning string
1095 const char *src = src_str.c_str ();
1096 std::size_t srclen = src_str.length ();
1097
1098 std::size_t length;
1099 uint8_t *utf8_str;
1100
1101 utf8_str = octave_u8_conv_from_encoding (encoding.c_str (), src, srclen,
1102 &length);
1103
1104 if (! utf8_str)
1105 error ("file_reader::get_input: "
1106 "converting from codepage '%s' to UTF-8: %s",
1107 encoding.c_str (), std::strerror (errno));
1108
1109 unwind_action free_utf8_str ([utf8_str] () { ::free (utf8_str); });
1110
1111 src_str = std::string (reinterpret_cast<char *> (utf8_str), length);
1112 }
1113
1114 return src_str;
1115}
1116
1117const std::string eval_string_reader::s_in_src ("eval_string");
1118
1119std::string
1120eval_string_reader::get_input (const std::string& /*prompt*/, bool& eof)
1121{
1122 octave_quit ();
1123
1124 eof = false;
1125
1126 std::string retval;
1127
1128 retval = m_eval_string;
1129
1130 // Clear the eval string so that the next call will return
1131 // an empty character string with EOF = true.
1132 m_eval_string = "";
1133
1134 if (retval.empty ())
1135 eof = true;
1136
1137 return retval;
1138}
1139
1140DEFMETHOD (input, interp, args, nargout,
1141 doc: /* -*- texinfo -*-
1142@deftypefn {} {@var{ans} =} input (@var{prompt})
1143@deftypefnx {} {@var{ans} =} input (@var{prompt}, "s")
1144Print @var{prompt} and wait for user input.
1145
1146For example,
1147
1148@example
1149input ("Pick a number, any number! ")
1150@end example
1151
1152@noindent
1153prints the prompt
1154
1155@example
1156Pick a number, any number!
1157@end example
1158
1159@noindent
1160and waits for the user to enter a value. The string entered by the user
1161is evaluated as an expression, so it may be a literal constant, a variable
1162name, or any other valid Octave code.
1163
1164The number of return arguments, their size, and their class depend on the
1165expression entered.
1166
1167If you are only interested in getting a literal string value, you can call
1168@code{input} with the character string @qcode{"s"} as the second argument.
1169This tells Octave to return the string entered by the user directly, without
1170evaluating it first.
1171
1172Because there may be output waiting to be displayed by the pager, it is a
1173good idea to always call @code{fflush (stdout)} before calling @code{input}.
1174 This will ensure that all pending output is written to the screen before
1175your prompt.
1176@seealso{yes_or_no, kbhit, pause, menu, listdlg}
1177@end deftypefn */)
1178{
1179 int nargin = args.length ();
1180
1181 if (nargin < 1 || nargin > 2)
1182 print_usage ();
1183
1184 input_system& input_sys = interp.get_input_system ();
1185
1186 return input_sys.get_user_input (args, std::max (nargout, 1));
1187}
1188
1189DEFMETHOD (yes_or_no, interp, args, ,
1190 doc: /* -*- texinfo -*-
1191@deftypefn {} {@var{ans} =} yes_or_no ("@var{prompt}")
1192Ask the user a yes-or-no question.
1193
1194Return logical true if the answer is yes or false if the answer is no.
1195
1196Takes one argument, @var{prompt}, which is the string to display when asking
1197the question. @var{prompt} should end in a space; @code{yes-or-no} adds the
1198string @samp{(yes or no) } to it. The user must confirm the answer with
1199@key{RET} and can edit it until it has been confirmed.
1200@seealso{input}
1201@end deftypefn */)
1202{
1203 int nargin = args.length ();
1204
1205 if (nargin > 1)
1206 print_usage ();
1207
1208 input_system& input_sys = interp.get_input_system ();
1209
1210 std::string prompt;
1211
1212 if (nargin == 1)
1213 prompt = args(0).xstring_value ("yes_or_no: PROMPT must be a string");
1214
1215 return ovl (input_sys.yes_or_no (prompt));
1216}
1217
1218DEFMETHOD (keyboard, interp, args, ,
1219 doc: /* -*- texinfo -*-
1220@deftypefn {} {} keyboard ()
1221@deftypefnx {} {} keyboard ("@var{prompt}")
1222Stop m-file execution and enter debug mode.
1223
1224When the @code{keyboard} function is executed, Octave prints a prompt and
1225waits for user input. The input strings are then evaluated and the results
1226are printed. This makes it possible to examine the values of variables
1227within a function, and to assign new values if necessary. To leave the
1228prompt and return to normal execution type @samp{return} or @samp{dbcont}.
1229The @code{keyboard} function does not return an exit status.
1230
1231If @code{keyboard} is invoked without arguments, a default prompt of
1232@samp{debug> } is used.
1233@seealso{dbstop, dbcont, dbquit}
1234@end deftypefn */)
1235{
1236 int nargin = args.length ();
1237
1238 if (nargin > 1)
1239 print_usage ();
1240
1241 tree_evaluator& tw = interp.get_evaluator ();
1242
1243 if (nargin == 1)
1244 {
1245 std::string prompt
1246 = args(0).xstring_value ("keyboard: PROMPT must be a string");
1247
1248 tw.keyboard (prompt);
1249 }
1250 else
1251 tw.keyboard ();
1252
1253 return ovl ();
1254}
1255
1256DEFUN (completion_matches, args, nargout,
1257 doc: /* -*- texinfo -*-
1258@deftypefn {} {@var{completion_list} =} completion_matches ("@var{hint}")
1259Generate possible word completions for Octave given the character sequence
1260@var{hint}.
1261
1262This function is provided for the benefit of programs like Emacs which might be
1263controlling Octave and handling user input. For example:
1264
1265@example
1266@group
1267completion_matches ("sine")
1268@result{}
1269sinetone
1270sinewave
1271@end group
1272@end example
1273
1274Programming Note: The current command number in Octave is not incremented when
1275this function is called. This is a feature, not a bug.
1276@end deftypefn */)
1277{
1278 if (args.length () != 1)
1279 print_usage ();
1280
1281 octave_value retval;
1282
1283 std::string hint = args(0).string_value ();
1284
1285 int n = 32;
1286
1287 string_vector list (n);
1288
1289 int k = 0;
1290
1291 for (;;)
1292 {
1293 std::string cmd = generate_completion (hint, k);
1294
1295 if (! cmd.empty ())
1296 {
1297 if (k == n)
1298 {
1299 n *= 2;
1300 list.resize (n);
1301 }
1302
1303 list[k++] = cmd;
1304 }
1305 else
1306 {
1307 list.resize (k);
1308 break;
1309 }
1310 }
1311
1312 if (nargout > 0)
1313 {
1314 if (! list.empty ())
1315 retval = list;
1316 else
1317 retval = "";
1318 }
1319 else
1320 {
1321 // We don't use string_vector::list_in_columns here
1322 // because it will be easier for Emacs if the names
1323 // appear in a single column.
1324
1325 int len = list.numel ();
1326
1327 for (int i = 0; i < len; i++)
1328 octave_stdout << list[i] << "\n";
1329 }
1330
1332
1333 return retval;
1334}
1335
1336/*
1337%!assert (ischar (completion_matches ("")))
1338%!assert (ischar (completion_matches ("a")))
1339%!assert (ischar (completion_matches (" ")))
1340%!assert (isempty (completion_matches (" ")))
1341%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches (""))))))
1342%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("a"))))))
1343%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("ab"))))))
1344%!assert (any (strcmp ("abs", deblank (cellstr (completion_matches ("abs"))))))
1345%!assert (! any (strcmp ("abs", deblank (cellstr (completion_matches ("absa"))))))
1346
1347%!error completion_matches ()
1348%!error completion_matches (1, 2)
1349*/
1350
1351DEFUN (readline_read_init_file, args, ,
1352 doc: /* -*- texinfo -*-
1353@deftypefn {} {} readline_read_init_file ()
1354@deftypefnx {} {} readline_read_init_file (@var{file})
1355Read the readline library initialization file @var{file}.
1356
1357If @var{file} is omitted, read the default initialization file
1358(normally @file{~/.inputrc}).
1359
1360@xref{Readline Init File,,,readline, GNU Readline Library},
1361for details.
1362@seealso{readline_re_read_init_file}
1363@end deftypefn */)
1364{
1365 int nargin = args.length ();
1366
1367 if (nargin > 1)
1368 print_usage ();
1369
1370 if (nargin == 0)
1372 else
1373 {
1374 std::string file = args(0).string_value ();
1375
1377 }
1378
1379 return ovl ();
1380}
1381
1382DEFUN (readline_re_read_init_file, args, ,
1383 doc: /* -*- texinfo -*-
1384@deftypefn {} {} readline_re_read_init_file ()
1385Re-read the last readline library initialization file that was read.
1386
1387@xref{Readline Init File,,,readline, GNU Readline Library},
1388for details.
1389@seealso{readline_read_init_file}
1390@end deftypefn */)
1391{
1392 if (args.length () != 0)
1393 print_usage ();
1394
1396
1397 return ovl ();
1398}
1399
1400DEFMETHOD (add_input_event_hook, interp, args, ,
1401 doc: /* -*- texinfo -*-
1402@deftypefn {} {@var{id} =} add_input_event_hook (@var{fcn})
1403@deftypefnx {} {@var{id} =} add_input_event_hook (@var{fcn}, @var{data})
1404Add the named function or function handle @var{fcn} to the list of functions
1405to call periodically when Octave is waiting for input.
1406
1407The function should have the form
1408
1409@example
1410@var{fcn} (@var{data})
1411@end example
1412
1413If @var{data} is omitted, Octave calls the function without any arguments.
1414
1415The returned identifier may be used to remove the function handle from the
1416list of input hook functions.
1417@seealso{remove_input_event_hook}
1418@end deftypefn */)
1419{
1420 int nargin = args.length ();
1421
1422 if (nargin < 1 || nargin > 2)
1423 print_usage ();
1424
1425 octave_value user_data;
1426
1427 if (nargin == 2)
1428 user_data = args(1);
1429
1430 input_system& input_sys = interp.get_input_system ();
1431
1432 hook_function hook_fcn (args(0), user_data);
1433
1434 input_sys.add_input_event_hook (hook_fcn);
1435
1436 return ovl (hook_fcn.id ());
1437}
1438
1439DEFMETHOD (remove_input_event_hook, interp, args, ,
1440 doc: /* -*- texinfo -*-
1441@deftypefn {} {} remove_input_event_hook (@var{name})
1442@deftypefnx {} {} remove_input_event_hook (@var{fcn_id})
1443Remove the named function or function handle with the given identifier
1444from the list of functions to call periodically when Octave is waiting
1445for input.
1446@seealso{add_input_event_hook}
1447@end deftypefn */)
1448{
1449 int nargin = args.length ();
1450
1451 if (nargin < 1 || nargin > 2)
1452 print_usage ();
1453
1454 std::string hook_fcn_id = args(0).xstring_value ("remove_input_event_hook: argument not valid as a hook function name or id");
1455
1456 bool warn = (nargin < 2);
1457
1458 input_system& input_sys = interp.get_input_system ();
1459
1460 if (! input_sys.remove_input_event_hook (hook_fcn_id) && warn)
1461 warning ("remove_input_event_hook: %s not found in list",
1462 hook_fcn_id.c_str ());
1463
1464 return ovl ();
1465}
1466
1467DEFMETHOD (PS1, interp, args, nargout,
1468 doc: /* -*- texinfo -*-
1469@deftypefn {} {@var{val} =} PS1 ()
1470@deftypefnx {} {@var{old_val} =} PS1 (@var{new_val})
1471@deftypefnx {} {@var{old_val} =} PS1 (@var{new_val}, "local")
1472Query or set the primary prompt string.
1473
1474When executing interactively, Octave displays the primary prompt when it is
1475ready to read a command.
1476
1477The default value of the primary prompt string is
1478@qcode{'octave:@backslashchar{}#> '}. To change it, use a command like
1479
1480@example
1481PS1 ('\u@@\H> ')
1482@end example
1483
1484@noindent
1485which will result in the prompt @samp{boris@@kremvax> } for the user
1486@samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two
1487backslashes are required to enter a backslash into a double-quoted
1488character string. @xref{Strings}.
1489
1490You can also use ANSI escape sequences if your terminal supports them.
1491This can be useful for coloring the prompt. For example,
1492
1493@example
1494PS1 ('\[\033[01;31m\]\s:\#> \[\033[0m\]')
1495@end example
1496
1497@noindent
1498will give the default Octave prompt a red coloring.
1499
1500When called from inside a function with the @qcode{"local"} option, the
1501variable is changed locally for the function and any subroutines it calls.
1502The original variable value is restored when exiting the function.
1503@seealso{PS2, PS4}
1504@end deftypefn */)
1505{
1506 return interp.PS1 (args, nargout);
1507}
1508
1509DEFMETHOD (PS2, interp, args, nargout,
1510 doc: /* -*- texinfo -*-
1511@deftypefn {} {@var{val} =} PS2 ()
1512@deftypefnx {} {@var{old_val} =} PS2 (@var{new_val})
1513@deftypefnx {} {@var{old_val} =} PS2 (@var{new_val}, "local")
1514Query or set the secondary prompt string.
1515
1516The secondary prompt is printed when Octave is expecting additional input to
1517complete a command. For example, if you are typing a @code{for} loop that
1518spans several lines, Octave will print the secondary prompt at the beginning
1519of each line after the first. The default value of the secondary prompt
1520string is @qcode{"> "}.
1521
1522When called from inside a function with the @qcode{"local"} option, the
1523variable is changed locally for the function and any subroutines it calls.
1524The original variable value is restored when exiting the function.
1525@seealso{PS1, PS4}
1526@end deftypefn */)
1527{
1528 return interp.PS2 (args, nargout);
1529}
1530
1531DEFMETHOD (completion_append_char, interp, args, nargout,
1532 doc: /* -*- texinfo -*-
1533@deftypefn {} {@var{val} =} completion_append_char ()
1534@deftypefnx {} {@var{old_val} =} completion_append_char (@var{new_val})
1535@deftypefnx {} {@var{old_val} =} completion_append_char (@var{new_val}, "local")
1536Query or set the internal character variable that is appended to
1537successful command-line completion attempts.
1538
1539The default value is @qcode{" "} (a single space).
1540
1541When called from inside a function with the @qcode{"local"} option, the
1542variable is changed locally for the function and any subroutines it calls.
1543The original variable value is restored when exiting the function.
1544@end deftypefn */)
1545{
1546 input_system& input_sys = interp.get_input_system ();
1547
1548 return input_sys.completion_append_char (args, nargout);
1549}
1550
1551DEFMETHOD (__request_drawnow__,, args, ,
1552 doc: /* -*- texinfo -*-
1553@deftypefn {} {} __request_drawnow__ ()
1554@deftypefnx {} {} __request_drawnow__ (@var{flag})
1555Undocumented internal function.
1556@end deftypefn */)
1557{
1558 int nargin = args.length ();
1559
1560 if (nargin > 1)
1561 print_usage ();
1562
1563 if (nargin == 0)
1564 Vdrawnow_requested = true;
1565 else
1566 Vdrawnow_requested = args(0).bool_value ();
1567
1568 return ovl ();
1569}
1570
1571DEFMETHOD (__gud_mode__, interp, args, nargout,
1572 doc: /* -*- texinfo -*-
1573@deftypefn {} {@var{state} =} __gud_mode__ ()
1574Undocumented internal function.
1575@end deftypefn */)
1576{
1577 input_system& input_sys = interp.get_input_system ();
1578
1579 return input_sys.gud_mode (args, nargout);
1580}
1581
1582DEFMETHOD (mfile_encoding, interp, args, nargout,
1583 doc: /* -*- texinfo -*-
1584@deftypefn {} {@var{current_encoding} =} mfile_encoding ()
1585@deftypefnx {} {} mfile_encoding (@var{new_encoding})
1586@deftypefnx {} {@var{old_encoding} =} mfile_encoding (@var{new_encoding})
1587Query or set the encoding that is used for reading m-files.
1588
1589The input and output are strings naming an encoding, e.g.,
1590@nospell{@qcode{"utf-8"}}.
1591
1592This encoding is used by Octave's parser when reading m-files unless a
1593different encoding was set for a specific directory containing m-files using
1594the function @code{dir_encoding} or in a file @file{.oct-config} in that
1595directory.
1596
1597The special value @qcode{"system"} selects the encoding that matches the system
1598locale.
1599
1600If the m-file encoding is changed after the m-files have already been parsed,
1601the files have to be parsed again for that change to take effect. That can be
1602triggered with the command @code{clear all}.
1603
1604Additionally, this encoding is used to load and save files with the built-in
1605editor in Octave's GUI.
1606
1607@seealso{dir_encoding}
1608@end deftypefn */)
1609{
1610 input_system& input_sys = interp.get_input_system ();
1611
1612 return input_sys.mfile_encoding (args, nargout);
1613}
1614
1615DEFALIAS (__mfile_encoding__, mfile_encoding);
1616
1617DEFMETHOD (dir_encoding, interp, args, nargout,
1618 doc: /* -*- texinfo -*-
1619@deftypefn {} {@var{current_encoding} =} dir_encoding (@var{dir})
1620@deftypefnx {} {} dir_encoding (@var{dir}, @var{new_encoding})
1621@deftypefnx {} {} dir_encoding (@var{dir}, "delete")
1622@deftypefnx {} {@var{old_encoding} =} dir_encoding (@var{dir}, @var{new_encoding})
1623Query or set the @var{encoding} that is used for reading m-files in @var{dir}.
1624
1625The per-directory encoding overrides the (globally set) m-file encoding,
1626@pxref{XREFmfile_encoding,,@code{mfile_encoding}}.
1627
1628The string @var{DIR} must match how the directory would appear in the load
1629path.
1630
1631The @var{new_encoding} input must be a valid encoding identifier or
1632@qcode{"delete"}. In the latter case, any per-directory encoding is removed
1633and the (globally set) m-file encoding will be used for the given @var{dir}.
1634
1635The currently or previously used encoding is returned only if an output
1636argument is requested.
1637
1638The directory encoding is automatically read from the file @file{.oct-config}
1639when a new path is added to the load path (for example with @code{addpath}).
1640To set the encoding for all files in the same folder, that file must contain
1641a line starting with @qcode{"encoding="} followed by the encoding identifier.
1642
1643For example to set the file encoding for all files in the same folder to
1644ISO 8859-1 (Latin-1), create a file @file{.oct-config} with the following
1645content:
1646
1647@example
1648encoding=iso8859-1
1649@end example
1650
1651If the file encoding is changed after the files have already been parsed, the
1652files have to be parsed again for that change to take effect. That can be done
1653with the command @code{clear all}.
1654
1655@seealso{addpath, path, mfile_encoding}
1656@end deftypefn */)
1657{
1658 int nargin = args.length ();
1659
1660 if (nargin < 1 || nargin > 2)
1661 print_usage ();
1662
1663 std::string dir
1664 = args(0).xstring_value ("dir_encoding: DIR must be a string");
1665
1666 octave_value retval;
1667
1668 input_system& input_sys = interp.get_input_system ();
1669
1670 if (nargout > 0)
1671 retval = input_sys.dir_encoding (dir);
1672
1673 if (nargin > 1)
1674 {
1675 std::string encoding
1676 = args(1).xstring_value ("dir_encoding: ENCODING must be a string");
1677
1678 input_sys.set_dir_encoding (dir, encoding);
1679 }
1680
1681 return ovl (retval);
1682
1683}
1684
1685DEFMETHOD (auto_repeat_debug_command, interp, args, nargout,
1686 doc: /* -*- texinfo -*-
1687@deftypefn {} {@var{val} =} auto_repeat_debug_command ()
1688@deftypefnx {} {@var{old_val} =} auto_repeat_debug_command (@var{new_val})
1689@deftypefnx {} {@var{old_val} =} auto_repeat_debug_command (@var{new_val}, "local")
1690Query or set the internal variable that controls whether debugging
1691commands are automatically repeated when the input line is empty (typing
1692just @key{RET}).
1693
1694When called from inside a function with the @qcode{"local"} option, the
1695variable is changed locally for the function and any subroutines it calls.
1696The original variable value is restored when exiting the function.
1697@end deftypefn */)
1698{
1699 input_system& input_sys = interp.get_input_system ();
1700
1701 return input_sys.auto_repeat_debug_command (args, nargout);
1702}
1703
1704OCTAVE_END_NAMESPACE(octave)
void add(F &&fcn, Args &&... args)
void run(std::size_t num)
virtual std::string input_source() const
Definition input.h:238
std::string octave_gets(const std::string &prompt, bool &eof)
virtual std::string get_input(const std::string &prompt, bool &eof)=0
virtual bool input_from_terminal() const
Definition input.h:242
virtual bool input_from_eval_string() const
Definition input.h:246
interpreter & m_interpreter
Definition input.h:250
virtual bool input_from_file() const
Definition input.h:244
static void set_quoting_function(quoting_fcn f)
Definition cmd-edit.cc:1368
static void set_completer_quote_characters(const std::string &s)
Definition cmd-edit.cc:1347
static string_vector generate_filename_completions(const std::string &text)
Definition cmd-edit.cc:1428
static char get_prev_char(int)
Definition cmd-edit.cc:1450
static void set_filename_quote_characters(const std::string &s)
Definition cmd-edit.cc:1340
static std::string readline(const std::string &prompt)
Definition cmd-edit.cc:1183
static void set_name(const std::string &n)
Definition cmd-edit.cc:1176
static void set_completer_word_break_characters(const std::string &s)
Definition cmd-edit.cc:1326
static void set_basic_word_break_characters(const std::string &s)
Definition cmd-edit.cc:1319
static void force_default_editor()
Definition cmd-edit.cc:1101
static void set_completion_function(completion_fcn f)
Definition cmd-edit.cc:1361
static void set_completion_append_character(char c)
Definition cmd-edit.cc:1354
static std::string get_line_buffer()
Definition cmd-edit.cc:1436
static void add_event_hook(event_hook_fcn f)
Definition cmd-edit.cc:1556
static void set_basic_quote_characters(const std::string &s)
Definition cmd-edit.cc:1333
static void re_read_init_file()
Definition cmd-edit.cc:1593
static void read_init_file(const std::string &file="")
Definition cmd-edit.cc:1582
static bool add(const std::string &)
Definition cmd-hist.cc:616
void set_discard_warning_messages(bool flag)
Definition error.h:104
octave_value discard_warning_messages(const octave_value_list &args, int nargout)
Definition error.cc:299
Provides threadsafe access to octave.
void append_history(const std::string &hist_entry)
void post_input_event()
void exit_debugger_event()
void pre_input_event()
map_type::iterator iterator
Definition hook-fcn.h:160
void run(const octave_value_list &initial_args=octave_value_list())
Definition hook-fcn.h:190
iterator end()
Definition hook-fcn.h:184
bool empty() const
Definition hook-fcn.h:165
void erase(iterator p)
Definition hook-fcn.h:188
iterator find(const std::string &id)
Definition hook-fcn.h:174
void insert(const std::string &id, const hook_function &f)
Definition hook-fcn.h:169
std::string id() const
Definition hook-fcn.h:75
input_reader()=delete
bool remove_input_event_hook(const std::string &hook_fcn_id)
octave_value auto_repeat_debug_command(const octave_value_list &args, int nargout)
input_system(interpreter &interp)
Definition input.cc:403
void initialize(bool line_editing)
Definition input.cc:412
std::string last_debugging_command() const
Definition input.h:93
bool yes_or_no(const std::string &prompt)
void clear_input_event_hooks()
char completion_append_char() const
Definition input.h:108
octave_value gud_mode(const octave_value_list &args, int nargout)
void run_input_event_hooks()
void add_input_event_hook(const hook_function &hook_fcn)
void set_dir_encoding(const std::string &dir, std::string &enc)
octave_value completion_append_char(const octave_value_list &args, int nargout)
std::string PS2() const
Definition input.h:82
octave_value_list get_user_input(const octave_value_list &args, int nargout)
std::string dir_encoding(const std::string &dir)
bool auto_repeat_debug_command() const
Definition input.h:155
std::string interactive_input(const std::string &s, bool &eof)
std::string mfile_encoding() const
Definition input.h:137
std::string PS1() const
Definition input.h:69
bool have_input_event_hooks() const
octave_value mfile_encoding(const octave_value_list &args, int nargout)
bool gud_mode() const
Definition input.h:124
error_system & get_error_system()
output_system & get_output_system()
load_path & get_load_path()
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
void handle_exception(const execution_exception &ee)
octave_value PS1(const octave_value_list &args, int nargout)
bool is_variable(const std::string &name) const
bool interactive() const
tree_evaluator & get_evaluator()
void recover_from_exception()
octave_value PS2(const octave_value_list &args, int nargout)
input_system & get_input_system()
event_manager & get_event_manager()
void update()
Definition load-path.cc:425
bool empty() const
Definition ovl.h:113
octave_idx_type length() const
Definition ovl.h:111
bool is_classdef_object() const
Definition ov.h:655
bool isjava() const
Definition ov.h:667
bool is_defined() const
Definition ov.h:592
string_vector map_keys() const
Definition ov.h:1003
octave_idx_type numel() const
Definition ov.h:559
bool isstruct() const
Definition ov.h:649
void reset()
Definition pager.cc:327
string_vector & append(const std::string &s)
Definition str-vec.cc:110
string_vector & sort(bool make_uniq=false)
Definition str-vec.cc:77
octave_idx_type numel() const
Definition str-vec.h:98
bool in_debug_repl() const
Definition pt-eval.cc:5145
void keyboard(const std::string &prompt="debug> ")
Definition pt-eval.cc:1457
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void print_usage()
Definition defun-int.h:72
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition defun.h:111
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition defun.h:56
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
Definition defun.h:160
void warning(const char *fmt,...)
Definition error.cc:1078
void warning_with_id(const char *id, const char *fmt,...)
Definition error.cc:1093
void error(const char *fmt,...)
Definition error.cc:1003
void message(const char *name, const char *fmt,...)
Definition error.cc:971
octave_value_list F__event_manager_gui_preference__(octave::interpreter &interp, const octave_value_list &args, int)
octave_value_list Fdrawnow(octave::interpreter &interp, const octave_value_list &args, int)
string_vector make_name_list()
void * octave_iconv_open_wrapper(const char *tocode, const char *fromcode)
int octave_iconv_close_wrapper(void *cd)
octave::sys::time Vlast_prompt_time
Definition input.cc:82
bool Vdrawnow_requested
Definition input.cc:89
bool octave_completion_matches_called
Definition input.cc:85
octave::sys::time Vlast_prompt_time
Definition input.cc:82
bool Vdrawnow_requested
Definition input.cc:89
input_system & __get_input_system__()
interpreter & __get_interpreter__()
std::string fgets(FILE *f)
Definition lo-utils.cc:90
const char * octave_locale_charset_wrapper(void)
void free(void *)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition ovl.h:217
void flush_stdout()
Definition pager.cc:268
#define octave_stdout
Definition pager.h:301
#define octave_diary
Definition pager.h:303
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)
Definition variables.cc:583
F77_RET_T len
Definition xerbla.cc:61