static VALUE
readline_s_get_basic_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
rb_secure(4);
if (rl_basic_quote_characters == NULL)
return Qnil;
return rb_tainted_str_new2(rl_basic_quote_characters);
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_BASIC_QUOTE_CHARACTERS */
}
static VALUE
readline_s_set_basic_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
static char *basic_quote_characters = NULL;
rb_secure(4);
SafeStringValue(str);
if (basic_quote_characters == NULL) {
basic_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
REALLOC_N(basic_quote_characters, char, RSTRING(str)->len + 1);
}
strncpy(basic_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
basic_quote_characters[RSTRING(str)->len] = '\0';
rl_basic_quote_characters = basic_quote_characters;
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_BASIC_QUOTE_CHARACTERS */
}
static VALUE
readline_s_get_basic_word_break_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
rb_secure(4);
if (rl_basic_word_break_characters == NULL)
return Qnil;
return rb_tainted_str_new2(rl_basic_word_break_characters);
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_BASIC_WORD_BREAK_CHARACTERS */
}
static VALUE
readline_s_set_basic_word_break_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_BASIC_WORD_BREAK_CHARACTERS
static char *basic_word_break_characters = NULL;
rb_secure(4);
SafeStringValue(str);
if (basic_word_break_characters == NULL) {
basic_word_break_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
REALLOC_N(basic_word_break_characters, char, RSTRING(str)->len + 1);
}
strncpy(basic_word_break_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
basic_word_break_characters[RSTRING(str)->len] = '\0';
rl_basic_word_break_characters = basic_word_break_characters;
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_BASIC_WORD_BREAK_CHARACTERS */
}
static VALUE
readline_s_get_completer_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
rb_secure(4);
if (rl_completer_quote_characters == NULL)
return Qnil;
return rb_tainted_str_new2(rl_completer_quote_characters);
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETER_QUOTE_CHARACTERS */
}
static VALUE
readline_s_set_completer_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_QUOTE_CHARACTERS
static char *completer_quote_characters = NULL;
rb_secure(4);
SafeStringValue(str);
if (completer_quote_characters == NULL) {
completer_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
REALLOC_N(completer_quote_characters, char, RSTRING(str)->len + 1);
}
strncpy(completer_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
completer_quote_characters[RSTRING(str)->len] = '\0';
rl_completer_quote_characters = completer_quote_characters;
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETER_QUOTE_CHARACTERS */
}
static VALUE
readline_s_get_completer_word_break_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
rb_secure(4);
if (rl_completer_word_break_characters == NULL)
return Qnil;
return rb_tainted_str_new2(rl_completer_word_break_characters);
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS */
}
static VALUE
readline_s_set_completer_word_break_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS
static char *completer_word_break_characters = NULL;
rb_secure(4);
SafeStringValue(str);
if (completer_word_break_characters == NULL) {
completer_word_break_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
REALLOC_N(completer_word_break_characters, char, RSTRING(str)->len + 1);
}
strncpy(completer_word_break_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
completer_word_break_characters[RSTRING(str)->len] = '\0';
rl_completer_word_break_characters = completer_word_break_characters;
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS */
}
static VALUE
readline_s_get_completion_append_character(self)
VALUE self;
{
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
VALUE str;
rb_secure(4);
if (rl_completion_append_character == '\0')
return Qnil;
str = rb_str_new("", 1);
RSTRING(str)->ptr[0] = rl_completion_append_character;
return str;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */
}
static VALUE
readline_s_set_completion_append_character(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
rb_secure(4);
if (NIL_P(str)) {
rl_completion_append_character = '\0';
}
else {
SafeStringValue(str);
if (RSTRING(str)->len == 0) {
rl_completion_append_character = '\0';
} else {
rl_completion_append_character = RSTRING(str)->ptr[0];
}
}
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_COMPLETION_APPEND_CHARACTER */
}
static VALUE
readline_s_get_completion_case_fold(self)
VALUE self;
{
rb_secure(4);
return rb_attr_get(mReadline, completion_case_fold);
}
static VALUE
readline_s_set_completion_case_fold(self, val)
VALUE self;
VALUE val;
{
rb_secure(4);
return rb_ivar_set(mReadline, completion_case_fold, val);
}
static VALUE
readline_s_get_completion_proc(self)
VALUE self;
{
rb_secure(4);
return rb_attr_get(mReadline, completion_proc);
}
static VALUE
readline_s_set_completion_proc(self, proc)
VALUE self;
VALUE proc;
{
rb_secure(4);
if (!rb_respond_to(proc, rb_intern("call")))
rb_raise(rb_eArgError, "argument must respond to `call'");
return rb_ivar_set(mReadline, completion_proc, proc);
}
static VALUE
readline_s_emacs_editing_mode(self)
VALUE self;
{
#ifdef HAVE_RL_EMACS_EDITING_MODE
rb_secure(4);
rl_emacs_editing_mode(1,0);
return Qnil;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_EMACS_EDITING_MODE */
}
static VALUE
readline_s_get_filename_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
rb_secure(4);
if (rl_filename_quote_characters == NULL)
return Qnil;
return rb_tainted_str_new2(rl_filename_quote_characters);
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_FILENAME_QUOTE_CHARACTERS */
}
static VALUE
readline_s_set_filename_quote_characters(self, str)
VALUE self, str;
{
#ifdef HAVE_RL_FILENAME_QUOTE_CHARACTERS
static char *filename_quote_characters = NULL;
rb_secure(4);
SafeStringValue(str);
if (filename_quote_characters == NULL) {
filename_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
}
else {
REALLOC_N(filename_quote_characters, char, RSTRING(str)->len + 1);
}
strncpy(filename_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
filename_quote_characters[RSTRING(str)->len] = '\0';
rl_filename_quote_characters = filename_quote_characters;
return self;
#else
rb_notimplement();
return Qnil; /* not reached */
#endif /* HAVE_RL_FILENAME_QUOTE_CHARACTERS */
}
static VALUE
readline_readline(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
VALUE tmp, add_hist, result;
char *prompt = NULL;
char *buff;
int status;
rb_io_t *ofp, *ifp;
rb_secure(4);
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
SafeStringValue(tmp);
prompt = RSTRING(tmp)->ptr;
}
if (!isatty(0) && errno == EBADF) rb_raise(rb_eIOError, "stdin closed");
Check_Type(rb_stdout, T_FILE);
GetOpenFile(rb_stdout, ofp);
rl_outstream = GetWriteFile(ofp);
Check_Type(rb_stdin, T_FILE);
GetOpenFile(rb_stdin, ifp);
rl_instream = GetReadFile(ifp);
buff = (char*)rb_protect((VALUE(*)_((VALUE)))readline, (VALUE)prompt,
&status);
if (status) {
#if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
/* restore terminal mode and signal handler*/
rl_cleanup_after_signal();
#elif defined HAVE_RL_DEPREP_TERM_FUNCTION
/* restore terminal mode */
if (rl_deprep_term_function != NULL) /* NULL in libedit. [ruby-dev:29116] */
(*rl_deprep_term_function)();
else
#else
rl_deprep_terminal();
#endif
rb_jump_tag(status);
}
if (RTEST(add_hist) && buff) {
add_history(buff);
}
if (buff)
result = rb_tainted_str_new2(buff);
else
result = Qnil;
if (buff) free(buff);
return result;
}
Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.
If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.