2926
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2926
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2926
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2926
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_cmd_edit_h) |
|
25 #define octave_cmd_edit_h 1 |
|
26 |
|
27 #include <cstdio> |
|
28 |
6913
|
29 #include <set> |
2926
|
30 #include <string> |
|
31 |
4604
|
32 #include "str-vec.h" |
|
33 |
2926
|
34 class |
6108
|
35 OCTAVE_API |
2926
|
36 command_editor |
|
37 { |
|
38 protected: |
|
39 |
|
40 command_editor (void) |
|
41 : command_number (0) { } |
|
42 |
|
43 public: |
|
44 |
4802
|
45 typedef int (*startup_hook_fcn) (void); |
3519
|
46 |
4802
|
47 typedef int (*event_hook_fcn) (void); |
2926
|
48 |
3504
|
49 typedef std::string (*completion_fcn) (const std::string&, int); |
2941
|
50 |
6979
|
51 typedef std::string (*quoting_fcn) (const std::string&, int, char); |
|
52 |
|
53 typedef std::string (*dequoting_fcn) (const std::string&, int); |
|
54 |
|
55 typedef int (*char_is_quoted_fcn) (const std::string&, int); |
|
56 |
|
57 typedef void (*user_accept_line_fcn) (const std::string&); |
|
58 |
2926
|
59 virtual ~command_editor (void) { } |
|
60 |
3504
|
61 static void set_name (const std::string& n); |
2926
|
62 |
3504
|
63 static std::string readline (const std::string& prompt); |
2926
|
64 |
3504
|
65 static std::string readline (const std::string& prompt, bool& eof); |
3219
|
66 |
2926
|
67 static void set_input_stream (FILE *f); |
|
68 |
|
69 static FILE *get_input_stream (void); |
|
70 |
|
71 static void set_output_stream (FILE *f); |
|
72 |
|
73 static FILE *get_output_stream (void); |
|
74 |
|
75 static int terminal_rows (void); |
|
76 |
|
77 static int terminal_cols (void); |
|
78 |
|
79 static void clear_screen (void); |
|
80 |
3281
|
81 static void resize_terminal (void); |
|
82 |
3504
|
83 static std::string decode_prompt_string (const std::string& s); |
2926
|
84 |
|
85 static void restore_terminal_state (void); |
|
86 |
|
87 static void blink_matching_paren (bool flag); |
|
88 |
4055
|
89 static void set_basic_word_break_characters (const std::string& s); |
3933
|
90 |
4055
|
91 static void set_completer_word_break_characters (const std::string& s); |
3933
|
92 |
3504
|
93 static void set_basic_quote_characters (const std::string& s); |
2926
|
94 |
6979
|
95 static void set_filename_quote_characters (const std::string& s); |
|
96 |
|
97 static void set_completer_quote_characters (const std::string& s); |
|
98 |
2926
|
99 static void set_completion_append_character (char c); |
|
100 |
2941
|
101 static void set_completion_function (completion_fcn f); |
|
102 |
6979
|
103 static void set_quoting_function (quoting_fcn f); |
|
104 |
|
105 static void set_dequoting_function (dequoting_fcn f); |
|
106 |
|
107 static void set_char_is_quoted_function (char_is_quoted_fcn f); |
|
108 |
|
109 static void set_user_accept_line_function (user_accept_line_fcn f); |
|
110 |
2941
|
111 static completion_fcn get_completion_function (void); |
2926
|
112 |
6979
|
113 static quoting_fcn get_quoting_function (void); |
|
114 |
|
115 static dequoting_fcn get_dequoting_function (void); |
|
116 |
|
117 static char_is_quoted_fcn get_char_is_quoted_function (void); |
|
118 |
|
119 static user_accept_line_fcn get_user_accept_line_function (void); |
|
120 |
4604
|
121 static string_vector generate_filename_completions (const std::string& text); |
|
122 |
3504
|
123 static void insert_text (const std::string& text); |
2926
|
124 |
|
125 static void newline (void); |
|
126 |
6979
|
127 static void accept_line (void); |
|
128 |
2926
|
129 static void clear_undo_list (void); |
|
130 |
6913
|
131 static void add_startup_hook (startup_hook_fcn f); |
2926
|
132 |
6913
|
133 static void remove_startup_hook (startup_hook_fcn f); |
2926
|
134 |
6913
|
135 static void add_event_hook (event_hook_fcn f); |
3215
|
136 |
6913
|
137 static void remove_event_hook (event_hook_fcn f); |
3215
|
138 |
3504
|
139 static void read_init_file (const std::string& file = std::string ()); |
3189
|
140 |
4143
|
141 static bool filename_completion_desired (bool); |
|
142 |
6979
|
143 static bool filename_quoting_desired (bool); |
|
144 |
2926
|
145 static int current_command_number (void); |
|
146 |
|
147 static void reset_current_command_number (int n); |
|
148 |
2967
|
149 static void increment_current_command_number (void); |
|
150 |
2926
|
151 private: |
|
152 |
|
153 // No copying! |
|
154 |
|
155 command_editor (const command_editor&); |
|
156 |
|
157 command_editor& operator = (const command_editor&); |
|
158 |
|
159 static bool instance_ok (void); |
|
160 |
|
161 static void make_command_editor (void); |
|
162 |
6913
|
163 static int startup_handler (void); |
|
164 |
|
165 static int event_handler (void); |
|
166 |
|
167 static std::set<startup_hook_fcn> startup_hook_set; |
|
168 |
|
169 static std::set<event_hook_fcn> event_hook_set; |
|
170 |
|
171 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator; |
|
172 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator; |
|
173 |
|
174 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator; |
|
175 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator; |
|
176 |
2926
|
177 // The real thing. |
|
178 static command_editor *instance; |
|
179 |
|
180 protected: |
|
181 |
|
182 // To use something other than the GNU readline library, derive a new |
|
183 // class from command_editor, overload these functions as |
|
184 // necessary, and make instance point to the new class. |
|
185 |
3504
|
186 virtual void do_set_name (const std::string&) { } |
2926
|
187 |
3504
|
188 std::string do_readline (const std::string& prompt) |
3219
|
189 { |
|
190 bool eof; |
|
191 |
|
192 return do_readline (prompt, eof); |
|
193 } |
|
194 |
3504
|
195 virtual std::string do_readline (const std::string&, bool&) = 0; |
2926
|
196 |
|
197 virtual void do_set_input_stream (FILE *) = 0; |
|
198 |
|
199 virtual FILE *do_get_input_stream (void) = 0; |
|
200 |
|
201 virtual void do_set_output_stream (FILE *) = 0; |
|
202 |
|
203 virtual FILE *do_get_output_stream (void) = 0; |
|
204 |
|
205 virtual int do_terminal_rows (void) { return 24; } |
|
206 |
|
207 virtual int do_terminal_cols (void) { return 80; } |
|
208 |
|
209 virtual void do_clear_screen (void) { } |
|
210 |
3281
|
211 virtual void do_resize_terminal (void) { } |
|
212 |
3504
|
213 virtual std::string do_decode_prompt_string (const std::string&); |
2926
|
214 |
3504
|
215 virtual std::string newline_chars (void) { return "\n"; } |
2926
|
216 |
|
217 virtual void do_restore_terminal_state (void) { } |
|
218 |
|
219 virtual void do_blink_matching_paren (bool) { } |
|
220 |
3933
|
221 virtual void do_set_basic_word_break_characters (const std::string&) { } |
|
222 |
|
223 virtual void do_set_completer_word_break_characters (const std::string&) { } |
|
224 |
3504
|
225 virtual void do_set_basic_quote_characters (const std::string&) { } |
2926
|
226 |
6979
|
227 virtual void do_set_filename_quote_characters (const std::string&) { } |
|
228 |
|
229 virtual void do_set_completer_quote_characters (const std::string&) { } |
|
230 |
2926
|
231 virtual void do_set_completion_append_character (char) { } |
|
232 |
2941
|
233 virtual void do_set_completion_function (completion_fcn) { } |
|
234 |
6979
|
235 virtual void do_set_quoting_function (quoting_fcn) { } |
|
236 |
|
237 virtual void do_set_dequoting_function (dequoting_fcn) { } |
|
238 |
|
239 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { } |
|
240 |
|
241 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { } |
|
242 |
2941
|
243 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926
|
244 |
6979
|
245 virtual quoting_fcn do_get_quoting_function (void) const { return 0; } |
|
246 |
|
247 virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; } |
|
248 |
|
249 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { return 0; } |
|
250 |
|
251 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const { return 0; } |
|
252 |
4604
|
253 virtual string_vector do_generate_filename_completions (const std::string& text) = 0; |
|
254 |
3504
|
255 virtual void do_insert_text (const std::string&) = 0; |
2926
|
256 |
|
257 virtual void do_newline (void) = 0; |
|
258 |
6979
|
259 virtual void do_accept_line (void) = 0; |
|
260 |
2926
|
261 virtual void do_clear_undo_list (void) { } |
|
262 |
6913
|
263 virtual void set_startup_hook (startup_hook_fcn) { } |
2926
|
264 |
6913
|
265 virtual void restore_startup_hook (void) { } |
2926
|
266 |
6913
|
267 virtual void set_event_hook (startup_hook_fcn) { } |
3215
|
268 |
6913
|
269 virtual void restore_event_hook (void) { } |
3215
|
270 |
3504
|
271 virtual void do_read_init_file (const std::string&) { } |
3189
|
272 |
4143
|
273 virtual bool do_filename_completion_desired (bool) { return false; } |
|
274 |
6979
|
275 virtual bool do_filename_quoting_desired (bool) { return false; } |
|
276 |
3504
|
277 int read_octal (const std::string& s); |
2926
|
278 |
|
279 void error (int); |
|
280 |
3504
|
281 void error (const std::string&); |
2926
|
282 |
|
283 // The current command number. |
|
284 int command_number; |
|
285 }; |
|
286 |
|
287 #endif |
|
288 |
|
289 /* |
|
290 ;;; Local Variables: *** |
|
291 ;;; mode: C++ *** |
|
292 ;;; End: *** |
|
293 */ |