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