Ruby  2.4.2p198(2017-09-14revision59899)
readline.c
Go to the documentation of this file.
1 /************************************************
2 
3  readline.c - GNU Readline module
4 
5  $Author: nobu $
6  created at: Wed Jan 20 13:59:32 JST 1999
7 
8  Copyright (C) 1997-2008 Shugo Maeda
9  Copyright (C) 2008-2013 Kouji Takao
10 
11  $Id: readline.c 56820 2016-11-17 11:52:11Z nobu $
12 
13  Contact:
14  - Kouji Takao <kouji dot takao at gmail dot com> (current maintainer)
15 
16 ************************************************/
17 
18 #ifdef RUBY_EXTCONF_H
19 #include RUBY_EXTCONF_H
20 #endif
21 
22 #include "ruby/config.h"
23 #include <errno.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_READLINE_READLINE_H
27 #include <readline/readline.h>
28 #endif
29 #ifdef HAVE_READLINE_HISTORY_H
30 #include <readline/history.h>
31 #endif
32 #ifdef HAVE_EDITLINE_READLINE_H
33 #include <editline/readline.h>
34 #endif
35 
36 #include "ruby/io.h"
37 #include "ruby/thread.h"
38 
39 #ifdef HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42 
43 #ifdef HAVE_SYS_STAT_H
44 #include <sys/stat.h>
45 #endif
46 
48 
49 #define EDIT_LINE_LIBRARY_VERSION "EditLine wrapper"
50 #ifndef USE_INSERT_IGNORE_ESCAPE
51 # if !defined(HAVE_EDITLINE_READLINE_H) && defined(RL_PROMPT_START_IGNORE) && defined(RL_PROMPT_END_IGNORE)
52 # define USE_INSERT_IGNORE_ESCAPE 1
53 # else
54 # define USE_INSERT_IGNORE_ESCAPE 0
55 # endif
56 #endif
57 
58 #define COMPLETION_PROC "completion_proc"
59 #define COMPLETION_CASE_FOLD "completion_case_fold"
61 #if defined HAVE_RL_CHAR_IS_QUOTED_P
62 #define QUOTING_DETECTION_PROC "quoting_detection_proc"
63 static ID quoting_detection_proc;
64 #endif
65 #if USE_INSERT_IGNORE_ESCAPE
66 static ID id_orig_prompt, id_last_prompt;
67 #endif
68 #if defined(HAVE_RL_PRE_INPUT_HOOK)
69 static ID id_pre_input_hook;
70 #endif
71 #if defined(HAVE_RL_SPECIAL_PREFIXES)
72 static ID id_special_prefixes;
73 #endif
74 
75 #ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
76 # define rl_filename_completion_function filename_completion_function
77 #endif
78 #ifndef HAVE_RL_USERNAME_COMPLETION_FUNCTION
79 # define rl_username_completion_function username_completion_function
80 #endif
81 #ifndef HAVE_RL_COMPLETION_MATCHES
82 # define rl_completion_matches completion_matches
83 #endif
84 
85 static int (*history_get_offset_func)(int);
86 static int (*history_replace_offset_func)(int);
87 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
88 static int readline_completion_append_character;
89 #endif
90 
91 static char **readline_attempted_completion_function(const char *text,
92  int start, int end);
93 
94 #define OutputStringValue(str) do {\
95  SafeStringValue(str);\
96  (str) = rb_str_conv_enc((str), rb_enc_get(str), rb_locale_encoding());\
97 } while (0)\
98 
99 
100 /*
101  * Document-class: Readline
102  *
103  * The Readline module provides interface for GNU Readline.
104  * This module defines a number of methods to facilitate completion
105  * and accesses input history from the Ruby interpreter.
106  * This module supported Edit Line(libedit) too.
107  * libedit is compatible with GNU Readline.
108  *
109  * GNU Readline:: http://www.gnu.org/directory/readline.html
110  * libedit:: http://www.thrysoee.dk/editline/
111  *
112  * Reads one inputted line with line edit by Readline.readline method.
113  * At this time, the facilitatation completion and the key
114  * bind like Emacs can be operated like GNU Readline.
115  *
116  * require "readline"
117  * while buf = Readline.readline("> ", true)
118  * p buf
119  * end
120  *
121  * The content that the user input can be recorded to the history.
122  * The history can be accessed by Readline::HISTORY constant.
123  *
124  * require "readline"
125  * while buf = Readline.readline("> ", true)
126  * p Readline::HISTORY.to_a
127  * print("-> ", buf, "\n")
128  * end
129  *
130  * Documented by Kouji Takao <kouji dot takao at gmail dot com>.
131  */
132 
137 
138 static void
140 {
141  if (!NIL_P(proc) && !rb_respond_to(proc, id_call))
142  rb_raise(rb_eArgError, "argument must respond to `call'");
143 }
144 
145 #if defined HAVE_RL_GETC_FUNCTION
146 
147 #ifndef HAVE_RL_GETC
148 #define rl_getc(f) EOF
149 #endif
150 
151 struct getc_struct {
152  FILE *input;
153  int fd;
154  int ret;
155  int err;
156 };
157 
158 static int
159 getc_body(struct getc_struct *p)
160 {
161  char ch;
162  ssize_t ss;
163 
164 #if defined(_WIN32)
165  {
166  INPUT_RECORD ir;
167  int n;
168  static int prior_key = '0';
169  for (;;) {
170  if (prior_key > 0xff) {
171  prior_key = rl_getc(p->input);
172  return prior_key;
173  }
174  if (PeekConsoleInput((HANDLE)_get_osfhandle(p->fd), &ir, 1, &n)) {
175  if (n == 1) {
176  if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) {
177  prior_key = rl_getc(p->input);
178  return prior_key;
179  } else {
180  ReadConsoleInput((HANDLE)_get_osfhandle(p->fd), &ir, 1, &n);
181  }
182  } else {
183  HANDLE h = (HANDLE)_get_osfhandle(p->fd);
184  rb_w32_wait_events(&h, 1, INFINITE);
185  }
186  } else {
187  break;
188  }
189  }
190  }
191 #endif
192 
193  ss = read(p->fd, &ch, 1);
194  if (ss == 0) {
195  errno = 0;
196  return EOF;
197  }
198  if (ss != 1)
199  return EOF;
200  return (unsigned char)ch;
201 }
202 
203 static void *
204 getc_func(void *data1)
205 {
206  struct getc_struct *p = data1;
207  errno = 0;
208  p->ret = getc_body(p);
209  p->err = errno;
210  return NULL;
211 }
212 
213 static int
214 readline_getc(FILE *input)
215 {
216  struct getc_struct data;
217  if (input == NULL) /* editline may give NULL as input. */
218  input = stdin;
219  data.input = input;
220  data.fd = fileno(input);
221  again:
222  data.ret = EOF;
223  data.err = EINTR; /* getc_func is not called if already interrupted. */
224  rb_thread_call_without_gvl2(getc_func, &data, RUBY_UBF_IO, NULL);
225  if (data.ret == EOF) {
226  if (data.err == 0) {
227  return EOF;
228  }
229  if (data.err == EINTR) {
231  goto again;
232  }
233  if (data.err == EWOULDBLOCK || data.err == EAGAIN) {
234  int ret;
235  if (fileno(input) != data.fd)
236  rb_bug("readline_getc: input closed unexpectedly or memory corrupted");
237  ret = rb_wait_for_single_fd(data.fd, RB_WAITFD_IN, NULL);
238  if (ret != -1 || errno == EINTR)
239  goto again;
240  rb_sys_fail("rb_wait_for_single_fd");
241  }
242  rb_syserr_fail(data.err, "read");
243  }
244  return data.ret;
245 }
246 
247 #elif defined HAVE_RL_EVENT_HOOK
248 #define BUSY_WAIT 0
249 
250 static int readline_event(void);
251 static int
252 readline_event(void)
253 {
254 #if BUSY_WAIT
256 #else
258  return 0;
259 #endif
260 }
261 #endif
262 
263 #if USE_INSERT_IGNORE_ESCAPE
264 static VALUE
265 insert_ignore_escape(VALUE self, VALUE prompt)
266 {
267  VALUE last_prompt, orig_prompt = rb_attr_get(self, id_orig_prompt);
268  int ignoring = 0;
269  const char *s0, *s, *e;
270  long len;
271  static const char ignore_code[2] = {RL_PROMPT_START_IGNORE, RL_PROMPT_END_IGNORE};
272 
273  prompt = rb_str_new_shared(prompt);
274  last_prompt = rb_attr_get(self, id_last_prompt);
275  if (orig_prompt == prompt) return last_prompt;
276  len = RSTRING_LEN(prompt);
277  if (NIL_P(last_prompt)) {
278  last_prompt = rb_str_tmp_new(len);
279  }
280 
281  s = s0 = RSTRING_PTR(prompt);
282  e = s0 + len;
283  rb_str_set_len(last_prompt, 0);
284  while (s < e && *s) {
285  switch (*s) {
286  case RL_PROMPT_START_IGNORE:
287  ignoring = -1;
288  rb_str_cat(last_prompt, s0, ++s - s0);
289  s0 = s;
290  break;
291  case RL_PROMPT_END_IGNORE:
292  ignoring = 0;
293  rb_str_cat(last_prompt, s0, ++s - s0);
294  s0 = s;
295  break;
296  case '\033':
297  if (++s < e && *s == '[') {
298  rb_str_cat(last_prompt, s0, s - s0 - 1);
299  s0 = s - 1;
300  while (++s < e && *s) {
301  if (ISALPHA(*(unsigned char *)s)) {
302  if (!ignoring) {
303  ignoring = 1;
304  rb_str_cat(last_prompt, ignore_code+0, 1);
305  }
306  rb_str_cat(last_prompt, s0, ++s - s0);
307  s0 = s;
308  break;
309  }
310  else if (!(('0' <= *s && *s <= '9') || *s == ';')) {
311  break;
312  }
313  }
314  }
315  break;
316  default:
317  if (ignoring > 0) {
318  ignoring = 0;
319  rb_str_cat(last_prompt, ignore_code+1, 1);
320  }
321  s++;
322  break;
323  }
324  }
325  if (ignoring > 0) {
326  ignoring = 0;
327  rb_str_cat(last_prompt, ignore_code+1, 1);
328  }
329  rb_str_cat(last_prompt, s0, s - s0);
330 
331  rb_ivar_set(self, id_orig_prompt, prompt);
332  rb_ivar_set(self, id_last_prompt, last_prompt);
333 
334  return last_prompt;
335 }
336 #endif
337 
338 static VALUE
340 {
341 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
342  readline_completion_append_character = rl_completion_append_character;
343 #endif
344  return (VALUE)readline((char *)prompt);
345 }
346 
347 static void
349 {
350  if (readline_rl_instream) {
351  fclose(readline_rl_instream);
352  if (rl_instream == readline_rl_instream)
353  rl_instream = NULL;
354  readline_rl_instream = NULL;
355  }
357 }
358 
359 static void
361 {
362  if (readline_rl_outstream) {
363  fclose(readline_rl_outstream);
364  if (rl_outstream == readline_rl_outstream)
365  rl_outstream = NULL;
366  readline_rl_outstream = NULL;
367  }
369 }
370 
371 static void
373 {
374  static int initialized = 0;
375  if (!initialized) {
376  rl_initialize();
377  initialized = 1;
378  }
379 
380  if (readline_instream) {
381  rb_io_t *ifp;
383  if (ifp->fd < 0) {
385  rb_raise(rb_eIOError, "closed readline input");
386  }
387  }
388 
389  if (readline_outstream) {
390  rb_io_t *ofp;
392  if (ofp->fd < 0) {
394  rb_raise(rb_eIOError, "closed readline output");
395  }
396  }
397 }
398 
399 /*
400  * call-seq:
401  * Readline.readline(prompt = "", add_hist = false) -> string or nil
402  *
403  * Shows the +prompt+ and reads the inputted line with line editing.
404  * The inputted line is added to the history if +add_hist+ is true.
405  *
406  * Returns nil when the inputted line is empty and user inputs EOF
407  * (Presses ^D on UNIX).
408  *
409  * Raises IOError exception if one of below conditions are satisfied.
410  * 1. stdin was closed.
411  * 2. stdout was closed.
412  *
413  * This method supports thread. Switches the thread context when waits
414  * inputting line.
415  *
416  * Supports line edit when inputs line. Provides VI and Emacs editing mode.
417  * Default is Emacs editing mode.
418  *
419  * NOTE: Terminates ruby interpreter and does not return the terminal
420  * status after user pressed '^C' when wait inputting line.
421  * Give 3 examples that avoid it.
422  *
423  * * Catches the Interrupt exception by pressed ^C after returns
424  * terminal status:
425  *
426  * require "readline"
427  *
428  * stty_save = `stty -g`.chomp
429  * begin
430  * while buf = Readline.readline
431  * p buf
432  * end
433  * rescue Interrupt
434  * system("stty", stty_save)
435  * exit
436  * end
437  * end
438  * end
439  *
440  * * Catches the INT signal by pressed ^C after returns terminal
441  * status:
442  *
443  * require "readline"
444  *
445  * stty_save = `stty -g`.chomp
446  * trap("INT") { system "stty", stty_save; exit }
447  *
448  * while buf = Readline.readline
449  * p buf
450  * end
451  *
452  * * Ignores pressing ^C:
453  *
454  * require "readline"
455  *
456  * trap("INT", "SIG_IGN")
457  *
458  * while buf = Readline.readline
459  * p buf
460  * end
461  *
462  * Can make as follows with Readline::HISTORY constant.
463  * It does not record to the history if the inputted line is empty or
464  * the same it as last one.
465  *
466  * require "readline"
467  *
468  * while buf = Readline.readline("> ", true)
469  * # p Readline::HISTORY.to_a
470  * Readline::HISTORY.pop if /^\s*$/ =~ buf
471  *
472  * begin
473  * if Readline::HISTORY[Readline::HISTORY.length-2] == buf
474  * Readline::HISTORY.pop
475  * end
476  * rescue IndexError
477  * end
478  *
479  * # p Readline::HISTORY.to_a
480  * print "-> ", buf, "\n"
481  * end
482  */
483 static VALUE
485 {
486  VALUE tmp, add_hist, result;
487  char *prompt = NULL;
488  char *buff;
489  int status;
490 
491  if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
492  OutputStringValue(tmp);
493 #if USE_INSERT_IGNORE_ESCAPE
494  tmp = insert_ignore_escape(self, tmp);
495  rb_str_locktmp(tmp);
496 #endif
497  prompt = RSTRING_PTR(tmp);
498  }
499 
501 
502 #ifdef _WIN32
503  rl_prep_terminal(1);
504 #endif
505  buff = (char*)rb_protect(readline_get, (VALUE)prompt, &status);
506 #if USE_INSERT_IGNORE_ESCAPE
507  if (prompt) {
508  rb_str_unlocktmp(tmp);
509  }
510 #endif
511  if (status) {
512 #if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
513  /* restore terminal mode and signal handler*/
514 #if defined HAVE_RL_FREE_LINE_STATE
515  rl_free_line_state();
516 #endif
517  rl_cleanup_after_signal();
518 #elif defined HAVE_RL_DEPREP_TERM_FUNCTION
519  /* restore terminal mode */
520  if (rl_deprep_term_function != NULL) /* NULL in libedit. [ruby-dev:29116] */
521  (*rl_deprep_term_function)();
522  else
523 #else
524  rl_deprep_terminal();
525 #endif
526  rb_jump_tag(status);
527  }
528 
529  if (RTEST(add_hist) && buff) {
530  add_history(buff);
531  }
532  if (buff) {
533  result = rb_locale_str_new_cstr(buff);
534  }
535  else
536  result = Qnil;
537  if (buff) free(buff);
538  return result;
539 }
540 
541 /*
542  * call-seq:
543  * Readline.input = input
544  *
545  * Specifies a File object +input+ that is input stream for
546  * Readline.readline method.
547  */
548 static VALUE
550 {
551  rb_io_t *ifp;
552  int fd;
553  FILE *f;
554 
555  if (NIL_P(input)) {
557  }
558  else {
559  Check_Type(input, T_FILE);
560  GetOpenFile(input, ifp);
562  fd = rb_cloexec_dup(ifp->fd);
563  if (fd == -1)
564  rb_sys_fail("dup");
565  f = fdopen(fd, "r");
566  if (f == NULL) {
567  int save_errno = errno;
568  close(fd);
569  rb_syserr_fail(save_errno, "fdopen");
570  }
571  rl_instream = readline_rl_instream = f;
573  }
574  return input;
575 }
576 
577 /*
578  * call-seq:
579  * Readline.output = output
580  *
581  * Specifies a File object +output+ that is output stream for
582  * Readline.readline method.
583  */
584 static VALUE
586 {
587  rb_io_t *ofp;
588  int fd;
589  FILE *f;
590 
591  if (NIL_P(output)) {
593  }
594  else {
595  Check_Type(output, T_FILE);
596  GetOpenFile(output, ofp);
598  fd = rb_cloexec_dup(ofp->fd);
599  if (fd == -1)
600  rb_sys_fail("dup");
601  f = fdopen(fd, "w");
602  if (f == NULL) {
603  int save_errno = errno;
604  close(fd);
605  rb_syserr_fail(save_errno, "fdopen");
606  }
607  rl_outstream = readline_rl_outstream = f;
609  }
610  return output;
611 }
612 
613 #if defined(HAVE_RL_PRE_INPUT_HOOK)
614 /*
615  * call-seq:
616  * Readline.pre_input_hook = proc
617  *
618  * Specifies a Proc object +proc+ to call after the first prompt has
619  * been printed and just before readline starts reading input
620  * characters.
621  *
622  * See GNU Readline's rl_pre_input_hook variable.
623  *
624  * Raises ArgumentError if +proc+ does not respond to the call method.
625  *
626  * Raises NotImplementedError if the using readline library does not support.
627  */
628 static VALUE
630 {
631  mustbe_callable(proc);
632  return rb_ivar_set(mReadline, id_pre_input_hook, proc);
633 }
634 
635 /*
636  * call-seq:
637  * Readline.pre_input_hook -> proc
638  *
639  * Returns a Proc object +proc+ to call after the first prompt has
640  * been printed and just before readline starts reading input
641  * characters. The default is nil.
642  *
643  * Raises NotImplementedError if the using readline library does not support.
644  */
645 static VALUE
647 {
648  return rb_attr_get(mReadline, id_pre_input_hook);
649 }
650 
651 static int
652 readline_pre_input_hook(void)
653 {
654  VALUE proc;
655 
656  proc = rb_attr_get(mReadline, id_pre_input_hook);
657  if (!NIL_P(proc))
658  rb_funcall(proc, id_call, 0);
659  return 0;
660 }
661 #else
662 #define readline_s_set_pre_input_hook rb_f_notimplement
663 #define readline_s_get_pre_input_hook rb_f_notimplement
664 #endif
665 
666 #if defined(HAVE_RL_INSERT_TEXT)
667 /*
668  * call-seq:
669  * Readline.insert_text(string) -> self
670  *
671  * Insert text into the line at the current cursor position.
672  *
673  * See GNU Readline's rl_insert_text function.
674  *
675  * Raises NotImplementedError if the using readline library does not support.
676  */
677 static VALUE
679 {
680  OutputStringValue(str);
681  rl_insert_text(RSTRING_PTR(str));
682  return self;
683 }
684 #else
685 #define readline_s_insert_text rb_f_notimplement
686 #endif
687 
688 #if defined(HAVE_RL_DELETE_TEXT)
689 static const char *
690 str_subpos(const char *ptr, const char *end, long beg, long *sublen, rb_encoding *enc)
691 {
692  VALUE str = rb_enc_str_new_static(ptr, end-ptr, enc);
693  OBJ_FREEZE(str);
694  ptr = rb_str_subpos(str, beg, sublen);
695  rb_gc_force_recycle(str);
696  return ptr;
697 }
698 
699 /*
700  * call-seq:
701  * Readline.delete_text([start[, length]]) -> self
702  * Readline.delete_text(start..end) -> self
703  * Readline.delete_text() -> self
704  *
705  * Delete text between start and end in the current line.
706  *
707  * See GNU Readline's rl_delete_text function.
708  *
709  * Raises NotImplementedError if the using readline library does not support.
710  */
711 static VALUE
713 {
714  rb_check_arity(argc, 0, 2);
715  if (rl_line_buffer) {
716  const char *p, *ptr = rl_line_buffer;
717  long beg = 0, len = strlen(ptr);
718  const char *end = ptr + len;
720  if (argc == 2) {
721  beg = NUM2LONG(argv[0]);
722  len = NUM2LONG(argv[1]);
723  num_pos:
724  p = str_subpos(ptr, end, beg, &len, enc);
725  if (!p) rb_raise(rb_eArgError, "invalid index");
726  beg = p - ptr;
727  }
728  else if (argc == 1) {
729  len = rb_enc_strlen(ptr, ptr + len, enc);
730  if (!rb_range_beg_len(argv[0], &beg, &len, len, 1)) {
731  beg = NUM2LONG(argv[0]);
732  goto num_pos;
733  }
734  }
735  rl_delete_text(rb_long2int(beg), rb_long2int(beg + len));
736  }
737  return self;
738 }
739 #else
740 #define readline_s_delete_text rb_f_notimplement
741 #endif
742 
743 #if defined(HAVE_RL_REDISPLAY)
744 /*
745  * call-seq:
746  * Readline.redisplay -> self
747  *
748  * Change what's displayed on the screen to reflect the current
749  * contents.
750  *
751  * See GNU Readline's rl_redisplay function.
752  *
753  * Raises NotImplementedError if the using readline library does not support.
754  */
755 static VALUE
757 {
758  rl_redisplay();
759  return self;
760 }
761 #else
762 #define readline_s_redisplay rb_f_notimplement
763 #endif
764 
765 /*
766  * call-seq:
767  * Readline.completion_proc = proc
768  *
769  * Specifies a Proc object +proc+ to determine completion behavior. It
770  * should take input string and return an array of completion candidates.
771  *
772  * The default completion is used if +proc+ is nil.
773  *
774  * The String that is passed to the Proc depends on the
775  * Readline.completer_word_break_characters property. By default the word
776  * under the cursor is passed to the Proc. For example, if the input is "foo
777  * bar" then only "bar" would be passed to the completion Proc.
778  *
779  * Upon successful completion the Readline.completion_append_character will be
780  * appended to the input so the user can start working on their next argument.
781  *
782  * = Examples
783  *
784  * == Completion for a Static List
785  *
786  * require 'readline'
787  *
788  * LIST = [
789  * 'search', 'download', 'open',
790  * 'help', 'history', 'quit',
791  * 'url', 'next', 'clear',
792  * 'prev', 'past'
793  * ].sort
794  *
795  * comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) }
796  *
797  * Readline.completion_append_character = " "
798  * Readline.completion_proc = comp
799  *
800  * while line = Readline.readline('> ', true)
801  * p line
802  * end
803  *
804  * == Completion For Directory Contents
805  *
806  * require 'readline'
807  *
808  * Readline.completion_append_character = " "
809  * Readline.completion_proc = Proc.new do |str|
810  * Dir[str+'*'].grep(/^#{Regexp.escape(str)}/)
811  * end
812  *
813  * while line = Readline.readline('> ', true)
814  * p line
815  * end
816  *
817  * = Autocomplete strategies
818  *
819  * When working with auto-complete there are some strategies that work well.
820  * To get some ideas you can take a look at the
821  * completion.rb[http://svn.ruby-lang.org/repos/ruby/trunk/lib/irb/completion.rb]
822  * file for irb.
823  *
824  * The common strategy is to take a list of possible completions and filter it
825  * down to those completions that start with the user input. In the above
826  * examples Enumerator.grep is used. The input is escaped to prevent Regexp
827  * special characters from interfering with the matching.
828  *
829  * It may also be helpful to use the Abbrev library to generate completions.
830  *
831  * Raises ArgumentError if +proc+ does not respond to the call method.
832  */
833 static VALUE
835 {
836  mustbe_callable(proc);
837  return rb_ivar_set(mReadline, completion_proc, proc);
838 }
839 
840 /*
841  * call-seq:
842  * Readline.completion_proc -> proc
843  *
844  * Returns the completion Proc object.
845  */
846 static VALUE
848 {
850 }
851 
852 #ifdef HAVE_RL_CHAR_IS_QUOTED_P
853 /*
854  * call-seq:
855  * Readline.quoting_detection_proc = proc
856  *
857  * Specifies a Proc object +proc+ to determine if a character in the user's
858  * input is escaped. It should take the user's input and the index of the
859  * character in question as input, and return a boolean (true if the specified
860  * character is escaped).
861  *
862  * Readline will only call this proc with characters specified in
863  * +completer_quote_characters+, to discover if they indicate the end of a
864  * quoted argument, or characters specified in
865  * +completer_word_break_characters+, to discover if they indicate a break
866  * between arguments.
867  *
868  * If +completer_quote_characters+ is not set, or if the user input doesn't
869  * contain one of the +completer_quote_characters+ or a +\+ character,
870  * Readline will not attempt to use this proc at all.
871  *
872  * Raises ArgumentError if +proc+ does not respond to the call method.
873  */
874 static VALUE
876 {
877  mustbe_callable(proc);
878  return rb_ivar_set(mReadline, quoting_detection_proc, proc);
879 }
880 
881 /*
882  * call-seq:
883  * Readline.quoting_detection_proc -> proc
884  *
885  * Returns the quoting detection Proc object.
886  */
887 static VALUE
889 {
890  return rb_attr_get(mReadline, quoting_detection_proc);
891 }
892 #else
893 #define readline_s_set_quoting_detection_proc rb_f_notimplement
894 #define readline_s_get_quoting_detection_proc rb_f_notimplement
895 #endif
896 
897 /*
898  * call-seq:
899  * Readline.completion_case_fold = bool
900  *
901  * Sets whether or not to ignore case on completion.
902  */
903 static VALUE
905 {
907 }
908 
909 /*
910  * call-seq:
911  * Readline.completion_case_fold -> bool
912  *
913  * Returns true if completion ignores case. If no, returns false.
914  *
915  * NOTE: Returns the same object that is specified by
916  * Readline.completion_case_fold= method.
917  *
918  * require "readline"
919  *
920  * Readline.completion_case_fold = "This is a String."
921  * p Readline.completion_case_fold # => "This is a String."
922  */
923 static VALUE
925 {
927 }
928 
929 #ifdef HAVE_RL_LINE_BUFFER
930 /*
931  * call-seq:
932  * Readline.line_buffer -> string
933  *
934  * Returns the full line that is being edited. This is useful from
935  * within the complete_proc for determining the context of the
936  * completion request.
937  *
938  * The length of +Readline.line_buffer+ and GNU Readline's rl_end are
939  * same.
940  *
941  * Raises NotImplementedError if the using readline library does not support.
942  */
943 static VALUE
945 {
946  if (rl_line_buffer == NULL)
947  return Qnil;
948  return rb_locale_str_new_cstr(rl_line_buffer);
949 }
950 #else
951 #define readline_s_get_line_buffer rb_f_notimplement
952 #endif
953 
954 #ifdef HAVE_RL_POINT
955 /*
956  * call-seq:
957  * Readline.point -> int
958  *
959  * Returns the index of the current cursor position in
960  * +Readline.line_buffer+.
961  *
962  * The index in +Readline.line_buffer+ which matches the start of
963  * input-string passed to completion_proc is computed by subtracting
964  * the length of input-string from +Readline.point+.
965  *
966  * start = (the length of input-string) - Readline.point
967  *
968  * Raises NotImplementedError if the using readline library does not support.
969  */
970 static VALUE
972 {
973  return INT2NUM(rl_point);
974 }
975 
976 /*
977  * call-seq:
978  * Readline.point = int
979  *
980  * Set the index of the current cursor position in
981  * +Readline.line_buffer+.
982  *
983  * Raises NotImplementedError if the using readline library does not support.
984  *
985  * See +Readline.point+.
986  */
987 static VALUE
989 {
990  rl_point = NUM2INT(pos);
991  return pos;
992 }
993 #else
994 #define readline_s_get_point rb_f_notimplement
995 #define readline_s_set_point rb_f_notimplement
996 #endif
997 
998 static char **
999 readline_attempted_completion_function(const char *text, int start, int end)
1000 {
1001  VALUE proc, ary, temp;
1002  char **result;
1003  int case_fold;
1004  long i, matches;
1005  rb_encoding *enc;
1006  VALUE encobj;
1007 
1009  if (NIL_P(proc))
1010  return NULL;
1011 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
1012  rl_completion_append_character = readline_completion_append_character;
1013 #endif
1014 #ifdef HAVE_RL_ATTEMPTED_COMPLETION_OVER
1015  rl_attempted_completion_over = 1;
1016 #endif
1018  ary = rb_funcall(proc, id_call, 1, rb_locale_str_new_cstr(text));
1019  if (!RB_TYPE_P(ary, T_ARRAY))
1020  ary = rb_Array(ary);
1021  matches = RARRAY_LEN(ary);
1022  if (matches == 0) return NULL;
1023  result = (char**)malloc((matches + 2)*sizeof(char*));
1024  if (result == NULL) rb_memerror();
1025  enc = rb_locale_encoding();
1026  encobj = rb_enc_from_encoding(enc);
1027  for (i = 0; i < matches; i++) {
1028  temp = rb_obj_as_string(RARRAY_AREF(ary, i));
1029  StringValueCStr(temp); /* must be NUL-terminated */
1030  rb_enc_check(encobj, temp);
1031  result[i + 1] = (char*)malloc(RSTRING_LEN(temp) + 1);
1032  if (result[i + 1] == NULL) rb_memerror();
1033  strcpy(result[i + 1], RSTRING_PTR(temp));
1034  }
1035  result[matches + 1] = NULL;
1036 
1037  if (matches == 1) {
1038  result[0] = strdup(result[1]);
1039  }
1040  else {
1041  const char *result1 = result[1];
1042  long low = strlen(result1);
1043 
1044  for (i = 1; i < matches; ++i) {
1045  register int c1, c2;
1046  long i1, i2, l2;
1047  int n1, n2;
1048  const char *p2 = result[i + 1];
1049 
1050  l2 = strlen(p2);
1051  for (i1 = i2 = 0; i1 < low && i2 < l2; i1 += n1, i2 += n2) {
1052  c1 = rb_enc_codepoint_len(result1 + i1, result1 + low, &n1, enc);
1053  c2 = rb_enc_codepoint_len(p2 + i2, p2 + l2, &n2, enc);
1054  if (case_fold) {
1055  c1 = rb_tolower(c1);
1056  c2 = rb_tolower(c2);
1057  }
1058  if (c1 != c2) break;
1059  }
1060 
1061  low = i1;
1062  }
1063  result[0] = (char*)malloc(low + 1);
1064  if (result[0] == NULL) rb_memerror();
1065  strncpy(result[0], result[1], low);
1066  result[0][low] = '\0';
1067  }
1068 
1069  return result;
1070 }
1071 
1072 #ifdef HAVE_RL_CHAR_IS_QUOTED_P
1073 static int
1074 readline_char_is_quoted(char *text, int byte_index)
1075 {
1076  VALUE proc, result, str;
1077  long char_index;
1078  size_t len;
1079 
1080  proc = rb_attr_get(mReadline, quoting_detection_proc);
1081  if (NIL_P(proc)) {
1082  return 0;
1083  }
1084 
1085  len = strlen(text);
1086  if (byte_index < 0 || len < (size_t)byte_index) {
1087  rb_raise(rb_eIndexError, "invalid byte index (%d in %"PRIdSIZE")",
1088  byte_index, len);
1089  }
1090 
1091  str = rb_locale_str_new(text, len);
1092  char_index = rb_str_sublen(str, byte_index);
1093  result = rb_funcall(proc, id_call, 2, str, LONG2FIX(char_index));
1094  return RTEST(result);
1095 }
1096 #endif
1097 
1098 #ifdef HAVE_RL_SET_SCREEN_SIZE
1099 /*
1100  * call-seq:
1101  * Readline.set_screen_size(rows, columns) -> self
1102  *
1103  * Set terminal size to +rows+ and +columns+.
1104  *
1105  * See GNU Readline's rl_set_screen_size function.
1106  *
1107  * Raises NotImplementedError if the using readline library does not support.
1108  */
1109 static VALUE
1110 readline_s_set_screen_size(VALUE self, VALUE rows, VALUE columns)
1111 {
1112  rl_set_screen_size(NUM2INT(rows), NUM2INT(columns));
1113  return self;
1114 }
1115 #else
1116 #define readline_s_set_screen_size rb_f_notimplement
1117 #endif
1118 
1119 #ifdef HAVE_RL_GET_SCREEN_SIZE
1120 /*
1121  * call-seq:
1122  * Readline.get_screen_size -> [rows, columns]
1123  *
1124  * Returns the terminal's rows and columns.
1125  *
1126  * See GNU Readline's rl_get_screen_size function.
1127  *
1128  * Raises NotImplementedError if the using readline library does not support.
1129  */
1130 static VALUE
1132 {
1133  int rows, columns;
1134  VALUE res;
1135 
1136  rl_get_screen_size(&rows, &columns);
1137  res = rb_ary_new();
1138  rb_ary_push(res, INT2NUM(rows));
1139  rb_ary_push(res, INT2NUM(columns));
1140  return res;
1141 }
1142 #else
1143 #define readline_s_get_screen_size rb_f_notimplement
1144 #endif
1145 
1146 #ifdef HAVE_RL_VI_EDITING_MODE
1147 /*
1148  * call-seq:
1149  * Readline.vi_editing_mode -> nil
1150  *
1151  * Specifies VI editing mode. See the manual of GNU Readline for
1152  * details of VI editing mode.
1153  *
1154  * Raises NotImplementedError if the using readline library does not support.
1155  */
1156 static VALUE
1158 {
1159  rl_vi_editing_mode(1,0);
1160  return Qnil;
1161 }
1162 #else
1163 #define readline_s_vi_editing_mode rb_f_notimplement
1164 #endif
1165 
1166 #ifdef HAVE_RL_EDITING_MODE
1167 /*
1168  * call-seq:
1169  * Readline.vi_editing_mode? -> bool
1170  *
1171  * Returns true if vi mode is active. Returns false if not.
1172  *
1173  * Raises NotImplementedError if the using readline library does not support.
1174  */
1175 static VALUE
1177 {
1178  return rl_editing_mode == 0 ? Qtrue : Qfalse;
1179 }
1180 #else
1181 #define readline_s_vi_editing_mode_p rb_f_notimplement
1182 #endif
1183 
1184 #ifdef HAVE_RL_EMACS_EDITING_MODE
1185 /*
1186  * call-seq:
1187  * Readline.emacs_editing_mode -> nil
1188  *
1189  * Specifies Emacs editing mode. The default is this mode. See the
1190  * manual of GNU Readline for details of Emacs editing mode.
1191  *
1192  * Raises NotImplementedError if the using readline library does not support.
1193  */
1194 static VALUE
1196 {
1197  rl_emacs_editing_mode(1,0);
1198  return Qnil;
1199 }
1200 #else
1201 #define readline_s_emacs_editing_mode rb_f_notimplement
1202 #endif
1203 
1204 #ifdef HAVE_RL_EDITING_MODE
1205 /*
1206  * call-seq:
1207  * Readline.emacs_editing_mode? -> bool
1208  *
1209  * Returns true if emacs mode is active. Returns false if not.
1210  *
1211  * Raises NotImplementedError if the using readline library does not support.
1212  */
1213 static VALUE
1215 {
1216  return rl_editing_mode == 1 ? Qtrue : Qfalse;
1217 }
1218 #else
1219 #define readline_s_emacs_editing_mode_p rb_f_notimplement
1220 #endif
1221 
1222 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
1223 /*
1224  * call-seq:
1225  * Readline.completion_append_character = char
1226  *
1227  * Specifies a character to be appended on completion.
1228  * Nothing will be appended if an empty string ("") or nil is
1229  * specified.
1230  *
1231  * For example:
1232  * require "readline"
1233  *
1234  * Readline.readline("> ", true)
1235  * Readline.completion_append_character = " "
1236  *
1237  * Result:
1238  * >
1239  * Input "/var/li".
1240  *
1241  * > /var/li
1242  * Press TAB key.
1243  *
1244  * > /var/lib
1245  * Completes "b" and appends " ". So, you can continuously input "/usr".
1246  *
1247  * > /var/lib /usr
1248  *
1249  * NOTE: Only one character can be specified. When "string" is
1250  * specified, sets only "s" that is the first.
1251  *
1252  * require "readline"
1253  *
1254  * Readline.completion_append_character = "string"
1255  * p Readline.completion_append_character # => "s"
1256  *
1257  * Raises NotImplementedError if the using readline library does not support.
1258  */
1259 static VALUE
1261 {
1262  if (NIL_P(str)) {
1263  rl_completion_append_character = '\0';
1264  }
1265  else {
1266  OutputStringValue(str);
1267  if (RSTRING_LEN(str) == 0) {
1268  rl_completion_append_character = '\0';
1269  } else {
1270  rl_completion_append_character = RSTRING_PTR(str)[0];
1271  }
1272  }
1273  return self;
1274 }
1275 #else
1276 #define readline_s_set_completion_append_character rb_f_notimplement
1277 #endif
1278 
1279 #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
1280 /*
1281  * call-seq:
1282  * Readline.completion_append_character -> char
1283  *
1284  * Returns a string containing a character to be appended on
1285  * completion. The default is a space (" ").
1286  *
1287  * Raises NotImplementedError if the using readline library does not support.
1288  */
1289 static VALUE
1291 {
1292  char buf[1];
1293 
1294  if (rl_completion_append_character == '\0')
1295  return Qnil;
1296 
1297  buf[0] = (char) rl_completion_append_character;
1298  return rb_locale_str_new(buf, 1);
1299 }
1300 #else
1301 #define readline_s_get_completion_append_character rb_f_notimplement
1302 #endif
1303 
1304 #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
1305 /*
1306  * call-seq:
1307  * Readline.basic_word_break_characters = string
1308  *
1309  * Sets the basic list of characters that signal a break between words
1310  * for the completer routine. The default is the characters which
1311  * break words for completion in Bash: " \t\n\"\\'`@$><=;|&{(".
1312  *
1313  * Raises NotImplementedError if the using readline library does not support.
1314  */
1315 static VALUE
1317 {
1318  static char *basic_word_break_characters = NULL;
1319 
1320  OutputStringValue(str);
1321  if (basic_word_break_characters == NULL) {
1322  basic_word_break_characters =
1323  ALLOC_N(char, RSTRING_LEN(str) + 1);
1324  }
1325  else {
1326  REALLOC_N(basic_word_break_characters, char, RSTRING_LEN(str) + 1);
1327  }
1328  strncpy(basic_word_break_characters,
1329  RSTRING_PTR(str), RSTRING_LEN(str));
1330  basic_word_break_characters[RSTRING_LEN(str)] = '\0';
1331  rl_basic_word_break_characters = basic_word_break_characters;
1332  return self;
1333 }
1334 #else
1335 #define readline_s_set_basic_word_break_characters rb_f_notimplement
1336 #endif
1337 
1338 #ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
1339 /*
1340  * call-seq:
1341  * Readline.basic_word_break_characters -> string
1342  *
1343  * Gets the basic list of characters that signal a break between words
1344  * for the completer routine.
1345  *
1346  * Raises NotImplementedError if the using readline library does not support.
1347  */
1348 static VALUE
1350 {
1351  if (rl_basic_word_break_characters == NULL)
1352  return Qnil;
1353  return rb_locale_str_new_cstr(rl_basic_word_break_characters);
1354 }
1355 #else
1356 #define readline_s_get_basic_word_break_characters rb_f_notimplement
1357 #endif
1358 
1359 #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
1360 /*
1361  * call-seq:
1362  * Readline.completer_word_break_characters = string
1363  *
1364  * Sets the basic list of characters that signal a break between words
1365  * for rl_complete_internal(). The default is the value of
1366  * Readline.basic_word_break_characters.
1367  *
1368  * Raises NotImplementedError if the using readline library does not support.
1369  */
1370 static VALUE
1372 {
1373  static char *completer_word_break_characters = NULL;
1374 
1375  OutputStringValue(str);
1376  if (completer_word_break_characters == NULL) {
1377  completer_word_break_characters =
1378  ALLOC_N(char, RSTRING_LEN(str) + 1);
1379  }
1380  else {
1381  REALLOC_N(completer_word_break_characters, char, RSTRING_LEN(str) + 1);
1382  }
1383  strncpy(completer_word_break_characters,
1384  RSTRING_PTR(str), RSTRING_LEN(str));
1385  completer_word_break_characters[RSTRING_LEN(str)] = '\0';
1386  rl_completer_word_break_characters = completer_word_break_characters;
1387  return self;
1388 }
1389 #else
1390 #define readline_s_set_completer_word_break_characters rb_f_notimplement
1391 #endif
1392 
1393 #ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
1394 /*
1395  * call-seq:
1396  * Readline.completer_word_break_characters -> string
1397  *
1398  * Gets the basic list of characters that signal a break between words
1399  * for rl_complete_internal().
1400  *
1401  * Raises NotImplementedError if the using readline library does not support.
1402  */
1403 static VALUE
1405 {
1406  if (rl_completer_word_break_characters == NULL)
1407  return Qnil;
1408  return rb_locale_str_new_cstr(rl_completer_word_break_characters);
1409 }
1410 #else
1411 #define readline_s_get_completer_word_break_characters rb_f_notimplement
1412 #endif
1413 
1414 #if defined(HAVE_RL_SPECIAL_PREFIXES)
1415 /*
1416  * call-seq:
1417  * Readline.special_prefixes = string
1418  *
1419  * Sets the list of characters that are word break characters, but
1420  * should be left in text when it is passed to the completion
1421  * function. Programs can use this to help determine what kind of
1422  * completing to do. For instance, Bash sets this variable to "$@" so
1423  * that it can complete shell variables and hostnames.
1424  *
1425  * See GNU Readline's rl_special_prefixes variable.
1426  *
1427  * Raises NotImplementedError if the using readline library does not support.
1428  */
1429 static VALUE
1431 {
1432  if (!NIL_P(str)) {
1433  OutputStringValue(str);
1434  str = rb_str_dup_frozen(str);
1435  rb_obj_hide(str);
1436  }
1437  rb_ivar_set(mReadline, id_special_prefixes, str);
1438  if (NIL_P(str)) {
1439  rl_special_prefixes = NULL;
1440  }
1441  else {
1442  rl_special_prefixes = RSTRING_PTR(str);
1443  }
1444  return self;
1445 }
1446 
1447 /*
1448  * call-seq:
1449  * Readline.special_prefixes -> string
1450  *
1451  * Gets the list of characters that are word break characters, but
1452  * should be left in text when it is passed to the completion
1453  * function.
1454  *
1455  * See GNU Readline's rl_special_prefixes variable.
1456  *
1457  * Raises NotImplementedError if the using readline library does not support.
1458  */
1459 static VALUE
1461 {
1462  VALUE str;
1463  if (rl_special_prefixes == NULL) return Qnil;
1464  str = rb_ivar_get(mReadline, id_special_prefixes);
1465  if (!NIL_P(str)) {
1466  str = rb_str_dup_frozen(str);
1467  rb_obj_reveal(str, rb_cString);
1468  }
1469  return str;
1470 }
1471 #else
1472 #define readline_s_set_special_prefixes rb_f_notimplement
1473 #define readline_s_get_special_prefixes rb_f_notimplement
1474 #endif
1475 
1476 #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
1477 /*
1478  * call-seq:
1479  * Readline.basic_quote_characters = string
1480  *
1481  * Sets a list of quote characters which can cause a word break.
1482  *
1483  * Raises NotImplementedError if the using readline library does not support.
1484  */
1485 static VALUE
1487 {
1488  static char *basic_quote_characters = NULL;
1489 
1490  OutputStringValue(str);
1491  if (basic_quote_characters == NULL) {
1492  basic_quote_characters =
1493  ALLOC_N(char, RSTRING_LEN(str) + 1);
1494  }
1495  else {
1496  REALLOC_N(basic_quote_characters, char, RSTRING_LEN(str) + 1);
1497  }
1498  strncpy(basic_quote_characters,
1499  RSTRING_PTR(str), RSTRING_LEN(str));
1500  basic_quote_characters[RSTRING_LEN(str)] = '\0';
1501  rl_basic_quote_characters = basic_quote_characters;
1502 
1503  return self;
1504 }
1505 #else
1506 #define readline_s_set_basic_quote_characters rb_f_notimplement
1507 #endif
1508 
1509 #ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
1510 /*
1511  * call-seq:
1512  * Readline.basic_quote_characters -> string
1513  *
1514  * Gets a list of quote characters which can cause a word break.
1515  *
1516  * Raises NotImplementedError if the using readline library does not support.
1517  */
1518 static VALUE
1520 {
1521  if (rl_basic_quote_characters == NULL)
1522  return Qnil;
1523  return rb_locale_str_new_cstr(rl_basic_quote_characters);
1524 }
1525 #else
1526 #define readline_s_get_basic_quote_characters rb_f_notimplement
1527 #endif
1528 
1529 #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
1530 /*
1531  * call-seq:
1532  * Readline.completer_quote_characters = string
1533  *
1534  * Sets a list of characters which can be used to quote a substring of
1535  * the line. Completion occurs on the entire substring, and within
1536  * the substring Readline.completer_word_break_characters are treated
1537  * as any other character, unless they also appear within this list.
1538  *
1539  * Raises NotImplementedError if the using readline library does not support.
1540  */
1541 static VALUE
1543 {
1544  static char *completer_quote_characters = NULL;
1545 
1546  OutputStringValue(str);
1547  if (completer_quote_characters == NULL) {
1548  completer_quote_characters =
1549  ALLOC_N(char, RSTRING_LEN(str) + 1);
1550  }
1551  else {
1552  REALLOC_N(completer_quote_characters, char, RSTRING_LEN(str) + 1);
1553  }
1554  strncpy(completer_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
1555  completer_quote_characters[RSTRING_LEN(str)] = '\0';
1556  rl_completer_quote_characters = completer_quote_characters;
1557 
1558  return self;
1559 }
1560 #else
1561 #define readline_s_set_completer_quote_characters rb_f_notimplement
1562 #endif
1563 
1564 #ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
1565 /*
1566  * call-seq:
1567  * Readline.completer_quote_characters -> string
1568  *
1569  * Gets a list of characters which can be used to quote a substring of
1570  * the line.
1571  *
1572  * Raises NotImplementedError if the using readline library does not support.
1573  */
1574 static VALUE
1576 {
1577  if (rl_completer_quote_characters == NULL)
1578  return Qnil;
1579  return rb_locale_str_new_cstr(rl_completer_quote_characters);
1580 }
1581 #else
1582 #define readline_s_get_completer_quote_characters rb_f_notimplement
1583 #endif
1584 
1585 #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
1586 /*
1587  * call-seq:
1588  * Readline.filename_quote_characters = string
1589  *
1590  * Sets a list of characters that cause a filename to be quoted by the completer
1591  * when they appear in a completed filename. The default is nil.
1592  *
1593  * Raises NotImplementedError if the using readline library does not support.
1594  */
1595 static VALUE
1597 {
1598  static char *filename_quote_characters = NULL;
1599 
1600  OutputStringValue(str);
1601  if (filename_quote_characters == NULL) {
1602  filename_quote_characters =
1603  ALLOC_N(char, RSTRING_LEN(str) + 1);
1604  }
1605  else {
1606  REALLOC_N(filename_quote_characters, char, RSTRING_LEN(str) + 1);
1607  }
1608  strncpy(filename_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
1609  filename_quote_characters[RSTRING_LEN(str)] = '\0';
1610  rl_filename_quote_characters = filename_quote_characters;
1611 
1612  return self;
1613 }
1614 #else
1615 #define readline_s_set_filename_quote_characters rb_f_notimplement
1616 #endif
1617 
1618 #ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
1619 /*
1620  * call-seq:
1621  * Readline.filename_quote_characters -> string
1622  *
1623  * Gets a list of characters that cause a filename to be quoted by the completer
1624  * when they appear in a completed filename.
1625  *
1626  * Raises NotImplementedError if the using readline library does not support.
1627  */
1628 static VALUE
1630 {
1631  if (rl_filename_quote_characters == NULL)
1632  return Qnil;
1633  return rb_locale_str_new_cstr(rl_filename_quote_characters);
1634 }
1635 #else
1636 #define readline_s_get_filename_quote_characters rb_f_notimplement
1637 #endif
1638 
1639 #ifdef HAVE_RL_REFRESH_LINE
1640 /*
1641  * call-seq:
1642  * Readline.refresh_line -> nil
1643  *
1644  * Clear the current input line.
1645  */
1646 static VALUE
1648 {
1649  prepare_readline();
1650  rl_refresh_line(0, 0);
1651  return Qnil;
1652 }
1653 #else
1654 #define readline_s_refresh_line rb_f_notimplement
1655 #endif
1656 
1657 static VALUE
1659 {
1660  return rb_str_new_cstr("HISTORY");
1661 }
1662 
1663 static int
1665 {
1666  return history_base + offset;
1667 }
1668 
1669 static int
1671 {
1672  return offset;
1673 }
1674 
1675 static VALUE
1676 hist_get(VALUE self, VALUE index)
1677 {
1678  HIST_ENTRY *entry = NULL;
1679  int i;
1680 
1681  i = NUM2INT(index);
1682  if (i < 0) {
1683  i += history_length;
1684  }
1685  if (i >= 0) {
1686  entry = history_get(history_get_offset_func(i));
1687  }
1688  if (entry == NULL) {
1689  rb_raise(rb_eIndexError, "invalid index");
1690  }
1691  return rb_locale_str_new_cstr(entry->line);
1692 }
1693 
1694 #ifdef HAVE_REPLACE_HISTORY_ENTRY
1695 static VALUE
1696 hist_set(VALUE self, VALUE index, VALUE str)
1697 {
1698  HIST_ENTRY *entry = NULL;
1699  int i;
1700 
1701  i = NUM2INT(index);
1702  OutputStringValue(str);
1703  if (i < 0) {
1704  i += history_length;
1705  }
1706  if (i >= 0) {
1707  entry = replace_history_entry(history_replace_offset_func(i), RSTRING_PTR(str), NULL);
1708  }
1709  if (entry == NULL) {
1710  rb_raise(rb_eIndexError, "invalid index");
1711  }
1712  return str;
1713 }
1714 #else
1715 #define hist_set rb_f_notimplement
1716 #endif
1717 
1718 static VALUE
1720 {
1721  OutputStringValue(str);
1722  add_history(RSTRING_PTR(str));
1723  return self;
1724 }
1725 
1726 static VALUE
1728 {
1729  VALUE str;
1730 
1731  while (argc--) {
1732  str = *argv++;
1733  OutputStringValue(str);
1734  add_history(RSTRING_PTR(str));
1735  }
1736  return self;
1737 }
1738 
1739 static VALUE
1741 {
1742 #ifdef HAVE_REMOVE_HISTORY
1743  HIST_ENTRY *entry;
1744  VALUE val;
1745 
1746  entry = remove_history(index);
1747  if (entry) {
1748  val = rb_locale_str_new_cstr(entry->line);
1749  free((void *) entry->line);
1750  free(entry);
1751  return val;
1752  }
1753  return Qnil;
1754 #else
1755  rb_notimplement();
1756 
1757  UNREACHABLE;
1758 #endif
1759 }
1760 
1761 static VALUE
1763 {
1764  if (history_length > 0) {
1765  return rb_remove_history(history_length - 1);
1766  } else {
1767  return Qnil;
1768  }
1769 }
1770 
1771 static VALUE
1773 {
1774  if (history_length > 0) {
1775  return rb_remove_history(0);
1776  } else {
1777  return Qnil;
1778  }
1779 }
1780 
1781 static VALUE
1783 {
1784  HIST_ENTRY *entry;
1785  int i;
1786 
1787  RETURN_ENUMERATOR(self, 0, 0);
1788 
1789  for (i = 0; i < history_length; i++) {
1790  entry = history_get(history_get_offset_func(i));
1791  if (entry == NULL)
1792  break;
1793  rb_yield(rb_locale_str_new_cstr(entry->line));
1794  }
1795  return self;
1796 }
1797 
1798 static VALUE
1800 {
1801  return INT2NUM(history_length);
1802 }
1803 
1804 static VALUE
1806 {
1807  return history_length == 0 ? Qtrue : Qfalse;
1808 }
1809 
1810 static VALUE
1812 {
1813  int i;
1814 
1815  i = NUM2INT(index);
1816  if (i < 0)
1817  i += history_length;
1818  if (i < 0 || i > history_length - 1) {
1819  rb_raise(rb_eIndexError, "invalid index");
1820  }
1821  return rb_remove_history(i);
1822 }
1823 
1824 #ifdef HAVE_CLEAR_HISTORY
1825 static VALUE
1826 hist_clear(VALUE self)
1827 {
1828  clear_history();
1829  return self;
1830 }
1831 #else
1832 #define hist_clear rb_f_notimplement
1833 #endif
1834 
1835 static VALUE
1837 {
1838  VALUE result;
1839  char **matches;
1840  int i;
1841 
1842  matches = rl_completion_matches(StringValuePtr(str),
1844  if (matches) {
1845  result = rb_ary_new();
1846  for (i = 0; matches[i]; i++) {
1847  rb_ary_push(result, rb_locale_str_new_cstr(matches[i]));
1848  free(matches[i]);
1849  }
1850  free(matches);
1851  if (RARRAY_LEN(result) >= 2)
1852  rb_ary_shift(result);
1853  }
1854  else {
1855  result = Qnil;
1856  }
1857  return result;
1858 }
1859 
1860 static VALUE
1862 {
1863  VALUE result;
1864  char **matches;
1865  int i;
1866 
1867  matches = rl_completion_matches(StringValuePtr(str),
1869  if (matches) {
1870  result = rb_ary_new();
1871  for (i = 0; matches[i]; i++) {
1872  rb_ary_push(result, rb_locale_str_new_cstr(matches[i]));
1873  free(matches[i]);
1874  }
1875  free(matches);
1876  if (RARRAY_LEN(result) >= 2)
1877  rb_ary_shift(result);
1878  }
1879  else {
1880  result = Qnil;
1881  }
1882  return result;
1883 }
1884 
1885 #undef rb_intern
1886 void
1888 {
1889  VALUE history, fcomp, ucomp, version;
1890 
1891  /* Allow conditional parsing of the ~/.inputrc file. */
1892  rl_readline_name = (char *)"Ruby";
1893 
1894 #if defined HAVE_RL_GETC_FUNCTION
1895  /* libedit check rl_getc_function only when rl_initialize() is called, */
1896  /* and using_history() call rl_initialize(). */
1897  /* This assignment should be placed before using_history() */
1898  rl_getc_function = readline_getc;
1899 #elif defined HAVE_RL_EVENT_HOOK
1900  rl_event_hook = readline_event;
1901 #endif
1902 
1903  using_history();
1904 
1905  id_call = rb_intern("call");
1908 #if defined(HAVE_RL_PRE_INPUT_HOOK)
1909  id_pre_input_hook = rb_intern("pre_input_hook");
1910 #endif
1911 #if defined(HAVE_RL_SPECIAL_PREFIXES)
1912  id_special_prefixes = rb_intern("special_prefixes");
1913 #endif
1914 #if defined HAVE_RL_CHAR_IS_QUOTED_P
1915  quoting_detection_proc = rb_intern(QUOTING_DETECTION_PROC);
1916 #endif
1917 
1918  mReadline = rb_define_module("Readline");
1920  readline_readline, -1);
1925  rb_define_singleton_method(mReadline, "completion_proc=",
1927  rb_define_singleton_method(mReadline, "completion_proc",
1929  rb_define_singleton_method(mReadline, "quoting_detection_proc=",
1931  rb_define_singleton_method(mReadline, "quoting_detection_proc",
1933  rb_define_singleton_method(mReadline, "completion_case_fold=",
1935  rb_define_singleton_method(mReadline, "completion_case_fold",
1937  rb_define_singleton_method(mReadline, "line_buffer",
1943  rb_define_singleton_method(mReadline, "set_screen_size",
1945  rb_define_singleton_method(mReadline, "get_screen_size",
1947  rb_define_singleton_method(mReadline, "vi_editing_mode",
1949  rb_define_singleton_method(mReadline, "vi_editing_mode?",
1951  rb_define_singleton_method(mReadline, "emacs_editing_mode",
1953  rb_define_singleton_method(mReadline, "emacs_editing_mode?",
1955  rb_define_singleton_method(mReadline, "completion_append_character=",
1957  rb_define_singleton_method(mReadline, "completion_append_character",
1959  rb_define_singleton_method(mReadline, "basic_word_break_characters=",
1961  rb_define_singleton_method(mReadline, "basic_word_break_characters",
1963  rb_define_singleton_method(mReadline, "completer_word_break_characters=",
1965  rb_define_singleton_method(mReadline, "completer_word_break_characters",
1967  rb_define_singleton_method(mReadline, "basic_quote_characters=",
1969  rb_define_singleton_method(mReadline, "basic_quote_characters",
1971  rb_define_singleton_method(mReadline, "completer_quote_characters=",
1973  rb_define_singleton_method(mReadline, "completer_quote_characters",
1975  rb_define_singleton_method(mReadline, "filename_quote_characters=",
1977  rb_define_singleton_method(mReadline, "filename_quote_characters",
1979  rb_define_singleton_method(mReadline, "refresh_line",
1981  rb_define_singleton_method(mReadline, "pre_input_hook=",
1983  rb_define_singleton_method(mReadline, "pre_input_hook",
1985  rb_define_singleton_method(mReadline, "insert_text",
1987  rb_define_singleton_method(mReadline, "delete_text",
1991  rb_define_singleton_method(mReadline, "special_prefixes=",
1993  rb_define_singleton_method(mReadline, "special_prefixes",
1995 
1996 #if USE_INSERT_IGNORE_ESCAPE
1997  CONST_ID(id_orig_prompt, "orig_prompt");
1998  CONST_ID(id_last_prompt, "last_prompt");
1999 #endif
2000 
2001  history = rb_obj_alloc(rb_cObject);
2002  rb_extend_object(history, rb_mEnumerable);
2003  rb_define_singleton_method(history,"to_s", hist_to_s, 0);
2004  rb_define_singleton_method(history,"[]", hist_get, 1);
2005  rb_define_singleton_method(history,"[]=", hist_set, 2);
2006  rb_define_singleton_method(history,"<<", hist_push, 1);
2007  rb_define_singleton_method(history,"push", hist_push_method, -1);
2008  rb_define_singleton_method(history,"pop", hist_pop, 0);
2009  rb_define_singleton_method(history,"shift", hist_shift, 0);
2010  rb_define_singleton_method(history,"each", hist_each, 0);
2011  rb_define_singleton_method(history,"length", hist_length, 0);
2012  rb_define_singleton_method(history,"size", hist_length, 0);
2013  rb_define_singleton_method(history,"empty?", hist_empty_p, 0);
2014  rb_define_singleton_method(history,"delete_at", hist_delete_at, 1);
2015  rb_define_singleton_method(history,"clear", hist_clear, 0);
2016 
2017  /*
2018  * The history buffer. It extends Enumerable module, so it behaves
2019  * just like an array.
2020  * For example, gets the fifth content that the user input by
2021  * HISTORY[4].
2022  */
2023  rb_define_const(mReadline, "HISTORY", history);
2024 
2025  fcomp = rb_obj_alloc(rb_cObject);
2026  rb_define_singleton_method(fcomp, "call",
2028  /*
2029  * The Object with the call method that is a completion for filename.
2030  * This is sets by Readline.completion_proc= method.
2031  */
2032  rb_define_const(mReadline, "FILENAME_COMPLETION_PROC", fcomp);
2033 
2034  ucomp = rb_obj_alloc(rb_cObject);
2035  rb_define_singleton_method(ucomp, "call",
2037  /*
2038  * The Object with the call method that is a completion for usernames.
2039  * This is sets by Readline.completion_proc= method.
2040  */
2041  rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
2044 #if defined HAVE_RL_LIBRARY_VERSION
2045  version = rb_str_new_cstr(rl_library_version);
2046 #if defined HAVE_CLEAR_HISTORY || defined HAVE_REMOVE_HISTORY
2047  if (strncmp(rl_library_version, EDIT_LINE_LIBRARY_VERSION,
2049  add_history("1");
2050  if (history_get(history_get_offset_func(0)) == NULL) {
2052  }
2053 #ifdef HAVE_REPLACE_HISTORY_ENTRY
2054  if (replace_history_entry(0, "a", NULL) == NULL) {
2056  }
2057 #endif
2058 #ifdef HAVE_CLEAR_HISTORY
2059  clear_history();
2060 #else
2061  {
2062  HIST_ENTRY *entry = remove_history(0);
2063  if (entry) {
2064  free((char *)entry->line);
2065  free(entry);
2066  }
2067  }
2068 #endif
2069  }
2070 #endif
2071 #else
2072  version = rb_str_new_cstr("2.0 or prior version");
2073 #endif
2074  /* Version string of GNU Readline or libedit. */
2075  rb_define_const(mReadline, "VERSION", version);
2076 
2077  rl_attempted_completion_function = readline_attempted_completion_function;
2078 #if defined(HAVE_RL_PRE_INPUT_HOOK)
2079  rl_pre_input_hook = readline_pre_input_hook;
2080 #endif
2081 #if defined HAVE_RL_CHAR_IS_QUOTED_P
2082  rl_char_is_quoted_p = &readline_char_is_quoted;
2083 #endif
2084 #ifdef HAVE_RL_CATCH_SIGNALS
2085  rl_catch_signals = 0;
2086 #endif
2087 #ifdef HAVE_RL_CLEAR_SIGNALS
2088  rl_clear_signals();
2089 #endif
2090 
2093 }
2094 
2095 /*
2096  * Local variables:
2097  * indent-tabs-mode: nil
2098  * end:
2099  */
RUBY_EXTERN VALUE rb_cString
Definition: ruby.h:1906
static ID completion_case_fold
Definition: readline.c:60
void rb_thread_schedule(void)
Definition: thread.c:1264
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
Definition: encoding.c:879
#define readline_s_get_line_buffer
Definition: readline.c:951
#define RARRAY_LEN(a)
Definition: ruby.h:1026
void rb_bug(const char *fmt,...)
Definition: error.c:482
static int rb_tolower(int c)
Definition: ruby.h:2117
#define readline_s_get_basic_quote_characters
Definition: readline.c:1526
size_t strlen(const char *)
#define INT2NUM(x)
Definition: ruby.h:1538
int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout)
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:2314
static VALUE readline_get(VALUE prompt)
Definition: readline.c:339
#define NUM2INT(x)
Definition: ruby.h:684
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1716
static VALUE mReadline
Definition: readline.c:47
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:2664
static VALUE readline_s_set_input(VALUE self, VALUE input)
Definition: readline.c:549
#define Qtrue
Definition: ruby.h:437
Definition: io.h:62
static VALUE hist_to_s(VALUE self)
Definition: readline.c:1658
void rb_io_check_initialized(rb_io_t *)
Definition: io.c:631
VALUE rb_ary_shift(VALUE ary)
Definition: array.c:1000
static char ** readline_attempted_completion_function(const char *text, int start, int end)
Definition: readline.c:999
void * rb_thread_call_without_gvl2(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
Definition: thread.c:1420
#define readline_s_set_completer_word_break_characters
Definition: readline.c:1390
#define readline_s_emacs_editing_mode
Definition: readline.c:1201
#define readline_s_set_pre_input_hook
Definition: readline.c:662
VALUE rb_str_unlocktmp(VALUE)
Definition: string.c:2528
VALUE rb_enc_from_encoding(rb_encoding *encoding)
Definition: encoding.c:117
static ID completion_proc
Definition: readline.c:60
static FILE * readline_rl_outstream
Definition: readline.c:136
#define rb_check_arity
Definition: intern.h:303
#define UNREACHABLE
Definition: ruby.h:46
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:905
#define rb_long2int(n)
Definition: ruby.h:319
#define readline_s_get_special_prefixes
Definition: readline.c:1473
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:821
void rb_str_set_len(VALUE, long)
Definition: string.c:2545
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:891
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
Definition: encoding.c:1056
#define Check_Type(v, t)
Definition: ruby.h:562
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2207
#define readline_s_get_quoting_detection_proc
Definition: readline.c:894
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1260
VALUE rb_io_taint_check(VALUE)
Definition: io.c:624
#define readline_s_insert_text
Definition: readline.c:685
#define COMPLETION_CASE_FOLD
Definition: readline.c:59
static VALUE hist_pop(VALUE self)
Definition: readline.c:1762
static VALUE readline_s_get_completion_case_fold(VALUE self)
Definition: readline.c:924
char * rb_str_subpos(VALUE, long, long *)
Definition: string.c:2348
#define T_ARRAY
Definition: ruby.h:498
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
Definition: range.c:1019
void rb_gc_register_address(VALUE *addr)
Definition: gc.c:6168
#define RFILE(obj)
Definition: ruby.h:1213
void rb_gc_force_recycle(VALUE obj)
Definition: gc.c:6102
static VALUE readline_s_set_output(VALUE self, VALUE output)
Definition: readline.c:585
VALUE rb_str_dup_frozen(VALUE)
VALUE rb_str_tmp_new(long)
Definition: string.c:1275
#define GetOpenFile(obj, fp)
Definition: io.h:120
static int history_get_offset_history_base(int offset)
Definition: readline.c:1664
static VALUE hist_push(VALUE self, VALUE str)
Definition: readline.c:1719
#define readline_s_delete_text
Definition: readline.c:740
#define readline_s_vi_editing_mode_p
Definition: readline.c:1181
VALUE rb_enc_str_new_static(const char *, long, rb_encoding *)
Definition: string.c:847
#define OutputStringValue(str)
Definition: readline.c:94
#define ISALPHA(c)
Definition: ruby.h:2128
static VALUE hist_length(VALUE self)
Definition: readline.c:1799
static unsigned char * output
Definition: nkf.c:32
static VALUE filename_completion_proc_call(VALUE self, VALUE str)
Definition: readline.c:1836
static VALUE hist_each(VALUE self)
Definition: readline.c:1782
#define RB_TYPE_P(obj, type)
Definition: ruby.h:527
#define readline_s_get_pre_input_hook
Definition: readline.c:663
#define rl_filename_completion_function
Definition: readline.c:76
static VALUE readline_outstream
Definition: readline.c:134
#define readline_s_set_quoting_detection_proc
Definition: readline.c:893
#define readline_s_set_completer_quote_characters
Definition: readline.c:1561
VALUE rb_Array(VALUE)
Definition: object.c:3126
unsigned int input
Definition: nkf.c:4312
#define ALLOC_N(type, n)
Definition: ruby.h:1587
VALUE rb_str_new_shared(VALUE)
Definition: string.c:1114
#define readline_s_get_basic_word_break_characters
Definition: readline.c:1356
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1872
#define COMPLETION_PROC
Definition: readline.c:58
#define EDIT_LINE_LIBRARY_VERSION
Definition: readline.c:49
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1364
#define readline_s_refresh_line
Definition: readline.c:1654
VALUE rb_ary_new(void)
Definition: array.c:493
static VALUE username_completion_proc_call(VALUE self, VALUE str)
Definition: readline.c:1861
VALUE rb_locale_str_new(const char *, long)
Definition: string.c:1032
#define NIL_P(v)
Definition: ruby.h:451
static VALUE hist_shift(VALUE self)
Definition: readline.c:1772
#define readline_s_get_filename_quote_characters
Definition: readline.c:1636
int fd
Definition: io.h:64
static ID id_call
Definition: readline.c:60
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2734
#define readline_s_vi_editing_mode
Definition: readline.c:1163
int argc
Definition: ruby.c:183
#define Qfalse
Definition: ruby.h:436
#define readline_s_emacs_editing_mode_p
Definition: readline.c:1219
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1845
int err
Definition: win32.c:135
#define OBJ_FREEZE(x)
Definition: ruby.h:1308
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Definition: object.c:60
VALUE rb_eIndexError
Definition: error.c:764
#define readline_s_set_point
Definition: readline.c:995
static VALUE hist_push_method(int argc, VALUE *argv, VALUE self)
Definition: readline.c:1727
#define EOF
Definition: vsnprintf.c:201
#define RSTRING_LEN(str)
Definition: ruby.h:978
VALUE rb_locale_str_new_cstr(const char *)
Definition: string.c:1038
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1731
VALUE rb_yield(VALUE)
Definition: vm_eval.c:1020
#define REALLOC_N(var, type, n)
Definition: ruby.h:1591
int errno
VALUE rb_mEnumerable
Definition: enum.c:18
#define malloc
Definition: ripper.c:116
#define strdup(s)
Definition: util.h:70
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1919
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1364
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309
unsigned long ID
Definition: ruby.h:86
static int history_get_offset_0(int offset)
Definition: readline.c:1670
#define Qnil
Definition: ruby.h:438
#define readline_s_set_special_prefixes
Definition: readline.c:1472
unsigned long VALUE
Definition: ruby.h:85
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1370
static VALUE result
Definition: nkf.c:40
VALUE rb_obj_hide(VALUE obj)
Definition: object.c:51
static VALUE readline_s_set_completion_proc(VALUE self, VALUE proc)
Definition: readline.c:834
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1429
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:3992
VALUE rb_str_new_cstr(const char *)
Definition: string.c:770
static void prepare_readline(void)
Definition: readline.c:372
void rb_sys_fail(const char *mesg)
Definition: error.c:2326
#define readline_s_get_point
Definition: readline.c:994
void rb_jump_tag(int tag)
Definition: eval.c:788
static VALUE hist_empty_p(VALUE self)
Definition: readline.c:1805
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1995
void rb_memerror(void)
Definition: gc.c:7622
register unsigned int len
Definition: zonetab.h:51
static VALUE readline_s_set_completion_case_fold(VALUE self, VALUE val)
Definition: readline.c:904
#define StringValueCStr(v)
Definition: ruby.h:571
#define RSTRING_PTR(str)
Definition: ruby.h:982
#define readline_s_set_filename_quote_characters
Definition: readline.c:1615
#define readline_s_redisplay
Definition: readline.c:762
#define f
long rb_enc_strlen(const char *, const char *, rb_encoding *)
Definition: string.c:1646
#define hist_set
Definition: readline.c:1715
#define RARRAY_AREF(a, i)
Definition: ruby.h:1040
static VALUE readline_s_get_completion_proc(VALUE self)
Definition: readline.c:847
static VALUE rb_remove_history(int index)
Definition: readline.c:1740
#define readline_s_get_completer_quote_characters
Definition: readline.c:1582
#define readline_s_set_screen_size
Definition: readline.c:1116
static VALUE readline_readline(int argc, VALUE *argv, VALUE self)
Definition: readline.c:484
static void mustbe_callable(VALUE proc)
Definition: readline.c:139
#define LONG2FIX(i)
Definition: ruby.h:234
#define RTEST(v)
Definition: ruby.h:450
void rb_thread_check_ints(void)
Definition: thread.c:1215
VALUE rb_str_locktmp(VALUE)
#define EWOULDBLOCK
Definition: rubysocket.h:128
#define T_FILE
Definition: ruby.h:502
long rb_str_sublen(VALUE, long)
Definition: string.c:2313
static VALUE hist_get(VALUE self, VALUE index)
Definition: readline.c:1676
void rb_notimplement(void)
Definition: error.c:2253
#define hist_clear
Definition: readline.c:1832
#define rl_username_completion_function
Definition: readline.c:79
#define RETURN_ENUMERATOR(obj, argc, argv)
Definition: intern.h:240
#define rl_completion_matches
Definition: readline.c:82
#define readline_s_get_screen_size
Definition: readline.c:1143
#define PRIdSIZE
Definition: ruby.h:174
#define readline_s_set_basic_word_break_characters
Definition: readline.c:1335
void Init_readline(void)
Definition: readline.c:1887
RUBY_EXTERN VALUE rb_eIOError
Definition: ruby.h:1926
static FILE * readline_rl_instream
Definition: readline.c:135
#define readline_s_get_completion_append_character
Definition: readline.c:1301
#define StringValuePtr(v)
Definition: ruby.h:570
static int(* history_get_offset_func)(int)
Definition: readline.c:85
int rb_cloexec_dup(int oldfd)
Definition: io.c:281
#define fileno(p)
Definition: vsnprintf.c:217
#define CONST_ID(var, str)
Definition: ruby.h:1743
#define RB_WAITFD_IN
Definition: io.h:47
VALUE rb_define_module(const char *name)
Definition: class.c:768
#define rb_intern(str)
static VALUE readline_instream
Definition: readline.c:133
#define readline_s_set_basic_quote_characters
Definition: readline.c:1506
static void clear_rl_instream(void)
Definition: readline.c:348
static void clear_rl_outstream(void)
Definition: readline.c:360
#define NULL
Definition: _sdbm.c:102
static VALUE hist_delete_at(VALUE self, VALUE index)
Definition: readline.c:1811
int version
Definition: ossl_ssl.c:55
free(psz)
VALUE rb_eArgError
Definition: error.c:763
#define NUM2LONG(x)
Definition: ruby.h:648
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1273
char ** argv
Definition: ruby.c:184
#define readline_s_get_completer_word_break_characters
Definition: readline.c:1411
static int(* history_replace_offset_func)(int)
Definition: readline.c:86
#define RUBY_UBF_IO
Definition: intern.h:900
#define readline_s_set_completion_append_character
Definition: readline.c:1276