00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_cmd_edit_h)
00025 #define octave_cmd_edit_h 1
00026
00027 #include <cstdio>
00028
00029 #include <set>
00030 #include <string>
00031
00032 #include "str-vec.h"
00033
00034 class
00035 OCTAVE_API
00036 command_editor
00037 {
00038 protected:
00039
00040 command_editor (void)
00041 : command_number (0) { }
00042
00043 public:
00044
00045 typedef int (*startup_hook_fcn) (void);
00046
00047 typedef int (*event_hook_fcn) (void);
00048
00049 typedef std::string (*completion_fcn) (const std::string&, int);
00050
00051 typedef std::string (*quoting_fcn) (const std::string&, int, char);
00052
00053 typedef std::string (*dequoting_fcn) (const std::string&, int);
00054
00055 typedef int (*char_is_quoted_fcn) (const std::string&, int);
00056
00057 typedef void (*user_accept_line_fcn) (const std::string&);
00058
00059 virtual ~command_editor (void) { }
00060
00061 static void set_name (const std::string& n);
00062
00063 static std::string readline (const std::string& prompt);
00064
00065 static std::string readline (const std::string& prompt, bool& eof);
00066
00067 static void set_input_stream (FILE *f);
00068
00069 static FILE *get_input_stream (void);
00070
00071 static void set_output_stream (FILE *f);
00072
00073 static FILE *get_output_stream (void);
00074
00075 static int terminal_rows (void);
00076
00077 static int terminal_cols (void);
00078
00079 static void clear_screen (void);
00080
00081 static void resize_terminal (void);
00082
00083 static std::string decode_prompt_string (const std::string& s);
00084
00085 static void restore_terminal_state (void);
00086
00087 static void blink_matching_paren (bool flag);
00088
00089 static void set_basic_word_break_characters (const std::string& s);
00090
00091 static void set_completer_word_break_characters (const std::string& s);
00092
00093 static void set_basic_quote_characters (const std::string& s);
00094
00095 static void set_filename_quote_characters (const std::string& s);
00096
00097 static void set_completer_quote_characters (const std::string& s);
00098
00099 static void set_completion_append_character (char c);
00100
00101 static void set_completion_function (completion_fcn f);
00102
00103 static void set_quoting_function (quoting_fcn f);
00104
00105 static void set_dequoting_function (dequoting_fcn f);
00106
00107 static void set_char_is_quoted_function (char_is_quoted_fcn f);
00108
00109 static void set_user_accept_line_function (user_accept_line_fcn f);
00110
00111 static completion_fcn get_completion_function (void);
00112
00113 static quoting_fcn get_quoting_function (void);
00114
00115 static dequoting_fcn get_dequoting_function (void);
00116
00117 static char_is_quoted_fcn get_char_is_quoted_function (void);
00118
00119 static user_accept_line_fcn get_user_accept_line_function (void);
00120
00121 static string_vector generate_filename_completions (const std::string& text);
00122
00123 static std::string get_line_buffer (void);
00124
00125 static void insert_text (const std::string& text);
00126
00127 static void newline (void);
00128
00129 static void accept_line (void);
00130
00131 static void clear_undo_list (void);
00132
00133 static void add_startup_hook (startup_hook_fcn f);
00134
00135 static void remove_startup_hook (startup_hook_fcn f);
00136
00137 static void add_event_hook (event_hook_fcn f);
00138
00139 static void remove_event_hook (event_hook_fcn f);
00140
00141 static void read_init_file (const std::string& file = std::string ());
00142
00143 static void re_read_init_file (void);
00144
00145 static bool filename_completion_desired (bool);
00146
00147 static bool filename_quoting_desired (bool);
00148
00149 static int current_command_number (void);
00150
00151 static void reset_current_command_number (int n);
00152
00153 static void increment_current_command_number (void);
00154
00155 static void force_default_editor (void);
00156
00157 private:
00158
00159
00160
00161 command_editor (const command_editor&);
00162
00163 command_editor& operator = (const command_editor&);
00164
00165 static bool instance_ok (void);
00166
00167 static void make_command_editor (void);
00168
00169 static int startup_handler (void);
00170
00171 static int event_handler (void);
00172
00173 static std::set<startup_hook_fcn> startup_hook_set;
00174
00175 static std::set<event_hook_fcn> event_hook_set;
00176
00177 typedef std::set<startup_hook_fcn>::iterator startup_hook_set_iterator;
00178 typedef std::set<startup_hook_fcn>::const_iterator startup_hook_set_const_iterator;
00179
00180 typedef std::set<event_hook_fcn>::iterator event_hook_set_iterator;
00181 typedef std::set<event_hook_fcn>::const_iterator event_hook_set_const_iterator;
00182
00183
00184 static command_editor *instance;
00185
00186 protected:
00187
00188
00189
00190
00191
00192 virtual void do_set_name (const std::string&) { }
00193
00194 std::string do_readline (const std::string& prompt)
00195 {
00196 bool eof;
00197
00198 return do_readline (prompt, eof);
00199 }
00200
00201 virtual std::string do_readline (const std::string&, bool&) = 0;
00202
00203 virtual void do_set_input_stream (FILE *) = 0;
00204
00205 virtual FILE *do_get_input_stream (void) = 0;
00206
00207 virtual void do_set_output_stream (FILE *) = 0;
00208
00209 virtual FILE *do_get_output_stream (void) = 0;
00210
00211 virtual int do_terminal_rows (void) { return 24; }
00212
00213 virtual int do_terminal_cols (void) { return 80; }
00214
00215 virtual void do_clear_screen (void) { }
00216
00217 virtual void do_resize_terminal (void) { }
00218
00219 virtual std::string do_decode_prompt_string (const std::string&);
00220
00221 virtual std::string newline_chars (void) { return "\n"; }
00222
00223 virtual void do_restore_terminal_state (void) { }
00224
00225 virtual void do_blink_matching_paren (bool) { }
00226
00227 virtual void do_set_basic_word_break_characters (const std::string&) { }
00228
00229 virtual void do_set_completer_word_break_characters (const std::string&) { }
00230
00231 virtual void do_set_basic_quote_characters (const std::string&) { }
00232
00233 virtual void do_set_filename_quote_characters (const std::string&) { }
00234
00235 virtual void do_set_completer_quote_characters (const std::string&) { }
00236
00237 virtual void do_set_completion_append_character (char) { }
00238
00239 virtual void do_set_completion_function (completion_fcn) { }
00240
00241 virtual void do_set_quoting_function (quoting_fcn) { }
00242
00243 virtual void do_set_dequoting_function (dequoting_fcn) { }
00244
00245 virtual void do_set_char_is_quoted_function (char_is_quoted_fcn) { }
00246
00247 virtual void do_set_user_accept_line_function (user_accept_line_fcn) { }
00248
00249 virtual completion_fcn do_get_completion_function (void) const { return 0; }
00250
00251 virtual quoting_fcn do_get_quoting_function (void) const { return 0; }
00252
00253 virtual dequoting_fcn do_get_dequoting_function (void) const { return 0; }
00254
00255 virtual char_is_quoted_fcn do_get_char_is_quoted_function (void) const { return 0; }
00256
00257 virtual user_accept_line_fcn do_get_user_accept_line_function (void) const { return 0; }
00258
00259 virtual string_vector do_generate_filename_completions (const std::string& text) = 0;
00260
00261 virtual std::string do_get_line_buffer (void) const = 0;
00262
00263 virtual void do_insert_text (const std::string&) = 0;
00264
00265 virtual void do_newline (void) = 0;
00266
00267 virtual void do_accept_line (void) = 0;
00268
00269 virtual void do_clear_undo_list (void) { }
00270
00271 virtual void set_startup_hook (startup_hook_fcn) { }
00272
00273 virtual void restore_startup_hook (void) { }
00274
00275 virtual void set_event_hook (startup_hook_fcn) { }
00276
00277 virtual void restore_event_hook (void) { }
00278
00279 virtual void do_read_init_file (const std::string&) { }
00280
00281 virtual void do_re_read_init_file (void) { }
00282
00283 virtual bool do_filename_completion_desired (bool) { return false; }
00284
00285 virtual bool do_filename_quoting_desired (bool) { return false; }
00286
00287 int read_octal (const std::string& s);
00288
00289 void error (int);
00290
00291 void error (const std::string&);
00292
00293
00294 int command_number;
00295 };
00296
00297 #endif
00298
00299
00300
00301
00302
00303