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