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