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