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