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