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