GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
cmd-edit.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-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 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdlib>
31 #include <cstring>
32 
33 #include <string>
34 
35 #include "cmd-edit.h"
36 #include "cmd-hist.h"
37 #include "file-ops.h"
38 #include "file-stat.h"
39 #include "lo-error.h"
40 #include "lo-sysdep.h"
41 #include "lo-utils.h"
42 #include "oct-env.h"
43 #include "oct-mutex.h"
44 #include "oct-time.h"
45 #include "quit.h"
46 #include "singleton-cleanup.h"
47 #include "strdup-wrapper.h"
48 #include "unistd-wrappers.h"
49 
50 #if defined (USE_READLINE)
51 #include <cstdio>
52 
53 #include "oct-rl-edit.h"
54 #endif
55 
57 
59 
60 command_editor *command_editor::s_instance = nullptr;
61 
62 std::set<command_editor::startup_hook_fcn> command_editor::s_startup_hook_set;
63 
64 std::set<command_editor::pre_input_hook_fcn> command_editor::s_pre_input_hook_set;
65 
66 std::set<command_editor::event_hook_fcn> command_editor::s_event_hook_set;
67 
68 static mutex event_hook_lock;
69 
70 #if defined (USE_READLINE)
71 
72 class
73 gnu_readline : public command_editor
74 {
75 public:
76 
77  typedef command_editor::startup_hook_fcn startup_hook_fcn;
78 
79  typedef command_editor::pre_input_hook_fcn pre_input_hook_fcn;
80 
81  typedef command_editor::event_hook_fcn event_hook_fcn;
82 
83  typedef command_editor::completion_fcn completion_fcn;
84 
85  gnu_readline ();
86 
87  OCTAVE_DISABLE_COPY_MOVE (gnu_readline)
88 
89  ~gnu_readline () = default;
90 
91  void do_set_name (const std::string& n);
92 
93  std::string do_readline (const std::string& prompt, bool& eof);
94 
95  void do_set_input_stream (FILE *f);
96 
97  FILE * do_get_input_stream ();
98 
99  void do_set_output_stream (FILE *f);
100 
101  FILE * do_get_output_stream ();
102 
103  void do_redisplay ();
104 
105  int do_terminal_rows ();
106 
107  int do_terminal_cols ();
108 
109  void do_clear_screen (bool skip_redisplay);
110 
111  void do_resize_terminal ();
112 
113  void do_set_screen_size (int ht, int wd);
114 
115  std::string newline_chars ();
116 
117  void do_restore_terminal_state ();
118 
119  void do_blink_matching_paren (bool flag);
120 
121  bool do_erase_empty_line (bool flag);
122 
123  void do_set_basic_word_break_characters (const std::string& s);
124 
125  void do_set_completer_word_break_characters (const std::string& s);
126 
127  void do_set_basic_quote_characters (const std::string& s);
128 
129  void do_set_filename_quote_characters (const std::string& s);
130 
131  void do_set_completer_quote_characters (const std::string& s);
132 
133  void do_set_completion_append_character (char c);
134 
135  void do_set_completion_function (completion_fcn f);
136 
137  void do_set_quoting_function (quoting_fcn f);
138 
139  void do_set_dequoting_function (dequoting_fcn f);
140 
141  void do_set_char_is_quoted_function (char_is_quoted_fcn f);
142 
143  void do_set_user_accept_line_function (user_accept_line_fcn f);
144 
145  completion_fcn do_get_completion_function () const;
146 
147  quoting_fcn do_get_quoting_function () const;
148 
149  dequoting_fcn do_get_dequoting_function () const;
150 
151  char_is_quoted_fcn do_get_char_is_quoted_function () const;
152 
153  user_accept_line_fcn do_get_user_accept_line_function () const;
154 
156  do_generate_filename_completions (const std::string& text);
157 
158  std::string do_get_line_buffer () const;
159 
160  std::string do_get_current_line () const;
161 
162  char do_get_prev_char (int) const;
163 
164  void do_replace_line (const std::string& text, bool clear_undo);
165 
166  void do_kill_full_line ();
167 
168  void do_insert_text (const std::string& text);
169 
170  void do_newline ();
171 
172  void do_accept_line ();
173 
174  bool do_undo ();
175 
176  void do_clear_undo_list ();
177 
178  void set_startup_hook (startup_hook_fcn f);
179 
180  void restore_startup_hook ();
181 
182  void set_pre_input_hook (pre_input_hook_fcn f);
183 
184  void restore_pre_input_hook ();
185 
186  void set_event_hook (event_hook_fcn f);
187 
188  void restore_event_hook ();
189 
190  void do_restore_event_hook ();
191 
192  void do_read_init_file (const std::string& file);
193 
194  void do_re_read_init_file ();
195 
196  bool do_filename_completion_desired (bool);
197 
198  bool do_filename_quoting_desired (bool);
199 
200  bool do_prefer_env_winsize (bool);
201 
202  void do_interrupt (bool);
203 
204  void do_handle_interrupt_signal ();
205 
206  static int operate_and_get_next (int, int);
207 
208  static int history_search_backward (int, int);
209 
210  static int history_search_forward (int, int);
211 
212 private:
213 
214  static char * command_generator (const char *text, int state);
215 
216  static char * command_quoter (char *text, int match_type,
217  char *quote_pointer);
218 
219  static char * command_dequoter (char *text, int match_type);
220 
221  static int command_char_is_quoted (char *text, int index);
222 
223  static int command_accept_line (int count, int key);
224 
225  static char ** command_completer (const char *text, int start, int end);
226 
227  static char * do_completer_word_break_hook ();
228 
229  startup_hook_fcn m_previous_startup_hook;
230 
231  pre_input_hook_fcn m_previous_pre_input_hook;
232 
233  event_hook_fcn m_previous_event_hook;
234 
235  completion_fcn m_completion_function;
236 
237  quoting_fcn m_quoting_function;
238 
239  dequoting_fcn m_dequoting_function;
240 
241  char_is_quoted_fcn m_char_is_quoted_function;
242 
243  user_accept_line_fcn m_user_accept_line_function;
244 
245  static std::string s_completer_quote_characters;
246 };
247 
248 std::string gnu_readline::s_completer_quote_characters = "";
249 
250 gnu_readline::gnu_readline ()
251  : command_editor (), m_previous_startup_hook (nullptr),
252  m_previous_pre_input_hook (nullptr),
253  m_previous_event_hook (nullptr), m_completion_function (nullptr),
254  m_quoting_function (nullptr), m_dequoting_function (nullptr),
255  m_char_is_quoted_function (nullptr), m_user_accept_line_function (nullptr)
256 {
257  // FIXME: need interface to rl_add_defun, rl_initialize, and
258  // a function to set rl_terminal_name
259 
260  std::string term = sys::env::getenv ("TERM");
261 
262  octave_rl_set_terminal_name (term.c_str ());
263 
265 
266  do_blink_matching_paren (true);
267 
268  // Bind operate-and-get-next.
269 
270  octave_rl_add_defun ("operate-and-get-next",
271  gnu_readline::operate_and_get_next,
272  octave_rl_ctrl ('O'));
273 }
274 
275 void
276 gnu_readline::do_set_name (const std::string& nm)
277 {
278  ::octave_rl_set_name (nm.c_str ());
279 }
280 
281 std::string
282 gnu_readline::do_readline (const std::string& prompt, bool& eof)
283 {
284  std::string retval;
285 
286  eof = false;
287 
288  const char *p = prompt.c_str ();
289 
290  char *line = ::octave_rl_readline (p);
291 
292  if (line)
293  {
294  retval = line;
295 
296  free (line);
297  }
298  else
299  eof = true;
300 
301  return retval;
302 }
303 
304 void
305 gnu_readline::do_set_input_stream (FILE *f)
306 {
308 }
309 
310 FILE *
311 gnu_readline::do_get_input_stream ()
312 {
314 }
315 
316 void
317 gnu_readline::do_set_output_stream (FILE *f)
318 {
320 }
321 
322 FILE *
323 gnu_readline::do_get_output_stream ()
324 {
326 }
327 
328 void
329 gnu_readline::do_redisplay ()
330 {
332 }
333 
334 // GNU readline handles SIGWINCH, so these values have a good chance
335 // of being correct even if the window changes size (they may be
336 // wrong if, for example, the luser changes the window size while the
337 // pager is running, and the signal is handled by the pager instead of
338 // us.
339 
340 int
341 gnu_readline::do_terminal_rows ()
342 {
343  int sh = ::octave_rl_screen_height ();
344 
345  return sh > 0 ? sh : 24;
346 }
347 
348 int
349 gnu_readline::do_terminal_cols ()
350 {
351  int sw = ::octave_rl_screen_width ();
352 
353  return sw > 0 ? sw : 80;
354 }
355 
356 void
357 gnu_readline::do_clear_screen (bool skip_redisplay)
358 {
359  ::octave_rl_clear_screen (skip_redisplay);
360 }
361 
362 void
363 gnu_readline::do_resize_terminal ()
364 {
366 }
367 
368 void
369 gnu_readline::do_set_screen_size (int ht, int wd)
370 {
372 }
373 
374 std::string
375 gnu_readline::newline_chars ()
376 {
377  return "\r\n";
378 }
379 
380 void
381 gnu_readline::do_restore_terminal_state ()
382 {
384 }
385 
386 void
387 gnu_readline::do_blink_matching_paren (bool flag)
388 {
389  ::octave_rl_enable_paren_matching (flag ? 1 : 0);
390 }
391 
392 bool
393 gnu_readline::do_erase_empty_line (bool flag)
394 {
396 }
397 
398 void
399 gnu_readline::do_set_basic_word_break_characters (const std::string& s)
400 {
402 }
403 
404 void
405 gnu_readline::do_set_completer_word_break_characters (const std::string& s)
406 {
408 
411 
412 }
413 
414 void
415 gnu_readline::do_set_basic_quote_characters (const std::string& s)
416 {
418 }
419 
420 void
421 gnu_readline::do_set_filename_quote_characters (const std::string& s)
422 {
424 }
425 
426 void
427 gnu_readline::do_set_completer_quote_characters (const std::string& s)
428 {
429  s_completer_quote_characters = s;
430 }
431 
432 void
433 gnu_readline::do_set_completion_append_character (char c)
434 {
436 }
437 
438 void
439 gnu_readline::do_set_completion_function (completion_fcn f)
440 {
441  m_completion_function = f;
442 
444  = (f ? gnu_readline::command_completer : nullptr);
445 
447 }
448 
449 void
450 gnu_readline::do_set_quoting_function (quoting_fcn f)
451 {
452  m_quoting_function = f;
453 
455  = (f ? gnu_readline::command_quoter : nullptr);
456 
458 }
459 
460 void
461 gnu_readline::do_set_dequoting_function (dequoting_fcn f)
462 {
463  m_dequoting_function = f;
464 
466  = (f ? gnu_readline::command_dequoter : nullptr);
467 
469 }
470 
471 void
472 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f)
473 {
474  m_char_is_quoted_function = f;
475 
477  = (f ? gnu_readline::command_char_is_quoted : nullptr);
478 
480 }
481 
482 void
483 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f)
484 {
485  m_user_accept_line_function = f;
486 
487  if (f)
488  octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line,
489  ::octave_rl_ctrl ('M'));
490  else
491  octave_rl_add_defun ("accept-line", ::octave_rl_newline,
492  ::octave_rl_ctrl ('M'));
493 }
494 
495 gnu_readline::completion_fcn
496 gnu_readline::do_get_completion_function () const
497 {
498  return m_completion_function;
499 }
500 
501 gnu_readline::quoting_fcn
502 gnu_readline::do_get_quoting_function () const
503 {
504  return m_quoting_function;
505 }
506 
507 gnu_readline::dequoting_fcn
508 gnu_readline::do_get_dequoting_function () const
509 {
510  return m_dequoting_function;
511 }
512 
513 gnu_readline::char_is_quoted_fcn
514 gnu_readline::do_get_char_is_quoted_function () const
515 {
516  return m_char_is_quoted_function;
517 }
518 
519 gnu_readline::user_accept_line_fcn
520 gnu_readline::do_get_user_accept_line_function () const
521 {
522  return m_user_accept_line_function;
523 }
524 
525 // True if the last "word" of the string line (delimited by delim) is
526 // an existing directory. Used by do_completer_word_break_hook.
527 
528 static bool
529 looks_like_filename (const char *line, char delim)
530 {
531  bool retval = false;
532 
533  const char *s = strrchr (line, delim);
534 
535  if (s)
536  {
537  // Remove incomplete component.
538  const char *f = strrchr (line, sys::file_ops::dir_sep_char ());
539 
540  if (f && (s[1] == '~' || f != s))
541  {
542  // For something like "A /b", f==s; don't assume a file.
543 
544  std::string candidate_filename = s+1;
545 
546  candidate_filename = candidate_filename.substr (0, f - s);
547 
548  // Handles any complete ~<username>, but doesn't expand usernames.
549 
550  if (candidate_filename[0] == '~')
551  candidate_filename
552  = sys::file_ops::tilde_expand (candidate_filename);
553 
554  retval = sys::dir_exists (candidate_filename);
555  }
556  }
557 
558  return retval;
559 }
560 
561 // Decide whether to interpret partial commands like "abc/def" as a
562 // filename or division. Return the set of delimiters appropriate for
563 // the decision.
564 
565 char *
567 {
568  static char *dir_sep = octave_strdup_wrapper (R"( '")");
569 
570  std::string word;
571  std::string line = get_line_buffer ();
572 
573  // For now, assume space or quote delimiter for file names.
574  const char *l = line.c_str ();
575 
576  if (looks_like_filename (l, ' ') || looks_like_filename (l, '\'')
577  || looks_like_filename (l, '"'))
578  {
580  (s_completer_quote_characters.c_str ());
581 
582  return dir_sep;
583  }
584  else
585  {
586  static char *word_break_chars = nullptr;
587 
589 
590  free (word_break_chars);
591 
592  word_break_chars
594 
595  return word_break_chars;
596  }
597 }
598 
600 gnu_readline::do_generate_filename_completions (const std::string& text)
601 {
602  string_vector retval;
603 
604  int n = 0;
605  int count = 0;
606 
607  char *fn = nullptr;
608 
609  while (1)
610  {
611  fn = ::octave_rl_filename_completion_function (text.c_str (), count);
612 
613  if (fn)
614  {
615  if (count == n)
616  {
617  // Famous last words: Most large directories will not
618  // have more than a few hundred files, so we should not
619  // resize too many times even if the growth is linear...
620  n += 100;
621  retval.resize (n);
622  }
623 
624  retval[count++] = fn;
625 
626  free (fn);
627  }
628  else
629  break;
630  }
631 
632  retval.resize (count);
633 
634  return retval;
635 }
636 
637 std::string
638 gnu_readline::do_get_line_buffer () const
639 {
641 }
642 
643 std::string
644 gnu_readline::do_get_current_line () const
645 {
646  std::string retval;
647  char *buf = ::octave_rl_copy_line ();
648  retval = buf;
649  free (buf);
650  return retval;
651 }
652 
653 // Return the character (offset+1) to the left of the cursor,
654 // or '\0' if the cursor is at the start of the line.
655 char
656 gnu_readline::do_get_prev_char (int offset) const
657 {
658  const char *buf = ::octave_rl_line_buffer ();
659  int p = ::octave_rl_point ();
660 
661  return p > offset ? buf[p - offset - 1] : '\0';
662 }
663 
664 void
665 gnu_readline::do_replace_line (const std::string& text, bool clear_undo)
666 {
667  ::octave_rl_replace_line (text.c_str (), clear_undo);
668 }
669 
670 void
671 gnu_readline::do_kill_full_line ()
672 {
674 }
675 
676 void
677 gnu_readline::do_insert_text (const std::string& text)
678 {
679  ::octave_rl_insert_text (text.c_str ());
680 }
681 
682 void
683 gnu_readline::do_newline ()
684 {
685  ::octave_rl_newline (1, '\n');
686 }
687 
688 void
689 gnu_readline::do_accept_line ()
690 {
691  command_accept_line (1, '\n');
692 }
693 
694 bool
695 gnu_readline::do_undo ()
696 {
698 }
699 
700 void
701 gnu_readline::do_clear_undo_list ()
702 {
704 }
705 
706 void
707 gnu_readline::set_startup_hook (startup_hook_fcn f)
708 {
709  m_previous_startup_hook = ::octave_rl_get_startup_hook ();
710 
711  if (f != m_previous_startup_hook)
713 }
714 
715 void
716 gnu_readline::restore_startup_hook ()
717 {
718  ::octave_rl_set_startup_hook (m_previous_startup_hook);
719 }
720 
721 void
722 gnu_readline::set_pre_input_hook (pre_input_hook_fcn f)
723 {
724  m_previous_pre_input_hook = ::octave_rl_get_pre_input_hook ();
725 
726  if (f != m_previous_pre_input_hook)
728 }
729 
730 void
731 gnu_readline::restore_pre_input_hook ()
732 {
733  ::octave_rl_set_pre_input_hook (m_previous_pre_input_hook);
734 }
735 
736 void
737 gnu_readline::set_event_hook (event_hook_fcn f)
738 {
739  m_previous_event_hook = octave_rl_get_event_hook ();
740 
742 }
743 
744 void
745 gnu_readline::restore_event_hook ()
746 {
747  ::octave_rl_set_event_hook (m_previous_event_hook);
748 }
749 
750 void
751 gnu_readline::do_read_init_file (const std::string& file)
752 {
753  ::octave_rl_read_init_file (file.c_str ());
754 }
755 
756 void
757 gnu_readline::do_re_read_init_file ()
758 {
760 }
761 
762 bool
763 gnu_readline::do_filename_completion_desired (bool arg)
764 {
766 }
767 
768 bool
769 gnu_readline::do_filename_quoting_desired (bool arg)
770 {
772 }
773 
774 bool
775 gnu_readline::do_prefer_env_winsize (bool arg)
776 {
778 }
779 
780 void
781 gnu_readline::do_interrupt (bool arg)
782 {
783  ::octave_rl_done (arg);
784 }
785 
786 void
787 gnu_readline::do_handle_interrupt_signal ()
788 {
789  octave_signal_caught = false;
791 
793 
794  throw interrupt_exception ();
795 }
796 
797 int
798 gnu_readline::operate_and_get_next (int /* count */, int /* c */)
799 {
800  // Accept the current line.
801 
803 
804  // Find the current line, and find the next line to use.
805 
806  int x_where = command_history::where ();
807 
808  int x_length = command_history::length ();
809 
811  && (x_length >= command_history::max_input_history ()))
812  || (x_where >= x_length - 1))
813  command_history::set_mark (x_where);
814  else
815  command_history::set_mark (x_where + 1);
816 
818 
819  return 0;
820 }
821 
822 int
823 gnu_readline::history_search_backward (int count, int c)
824 {
825  return octave_rl_history_search_backward (count, c);
826 }
827 
828 int
829 gnu_readline::history_search_forward (int count, int c)
830 {
831  return octave_rl_history_search_forward (count, c);
832 }
833 
834 char *
835 gnu_readline::command_generator (const char *text, int state)
836 {
837  char *retval = nullptr;
838 
839  completion_fcn f = command_editor::get_completion_function ();
840 
841  std::string tmp = f (text, state);
842 
843  std::size_t len = tmp.length ();
844 
845  if (len > 0)
846  {
847  retval = static_cast<char *> (std::malloc (len+1));
848 
849  if (retval)
850  strcpy (retval, tmp.c_str ());
851  }
852 
853  return retval;
854 }
855 
856 char *
857 gnu_readline::command_quoter (char *text, int matches, char *qcp)
858 {
859  char *retval = nullptr;
860 
861  quoting_fcn f = command_editor::get_quoting_function ();
862 
863  std::string tmp = f (text, matches, *qcp);
864 
865  std::size_t len = tmp.length ();
866 
867  if (len > 0)
868  {
869  retval = static_cast<char *> (std::malloc (len+1));
870 
871  if (retval)
872  strcpy (retval, tmp.c_str ());
873  }
874 
875  return retval;
876 }
877 
878 char *
879 gnu_readline::command_dequoter (char *text, int quote)
880 {
881  char *retval = nullptr;
882 
883  dequoting_fcn f = command_editor::get_dequoting_function ();
884 
885  std::string tmp = f (text, quote);
886 
887  std::size_t len = tmp.length ();
888 
889  if (len > 0)
890  {
891  retval = static_cast<char *> (std::malloc (len+1));
892 
893  if (retval)
894  strcpy (retval, tmp.c_str ());
895  }
896 
897  return retval;
898 }
899 
900 int
901 gnu_readline::command_char_is_quoted (char *text, int quote)
902 {
903  char_is_quoted_fcn f = command_editor::get_char_is_quoted_function ();
904 
905  return f (text, quote);
906 }
907 
908 int
909 gnu_readline::command_accept_line (int count, int key)
910 {
911  user_accept_line_fcn f = command_editor::get_user_accept_line_function ();
912 
913  if (f)
914  f (::octave_rl_line_buffer ());
915 
917 
918  return ::octave_rl_newline (count, key);
919 }
920 
921 char **
922 gnu_readline::command_completer (const char *text, int, int)
923 {
924  char **matches
925  = ::octave_rl_completion_matches (text, gnu_readline::command_generator);
926 
927  return matches;
928 }
929 
930 #endif
931 
932 class
933 default_command_editor : public command_editor
934 {
935 public:
936 
937  default_command_editor ()
938  : command_editor (), m_input_stream (stdin), m_output_stream (stdout) { }
939 
940  OCTAVE_DISABLE_COPY_MOVE (default_command_editor)
941 
942  ~default_command_editor () = default;
943 
944  std::string do_readline (const std::string& prompt, bool& eof);
945 
946  void do_set_input_stream (FILE *f);
947 
948  FILE * do_get_input_stream ();
949 
950  void do_set_output_stream (FILE *f);
951 
952  FILE * do_get_output_stream ();
953 
954  string_vector do_generate_filename_completions (const std::string& text);
955 
956  std::string do_get_line_buffer () const;
957 
958  std::string do_get_current_line () const;
959 
960  char do_get_prev_char (int) const;
961 
962  void do_replace_line (const std::string& text, bool clear_undo);
963 
964  void do_kill_full_line ();
965 
966  void do_insert_text (const std::string& text);
967 
968  void do_newline ();
969 
970  void do_accept_line ();
971 
972 private:
973 
974  FILE *m_input_stream;
975 
976  FILE *m_output_stream;
977 };
978 
979 std::string
980 default_command_editor::do_readline (const std::string& prompt, bool& eof)
981 {
982  std::fputs (prompt.c_str (), m_output_stream);
983  std::fflush (m_output_stream);
984 
985  return fgetl (m_input_stream, eof);
986 }
987 
988 void
989 default_command_editor::do_set_input_stream (FILE *f)
990 {
991  m_input_stream = f;
992 }
993 
994 FILE *
995 default_command_editor::do_get_input_stream ()
996 {
997  return m_input_stream;
998 }
999 
1000 void
1001 default_command_editor::do_set_output_stream (FILE *f)
1002 {
1003  m_output_stream = f;
1004 }
1005 
1006 FILE *
1007 default_command_editor::do_get_output_stream ()
1008 {
1009  return m_output_stream;
1010 }
1011 
1013 default_command_editor::do_generate_filename_completions (const std::string&)
1014 {
1015  // FIXME
1016  return string_vector ();
1017 }
1018 
1019 std::string
1020 default_command_editor::do_get_line_buffer () const
1021 {
1022  return "";
1023 }
1024 
1025 std::string
1026 default_command_editor::do_get_current_line () const
1027 {
1028  // FIXME
1029  return "";
1030 }
1031 
1032 char
1033 default_command_editor::do_get_prev_char (int) const
1034 {
1035  return '\0';
1036 }
1037 
1038 void
1039 default_command_editor::do_replace_line (const std::string&, bool)
1040 {
1041  // FIXME
1042 }
1043 
1044 void
1045 default_command_editor::do_kill_full_line ()
1046 {
1047  // FIXME
1048 }
1049 
1050 void
1051 default_command_editor::do_insert_text (const std::string&)
1052 {
1053  // FIXME
1054 }
1055 
1056 void
1057 default_command_editor::do_newline ()
1058 {
1059  // FIXME
1060 }
1061 
1062 void
1063 default_command_editor::do_accept_line ()
1064 {
1065  // FIXME
1066 }
1067 
1068 bool
1069 command_editor::instance_ok ()
1070 {
1071  bool retval = true;
1072 
1073  if (! s_instance)
1074  {
1075  make_command_editor ();
1076 
1077  if (s_instance)
1078  {
1079  s_instance->set_event_hook (event_handler);
1080 
1081  singleton_cleanup_list::add (cleanup_instance);
1082  }
1083  }
1084 
1085  if (! s_instance)
1086  (*current_liboctave_error_handler)
1087  ("unable to create command history object!");
1088 
1089  return retval;
1090 }
1091 
1092 void
1093 command_editor::make_command_editor ()
1094 {
1095 #if defined (USE_READLINE)
1096  s_instance = new gnu_readline ();
1097 #else
1098  s_instance = new default_command_editor ();
1099 #endif
1100 }
1101 
1102 void
1104 {
1105  delete s_instance;
1106  s_instance = new default_command_editor ();
1107 }
1108 
1109 void
1111 {
1112  if (instance_ok ())
1113  s_instance->m_initial_input = text;
1114 }
1115 
1116 int
1118 {
1119  return instance_ok () ? s_instance->do_insert_initial_input () : 0;
1120 }
1121 
1122 int
1123 command_editor::startup_handler ()
1124 {
1125  // Iterate over a copy of the set to avoid problems if a hook
1126  // function attempts to remove itself from the startup_hook_set.
1127 
1128  std::set<startup_hook_fcn> hook_set = s_startup_hook_set;
1129 
1130  for (startup_hook_fcn f : hook_set)
1131  {
1132  if (f)
1133  f ();
1134  }
1135 
1136  return 0;
1137 }
1138 
1139 int
1140 command_editor::pre_input_handler ()
1141 {
1142  // Iterate over copy of the set to avoid problems if a hook function
1143  // attempts to remove itself from the pre_input_hook_set.
1144 
1145  std::set<pre_input_hook_fcn> hook_set = s_pre_input_hook_set;
1146 
1147  for (pre_input_hook_fcn f : hook_set)
1148  {
1149  if (f)
1150  f ();
1151  }
1152 
1153  return 0;
1154 }
1155 
1156 int
1157 command_editor::event_handler ()
1158 {
1160  handle_interrupt_signal ();
1161 
1162  event_hook_lock.lock ();
1163 
1164  std::set<event_hook_fcn> hook_set (s_event_hook_set);
1165 
1166  event_hook_lock.unlock ();
1167 
1168  for (event_hook_fcn f : hook_set)
1169  {
1170  if (f)
1171  f ();
1172  }
1173 
1174  return 0;
1175 }
1176 
1177 void
1178 command_editor::set_name (const std::string& n)
1179 {
1180  if (instance_ok ())
1181  s_instance->do_set_name (n);
1182 }
1183 
1184 std::string
1185 command_editor::readline (const std::string& prompt)
1186 {
1187  bool eof;
1188 
1189  return readline (prompt, eof);
1190 }
1191 
1192 std::string
1193 command_editor::readline (const std::string& prompt, bool& eof)
1194 {
1195  std::string retval;
1196 
1197  if (instance_ok ())
1198  {
1199  if (! s_instance->m_initial_input.empty ())
1201 
1202  retval = s_instance->do_readline (prompt, eof);
1203  }
1204 
1205  return retval;
1206 }
1207 
1208 void
1210 {
1211  if (instance_ok ())
1212  s_instance->do_set_input_stream (f);
1213 }
1214 
1215 FILE *
1217 {
1218  return instance_ok () ? s_instance->do_get_input_stream () : nullptr;
1219 }
1220 
1221 void
1223 {
1224  if (instance_ok ())
1225  s_instance->do_set_output_stream (f);
1226 }
1227 
1228 FILE *
1230 {
1231  return instance_ok () ? s_instance->do_get_output_stream () : nullptr;
1232 }
1233 
1234 void
1236 {
1237  if (instance_ok ())
1238  s_instance->do_redisplay ();
1239 }
1240 
1241 int
1243 {
1244  return instance_ok () ? s_instance->do_terminal_rows () : -1;
1245 }
1246 
1247 int
1249 {
1250  return instance_ok () ? s_instance->do_terminal_cols () : -1;
1251 }
1252 
1253 void
1254 command_editor::clear_screen (bool skip_redisplay)
1255 {
1256  if (instance_ok ())
1257  s_instance->do_clear_screen (skip_redisplay);
1258 }
1259 
1260 void
1262 {
1263  if (instance_ok ())
1264  s_instance->do_resize_terminal ();
1265 }
1266 
1267 void
1269 {
1270  if (instance_ok ())
1271  s_instance->do_set_screen_size (ht, wd);
1272 }
1273 
1274 std::string
1276 {
1277  return instance_ok () ? s_instance->do_decode_prompt_string (s) : "";
1278 }
1279 
1280 int
1282 {
1283  return instance_ok () ? s_instance->m_command_number : 0;
1284 }
1285 
1286 void
1288 {
1289  if (instance_ok ())
1290  s_instance->m_command_number = n;
1291 }
1292 
1293 void
1295 {
1296  if (instance_ok ())
1297  s_instance->m_command_number++;
1298 }
1299 
1300 void
1302 {
1303  if (instance_ok ())
1304  s_instance->do_restore_terminal_state ();
1305 }
1306 
1307 void
1309 {
1310  if (instance_ok ())
1311  s_instance->do_blink_matching_paren (flag);
1312 }
1313 
1314 bool
1316 {
1317  return instance_ok () ? s_instance->do_erase_empty_line (flag) : false;
1318 }
1319 
1320 void
1322 {
1323  if (instance_ok ())
1324  s_instance->do_set_basic_word_break_characters (s);
1325 }
1326 
1327 void
1329 {
1330  if (instance_ok ())
1332 }
1333 
1334 void
1336 {
1337  if (instance_ok ())
1338  s_instance->do_set_basic_quote_characters (s);
1339 }
1340 
1341 void
1343 {
1344  if (instance_ok ())
1345  s_instance->do_set_filename_quote_characters (s);
1346 }
1347 
1348 void
1350 {
1351  if (instance_ok ())
1352  s_instance->do_set_completer_quote_characters (s);
1353 }
1354 
1355 void
1357 {
1358  if (instance_ok ())
1359  s_instance->do_set_completion_append_character (c);
1360 }
1361 
1362 void
1364 {
1365  if (instance_ok ())
1366  s_instance->do_set_completion_function (f);
1367 }
1368 
1369 void
1371 {
1372  if (instance_ok ())
1373  s_instance->do_set_quoting_function (f);
1374 }
1375 
1376 void
1378 {
1379  if (instance_ok ())
1380  s_instance->do_set_dequoting_function (f);
1381 }
1382 
1383 void
1385 {
1386  if (instance_ok ())
1387  s_instance->do_set_char_is_quoted_function (f);
1388 }
1389 
1390 void
1392 {
1393  if (instance_ok ())
1394  s_instance->do_set_user_accept_line_function (f);
1395 }
1396 
1399 {
1400  return instance_ok () ? s_instance->do_get_completion_function () : nullptr;
1401 }
1402 
1405 {
1406  return instance_ok () ? s_instance->do_get_quoting_function () : nullptr;
1407 }
1408 
1411 {
1412  return instance_ok () ? s_instance->do_get_dequoting_function () : nullptr;
1413 }
1414 
1417 {
1418  return (instance_ok ()
1419  ? s_instance->do_get_char_is_quoted_function () : nullptr);
1420 }
1421 
1424 {
1425  return (instance_ok ()
1426  ? s_instance->do_get_user_accept_line_function () : nullptr);
1427 }
1428 
1431 {
1432  return (instance_ok ()
1433  ? s_instance->do_generate_filename_completions (text)
1434  : string_vector ());
1435 }
1436 
1437 std::string
1439 {
1440  return instance_ok () ? s_instance->do_get_line_buffer () : "";
1441 }
1442 
1443 std::string
1445 {
1446  return instance_ok () ? s_instance->do_get_current_line () : "";
1447 }
1448 
1449 // Return the character (offset+1) to the left of the cursor,
1450 // or '\0' if the cursor is at the start of the line.
1451 char
1453 {
1454  return instance_ok () ? s_instance->do_get_prev_char (offset) : '\0';
1455 }
1456 
1457 void
1458 command_editor::replace_line (const std::string& text, bool clear_undo)
1459 {
1460  if (instance_ok ())
1461  s_instance->do_replace_line (text, clear_undo);
1462 }
1463 
1464 void
1466 {
1467  if (instance_ok ())
1468  s_instance->do_kill_full_line ();
1469 }
1470 
1471 void
1472 command_editor::insert_text (const std::string& text)
1473 {
1474  if (instance_ok ())
1475  s_instance->do_insert_text (text);
1476 }
1477 
1478 void
1480 {
1481  if (instance_ok ())
1482  s_instance->do_newline ();
1483 }
1484 
1485 void
1487 {
1488  if (instance_ok ())
1489  s_instance->do_accept_line ();
1490 }
1491 
1492 bool
1494 {
1495  return instance_ok () ? s_instance->do_undo () : false;
1496 }
1497 
1498 void
1500 {
1501  if (instance_ok ())
1502  s_instance->do_clear_undo_list ();
1503 }
1504 
1505 void
1507 {
1508  if (instance_ok ())
1509  {
1510  s_startup_hook_set.insert (f);
1511 
1512  s_instance->set_startup_hook (startup_handler);
1513  }
1514 }
1515 
1516 void
1518 {
1519  if (instance_ok ())
1520  {
1521  auto p = s_startup_hook_set.find (f);
1522 
1523  if (p != s_startup_hook_set.end ())
1524  s_startup_hook_set.erase (p);
1525 
1526  if (s_startup_hook_set.empty ())
1527  s_instance->restore_startup_hook ();
1528  }
1529 }
1530 
1531 void
1533 {
1534  if (instance_ok ())
1535  {
1536  s_pre_input_hook_set.insert (f);
1537 
1538  s_instance->set_pre_input_hook (pre_input_handler);
1539  }
1540 }
1541 
1542 void
1544 {
1545  if (instance_ok ())
1546  {
1547  auto p = s_pre_input_hook_set.find (f);
1548 
1549  if (p != s_pre_input_hook_set.end ())
1550  s_pre_input_hook_set.erase (p);
1551 
1552  if (s_pre_input_hook_set.empty ())
1553  s_instance->restore_pre_input_hook ();
1554  }
1555 }
1556 
1557 void
1559 {
1560  autolock guard (event_hook_lock);
1561 
1562  s_event_hook_set.insert (f);
1563 }
1564 
1565 void
1567 {
1568  autolock guard (event_hook_lock);
1569 
1570  auto p = s_event_hook_set.find (f);
1571 
1572  if (p != s_event_hook_set.end ())
1573  s_event_hook_set.erase (p);
1574 
1575 }
1576 
1577 void
1579 {
1580  event_handler ();
1581 }
1582 
1583 void
1584 command_editor::read_init_file (const std::string& file_arg)
1585 {
1586  if (instance_ok ())
1587  {
1588  std::string file = sys::file_ops::tilde_expand (file_arg);
1589 
1590  s_instance->do_read_init_file (file);
1591  }
1592 }
1593 
1594 void
1596 {
1597  if (instance_ok ())
1598  s_instance->do_re_read_init_file ();
1599 }
1600 
1601 bool
1603 {
1604  return (instance_ok ()
1605  ? s_instance->do_filename_completion_desired (arg) : false);
1606 }
1607 
1608 bool
1610 {
1611  return (instance_ok ())
1612  ? s_instance->do_filename_quoting_desired (arg) : false;
1613 }
1614 
1615 bool
1617 {
1618  return instance_ok () ? s_instance->do_prefer_env_winsize (arg) : false;
1619 }
1620 
1621 bool
1623 {
1624  bool retval;
1625 
1626  if (instance_ok ())
1627  {
1628  // Return the current interrupt state.
1629  retval = s_instance->m_interrupted;
1630 
1631  s_instance->do_interrupt (arg);
1632 
1633  s_instance->m_interrupted = arg;
1634  }
1635  else
1636  retval = false;
1637 
1638  return retval;
1639 }
1640 
1641 void
1643 {
1644  if (instance_ok ())
1645  s_instance->do_interrupt_event_loop (arg);
1646 }
1647 
1648 bool
1650 {
1651  return instance_ok () ? s_instance->do_event_loop_interrupted () : false;
1652 }
1653 
1654 void
1655 command_editor::handle_interrupt_signal ()
1656 {
1657  if (instance_ok ())
1658  s_instance->do_handle_interrupt_signal ();
1659 }
1660 
1661 // Return a string which will be printed as a prompt. The string may
1662 // contain special characters which are decoded as follows:
1663 //
1664 // \a bell (ascii 07)
1665 // \d the date
1666 // \e escape (ascii 033)
1667 // \h the hostname up to the first '.'
1668 // \H the hostname
1669 // \n CRLF
1670 // \r CR
1671 // \s the name of the shell (program)
1672 // \t the time
1673 // \T the time in 12-hour hh:mm:ss format
1674 // \@ the time in 12-hour hh:mm am/pm format
1675 // \A the time in 24-hour hh:mm format
1676 // \u your username
1677 // \w the current working directory
1678 // \W the last element of PWD
1679 // \! the history number of this command
1680 // \# the command number of this command
1681 // \$ a $ or a # if you are root
1682 // \nnn character code nnn in octal
1683 // \\ a backslash
1684 // \[ begin a sequence of non-printing chars
1685 // \] end a sequence of non-printing chars
1686 
1687 std::string
1689 {
1690  std::string retval;
1691  std::string tmpstr;
1692  std::size_t i = 0;
1693  std::size_t slen = s.length ();
1694  int c;
1695 
1696  while (i < slen)
1697  {
1698  c = s[i];
1699 
1700  i++;
1701 
1702  if (c == '\\')
1703  {
1704  c = s[i];
1705 
1706  switch (c)
1707  {
1708  case '0':
1709  case '1':
1710  case '2':
1711  case '3':
1712  case '4':
1713  case '5':
1714  case '6':
1715  case '7':
1716  // Maybe convert an octal number.
1717  {
1718  int n = read_octal (s.substr (i, 3));
1719 
1720  tmpstr = '\\';
1721 
1722  if (n != -1)
1723  {
1724  tmpstr[0] = n;
1725  i += 2; // i++ makes this += 3 later
1726  }
1727 
1728  break;
1729  }
1730 
1731  case 'a':
1732  {
1733  tmpstr = '\a';
1734 
1735  break;
1736  }
1737 
1738  case 'd':
1739  case 't':
1740  case 'T':
1741  case '@':
1742  case 'A':
1743  // Make the current time/date into a string.
1744  {
1745  sys::localtime now;
1746 
1747  if (c == 'd')
1748  tmpstr = now.strftime ("%a %b %d");
1749  else if (c == 't')
1750  tmpstr = now.strftime ("%H:%M:%S");
1751  else if (c == 'T')
1752  tmpstr = now.strftime ("%I:%M:%S");
1753  else if (c == '@')
1754  tmpstr = now.strftime ("%I:%M %p");
1755  else // (c == 'A')
1756  tmpstr = now.strftime ("%H:%M");
1757 
1758  break;
1759  }
1760 
1761  case 'e':
1762  {
1763  tmpstr = '\033';
1764 
1765  break;
1766  }
1767 
1768  case 'h':
1769  {
1770  tmpstr = sys::env::get_host_name ();
1771 
1772  std::size_t pos = tmpstr.find ('.');
1773 
1774  if (pos != std::string::npos)
1775  tmpstr.resize (pos);
1776 
1777  break;
1778  }
1779 
1780  case 'H':
1781  {
1782  tmpstr = sys::env::get_host_name ();
1783 
1784  break;
1785  }
1786 
1787  case 'n':
1788  {
1789  tmpstr = newline_chars ();
1790 
1791  break;
1792  }
1793 
1794  case 'r':
1795  {
1796  tmpstr = '\r';
1797 
1798  break;
1799  }
1800 
1801  case 's':
1802  {
1803  tmpstr = sys::env::get_program_name ();
1804  tmpstr = sys::env::base_pathname (tmpstr);
1805 
1806  break;
1807  }
1808 
1809  case 'u':
1810  {
1811  tmpstr = sys::env::get_user_name ();
1812 
1813  break;
1814  }
1815 
1816  case 'w':
1817  case 'W':
1818  {
1819  try
1820  {
1821  tmpstr = sys::env::get_current_directory ();
1822  }
1823  catch (const execution_exception&)
1824  {
1825  tmpstr = "";
1826  }
1827 
1828  std::string home_dir = sys::env::get_home_directory ();
1829 
1830  if (c == 'W' && (home_dir.empty () || tmpstr != home_dir))
1831  {
1832  if (tmpstr != "/" && tmpstr != "//")
1833  {
1834  std::size_t pos = tmpstr.rfind ('/');
1835 
1836  if (pos != std::string::npos && pos != 0)
1837  tmpstr = tmpstr.substr (pos + 1);
1838  }
1839  }
1840  else
1841  tmpstr = sys::env::polite_directory_format (tmpstr);
1842 
1843  break;
1844  }
1845 
1846  case '!':
1847  {
1848  char number_buffer[32];
1849  int num = command_history::current_number ();
1850  if (num > 0)
1851  sprintf (number_buffer, "%d", num);
1852  else
1853  strcpy (number_buffer, "!");
1854  tmpstr = number_buffer;
1855 
1856  break;
1857  }
1858 
1859  case '#':
1860  {
1861  char number_buffer[32];
1862  sprintf (number_buffer, "%d", m_command_number);
1863  tmpstr = number_buffer;
1864 
1865  break;
1866  }
1867 
1868  case '$':
1869  {
1870  tmpstr = (octave_geteuid_wrapper () == 0 ? '#' : '$');
1871  break;
1872  }
1873 
1874 #if defined (USE_READLINE)
1875  case '[':
1876  case ']':
1877  {
1878  tmpstr.resize (1);
1879 
1880  tmpstr[0] = ((c == '[')
1883 
1884  break;
1885  }
1886 #endif
1887 
1888  case '\\':
1889  {
1890  tmpstr = '\\';
1891 
1892  break;
1893  }
1894 
1895  default:
1896  {
1897  tmpstr = "\\ ";
1898  tmpstr[1] = c;
1899 
1900  break;
1901  }
1902  }
1903 
1904  retval.append (tmpstr);
1905  i++; // Move past processed escape character
1906  }
1907  else
1908  retval += c;
1909  }
1910 
1911  return retval;
1912 }
1913 
1914 int
1916 {
1917  std::string input = m_initial_input;
1918 
1919  m_initial_input = "";
1920 
1921  do_insert_text (input);
1922 
1923  // Is it really right to redisplay here?
1924  do_redisplay ();
1925 
1926  return 0;
1927 }
1928 
1929 // Return the octal number parsed from STRING, or -1 to indicate that
1930 // the string contained a bad number.
1931 
1932 int
1933 command_editor::read_octal (const std::string& s)
1934 {
1935  int result = 0;
1936  int digits = 0;
1937 
1938  std::size_t i = 0;
1939  std::size_t slen = s.length ();
1940 
1941  while (i < slen && s[i] >= '0' && s[i] < '8')
1942  {
1943  digits++;
1944  result = (result * 8) + s[i] - '0';
1945  i++;
1946  }
1947 
1948  if (! digits || result > 0777 || i < slen)
1949  result = -1;
1950 
1951  return result;
1952 }
1953 
1954 void
1956 {
1957  (*current_liboctave_error_handler) ("%s", std::strerror (err_num));
1958 }
1959 
1960 void
1961 command_editor::error (const std::string& s)
1962 {
1963  (*current_liboctave_error_handler) ("%s", s.c_str ());
1964 }
1965 
1966 OCTAVE_END_NAMESPACE(octave)
virtual void do_resize_terminal()
Definition: cmd-edit.h:267
static void replace_line(const std::string &text, bool clear_undo=true)
Definition: cmd-edit.cc:1458
static void set_input_stream(FILE *f)
Definition: cmd-edit.cc:1209
static void set_quoting_function(quoting_fcn f)
Definition: cmd-edit.cc:1370
virtual string_vector do_generate_filename_completions(const std::string &text)=0
static bool filename_quoting_desired(bool)
Definition: cmd-edit.cc:1609
int(* pre_input_hook_fcn)()
Definition: cmd-edit.h:55
void error(int)
Definition: cmd-edit.cc:1955
int(* event_hook_fcn)()
Definition: cmd-edit.h:57
virtual FILE * do_get_input_stream()=0
static void add_startup_hook(startup_hook_fcn f)
Definition: cmd-edit.cc:1506
void(* user_accept_line_fcn)(const std::string &)
Definition: cmd-edit.h:69
static void run_event_hooks()
Definition: cmd-edit.cc:1578
static void set_completer_quote_characters(const std::string &s)
Definition: cmd-edit.cc:1349
static int current_command_number()
Definition: cmd-edit.cc:1281
virtual std::string newline_chars()
Definition: cmd-edit.h:277
virtual user_accept_line_fcn do_get_user_accept_line_function() const
Definition: cmd-edit.h:321
static void blink_matching_paren(bool flag)
Definition: cmd-edit.cc:1308
static void set_user_accept_line_function(user_accept_line_fcn f)
Definition: cmd-edit.cc:1391
static string_vector generate_filename_completions(const std::string &text)
Definition: cmd-edit.cc:1430
virtual std::string do_get_current_line() const =0
static void newline()
Definition: cmd-edit.cc:1479
static char get_prev_char(int)
Definition: cmd-edit.cc:1452
virtual void do_set_screen_size(int ht, int wd)
Definition: cmd-edit.h:269
static void remove_startup_hook(startup_hook_fcn f)
Definition: cmd-edit.cc:1517
virtual std::string do_get_line_buffer() const =0
static void set_filename_quote_characters(const std::string &s)
Definition: cmd-edit.cc:1342
static FILE * get_input_stream()
Definition: cmd-edit.cc:1216
static int terminal_rows()
Definition: cmd-edit.cc:1242
virtual bool do_erase_empty_line(bool)
Definition: cmd-edit.h:283
static void redisplay()
Definition: cmd-edit.cc:1235
virtual void do_redisplay()
Definition: cmd-edit.h:259
virtual void do_set_basic_quote_characters(const std::string &)
Definition: cmd-edit.h:291
std::string do_readline(const std::string &prompt)
Definition: cmd-edit.h:242
int m_command_number
Definition: cmd-edit.h:388
static std::string readline(const std::string &prompt)
Definition: cmd-edit.cc:1185
virtual void do_kill_full_line()=0
virtual void do_set_user_accept_line_function(user_accept_line_fcn)
Definition: cmd-edit.h:307
virtual completion_fcn do_get_completion_function() const
Definition: cmd-edit.h:309
virtual FILE * do_get_output_stream()=0
virtual void do_set_name(const std::string &)
Definition: cmd-edit.h:240
virtual char do_get_prev_char(int) const =0
virtual void do_set_filename_quote_characters(const std::string &)
Definition: cmd-edit.h:293
static void set_name(const std::string &n)
Definition: cmd-edit.cc:1178
virtual void do_set_completer_word_break_characters(const std::string &)
Definition: cmd-edit.h:287
bool m_interrupted
Definition: cmd-edit.h:393
virtual void restore_startup_hook()
Definition: cmd-edit.h:350
virtual void do_set_input_stream(FILE *)=0
std::string m_initial_input
Definition: cmd-edit.h:397
static void set_completer_word_break_characters(const std::string &s)
Definition: cmd-edit.cc:1328
static void increment_current_command_number()
Definition: cmd-edit.cc:1294
virtual void do_read_init_file(const std::string &)
Definition: cmd-edit.h:360
static void clear_undo_list()
Definition: cmd-edit.cc:1499
virtual void do_set_completion_append_character(char)
Definition: cmd-edit.h:297
virtual dequoting_fcn do_get_dequoting_function() const
Definition: cmd-edit.h:315
virtual int do_terminal_cols()
Definition: cmd-edit.h:263
virtual bool do_filename_completion_desired(bool)
Definition: cmd-edit.h:364
static FILE * get_output_stream()
Definition: cmd-edit.cc:1229
static bool prefer_env_winsize(bool)
Definition: cmd-edit.cc:1616
static void reset_current_command_number(int n)
Definition: cmd-edit.cc:1287
virtual char_is_quoted_fcn do_get_char_is_quoted_function() const
Definition: cmd-edit.h:318
int read_octal(const std::string &s)
Definition: cmd-edit.cc:1933
static void insert_text(const std::string &text)
Definition: cmd-edit.cc:1472
static bool interrupt(bool=true)
Definition: cmd-edit.cc:1622
virtual void do_replace_line(const std::string &text, bool clear_undo)=0
virtual void do_re_read_init_file()
Definition: cmd-edit.h:362
static void resize_terminal()
Definition: cmd-edit.cc:1261
virtual void do_set_output_stream(FILE *)=0
static bool event_loop_interrupted()
Definition: cmd-edit.cc:1649
static void clear_screen(bool skip_redisplay=false)
Definition: cmd-edit.cc:1254
static void set_initial_input(const std::string &text)
Definition: cmd-edit.cc:1110
static void set_output_stream(FILE *f)
Definition: cmd-edit.cc:1222
void do_interrupt_event_loop(bool arg)
Definition: cmd-edit.h:374
static void accept_line()
Definition: cmd-edit.cc:1486
static void set_screen_size(int ht, int wd)
Definition: cmd-edit.cc:1268
virtual void do_set_quoting_function(quoting_fcn)
Definition: cmd-edit.h:301
static void set_basic_word_break_characters(const std::string &s)
Definition: cmd-edit.cc:1321
static std::string get_current_line()
Definition: cmd-edit.cc:1444
static bool erase_empty_line(bool flag)
Definition: cmd-edit.cc:1315
std::string(* quoting_fcn)(const std::string &, int, char)
Definition: cmd-edit.h:63
virtual quoting_fcn do_get_quoting_function() const
Definition: cmd-edit.h:312
virtual void do_set_char_is_quoted_function(char_is_quoted_fcn)
Definition: cmd-edit.h:305
static void add_pre_input_hook(pre_input_hook_fcn f)
Definition: cmd-edit.cc:1532
virtual int do_terminal_rows()
Definition: cmd-edit.h:261
static void force_default_editor()
Definition: cmd-edit.cc:1103
static char_is_quoted_fcn get_char_is_quoted_function()
Definition: cmd-edit.cc:1416
static bool undo()
Definition: cmd-edit.cc:1493
static void set_completion_function(completion_fcn f)
Definition: cmd-edit.cc:1363
static void remove_event_hook(event_hook_fcn f)
Definition: cmd-edit.cc:1566
static void set_char_is_quoted_function(char_is_quoted_fcn f)
Definition: cmd-edit.cc:1384
virtual void do_interrupt(bool)
Definition: cmd-edit.h:370
static bool filename_completion_desired(bool)
Definition: cmd-edit.cc:1602
static void set_dequoting_function(dequoting_fcn f)
Definition: cmd-edit.cc:1377
bool do_event_loop_interrupted() const
Definition: cmd-edit.h:376
static quoting_fcn get_quoting_function()
Definition: cmd-edit.cc:1404
static int insert_initial_input()
Definition: cmd-edit.cc:1117
static void set_completion_append_character(char c)
Definition: cmd-edit.cc:1356
virtual void do_clear_screen(bool)
Definition: cmd-edit.h:265
static void restore_terminal_state()
Definition: cmd-edit.cc:1301
virtual void do_restore_terminal_state()
Definition: cmd-edit.h:279
virtual void do_set_basic_word_break_characters(const std::string &)
Definition: cmd-edit.h:285
virtual std::string do_decode_prompt_string(const std::string &)
Definition: cmd-edit.cc:1688
virtual void do_set_completion_function(completion_fcn)
Definition: cmd-edit.h:299
virtual void do_blink_matching_paren(bool)
Definition: cmd-edit.h:281
virtual void restore_pre_input_hook()
Definition: cmd-edit.h:354
int(* char_is_quoted_fcn)(const std::string &, int)
Definition: cmd-edit.h:67
virtual void do_clear_undo_list()
Definition: cmd-edit.h:346
static completion_fcn get_completion_function()
Definition: cmd-edit.cc:1398
static std::string get_line_buffer()
Definition: cmd-edit.cc:1438
virtual void do_newline()=0
static void kill_full_line()
Definition: cmd-edit.cc:1465
virtual void do_accept_line()=0
static std::string decode_prompt_string(const std::string &s)
Definition: cmd-edit.cc:1275
virtual void do_insert_text(const std::string &text)=0
static void interrupt_event_loop(bool flag=true)
Definition: cmd-edit.cc:1642
static user_accept_line_fcn get_user_accept_line_function()
Definition: cmd-edit.cc:1423
virtual void set_pre_input_hook(pre_input_hook_fcn)
Definition: cmd-edit.h:352
virtual bool do_prefer_env_winsize(bool)
Definition: cmd-edit.h:368
virtual void do_set_completer_quote_characters(const std::string &)
Definition: cmd-edit.h:295
static dequoting_fcn get_dequoting_function()
Definition: cmd-edit.cc:1410
static void add_event_hook(event_hook_fcn f)
Definition: cmd-edit.cc:1558
virtual bool do_filename_quoting_desired(bool)
Definition: cmd-edit.h:366
static void set_basic_quote_characters(const std::string &s)
Definition: cmd-edit.cc:1335
virtual void do_handle_interrupt_signal()
Definition: cmd-edit.h:372
virtual void do_set_dequoting_function(dequoting_fcn)
Definition: cmd-edit.h:303
std::string(* completion_fcn)(const std::string &, int)
Definition: cmd-edit.h:59
std::string(* dequoting_fcn)(const std::string &, int)
Definition: cmd-edit.h:65
virtual void set_event_hook(event_hook_fcn)
Definition: cmd-edit.h:356
static void re_read_init_file()
Definition: cmd-edit.cc:1595
virtual bool do_undo()
Definition: cmd-edit.h:344
static void read_init_file(const std::string &file="")
Definition: cmd-edit.cc:1584
static void remove_pre_input_hook(pre_input_hook_fcn f)
Definition: cmd-edit.cc:1543
static int terminal_cols()
Definition: cmd-edit.cc:1248
virtual void set_startup_hook(startup_hook_fcn)
Definition: cmd-edit.h:348
int(* startup_hook_fcn)()
Definition: cmd-edit.h:53
int do_insert_initial_input()
Definition: cmd-edit.cc:1915
static int current_number()
Definition: cmd-hist.cc:663
static int length()
Definition: cmd-hist.cc:645
static int where()
Definition: cmd-hist.cc:639
static void set_mark(int n)
Definition: cmd-hist.cc:688
static int goto_mark()
Definition: cmd-hist.cc:695
static int is_stifled()
Definition: cmd-hist.cc:682
static int max_input_history()
Definition: cmd-hist.cc:651
void unlock()
Definition: oct-mutex.h:69
void lock()
Definition: oct-mutex.h:64
static void add(fptr f)
void resize(octave_idx_type n, const std::string &rfv="")
Definition: str-vec.h:95
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
char dir_sep_char()
F77_RET_T const F77_DBLE const F77_DBLE * f
bool dir_exists(const std::string &dirname)
Definition: lo-sysdep.cc:389
std::string fgetl(FILE *f)
Definition: lo-utils.cc:172
octave_idx_type n
Definition: mx-inlines.cc:761
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:289
char * do_completer_word_break_hook()
const char * octave_rl_line_buffer(void)
int octave_rl_history_search_backward(int, int)
void octave_rl_set_startup_hook(rl_startup_hook_fcn_ptr)
void octave_rl_set_quoting_function(rl_quoting_fcn_ptr)
void octave_rl_re_read_init_file(void)
void octave_rl_set_completer_word_break_characters(const char *)
void octave_rl_set_pre_input_hook(rl_startup_hook_fcn_ptr)
char *(* rl_quoting_fcn_ptr)(char *, int, char *)
Definition: oct-rl-edit.h:51
void octave_rl_kill_full_line(void)
char octave_rl_prompt_end_ignore(void)
char **(* rl_attempted_completion_fcn_ptr)(const char *, int, int)
Definition: oct-rl-edit.h:45
void octave_rl_clear_undo_list(void)
void octave_rl_resize_terminal(void)
int octave_rl_history_search_forward(int, int)
void octave_rl_read_init_file(const char *)
void octave_rl_set_dequoting_function(rl_dequoting_fcn_ptr)
void octave_rl_set_basic_quote_characters(const char *)
void octave_rl_clear_screen(int skip_redisplay)
char *(* rl_dequoting_fcn_ptr)(char *, int)
Definition: oct-rl-edit.h:53
int octave_rl_screen_width(void)
char * octave_rl_filename_completion_function(const char *, int)
char octave_rl_prompt_start_ignore(void)
const char * octave_rl_get_completer_word_break_characters(void)
char * octave_rl_copy_line(void)
void octave_rl_set_terminal_name(const char *)
void octave_rl_restore_terminal_state(void)
char * octave_rl_readline(const char *)
void octave_rl_set_name(const char *)
char ** octave_rl_completion_matches(const char *, rl_completer_fcn_ptr)
int octave_rl_do_undo(void)
int octave_rl_filename_completion_desired(int)
void octave_rl_set_output_stream(FILE *)
int octave_rl_ctrl(char)
FILE * octave_rl_get_input_stream(void)
void octave_rl_set_completion_word_break_hook(rl_completion_hook_fcn_ptr)
void octave_rl_initialize(void)
void octave_rl_set_filename_quote_characters(const char *)
void octave_rl_enable_paren_matching(int)
void octave_rl_set_event_hook(rl_event_hook_fcn_ptr f)
void octave_rl_set_completion_append_character(char)
int octave_rl_screen_height(void)
rl_startup_hook_fcn_ptr octave_rl_get_startup_hook(void)
void octave_rl_done(int)
void octave_rl_set_completion_function(rl_attempted_completion_fcn_ptr)
int octave_rl_point(void)
rl_event_hook_fcn_ptr octave_rl_get_event_hook(void)
rl_pre_input_hook_fcn_ptr octave_rl_get_pre_input_hook(void)
void octave_rl_insert_text(const char *)
int(* rl_char_is_quoted_fcn_ptr)(char *, int)
Definition: oct-rl-edit.h:55
int octave_rl_erase_empty_line(int)
FILE * octave_rl_get_output_stream(void)
int octave_rl_filename_quoting_desired(int)
void octave_rl_recover_from_interrupt(void)
void octave_rl_add_defun(const char *, rl_fcn_ptr, int)
void octave_rl_set_completer_quote_characters(const char *)
void octave_rl_set_screen_size(int ht, int wd)
void octave_rl_replace_line(const char *s, int clear_undo)
void octave_rl_set_char_is_quoted_function(rl_char_is_quoted_fcn_ptr)
int octave_rl_newline(int, int)
void octave_rl_set_input_stream(FILE *)
int octave_rl_prefer_env_winsize(int)
void octave_rl_redisplay(void)
void octave_rl_set_basic_word_break_characters(const char *)
void * malloc(unsigned)
void free(void *)
std::atomic< sig_atomic_t > octave_interrupt_state
Definition: quit.cc:39
volatile std::atomic< bool > octave_signal_caught
Definition: quit.cc:41
char * octave_strdup_wrapper(const char *str)
uid_t octave_geteuid_wrapper(void)
F77_RET_T len
Definition: xerbla.cc:61