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 std::string newline_chars (
void);
105 void do_restore_terminal_state (
void);
107 void do_blink_matching_paren (
bool flag);
109 void do_set_basic_word_break_characters (
const std::string& s);
111 void do_set_completer_word_break_characters (
const std::string& s);
113 void do_set_basic_quote_characters (
const std::string& s);
115 void do_set_filename_quote_characters (
const std::string& s);
117 void do_set_completer_quote_characters (
const std::string& s);
119 void do_set_completion_append_character (
char c);
121 void do_set_completion_function (completion_fcn f);
123 void do_set_quoting_function (quoting_fcn f);
125 void do_set_dequoting_function (dequoting_fcn f);
127 void do_set_char_is_quoted_function (char_is_quoted_fcn f);
129 void do_set_user_accept_line_function (user_accept_line_fcn f);
131 completion_fcn do_get_completion_function (
void)
const;
133 quoting_fcn do_get_quoting_function (
void)
const;
135 dequoting_fcn do_get_dequoting_function (
void)
const;
137 char_is_quoted_fcn do_get_char_is_quoted_function (
void)
const;
139 user_accept_line_fcn do_get_user_accept_line_function (
void)
const;
142 do_generate_filename_completions (
const std::string&
text);
144 std::string do_get_line_buffer (
void)
const;
146 std::string do_get_current_line (
void)
const;
148 void do_replace_line (
const std::string& text,
bool clear_undo);
150 void do_insert_text (
const std::string& text);
152 void do_newline (
void);
154 void do_accept_line (
void);
158 void do_clear_undo_list (
void);
160 void set_startup_hook (startup_hook_fcn f);
162 void restore_startup_hook (
void);
164 void set_pre_input_hook (pre_input_hook_fcn f);
166 void restore_pre_input_hook (
void);
168 void set_event_hook (event_hook_fcn f);
170 void restore_event_hook (
void);
172 void do_restore_event_hook (
void);
174 void do_read_init_file (
const std::string& file);
176 void do_re_read_init_file (
void);
178 bool do_filename_completion_desired (
bool);
180 bool do_filename_quoting_desired (
bool);
182 void do_interrupt (
bool);
184 static int operate_and_get_next (
int,
int);
186 static int history_search_backward (
int,
int);
188 static int history_search_forward (
int,
int);
192 startup_hook_fcn previous_startup_hook;
194 pre_input_hook_fcn previous_pre_input_hook;
196 event_hook_fcn previous_event_hook;
198 completion_fcn completion_function;
200 quoting_fcn quoting_function;
202 dequoting_fcn dequoting_function;
204 char_is_quoted_fcn char_is_quoted_function;
206 user_accept_line_fcn user_accept_line_function;
208 static char *command_generator (
const char *text,
int state);
210 static char *command_quoter (
char *text,
int match_type,
char *quote_pointer);
211 static char *command_dequoter (
char *text,
int match_type);
213 static int command_char_is_quoted (
char *text,
int index);
215 static int command_accept_line (
int count,
int key);
217 static char **command_completer (
const char *text,
int start,
int end);
222 previous_pre_input_hook (0),
223 previous_event_hook (0), completion_function (0),
224 quoting_function (0), dequoting_function (0),
225 char_is_quoted_function (0), user_accept_line_function (0)
236 do_blink_matching_paren (
true);
241 gnu_readline::operate_and_get_next,
247 gnu_readline::history_search_backward,
251 gnu_readline::history_search_forward,
256 gnu_readline::do_set_name (
const std::string& nm)
262 gnu_readline::do_readline (
const std::string& prompt,
bool& eof)
270 const char *p = prompt.c_str ();
291 gnu_readline::do_set_input_stream (FILE *
f)
297 gnu_readline::do_get_input_stream (
void)
303 gnu_readline::do_set_output_stream (FILE *
f)
309 gnu_readline::do_get_output_stream (
void)
315 gnu_readline::do_redisplay (
void)
327 gnu_readline::do_terminal_rows (
void)
331 return sh > 0 ? sh : 24;
335 gnu_readline::do_terminal_cols (
void)
339 return sw > 0 ? sw : 80;
343 gnu_readline::do_clear_screen (
bool skip_redisplay)
349 gnu_readline::do_resize_terminal (
void)
355 gnu_readline::newline_chars (
void)
361 gnu_readline::do_restore_terminal_state (
void)
367 gnu_readline::do_blink_matching_paren (
bool flag)
373 gnu_readline::do_set_basic_word_break_characters (
const std::string& s)
379 gnu_readline::do_set_completer_word_break_characters (
const std::string& s)
385 gnu_readline::do_set_basic_quote_characters (
const std::string& s)
391 gnu_readline::do_set_filename_quote_characters (
const std::string& s)
397 gnu_readline::do_set_completer_quote_characters (
const std::string& s)
403 gnu_readline::do_set_completion_append_character (
char c)
409 gnu_readline::do_set_completion_function (completion_fcn
f)
411 completion_function =
f;
414 = f ? gnu_readline::command_completer : 0;
420 gnu_readline::do_set_quoting_function (quoting_fcn
f)
422 quoting_function =
f;
425 = f ? gnu_readline::command_quoter : 0;
431 gnu_readline::do_set_dequoting_function (dequoting_fcn
f)
433 dequoting_function =
f;
436 = f ? gnu_readline::command_dequoter : 0;
442 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn
f)
444 char_is_quoted_function =
f;
447 = f ? gnu_readline::command_char_is_quoted : 0;
453 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn
f)
455 user_accept_line_function =
f;
465 gnu_readline::completion_fcn
466 gnu_readline::do_get_completion_function (
void)
const
468 return completion_function;
471 gnu_readline::quoting_fcn
472 gnu_readline::do_get_quoting_function (
void)
const
474 return quoting_function;
477 gnu_readline::dequoting_fcn
478 gnu_readline::do_get_dequoting_function (
void)
const
480 return dequoting_function;
483 gnu_readline::char_is_quoted_fcn
484 gnu_readline::do_get_char_is_quoted_function (
void)
const
486 return char_is_quoted_function;
489 gnu_readline::user_accept_line_fcn
490 gnu_readline::do_get_user_accept_line_function (
void)
const
492 return user_accept_line_function;
496 gnu_readline::do_generate_filename_completions (
const std::string&
text)
521 retval[count++] = fn;
535 gnu_readline::do_get_line_buffer (
void)
const
541 gnu_readline::do_get_current_line (
void)
const
551 gnu_readline::do_replace_line (
const std::string& text,
bool clear_undo)
557 gnu_readline::do_insert_text (
const std::string& text)
563 gnu_readline::do_newline (
void)
569 gnu_readline::do_accept_line (
void)
571 command_accept_line (1,
'\n');
575 gnu_readline::do_undo (
void)
581 gnu_readline::do_clear_undo_list ()
587 gnu_readline::set_startup_hook (startup_hook_fcn f)
591 if (f != previous_startup_hook)
596 gnu_readline::restore_startup_hook (
void)
602 gnu_readline::set_pre_input_hook (pre_input_hook_fcn f)
606 if (f != previous_pre_input_hook)
611 gnu_readline::restore_pre_input_hook (
void)
617 gnu_readline::set_event_hook (event_hook_fcn f)
625 gnu_readline::restore_event_hook (
void)
631 gnu_readline::do_read_init_file (
const std::string& file)
637 gnu_readline::do_re_read_init_file (
void)
643 gnu_readline::do_filename_completion_desired (
bool arg)
649 gnu_readline::do_filename_quoting_desired (
bool arg)
655 gnu_readline::do_interrupt (
bool arg)
661 gnu_readline::operate_and_get_next (
int ,
int )
675 || (x_where >= x_length - 1))
686 gnu_readline::history_search_backward (
int count,
int c)
692 gnu_readline::history_search_forward (
int count,
int c)
698 gnu_readline::command_generator (
const char *text,
int state)
704 std::string tmp =
f (text, state);
706 size_t len = tmp.length ();
710 retval =
static_cast<char *
> (gnulib::malloc (len+1));
712 strcpy (retval, tmp.c_str ());
719 gnu_readline::command_quoter (
char *text,
int matches,
char *qcp)
725 std::string tmp =
f (text, matches, *qcp);
727 size_t len = tmp.length ();
731 retval =
static_cast<char *
> (gnulib::malloc (len+1));
733 strcpy (retval, tmp.c_str ());
740 gnu_readline::command_dequoter (
char *text,
int quote)
746 std::string tmp =
f (text, quote);
748 size_t len = tmp.length ();
752 retval =
static_cast<char *
> (gnulib::malloc (len+1));
754 strcpy (retval, tmp.c_str ());
761 gnu_readline::command_char_is_quoted (
char *text,
int quote)
765 return f (text, quote);
769 gnu_readline::command_accept_line (
int count,
int key)
782 gnu_readline::command_completer (
const char *text,
int,
int)
798 :
command_editor (), input_stream (stdin), output_stream (stdout) { }
802 std::string do_readline (
const std::string& prompt,
bool& eof);
804 void do_set_input_stream (FILE *f);
806 FILE *do_get_input_stream (
void);
808 void do_set_output_stream (FILE *f);
810 FILE *do_get_output_stream (
void);
812 string_vector do_generate_filename_completions (
const std::string& text);
814 std::string do_get_line_buffer (
void)
const;
816 std::string do_get_current_line (
void)
const;
818 void do_replace_line (
const std::string& text,
bool clear_undo);
820 void do_insert_text (
const std::string& text);
822 void do_newline (
void);
824 void do_accept_line (
void);
889 return std::string ();
932 (
"unable to create command history object!");
943 #if defined (USE_READLINE)
1003 event_hook_lock.
lock ();
1007 event_hook_lock.
unlock ();
1010 p != hook_set.end (); p++)
1501 size_t slen = s.length ();
1606 catch (octave_execution_exception)
1613 if (c ==
'W' && (home_dir.empty () || temp != home_dir))
1615 if (temp !=
"/" && temp !=
"//")
1617 size_t pos = temp.rfind (
'/');
1619 if (pos != std::string::npos && pos != 0)
1620 temp = temp.substr (pos + 1);
1647 size_t pos = temp.find (
'.');
1649 if (pos != std::string::npos)
1657 char number_buffer[128];
1659 temp = number_buffer;
1666 char number_buffer[128];
1669 sprintf (number_buffer,
"%d", num);
1671 strcpy (number_buffer,
"!");
1672 temp = number_buffer;
1679 #if defined (HAVE_GETEUID)
1680 temp = (::geteuid () == 0 ?
"#" :
"$");
1688 #if defined (USE_READLINE)
1694 temp[0] = ((c ==
'[')
1722 result.append (temp);
1760 size_t slen = s.length ();
1762 while (i < slen && s[i] >=
'0' && s[i] <
'8')
1765 result = (result * 8) + s[i] -
'0';
1769 if (! digits || result > 0777 || i < slen)