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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_cmd_edit_h) |
|
24 #define octave_cmd_edit_h 1 |
|
25 |
|
26 #include <cstdio> |
|
27 |
|
28 #include <string> |
|
29 |
|
30 class |
|
31 command_editor |
|
32 { |
|
33 protected: |
|
34 |
|
35 command_editor (void) |
|
36 : command_number (0) { } |
|
37 |
|
38 public: |
|
39 |
|
40 typedef int (*fcn) (...); |
|
41 |
2941
|
42 typedef string (*completion_fcn) (const string&, int); |
|
43 |
2926
|
44 virtual ~command_editor (void) { } |
|
45 |
|
46 static void set_name (const string& n); |
|
47 |
|
48 static string readline (const string& prompt); |
|
49 |
|
50 static void set_input_stream (FILE *f); |
|
51 |
|
52 static FILE *get_input_stream (void); |
|
53 |
|
54 static void set_output_stream (FILE *f); |
|
55 |
|
56 static FILE *get_output_stream (void); |
|
57 |
|
58 static int terminal_rows (void); |
|
59 |
|
60 static int terminal_cols (void); |
|
61 |
|
62 static void clear_screen (void); |
|
63 |
|
64 static string decode_prompt_string (const string& s); |
|
65 |
|
66 static void restore_terminal_state (void); |
|
67 |
|
68 static void blink_matching_paren (bool flag); |
|
69 |
3004
|
70 static void set_basic_quote_characters (const string& s); |
2926
|
71 |
|
72 static void set_completion_append_character (char c); |
|
73 |
2941
|
74 static void set_completion_function (completion_fcn f); |
|
75 |
|
76 static completion_fcn get_completion_function (void); |
2926
|
77 |
|
78 static void insert_text (const string& text); |
|
79 |
|
80 static void newline (void); |
|
81 |
|
82 static void clear_undo_list (void); |
|
83 |
|
84 static void set_startup_hook (fcn f); |
|
85 |
|
86 static void restore_startup_hook (void); |
|
87 |
3189
|
88 static void read_init_file (const string& file = string ()); |
|
89 |
2926
|
90 static int current_command_number (void); |
|
91 |
|
92 static void reset_current_command_number (int n); |
|
93 |
2967
|
94 static void increment_current_command_number (void); |
|
95 |
2926
|
96 private: |
|
97 |
|
98 // No copying! |
|
99 |
|
100 command_editor (const command_editor&); |
|
101 |
|
102 command_editor& operator = (const command_editor&); |
|
103 |
|
104 static bool instance_ok (void); |
|
105 |
|
106 static void make_command_editor (void); |
|
107 |
|
108 // The real thing. |
|
109 static command_editor *instance; |
|
110 |
|
111 protected: |
|
112 |
|
113 // To use something other than the GNU readline library, derive a new |
|
114 // class from command_editor, overload these functions as |
|
115 // necessary, and make instance point to the new class. |
|
116 |
|
117 virtual void do_set_name (const string&) { } |
|
118 |
|
119 virtual string do_readline (const string&) = 0; |
|
120 |
|
121 virtual void do_set_input_stream (FILE *) = 0; |
|
122 |
|
123 virtual FILE *do_get_input_stream (void) = 0; |
|
124 |
|
125 virtual void do_set_output_stream (FILE *) = 0; |
|
126 |
|
127 virtual FILE *do_get_output_stream (void) = 0; |
|
128 |
|
129 virtual int do_terminal_rows (void) { return 24; } |
|
130 |
|
131 virtual int do_terminal_cols (void) { return 80; } |
|
132 |
|
133 virtual void do_clear_screen (void) { } |
|
134 |
|
135 virtual string do_decode_prompt_string (const string&); |
|
136 |
|
137 virtual string newline_chars (void) { return "\n"; } |
|
138 |
|
139 virtual void do_restore_terminal_state (void) { } |
|
140 |
|
141 virtual void do_blink_matching_paren (bool) { } |
|
142 |
3004
|
143 virtual void do_set_basic_quote_characters (const string&) { } |
2926
|
144 |
|
145 virtual void do_set_completion_append_character (char) { } |
|
146 |
2941
|
147 virtual void do_set_completion_function (completion_fcn) { } |
|
148 |
|
149 virtual completion_fcn do_get_completion_function (void) const { return 0; } |
2926
|
150 |
|
151 virtual void do_insert_text (const string&) = 0; |
|
152 |
|
153 virtual void do_newline (void) = 0; |
|
154 |
|
155 virtual void do_clear_undo_list (void) { } |
|
156 |
|
157 virtual void do_set_startup_hook (fcn) { } |
|
158 |
|
159 virtual void do_restore_startup_hook (void) { } |
|
160 |
3189
|
161 virtual void do_read_init_file (const string&) { } |
|
162 |
2926
|
163 int read_octal (const string& s); |
|
164 |
|
165 void error (int); |
|
166 |
|
167 void error (const string&); |
|
168 |
|
169 // The current command number. |
|
170 int command_number; |
|
171 }; |
|
172 |
|
173 #endif |
|
174 |
|
175 /* |
|
176 ;;; Local Variables: *** |
|
177 ;;; mode: C++ *** |
|
178 ;;; End: *** |
|
179 */ |