GNU Octave  4.2.1
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-2017 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 #if defined (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 interrupts... */
93 
94 static void
95 flush_stdout (void)
96 {
97  fflush (stdout);
98 }
99 
100 void
101 octave_rl_clear_screen (int skip_redisplay)
102 {
103  int ignore1 = 0;
104  int ignore2 = 0;
105 
106  if (skip_redisplay)
107  {
108  rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function;
109 
110  rl_redisplay_function = flush_stdout;
111 
112  rl_clear_screen (ignore1, ignore2);
113 
114  rl_redisplay_function = saved_redisplay_function;
115  }
116  else
117  rl_clear_screen (ignore1, ignore2);
118 }
119 
120 void
122 {
123  rl_resize_terminal ();
124 }
125 
126 void
127 octave_rl_set_screen_size (int ht, int wd)
128 {
129  rl_set_screen_size (ht, wd);
130 }
131 
132 void
134 {
135  if (rl_deprep_term_function)
136  rl_deprep_term_function ();
137 }
138 
139 char *
140 octave_rl_copy_line (void)
141 {
142  return rl_copy_text (0, rl_end);
143 }
144 
145 void
146 octave_rl_replace_line (const char *s, int clear_undo)
147 {
148  rl_replace_line (s, clear_undo);
149 }
150 
151 void
153 {
154  rl_kill_full_line (0, 0);
155 }
156 
157 void
158 octave_rl_insert_text (const char *s)
159 {
160  rl_insert_text (s);
161 }
162 
163 int
164 octave_rl_newline (int count, int key)
165 {
166  return rl_newline (count, key);
167 }
168 
169 const char *
171 {
172  return rl_line_buffer;
173 }
174 
175 int
176 octave_rl_point (void)
177 {
178  return rl_point;
179 }
180 
181 int
182 octave_rl_do_undo (void)
183 {
184  return rl_do_undo ();
185 }
186 
187 void
189 {
190  if (rl_undo_list)
191  {
192  rl_free_undo_list ();
193 
194  rl_undo_list = 0;
195  }
196 }
197 
198 void
199 octave_rl_set_name (const char *n)
200 {
201  OCTAVE_RL_SAVE_STRING (nm, n);
202 
203  rl_readline_name = nm;
204 
205  /* Since we've already called rl_initialize, we need to re-read the
206  init file to take advantage of the conditional parsing feature
207  based on rl_readline_name; */
208 
209  rl_re_read_init_file (0, 0);
210 }
211 
212 char *
213 octave_rl_readline (const char *prompt)
214 {
215  return readline (prompt);
216 }
217 
218 void
220 {
221  rl_instream = f;
222 }
223 
224 FILE *
226 {
227  return rl_instream;
228 }
229 
230 void
232 {
233  rl_outstream = f;
234 }
235 
236 FILE *
238 {
239  return rl_outstream;
240 }
241 
242 void
243 octave_rl_read_init_file (const char *f)
244 {
245  rl_read_init_file (f);
246 }
247 
248 void
250 {
251  rl_re_read_init_file (0, 0);
252 }
253 
254 int
256 {
257  int retval = rl_filename_completion_desired;
258  rl_filename_completion_desired = arg;
259  return retval;
260 }
261 
262 int
264 {
265  int retval = rl_filename_quoting_desired;
266  rl_filename_quoting_desired = arg;
267  return retval;
268 }
269 
270 int
272 {
273  int retval = rl_prefer_env_winsize;
274  rl_prefer_env_winsize = arg;
275  return retval;
276 }
277 
278 void
279 octave_rl_done (int arg)
280 {
281  rl_done = arg;
282 }
283 
284 char *
286 {
287  return rl_filename_completion_function (text, state);
288 }
289 
290 void
292 {
293  OCTAVE_RL_SAVE_STRING (ss, s);
294 
295  rl_basic_word_break_characters = ss;
296 }
297 
298 void
300 {
301  OCTAVE_RL_SAVE_STRING (ss, s);
302 
303  rl_completer_word_break_characters = ss;
304 }
305 
306 char *
308 {
309  return rl_completer_word_break_characters;
310 }
311 
312 void
314 {
315  rl_completion_word_break_hook = f;
316 }
317 
318 void
320 {
321  OCTAVE_RL_SAVE_STRING (ss, s);
322 
323  rl_basic_quote_characters = ss;
324 }
325 
326 void
328 {
329  OCTAVE_RL_SAVE_STRING (ss, s);
330 
331  rl_filename_quote_characters = ss;
332 }
333 
334 void
336 {
337  OCTAVE_RL_SAVE_STRING (ss, s);
338 
339  rl_completer_quote_characters = ss;
340 }
341 
342 void
344 {
345  rl_completion_append_character = c;
346 }
347 
348 void
350 {
351  rl_attempted_completion_function = f;
352 }
353 
354 void
356 {
357  rl_filename_quoting_function = f;
358 }
359 
360 void
362 {
363  rl_filename_dequoting_function = f;
364 }
365 
366 void
368 {
369  rl_char_is_quoted_p = f;
370 }
371 
372 void
374 {
375  rl_startup_hook = f;
376 }
377 
380 {
381  return rl_startup_hook;
382 }
383 
384 void
386 {
387  rl_pre_input_hook = f;
388 }
389 
392 {
393  return rl_pre_input_hook;
394 }
395 
396 void
398 {
399  rl_event_hook = f;
400 }
401 
404 {
405  return rl_event_hook;
406 }
407 
408 char **
410 {
411  return rl_completion_matches (text, f);
412 }
413 
414 char
416 {
417  return RL_PROMPT_START_IGNORE;
418 }
419 
420 char
422 {
423  return RL_PROMPT_END_IGNORE;
424 }
425 
426 void
427 octave_rl_add_defun (const char *name, rl_fcn_ptr f, int key)
428 {
429  rl_add_defun (name, f, key);
430 }
431 
432 void
433 octave_rl_set_terminal_name (const char *term)
434 {
435  OCTAVE_RL_SAVE_STRING (saved_term, term);
436 
437  rl_terminal_name = saved_term;
438 }
439 
440 void
442 {
443 #if defined (__WIN32__) && ! defined (__CYGWIN__)
444  rl_catch_signals = 0;
445 #endif
446 
447  rl_initialize ();
448 }
449 
450 int
451 octave_rl_history_search_forward (int count, int ignore)
452 {
453  return rl_history_search_forward (count, ignore);
454 }
455 
456 int
457 octave_rl_history_search_backward (int count, int ignore)
458 {
459  return rl_history_search_backward (count, ignore);
460 }
461 
462 int
463 octave_rl_ctrl (char c)
464 {
465  return CTRL (c);
466 }
467 
468 int
469 octave_rl_meta (char c)
470 {
471  return META (c);
472 }
473 
474 #endif
int octave_rl_do_undo(void)
int(* rl_fcn_ptr)(int, int)
Definition: oct-rl-edit.h:34
int octave_rl_newline(int, int)
void octave_rl_set_dequoting_function(rl_dequoting_fcn_ptr)
char * octave_rl_readline(const char *)
void octave_rl_set_terminal_name(const char *)
void octave_rl_set_completion_word_break_hook(rl_completion_hook_fcn_ptr)
void octave_rl_redisplay(void)
int octave_rl_filename_quoting_desired(int)
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
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:32
void octave_rl_set_event_hook(rl_event_hook_fcn_ptr f)
int octave_rl_ctrl(char)
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 *)
char * octave_rl_get_completer_word_break_characters(void)
s
Definition: file-io.cc:2682
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:42
void octave_rl_resize_terminal(void)
octave_value arg
Definition: pr-output.cc:3440
char *(* rl_completer_fcn_ptr)(const char *, int)
Definition: oct-rl-edit.h:38
char octave_rl_prompt_start_ignore(void)
int octave_rl_point(void)
void octave_rl_restore_terminal_state(void)
int octave_rl_filename_completion_desired(int)
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
int(* rl_pre_input_hook_fcn_ptr)(void)
Definition: oct-rl-edit.h:30
void octave_rl_clear_screen(int skip_redisplay)
int octave_rl_history_search_forward(int, int)
void octave_rl_read_init_file(const char *)
char *(* rl_dequoting_fcn_ptr)(char *, int)
Definition: oct-rl-edit.h:44
void octave_rl_set_completer_word_break_characters(const char *)
void octave_rl_done(int)
octave_value retval
Definition: data.cc:6294
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:28
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)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
char * octave_rl_filename_completion_function(const char *, int)
void octave_rl_set_name(const char *)
void octave_rl_insert_text(const char *)
static uint32_t state[624]
Definition: randmtzig.cc:184
char **(* rl_attempted_completion_fcn_ptr)(const char *, int, int)
Definition: oct-rl-edit.h:36
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:46
rl_event_hook_fcn_ptr octave_rl_get_event_hook(void)
int octave_rl_meta(char)
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_add_defun(const char *, rl_fcn_ptr, int)
void octave_rl_replace_line(const char *s, int clear_undo)
char *(* rl_completion_hook_fcn_ptr)(void)
Definition: oct-rl-edit.h:40
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)
enum echo_state fflush
void octave_rl_set_input_stream(FILE *)
void octave_rl_set_output_stream(FILE *)