oct-rl-edit.c

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2000-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #if defined (USE_READLINE)
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 
00032 #include <readline/readline.h>
00033 
00034 #include "oct-rl-edit.h"
00035 
00036 #define OCTAVE_RL_SAVE_STRING(ss, s) \
00037   static char *ss = 0; \
00038  \
00039   if (ss) \
00040     { \
00041       free (ss); \
00042       ss = 0; \
00043     } \
00044  \
00045   ss = malloc (strlen (s) + 1); \
00046  \
00047   strcpy (ss, s)
00048 
00049 void
00050 octave_rl_redisplay (void)
00051 {
00052   rl_redisplay ();
00053 }
00054 
00055 int
00056 octave_rl_screen_height (void)
00057 {
00058   int rows, cols;
00059   rl_get_screen_size (&rows, &cols);
00060   return rows;
00061 }
00062 
00063 int
00064 octave_rl_screen_width (void)
00065 {
00066   int rows, cols;
00067   rl_get_screen_size (&rows, &cols);
00068   return cols;
00069 }
00070 
00071 void
00072 octave_rl_enable_paren_matching (int val)
00073 {
00074   rl_variable_bind ("blink-matching-paren", val ? "1" : "0");
00075 }
00076 
00077 /* It would be much simpler if we could just call _rl_clear_screen to
00078    only clear the screen, but it is not a public function, and on some
00079    systems, it is not exported from shared library versions of
00080    readline, so we can't use it.
00081 
00082    Instead, temporarily redefine the redisplay function to do nothing.
00083 
00084    FIXME -- It would be safer to do this when protected from
00085    interrupts... */
00086 
00087 static void
00088 flush_stdout (void)
00089 {
00090   fflush (stdout);
00091 }
00092 
00093 void
00094 octave_rl_clear_screen (void)
00095 {
00096   int ignore1 = 0;
00097   int ignore2 = 0;
00098 
00099   rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function;
00100   rl_redisplay_function = flush_stdout;
00101 
00102   rl_clear_screen (ignore1, ignore2);
00103 
00104   rl_redisplay_function = saved_redisplay_function;
00105 }
00106 
00107 void
00108 octave_rl_resize_terminal (void)
00109 {
00110   rl_resize_terminal ();
00111 }
00112 
00113 void
00114 octave_rl_restore_terminal_state ()
00115 {
00116   if (rl_deprep_term_function)
00117     rl_deprep_term_function ();
00118 }
00119 
00120 void
00121 octave_rl_insert_text (const char *s)
00122 {
00123   rl_insert_text (s);
00124 }
00125 
00126 int
00127 octave_rl_newline (int count, int key)
00128 {
00129   return rl_newline (count, key);
00130 }
00131 
00132 const char *
00133 octave_rl_line_buffer (void)
00134 {
00135   return rl_line_buffer;
00136 }
00137 
00138 void
00139 octave_rl_clear_undo_list (void)
00140 {
00141   if (rl_undo_list)
00142     {
00143       rl_free_undo_list ();
00144 
00145       rl_undo_list = 0;
00146     }
00147 }
00148 
00149 void
00150 octave_rl_set_name (const char *n)
00151 {
00152   OCTAVE_RL_SAVE_STRING (nm, n);
00153 
00154   rl_readline_name = nm;
00155 
00156   /* Since we've already called rl_initialize, we need to re-read the
00157      init file to take advantage of the conditional parsing feature
00158      based on rl_readline_name; */
00159 
00160   rl_re_read_init_file (0, 0);
00161 }
00162 
00163 char *
00164 octave_rl_readline (const char *prompt)
00165 {
00166   return readline (prompt);
00167 }
00168 
00169 void
00170 octave_rl_set_input_stream (FILE *f)
00171 {
00172   rl_instream = f;
00173 }
00174 
00175 FILE *
00176 octave_rl_get_input_stream (void)
00177 {
00178   return rl_instream;
00179 }
00180 
00181 void
00182 octave_rl_set_output_stream (FILE *f)
00183 {
00184   rl_outstream = f;
00185 }
00186 
00187 FILE *
00188 octave_rl_get_output_stream (void)
00189 {
00190   return rl_outstream;
00191 }
00192 
00193 void
00194 octave_rl_read_init_file (const char *f)
00195 {
00196   rl_read_init_file (f);
00197 }
00198 
00199 void
00200 octave_rl_re_read_init_file (void)
00201 {
00202   rl_re_read_init_file (0, 0);
00203 }
00204 
00205 int
00206 octave_rl_filename_completion_desired (int arg)
00207 {
00208   int retval = rl_filename_completion_desired;
00209   rl_filename_completion_desired = arg;
00210   return retval;
00211 }
00212 
00213 int
00214 octave_rl_filename_quoting_desired (int arg)
00215 {
00216   int retval = rl_filename_quoting_desired;
00217   rl_filename_quoting_desired = arg;
00218   return retval;
00219 }
00220 
00221 char *
00222 octave_rl_filename_completion_function (const char *text, int state)
00223 {
00224   return rl_filename_completion_function (text, state);
00225 }
00226 
00227 void
00228 octave_rl_set_basic_word_break_characters (const char *s)
00229 {
00230   OCTAVE_RL_SAVE_STRING (ss, s);
00231 
00232   rl_basic_word_break_characters = ss;
00233 }
00234 
00235 void
00236 octave_rl_set_completer_word_break_characters (const char *s)
00237 {
00238   OCTAVE_RL_SAVE_STRING (ss, s);
00239 
00240   rl_completer_word_break_characters = ss;
00241 }
00242 
00243 void
00244 octave_rl_set_basic_quote_characters (const char *s)
00245 {
00246   OCTAVE_RL_SAVE_STRING (ss, s);
00247 
00248   rl_basic_quote_characters = ss;
00249 }
00250 
00251 void
00252 octave_rl_set_filename_quote_characters (const char *s)
00253 {
00254   OCTAVE_RL_SAVE_STRING (ss, s);
00255 
00256   rl_filename_quote_characters = ss;
00257 }
00258 
00259 void
00260 octave_rl_set_completer_quote_characters (const char *s)
00261 {
00262   OCTAVE_RL_SAVE_STRING (ss, s);
00263 
00264   rl_completer_quote_characters = ss;
00265 }
00266 
00267 void
00268 octave_rl_set_completion_append_character (char c)
00269 {
00270   rl_completion_append_character = c;
00271 }
00272 
00273 void
00274 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f)
00275 {
00276   rl_attempted_completion_function = f;
00277 }
00278 
00279 void
00280 octave_rl_set_quoting_function (rl_quoting_fcn_ptr f)
00281 {
00282   rl_filename_quoting_function = f;
00283 }
00284 
00285 void
00286 octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f)
00287 {
00288   rl_filename_dequoting_function = f;
00289 }
00290 
00291 void
00292 octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f)
00293 {
00294   rl_char_is_quoted_p = f;
00295 }
00296 
00297 void
00298 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f)
00299 {
00300   rl_startup_hook = f;
00301 }
00302 
00303 rl_startup_hook_fcn_ptr
00304 octave_rl_get_startup_hook (void)
00305 {
00306   return rl_startup_hook;
00307 }
00308 
00309 void
00310 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f)
00311 {
00312   rl_event_hook = f;
00313 }
00314 
00315 rl_event_hook_fcn_ptr
00316 octave_rl_get_event_hook (void)
00317 {
00318   return rl_event_hook;
00319 }
00320 
00321 char **
00322 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f)
00323 {
00324   return rl_completion_matches (text, f);
00325 }
00326 
00327 char
00328 octave_rl_prompt_start_ignore (void)
00329 {
00330   return RL_PROMPT_START_IGNORE;
00331 }
00332 
00333 char
00334 octave_rl_prompt_end_ignore (void)
00335 {
00336   return RL_PROMPT_END_IGNORE;
00337 }
00338 
00339 void
00340 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key)
00341 {
00342   rl_add_defun (name, f, key);
00343 }
00344 
00345 void
00346 octave_rl_set_terminal_name (const char *term)
00347 {
00348   OCTAVE_RL_SAVE_STRING (saved_term, term);
00349 
00350   rl_terminal_name = saved_term;
00351 }
00352 
00353 void
00354 octave_rl_initialize (void)
00355 {
00356   rl_initialize ();
00357 }
00358 
00359 int
00360 octave_rl_history_search_forward (int count, int ignore)
00361 {
00362   return rl_history_search_forward (count, ignore);
00363 }
00364 
00365 int
00366 octave_rl_history_search_backward (int count, int ignore)
00367 {
00368   return rl_history_search_backward (count, ignore);
00369 }
00370 
00371 char
00372 octave_rl_ctrl (char c)
00373 {
00374   return CTRL (c);
00375 }
00376 
00377 char
00378 octave_rl_meta (char c)
00379 {
00380   return META (c);
00381 }
00382 
00383 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines