GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-rl-edit.c
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2000-2015 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #if defined (USE_READLINE)
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 
32 #include <readline/readline.h>
33 
34 #include "oct-rl-edit.h"
35 
36 #define OCTAVE_RL_SAVE_STRING(ss, s) \
37  static char *ss = 0; \
38  \
39  if (ss) \
40  { \
41  free (ss); \
42  ss = 0; \
43  } \
44  \
45  ss = malloc (strlen (s) + 1); \
46  \
47  strcpy (ss, s)
48 
49 void
51 {
52  rl_redisplay ();
53 }
54 
55 int
57 {
58  int rows, cols;
59  rl_get_screen_size (&rows, &cols);
60  return rows;
61 }
62 
63 int
65 {
66  int rows, cols;
67  rl_get_screen_size (&rows, &cols);
68  return cols;
69 }
70 
71 void
73 {
74  rl_variable_bind ("blink-matching-paren", val ? "1" : "0");
75 }
76 
77 int
79 {
80  int retval = rl_erase_empty_line;
81  rl_erase_empty_line = val;
82  return retval;
83 }
84 
85 /* It would be much simpler if we could just call _rl_clear_screen to
86  only clear the screen, but it is not a public function, and on some
87  systems, it is not exported from shared library versions of
88  readline, so we can't use it.
89 
90  Instead, temporarily redefine the redisplay function to do nothing.
91 
92  FIXME -- It would be safer to do this when protected from
93  interrupts... */
94 
95 static void
96 flush_stdout (void)
97 {
98  fflush (stdout);
99 }
100 
101 void
102 octave_rl_clear_screen (int skip_redisplay)
103 {
104  int ignore1 = 0;
105  int ignore2 = 0;
106 
107  if (skip_redisplay)
108  {
109  rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function;
110 
111  rl_redisplay_function = flush_stdout;
112 
113  rl_clear_screen (ignore1, ignore2);
114 
115  rl_redisplay_function = saved_redisplay_function;
116  }
117  else
118  rl_clear_screen (ignore1, ignore2);
119 }
120 
121 void
123 {
124  rl_resize_terminal ();
125 }
126 
127 void
128 octave_rl_set_screen_size (int ht, int wd)
129 {
130  rl_set_screen_size (ht, wd);
131 }
132 
133 void
135 {
136  if (rl_deprep_term_function)
137  rl_deprep_term_function ();
138 }
139 
140 char *
141 octave_rl_copy_line (void)
142 {
143  return rl_copy_text (0, rl_end);
144 }
145 
146 void
147 octave_rl_replace_line (const char *s, int clear_undo)
148 {
149  rl_replace_line (s, clear_undo);
150 }
151 
152 void
154 {
155  rl_kill_full_line (0, 0);
156 }
157 
158 void
159 octave_rl_insert_text (const char *s)
160 {
161  rl_insert_text (s);
162 }
163 
164 int
165 octave_rl_newline (int count, int key)
166 {
167  return rl_newline (count, key);
168 }
169 
170 const char *
172 {
173  return rl_line_buffer;
174 }
175 
176 int
177 octave_rl_do_undo (void)
178 {
179  return rl_do_undo ();
180 }
181 
182 void
184 {
185  if (rl_undo_list)
186  {
187  rl_free_undo_list ();
188 
189  rl_undo_list = 0;
190  }
191 }
192 
193 void
194 octave_rl_set_name (const char *n)
195 {
196  OCTAVE_RL_SAVE_STRING (nm, n);
197 
198  rl_readline_name = nm;
199 
200  /* Since we've already called rl_initialize, we need to re-read the
201  init file to take advantage of the conditional parsing feature
202  based on rl_readline_name; */
203 
204  rl_re_read_init_file (0, 0);
205 }
206 
207 char *
208 octave_rl_readline (const char *prompt)
209 {
210  return readline (prompt);
211 }
212 
213 void
215 {
216  rl_instream = f;
217 }
218 
219 FILE *
221 {
222  return rl_instream;
223 }
224 
225 void
227 {
228  rl_outstream = f;
229 }
230 
231 FILE *
233 {
234  return rl_outstream;
235 }
236 
237 void
238 octave_rl_read_init_file (const char *f)
239 {
240  rl_read_init_file (f);
241 }
242 
243 void
245 {
246  rl_re_read_init_file (0, 0);
247 }
248 
249 int
251 {
252  int retval = rl_filename_completion_desired;
253  rl_filename_completion_desired = arg;
254  return retval;
255 }
256 
257 int
259 {
260  int retval = rl_filename_quoting_desired;
261  rl_filename_quoting_desired = arg;
262  return retval;
263 }
264 
265 int
267 {
268  int retval = rl_prefer_env_winsize;
269  rl_prefer_env_winsize = arg;
270  return retval;
271 }
272 
273 void
274 octave_rl_done (int arg)
275 {
276  rl_done = arg;
277 }
278 
279 char *
281 {
282  return rl_filename_completion_function (text, state);
283 }
284 
285 void
287 {
288  OCTAVE_RL_SAVE_STRING (ss, s);
289 
290  rl_basic_word_break_characters = ss;
291 }
292 
293 void
295 {
296  OCTAVE_RL_SAVE_STRING (ss, s);
297 
298  rl_completer_word_break_characters = ss;
299 }
300 
301 void
303 {
304  OCTAVE_RL_SAVE_STRING (ss, s);
305 
306  rl_basic_quote_characters = ss;
307 }
308 
309 void
311 {
312  OCTAVE_RL_SAVE_STRING (ss, s);
313 
314  rl_filename_quote_characters = ss;
315 }
316 
317 void
319 {
320  OCTAVE_RL_SAVE_STRING (ss, s);
321 
322  rl_completer_quote_characters = ss;
323 }
324 
325 void
327 {
328  rl_completion_append_character = c;
329 }
330 
331 void
333 {
334  rl_attempted_completion_function = f;
335 }
336 
337 void
339 {
340  rl_filename_quoting_function = f;
341 }
342 
343 void
345 {
346  rl_filename_dequoting_function = f;
347 }
348 
349 void
351 {
352  rl_char_is_quoted_p = f;
353 }
354 
355 void
357 {
358  rl_startup_hook = f;
359 }
360 
363 {
364  return rl_startup_hook;
365 }
366 
367 void
369 {
370  rl_pre_input_hook = f;
371 }
372 
375 {
376  return rl_pre_input_hook;
377 }
378 
379 void
381 {
382  rl_event_hook = f;
383 }
384 
387 {
388  return rl_event_hook;
389 }
390 
391 char **
393 {
394  return rl_completion_matches (text, f);
395 }
396 
397 char
399 {
400  return RL_PROMPT_START_IGNORE;
401 }
402 
403 char
405 {
406  return RL_PROMPT_END_IGNORE;
407 }
408 
409 void
410 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key)
411 {
412  rl_add_defun (name, f, key);
413 }
414 
415 void
416 octave_rl_set_terminal_name (const char *term)
417 {
418  OCTAVE_RL_SAVE_STRING (saved_term, term);
419 
420  rl_terminal_name = saved_term;
421 }
422 
423 void
425 {
426 #if defined (__WIN32__) && ! defined (__CYGWIN__)
427  rl_catch_signals = 0;
428 #endif
429 
430  rl_initialize ();
431 }
432 
433 int
434 octave_rl_history_search_forward (int count, int ignore)
435 {
436  return rl_history_search_forward (count, ignore);
437 }
438 
439 int
440 octave_rl_history_search_backward (int count, int ignore)
441 {
442  return rl_history_search_backward (count, ignore);
443 }
444 
445 char
446 octave_rl_ctrl (char c)
447 {
448  return CTRL (c);
449 }
450 
451 char
452 octave_rl_meta (char c)
453 {
454  return META (c);
455 }
456 
457 #endif
char octave_rl_meta(char)
int octave_rl_do_undo(void)
int(* rl_fcn_ptr)(int, int)
Definition: oct-rl-edit.h:32
int octave_rl_newline(int, int)
void octave_rl_set_dequoting_function(rl_dequoting_fcn_ptr)
char octave_rl_ctrl(char)
char * octave_rl_readline(const char *)
void octave_rl_set_terminal_name(const char *)
static uint32_t state[624]
Definition: randmtzig.c:188
void octave_rl_redisplay(void)
int octave_rl_filename_quoting_desired(int)
int octave_rl_screen_width(void)
#define CTRL(x)
Definition: kpty.cpp:143
int(* rl_event_hook_fcn_ptr)(void)
Definition: oct-rl-edit.h:30
void octave_rl_set_event_hook(rl_event_hook_fcn_ptr f)
void octave_rl_clear_undo_list(void)
void octave_rl_set_completion_function(rl_attempted_completion_fcn_ptr)
int octave_rl_erase_empty_line(int)
void octave_rl_set_basic_word_break_characters(const char *)
void octave_rl_set_basic_quote_characters(const char *)
char octave_rl_prompt_end_ignore(void)
void octave_rl_set_completer_quote_characters(const char *)
char *(* rl_quoting_fcn_ptr)(char *, int, char *)
Definition: oct-rl-edit.h:38
void octave_rl_resize_terminal(void)
char *(* rl_completer_fcn_ptr)(const char *, int)
Definition: oct-rl-edit.h:36
char octave_rl_prompt_start_ignore(void)
void octave_rl_restore_terminal_state(void)
int octave_rl_filename_completion_desired(int)
int(* rl_pre_input_hook_fcn_ptr)(void)
Definition: oct-rl-edit.h:28
void octave_rl_clear_screen(int skip_redisplay)
int octave_rl_history_search_forward(int, int)
void octave_rl_add_defun(const char *, rl_fcn_ptr, char)
F77_RET_T const double const double * f
void octave_rl_read_init_file(const char *)
char *(* rl_dequoting_fcn_ptr)(char *, int)
Definition: oct-rl-edit.h:40
void octave_rl_set_completer_word_break_characters(const char *)
void octave_rl_done(int)
void octave_rl_set_filename_quote_characters(const char *)
void octave_rl_initialize(void)
int(* rl_startup_hook_fcn_ptr)(void)
Definition: oct-rl-edit.h:26
void octave_rl_set_pre_input_hook(rl_startup_hook_fcn_ptr)
void octave_rl_enable_paren_matching(int)
char ** octave_rl_completion_matches(const char *, rl_completer_fcn_ptr)
void octave_rl_set_completion_append_character(char)
void octave_rl_set_screen_size(int ht, int wd)
char * octave_rl_filename_completion_function(const char *, int)
void octave_rl_set_name(const char *)
void octave_rl_insert_text(const char *)
double arg(double x)
Definition: lo-mappers.h:37
char **(* rl_attempted_completion_fcn_ptr)(const char *, int, int)
Definition: oct-rl-edit.h:34
int octave_rl_prefer_env_winsize(int)
char * octave_rl_copy_line(void)
void octave_rl_set_startup_hook(rl_startup_hook_fcn_ptr)
int(* rl_char_is_quoted_fcn_ptr)(char *, int)
Definition: oct-rl-edit.h:42
rl_event_hook_fcn_ptr octave_rl_get_event_hook(void)
void octave_rl_kill_full_line(void)
rl_pre_input_hook_fcn_ptr octave_rl_get_pre_input_hook(void)
void octave_rl_re_read_init_file(void)
const char * octave_rl_line_buffer(void)
FILE * octave_rl_get_input_stream(void)
int octave_rl_screen_height(void)
void octave_rl_replace_line(const char *s, int clear_undo)
FILE * octave_rl_get_output_stream(void)
rl_startup_hook_fcn_ptr octave_rl_get_startup_hook(void)
void octave_rl_set_char_is_quoted_function(rl_char_is_quoted_fcn_ptr)
void octave_rl_set_quoting_function(rl_quoting_fcn_ptr)
int octave_rl_history_search_backward(int, int)
void octave_rl_set_input_stream(FILE *)
void octave_rl_set_output_stream(FILE *)