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