32 #include <sys/types.h>
57 #if defined (USE_READLINE)
81 void do_set_name (
const std::string& n);
83 std::string do_readline (
const std::string& prompt,
bool& eof);
85 void do_set_input_stream (FILE *
f);
87 FILE *do_get_input_stream (
void);
89 void do_set_output_stream (FILE *f);
91 FILE *do_get_output_stream (
void);
93 void do_redisplay (
void);
95 int do_terminal_rows (
void);
97 int do_terminal_cols (
void);
99 void do_clear_screen (
bool skip_redisplay);
101 void do_resize_terminal (
void);
103 void do_set_screen_size (
int ht,
int wd);
105 std::string newline_chars (
void);
107 void do_restore_terminal_state (
void);
109 void do_blink_matching_paren (
bool flag);
111 bool do_erase_empty_line (
bool flag);
113 void do_set_basic_word_break_characters (
const std::string& s);
115 void do_set_completer_word_break_characters (
const std::string& s);
117 void do_set_basic_quote_characters (
const std::string& s);
119 void do_set_filename_quote_characters (
const std::string& s);
121 void do_set_completer_quote_characters (
const std::string& s);
123 void do_set_completion_append_character (
char c);
125 void do_set_completion_function (completion_fcn f);
127 void do_set_quoting_function (quoting_fcn f);
129 void do_set_dequoting_function (dequoting_fcn f);
131 void do_set_char_is_quoted_function (char_is_quoted_fcn f);
133 void do_set_user_accept_line_function (user_accept_line_fcn f);
135 completion_fcn do_get_completion_function (
void)
const;
137 quoting_fcn do_get_quoting_function (
void)
const;
139 dequoting_fcn do_get_dequoting_function (
void)
const;
141 char_is_quoted_fcn do_get_char_is_quoted_function (
void)
const;
143 user_accept_line_fcn do_get_user_accept_line_function (
void)
const;
146 do_generate_filename_completions (
const std::string&
text);
148 std::string do_get_line_buffer (
void)
const;
150 std::string do_get_current_line (
void)
const;
152 void do_replace_line (
const std::string& text,
bool clear_undo);
154 void do_kill_full_line (
void);
156 void do_insert_text (
const std::string& text);
158 void do_newline (
void);
160 void do_accept_line (
void);
164 void do_clear_undo_list (
void);
166 void set_startup_hook (startup_hook_fcn f);
168 void restore_startup_hook (
void);
170 void set_pre_input_hook (pre_input_hook_fcn f);
172 void restore_pre_input_hook (
void);
174 void set_event_hook (event_hook_fcn f);
176 void restore_event_hook (
void);
178 void do_restore_event_hook (
void);
180 void do_read_init_file (
const std::string& file);
182 void do_re_read_init_file (
void);
184 bool do_filename_completion_desired (
bool);
186 bool do_filename_quoting_desired (
bool);
188 bool do_prefer_env_winsize (
bool);
190 void do_interrupt (
bool);
192 static int operate_and_get_next (
int,
int);
194 static int history_search_backward (
int,
int);
196 static int history_search_forward (
int,
int);
200 startup_hook_fcn previous_startup_hook;
202 pre_input_hook_fcn previous_pre_input_hook;
204 event_hook_fcn previous_event_hook;
206 completion_fcn completion_function;
208 quoting_fcn quoting_function;
210 dequoting_fcn dequoting_function;
212 char_is_quoted_fcn char_is_quoted_function;
214 user_accept_line_fcn user_accept_line_function;
216 static char *command_generator (
const char *text,
int state);
218 static char *command_quoter (
char *text,
int match_type,
char *quote_pointer);
219 static char *command_dequoter (
char *text,
int match_type);
221 static int command_char_is_quoted (
char *text,
int index);
223 static int command_accept_line (
int count,
int key);
225 static char **command_completer (
const char *text,
int start,
int end);
230 previous_pre_input_hook (0),
231 previous_event_hook (0), completion_function (0),
232 quoting_function (0), dequoting_function (0),
233 char_is_quoted_function (0), user_accept_line_function (0)
244 do_blink_matching_paren (
true);
249 gnu_readline::operate_and_get_next,
255 gnu_readline::history_search_backward,
259 gnu_readline::history_search_forward,
264 gnu_readline::do_set_name (
const std::string& nm)
270 gnu_readline::do_readline (
const std::string& prompt,
bool& eof)
276 const char *p = prompt.c_str ();
297 gnu_readline::do_set_input_stream (FILE *
f)
303 gnu_readline::do_get_input_stream (
void)
309 gnu_readline::do_set_output_stream (FILE *
f)
315 gnu_readline::do_get_output_stream (
void)
321 gnu_readline::do_redisplay (
void)
333 gnu_readline::do_terminal_rows (
void)
337 return sh > 0 ? sh : 24;
341 gnu_readline::do_terminal_cols (
void)
345 return sw > 0 ? sw : 80;
349 gnu_readline::do_clear_screen (
bool skip_redisplay)
355 gnu_readline::do_resize_terminal (
void)
361 gnu_readline::do_set_screen_size (
int ht,
int wd)
367 gnu_readline::newline_chars (
void)
373 gnu_readline::do_restore_terminal_state (
void)
379 gnu_readline::do_blink_matching_paren (
bool flag)
385 gnu_readline::do_erase_empty_line (
bool flag)
391 gnu_readline::do_set_basic_word_break_characters (
const std::string& s)
397 gnu_readline::do_set_completer_word_break_characters (
const std::string& s)
403 gnu_readline::do_set_basic_quote_characters (
const std::string& s)
409 gnu_readline::do_set_filename_quote_characters (
const std::string& s)
415 gnu_readline::do_set_completer_quote_characters (
const std::string& s)
421 gnu_readline::do_set_completion_append_character (
char c)
427 gnu_readline::do_set_completion_function (completion_fcn
f)
429 completion_function =
f;
432 = f ? gnu_readline::command_completer : 0;
438 gnu_readline::do_set_quoting_function (quoting_fcn
f)
440 quoting_function =
f;
443 = f ? gnu_readline::command_quoter : 0;
449 gnu_readline::do_set_dequoting_function (dequoting_fcn
f)
451 dequoting_function =
f;
454 = f ? gnu_readline::command_dequoter : 0;
460 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn
f)
462 char_is_quoted_function =
f;
465 = f ? gnu_readline::command_char_is_quoted : 0;
471 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn
f)
473 user_accept_line_function =
f;
483 gnu_readline::completion_fcn
484 gnu_readline::do_get_completion_function (
void)
const
486 return completion_function;
489 gnu_readline::quoting_fcn
490 gnu_readline::do_get_quoting_function (
void)
const
492 return quoting_function;
495 gnu_readline::dequoting_fcn
496 gnu_readline::do_get_dequoting_function (
void)
const
498 return dequoting_function;
501 gnu_readline::char_is_quoted_fcn
502 gnu_readline::do_get_char_is_quoted_function (
void)
const
504 return char_is_quoted_function;
507 gnu_readline::user_accept_line_fcn
508 gnu_readline::do_get_user_accept_line_function (
void)
const
510 return user_accept_line_function;
514 gnu_readline::do_generate_filename_completions (
const std::string&
text)
539 retval[count++] = fn;
553 gnu_readline::do_get_line_buffer (
void)
const
559 gnu_readline::do_get_current_line (
void)
const
569 gnu_readline::do_replace_line (
const std::string& text,
bool clear_undo)
575 gnu_readline::do_kill_full_line (
void)
581 gnu_readline::do_insert_text (
const std::string& text)
587 gnu_readline::do_newline (
void)
593 gnu_readline::do_accept_line (
void)
595 command_accept_line (1,
'\n');
599 gnu_readline::do_undo (
void)
605 gnu_readline::do_clear_undo_list ()
611 gnu_readline::set_startup_hook (startup_hook_fcn f)
615 if (f != previous_startup_hook)
620 gnu_readline::restore_startup_hook (
void)
626 gnu_readline::set_pre_input_hook (pre_input_hook_fcn f)
630 if (f != previous_pre_input_hook)
635 gnu_readline::restore_pre_input_hook (
void)
641 gnu_readline::set_event_hook (event_hook_fcn f)
649 gnu_readline::restore_event_hook (
void)
655 gnu_readline::do_read_init_file (
const std::string& file)
661 gnu_readline::do_re_read_init_file (
void)
667 gnu_readline::do_filename_completion_desired (
bool arg)
673 gnu_readline::do_filename_quoting_desired (
bool arg)
679 gnu_readline::do_prefer_env_winsize (
bool arg)
685 gnu_readline::do_interrupt (
bool arg)
691 gnu_readline::operate_and_get_next (
int ,
int )
705 || (x_where >= x_length - 1))
716 gnu_readline::history_search_backward (
int count,
int c)
722 gnu_readline::history_search_forward (
int count,
int c)
728 gnu_readline::command_generator (
const char *text,
int state)
734 std::string tmp =
f (text, state);
736 size_t len = tmp.length ();
742 strcpy (retval, tmp.c_str ());
749 gnu_readline::command_quoter (
char *text,
int matches,
char *qcp)
755 std::string tmp =
f (text, matches, *qcp);
757 size_t len = tmp.length ();
763 strcpy (retval, tmp.c_str ());
770 gnu_readline::command_dequoter (
char *text,
int quote)
776 std::string tmp =
f (text, quote);
778 size_t len = tmp.length ();
784 strcpy (retval, tmp.c_str ());
791 gnu_readline::command_char_is_quoted (
char *text,
int quote)
795 return f (text, quote);
799 gnu_readline::command_accept_line (
int count,
int key)
812 gnu_readline::command_completer (
const char *text,
int,
int)
828 :
command_editor (), input_stream (stdin), output_stream (stdout) { }
832 std::string do_readline (
const std::string& prompt,
bool& eof);
834 void do_set_input_stream (FILE *f);
836 FILE *do_get_input_stream (
void);
838 void do_set_output_stream (FILE *f);
840 FILE *do_get_output_stream (
void);
842 string_vector do_generate_filename_completions (
const std::string& text);
844 std::string do_get_line_buffer (
void)
const;
846 std::string do_get_current_line (
void)
const;
848 void do_replace_line (
const std::string& text,
bool clear_undo);
850 void do_kill_full_line (
void);
852 void do_insert_text (
const std::string& text);
854 void do_newline (
void);
856 void do_accept_line (
void);
921 return std::string ();
970 (
"unable to create command history object!");
981 #if defined (USE_READLINE)
1041 event_hook_lock.
lock ();
1045 event_hook_lock.
unlock ();
1048 p != hook_set.end (); p++)
1566 size_t slen = s.length ();
1671 catch (octave_execution_exception)
1678 if (c ==
'W' && (home_dir.empty () || temp != home_dir))
1680 if (temp !=
"/" && temp !=
"//")
1682 size_t pos = temp.rfind (
'/');
1684 if (pos != std::string::npos && pos != 0)
1685 temp = temp.substr (pos + 1);
1712 size_t pos = temp.find (
'.');
1714 if (pos != std::string::npos)
1722 char number_buffer[128];
1724 temp = number_buffer;
1731 char number_buffer[128];
1734 sprintf (number_buffer,
"%d", num);
1736 strcpy (number_buffer,
"!");
1737 temp = number_buffer;
1744 #if defined (HAVE_GETEUID)
1745 temp = (::geteuid () == 0 ?
"#" :
"$");
1753 #if defined (USE_READLINE)
1759 temp[0] = ((c ==
'[')
1787 result.append (temp);
1825 size_t slen = s.length ();
1827 while (i < slen && s[i] >=
'0' && s[i] <
'8')
1830 result = (result * 8) + s[i] -
'0';
1834 if (! digits || result > 0777 || i < slen)
static FILE * get_input_stream(void)
char octave_rl_meta(char)
virtual bool do_undo(void)
int octave_rl_do_undo(void)
int octave_rl_newline(int, int)
static octave_mutex event_hook_lock
virtual string_vector do_generate_filename_completions(const std::string &text)=0
void octave_rl_set_dequoting_function(rl_dequoting_fcn_ptr)
virtual quoting_fcn do_get_quoting_function(void) const
int(* char_is_quoted_fcn)(const std::string &, int)
char octave_rl_ctrl(char)
char * octave_rl_readline(const char *)
static int terminal_cols(void)
void do_set_input_stream(FILE *f)
static std::string get_program_name(void)
void do_replace_line(const std::string &text, bool clear_undo)
virtual void do_set_filename_quote_characters(const std::string &)
void octave_rl_set_terminal_name(const char *)
static void make_command_editor(void)
virtual int do_terminal_cols(void)
virtual void restore_event_hook(void)
virtual void do_set_completion_function(completion_fcn)
virtual void do_set_quoting_function(quoting_fcn)
static bool erase_empty_line(bool flag)
virtual void do_set_basic_quote_characters(const std::string &)
static uint32_t state[624]
virtual void do_newline(void)=0
string_vector do_generate_filename_completions(const std::string &text)
static void set_screen_size(int ht, int wd)
FILE * do_get_output_stream(void)
static void clear_undo_list(void)
virtual void do_set_user_accept_line_function(user_accept_line_fcn)
static std::set< pre_input_hook_fcn > pre_input_hook_set
void octave_rl_redisplay(void)
static void restore_terminal_state(void)
int octave_rl_filename_quoting_desired(int)
virtual dequoting_fcn do_get_dequoting_function(void) const
std::string strftime(const std::string &fmt) const
static void reset_current_command_number(int n)
int octave_rl_screen_width(void)
static FILE * get_output_stream(void)
static bool filename_quoting_desired(bool)
std::string do_get_current_line(void) const
virtual void set_pre_input_hook(pre_input_hook_fcn)
virtual void set_event_hook(event_hook_fcn)
void do_insert_text(const std::string &text)
std::set< startup_hook_fcn >::iterator startup_hook_set_iterator
void do_kill_full_line(void)
void octave_rl_set_event_hook(rl_event_hook_fcn_ptr f)
static void re_read_init_file(void)
void(* user_accept_line_fcn)(const std::string &)
static void set_filename_quote_characters(const std::string &s)
void octave_rl_clear_undo_list(void)
static void add_event_hook(event_hook_fcn f)
int(* pre_input_hook_fcn)(void)
int(* event_hook_fcn)(void)
virtual void restore_pre_input_hook(void)
void octave_rl_set_completion_function(rl_attempted_completion_fcn_ptr)
std::string(* dequoting_fcn)(const std::string &, int)
static void run_event_hooks(void)
static void set_completion_append_character(char c)
virtual void do_set_output_stream(FILE *)=0
int octave_rl_erase_empty_line(int)
static user_accept_line_fcn get_user_accept_line_function(void)
static bool instance_ok(void)
void octave_rl_set_basic_word_break_characters(const char *)
static int max_input_history(void)
virtual void do_set_completer_word_break_characters(const std::string &)
void octave_rl_set_basic_quote_characters(const char *)
virtual void do_restore_terminal_state(void)
char octave_rl_prompt_end_ignore(void)
void octave_rl_set_completer_quote_characters(const char *)
char *(* rl_quoting_fcn_ptr)(char *, int, char *)
static int terminal_rows(void)
void octave_rl_resize_terminal(void)
default_command_editor(void)
virtual void do_set_basic_word_break_characters(const std::string &)
static void set_mark(int n)
static void set_name(const std::string &n)
virtual bool do_prefer_env_winsize(bool)
static std::string tilde_expand(const std::string &)
static void insert_text(const std::string &text)
static void remove_startup_hook(startup_hook_fcn f)
virtual void do_read_init_file(const std::string &)
char octave_rl_prompt_start_ignore(void)
static void set_basic_quote_characters(const std::string &s)
void octave_rl_restore_terminal_state(void)
static int insert_initial_input(void)
virtual void restore_startup_hook(void)
virtual void do_set_screen_size(int, int)
int octave_rl_filename_completion_desired(int)
virtual void do_set_name(const std::string &)
liboctave_error_handler current_liboctave_error_handler
static void remove_pre_input_hook(pre_input_hook_fcn f)
static command_editor * instance
static int is_stifled(void)
static void newline(void)
std::string do_readline(const std::string &prompt)
void octave_rl_clear_screen(int skip_redisplay)
int octave_rl_history_search_forward(int, int)
void octave_rl_add_defun(const char *, rl_fcn_ptr, char)
static int pre_input_handler(void)
F77_RET_T const double const double * f
std::string do_readline(const std::string &prompt, bool &eof)
static void resize_terminal(void)
static void accept_line(void)
void octave_rl_read_init_file(const char *)
static string_vector generate_filename_completions(const std::string &text)
virtual std::string do_decode_prompt_string(const std::string &)
static std::string get_current_directory(void)
static int current_command_number(void)
static void set_input_stream(FILE *f)
virtual std::string newline_chars(void)
char *(* rl_dequoting_fcn_ptr)(char *, int)
void resize(octave_idx_type n, const std::string &rfv=std::string())
virtual void do_redisplay(void)
std::set< pre_input_hook_fcn >::iterator pre_input_hook_set_iterator
static std::string get_current_line(void)
void octave_rl_set_completer_word_break_characters(const char *)
static std::string getenv(const std::string &name)
static void set_char_is_quoted_function(char_is_quoted_fcn f)
virtual void do_clear_screen(bool)
virtual int do_terminal_rows(void)
static void read_init_file(const std::string &file=std::string())
static int current_number(void)
static bool interrupt(bool=true)
int do_insert_initial_input(void)
void octave_rl_set_filename_quote_characters(const char *)
static void set_completion_function(completion_fcn f)
void octave_rl_initialize(void)
virtual void do_set_dequoting_function(dequoting_fcn)
std::string initial_input
int read_octal(const std::string &s)
std::set< event_hook_fcn >::iterator event_hook_set_iterator
void octave_rl_set_pre_input_hook(rl_startup_hook_fcn_ptr)
void octave_rl_enable_paren_matching(int)
char ** octave_rl_completion_matches(const char *, rl_completer_fcn_ptr)
void octave_rl_set_completion_append_character(char)
void octave_rl_set_screen_size(int ht, int wd)
char * octave_rl_filename_completion_function(const char *, int)
static void kill_full_line(void)
static int event_handler(void)
static std::string decode_prompt_string(const std::string &s)
void octave_rl_set_name(const char *)
static std::set< event_hook_fcn > event_hook_set
static quoting_fcn get_quoting_function(void)
static void cleanup_instance(void)
static std::string get_line_buffer(void)
void octave_rl_insert_text(const char *)
static char_is_quoted_fcn get_char_is_quoted_function(void)
static void remove_event_hook(event_hook_fcn f)
static std::string polite_directory_format(const std::string &name)
std::string(* quoting_fcn)(const std::string &, int, char)
static std::string readline(const std::string &prompt)
static void set_output_stream(FILE *f)
virtual void do_accept_line(void)=0
char **(* rl_attempted_completion_fcn_ptr)(const char *, int, int)
static void clear_screen(bool skip_redisplay=false)
static void set_basic_word_break_characters(const std::string &s)
void do_set_output_stream(FILE *f)
static std::string base_pathname(const std::string &s)
int octave_rl_prefer_env_winsize(int)
char * octave_rl_copy_line(void)
virtual void do_re_read_init_file(void)
static void add_pre_input_hook(pre_input_hook_fcn f)
virtual std::string do_get_line_buffer(void) const =0
#define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
static void set_quoting_function(quoting_fcn f)
virtual void set_startup_hook(startup_hook_fcn)
std::string do_get_line_buffer(void) const
static dequoting_fcn get_dequoting_function(void)
static void force_default_editor(void)
virtual FILE * do_get_output_stream(void)=0
void octave_rl_set_startup_hook(rl_startup_hook_fcn_ptr)
virtual void do_set_completion_append_character(char)
static std::string get_user_name(void)
static void redisplay(void)
static int startup_handler(void)
int(* rl_char_is_quoted_fcn_ptr)(char *, int)
int(* startup_hook_fcn)(void)
static void add_startup_hook(startup_hook_fcn f)
rl_event_hook_fcn_ptr octave_rl_get_event_hook(void)
virtual void do_kill_full_line(void)=0
virtual void do_interrupt(bool)
virtual void do_resize_terminal(void)
virtual void do_blink_matching_paren(bool)
virtual bool do_filename_quoting_desired(bool)
virtual FILE * do_get_input_stream(void)=0
virtual user_accept_line_fcn do_get_user_accept_line_function(void) const
static void set_user_accept_line_function(user_accept_line_fcn f)
void octave_rl_kill_full_line(void)
rl_pre_input_hook_fcn_ptr octave_rl_get_pre_input_hook(void)
static void set_completer_word_break_characters(const std::string &s)
void octave_rl_re_read_init_file(void)
virtual completion_fcn do_get_completion_function(void) const
static int input(yyscan_t yyscanner)
const char * octave_rl_line_buffer(void)
~default_command_editor(void)
FILE * octave_rl_get_input_stream(void)
virtual std::string do_get_current_line(void) const =0
virtual void do_replace_line(const std::string &text, bool clear_undo)=0
int octave_rl_screen_height(void)
static void set_dequoting_function(dequoting_fcn f)
#define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
static void set_completer_quote_characters(const std::string &s)
static void blink_matching_paren(bool flag)
static int goto_mark(void)
void do_accept_line(void)
static completion_fcn get_completion_function(void)
virtual void do_insert_text(const std::string &text)=0
static bool prefer_env_winsize(bool)
static void increment_current_command_number(void)
void octave_rl_replace_line(const char *s, int clear_undo)
static void replace_line(const std::string &text, bool clear_undo=true)
static bool filename_completion_desired(bool)
FILE * octave_rl_get_output_stream(void)
static void set_initial_input(const std::string &text)
static std::set< startup_hook_fcn > startup_hook_set
virtual void do_clear_undo_list(void)
virtual void do_set_input_stream(FILE *)=0
virtual bool do_erase_empty_line(bool)
virtual bool do_filename_completion_desired(bool)
FILE * do_get_input_stream(void)
virtual void do_set_char_is_quoted_function(char_is_quoted_fcn)
rl_startup_hook_fcn_ptr octave_rl_get_startup_hook(void)
static std::string get_host_name(void)
std::string(* completion_fcn)(const std::string &, int)
void octave_rl_set_char_is_quoted_function(rl_char_is_quoted_fcn_ptr)
void octave_rl_set_quoting_function(rl_quoting_fcn_ptr)
virtual void do_set_completer_quote_characters(const std::string &)
int octave_rl_history_search_backward(int, int)
virtual char_is_quoted_fcn do_get_char_is_quoted_function(void) const
std::string octave_fgetl(FILE *f)
static std::string get_home_directory(void)
void octave_rl_set_input_stream(FILE *)
void octave_rl_set_output_stream(FILE *)