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